Skip to content

Commit 6e10c0e

Browse files
meteorcloudycopybara-github
authored andcommitted
Make virtual include paths shorter
Fixes #18683 RELNOTES[INC]: Virtual include header files are linked under `bin/_v_inc/<hash of target path>` instead of `bin/<target package path>/_virtual_include/<target name>`. This shortens the virtual include paths which is critical for mitigating long path issue with MSVC on Windows. Closes #26005. PiperOrigin-RevId: 754930166 Change-Id: Ie1e5bad06a9f945c0cf71c5e122d444e527f7ca6
1 parent 99a0115 commit 6e10c0e

File tree

7 files changed

+24
-21
lines changed

7 files changed

+24
-21
lines changed

src/main/java/com/google/devtools/build/lib/analysis/test/InstrumentedFilesInfo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ public ImmutableMap<String, String> getCoverageEnvironment() {
116116
*
117117
* <p>This is useful for virtual include paths in C++, which get reported at the include location
118118
* and not the real source path. For example, the reported include source file can be
119-
* "bazel-out/k8-fastbuild/bin/include/common/_virtual_includes/strategy/strategy.h", but its
120-
* actual source path is "include/common/strategy.h".
119+
* "bazel-out/k8-fastbuild/_virtual_includes/XXXXXXXX/strategy.h", but its actual source path is
120+
* "include/common/strategy.h".
121121
*/
122122
NestedSet<Tuple> getReportedToActualSources() {
123123
return reportedToActualSources;

src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationContext.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,19 @@ public final class CcCompilationContext implements CcCompilationContextApi<Artif
8888
// Each pair maps the Bazel generated paths of virtual include headers back to their original path
8989
// relative to the workspace directory.
9090
// For example it can map
91-
// "bazel-out/k8-fastbuild/bin/include/common/_virtual_includes/strategy/strategy.h"
91+
// "bazel-out/k8-fastbuild/_virtual_includes/XXXXXXXX/strategy.h"
9292
// back to the path of the header in the workspace directory "include/common/strategy.h".
9393
// This is needed only when code coverage collection is enabled, to report the actual source file
9494
// name in the coverage output file.
9595
private final NestedSet<Tuple> virtualToOriginalHeaders;
96+
9697
/**
9798
* Caches the actual number of transitive headers reachable through transitiveHeaderInfos. We need
9899
* to create maps to store these and so caching this count can substantially help with memory
99100
* allocations.
100101
*/
101102
private int transitiveHeaderCount;
103+
102104
/** Aftifacts generated by the header validation actions. */
103105
private final NestedSet<Artifact> headerTokens;
104106

src/main/starlark/builtins_bzl/common/cc/compile/cc_compilation_helper.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def _compute_public_headers(
111111

112112
module_map_headers = []
113113
virtual_to_original_headers_list = []
114-
virtual_include_dir = paths.join(paths.join(package_source_root(label.workspace_name, label.package, is_sibling_repository_layout), _VIRTUAL_INCLUDES_DIR), label.name)
114+
virtual_include_dir = paths.join(_VIRTUAL_INCLUDES_DIR, "%x" % hash(paths.join(cc_helper.package_source_root(label.workspace_name, label.package, is_sibling_repository_layout), label.name)))
115115
for original_header in public_headers_artifacts:
116116
repo_relative_path = _repo_relative_path(original_header)
117117
if not repo_relative_path.startswith(strip_prefix):

src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonTest.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import static com.google.devtools.build.lib.actions.util.ActionsTestUtil.baseArtifactNames;
1919
import static com.google.devtools.build.lib.actions.util.ActionsTestUtil.baseNamesOf;
2020

21+
import com.google.common.base.Joiner;
2122
import com.google.common.collect.ImmutableList;
2223
import com.google.common.truth.IterableSubject;
2324
import com.google.devtools.build.lib.actions.Action;
@@ -1071,12 +1072,12 @@ public void testIncludeManglingSmoke() throws Exception {
10711072
ConfiguredTarget lib = getConfiguredTarget("//third_party/a");
10721073
CcCompilationContext ccCompilationContext = lib.get(CcInfo.PROVIDER).getCcCompilationContext();
10731074
assertThat(ActionsTestUtil.prettyArtifactNames(ccCompilationContext.getDeclaredIncludeSrcs()))
1074-
.containsExactly("third_party/a/_virtual_includes/a/lib/b/c.h", "third_party/a/v1/b/c.h");
1075+
.containsExactly("_virtual_includes/207132b2/lib/b/c.h", "third_party/a/v1/b/c.h");
10751076
assertThat(ccCompilationContext.getIncludeDirs())
10761077
.containsExactly(
10771078
getTargetConfiguration()
10781079
.getBinFragment(RepositoryName.MAIN)
1079-
.getRelative("third_party/a/_virtual_includes/a"));
1080+
.getRelative("_virtual_includes/207132b2"));
10801081
}
10811082

10821083
@Test
@@ -1148,10 +1149,9 @@ public void testAbsoluteAndRelativeStripPrefix() throws Exception {
11481149
.getCcCompilationContext();
11491150

11501151
assertThat(ActionsTestUtil.prettyArtifactNames(relative.getDeclaredIncludeSrcs()))
1151-
.containsExactly("third_party/a/_virtual_includes/relative/b.h", "third_party/a/v1/b.h");
1152+
.containsExactly("_virtual_includes/6665bb5b/b.h", "third_party/a/v1/b.h");
11521153
assertThat(ActionsTestUtil.prettyArtifactNames(absolute.getDeclaredIncludeSrcs()))
1153-
.containsExactly(
1154-
"third_party/a/_virtual_includes/absolute/a/v1/b.h", "third_party/a/v1/b.h");
1154+
.containsExactly("_virtual_includes/ee72ce06/a/v1/b.h", "third_party/a/v1/b.h");
11551155
}
11561156

11571157
@Test
@@ -1205,8 +1205,12 @@ public void testSymlinkActionIsNotRegisteredWhenIncludePrefixDoesntChangePath()
12051205

12061206
CcCompilationContext ccCompilationContext =
12071207
getConfiguredTarget("//third_party:a").get(CcInfo.PROVIDER).getCcCompilationContext();
1208-
assertThat(ActionsTestUtil.prettyArtifactNames(ccCompilationContext.getDeclaredIncludeSrcs()))
1209-
.doesNotContain("third_party/_virtual_includes/a/third_party/a.h");
1208+
assertThat(
1209+
Joiner.on(" ")
1210+
.join(
1211+
ActionsTestUtil.prettyArtifactNames(
1212+
ccCompilationContext.getDeclaredIncludeSrcs())))
1213+
.doesNotContainMatch("_virtual_includes/[a-z0-9]{8}/third_party/a.h");
12101214
}
12111215

12121216
@Test

src/test/java/com/google/devtools/build/lib/rules/cpp/CompileBuildVariablesTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ public void testExternalIncludePathsVariable() throws Exception {
432432
ImmutableList.Builder<String> entries =
433433
ImmutableList.<String>builder()
434434
.add(
435-
"/k8-fastbuild/bin/external/pkg+/_virtual_includes/foo2",
435+
"/k8-fastbuild/bin/_virtual_includes/8a060f18",
436436
"external/pkg+",
437437
"/k8-fastbuild/bin/external/pkg+");
438438
if (analysisMock.isThisBazel()) {

src/test/java/com/google/devtools/build/lib/rules/cpp/StarlarkCcCommonTest.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5849,8 +5849,7 @@ public void testIncludePrefix() throws Exception {
58495849
assertThat(target).isNotNull();
58505850
CcInfo ccInfo = target.get(CcInfo.PROVIDER);
58515851
assertThat(artifactsToStrings(ccInfo.getCcCompilationContext().getDirectPublicHdrs()))
5852-
.contains(
5853-
"bin third_party/bar/_virtual_includes/starlark_lib_suffix/prefix/starlark_lib.h");
5852+
.contains("bin _virtual_includes/c203db2d/prefix/starlark_lib.h");
58545853
}
58555854

58565855
@Test
@@ -5873,7 +5872,7 @@ public void testStripIncludePrefix() throws Exception {
58735872
assertThat(target).isNotNull();
58745873
CcInfo ccInfo = target.get(CcInfo.PROVIDER);
58755874
assertThat(artifactsToStrings(ccInfo.getCcCompilationContext().getDirectPublicHdrs()))
5876-
.contains("bin third_party/bar/_virtual_includes/starlark_lib_suffix/starlark_lib.h");
5875+
.contains("bin _virtual_includes/c203db2d/starlark_lib.h");
58775876
}
58785877

58795878
@Test
@@ -5900,7 +5899,7 @@ public void testStripIncludePrefixIncludePath() throws Exception {
59005899
.containsExactly(
59015900
getTargetConfiguration()
59025901
.getBinFragment(RepositoryName.MAIN)
5903-
.getRelative("third_party/bar/_virtual_includes/starlark_lib_suffix"));
5902+
.getRelative("_virtual_includes/c203db2d"));
59045903
}
59055904

59065905
@Test
@@ -5925,8 +5924,7 @@ public void testStripIncludePrefixAndIncludePrefix() throws Exception {
59255924
assertThat(target).isNotNull();
59265925
CcInfo ccInfo = target.get(CcInfo.PROVIDER);
59275926
assertThat(artifactsToStrings(ccInfo.getCcCompilationContext().getDirectPublicHdrs()))
5928-
.contains(
5929-
"bin third_party/bar/_virtual_includes/starlark_lib_suffix/prefix/starlark_lib.h");
5927+
.contains("bin _virtual_includes/c203db2d/prefix/starlark_lib.h");
59305928
}
59315929

59325930
@Test
@@ -5951,7 +5949,7 @@ public void testStripIncludePrefixAndIncludePrefixIncludePath() throws Exception
59515949
.containsExactly(
59525950
getTargetConfiguration()
59535951
.getBinFragment(RepositoryName.MAIN)
5954-
.getRelative("third_party/bar/_virtual_includes/starlark_lib_suffix"));
5952+
.getRelative("_virtual_includes/c203db2d"));
59555953
}
59565954

59575955
@Test

src/test/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,8 +1436,7 @@ public void testIncludesDirsOfTransitiveCcIncDepsGetPassedToCompileAction() thro
14361436
CommandAction compileAction = compileAction("//package:objc_lib", "b.o");
14371437
// We remove spaces, since the crosstool rules do not use spaces for include paths.
14381438
String compileActionArgs = Joiner.on("").join(compileAction.getArguments()).replace(" ", "");
1439-
assertThat(compileActionArgs)
1440-
.matches(".*-iquote.*/third_party/cc_lib/_virtual_includes/cc_lib.*");
1439+
assertThat(compileActionArgs).matches(".*-iquote.*/_virtual_includes/848637ee.*");
14411440
}
14421441

14431442
@Test

0 commit comments

Comments
 (0)