diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java index 59c68de26631d0..c2b11c6f5d23b1 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java @@ -949,9 +949,9 @@ private PublicHeaders computePublicHeaders() throws InterruptedException { virtualToOriginalHeaders.add( Pair.of(virtualHeader.getExecPathString(), originalHeader.getExecPathString())); } - } else { - moduleHeadersBuilder.add(originalHeader); } + + moduleHeadersBuilder.add(originalHeader); } ImmutableList moduleMapHeaders = moduleHeadersBuilder.build(); diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonTest.java index 3278276609f9e8..0eeefc15980185 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonTest.java @@ -840,7 +840,7 @@ public void testIncludeManglingSmoke() throws Exception { ConfiguredTarget lib = getConfiguredTarget("//third_party/a"); CcCompilationContext ccCompilationContext = lib.get(CcInfo.PROVIDER).getCcCompilationContext(); assertThat(ActionsTestUtil.prettyArtifactNames(ccCompilationContext.getDeclaredIncludeSrcs())) - .containsExactly("third_party/a/_virtual_includes/a/lib/b/c.h"); + .containsExactly("third_party/a/_virtual_includes/a/lib/b/c.h", "third_party/a/v1/b/c.h"); assertThat(ccCompilationContext.getIncludeDirs()) .containsExactly( getTargetConfiguration() @@ -887,9 +887,10 @@ public void testAbsoluteAndRelativeStripPrefix() throws Exception { .getCcCompilationContext(); assertThat(ActionsTestUtil.prettyArtifactNames(relative.getDeclaredIncludeSrcs())) - .containsExactly("third_party/a/_virtual_includes/relative/b.h"); + .containsExactly("third_party/a/_virtual_includes/relative/b.h", "third_party/a/v1/b.h"); assertThat(ActionsTestUtil.prettyArtifactNames(absolute.getDeclaredIncludeSrcs())) - .containsExactly("third_party/a/_virtual_includes/absolute/a/v1/b.h"); + .containsExactly( + "third_party/a/_virtual_includes/absolute/a/v1/b.h", "third_party/a/v1/b.h"); } @Test diff --git a/src/test/shell/bazel/cc_integration_test.sh b/src/test/shell/bazel/cc_integration_test.sh index b2d3c4669e10d3..7b9756ae423d2c 100755 --- a/src/test/shell/bazel/cc_integration_test.sh +++ b/src/test/shell/bazel/cc_integration_test.sh @@ -76,8 +76,8 @@ cc_binary( ) cc_binary( - name = "bad", - srcs = ["bad.cc"], + name = "still_ok", + srcs = ["still_ok.cc"], deps = ["@foo//foo"], ) EOF @@ -90,7 +90,7 @@ int main() { } EOF - cat > bad.cc < still_ok.cc < #include "foo/v1/foo.h" int main() { @@ -98,8 +98,34 @@ int main() { } EOF - bazel build :bad && fail "Should not have found include at repository-relative path" bazel build :ok || fail "Should have found include at synthetic path" + bazel build :still_ok \ + || fail "Should have found include at repository-relative path" +} + + +function test_include_validation_sandbox_disabled() { + local workspace="${FUNCNAME[0]}" + mkdir -p "${workspace}"/lib + + create_workspace_with_default_repos "${workspace}/WORKSPACE" + cat >> "${workspace}/BUILD" << EOF +cc_library( + name = "foo", + srcs = ["lib/foo.cc"], + hdrs = ["lib/foo.h"], + strip_include_prefix = "lib", +) +EOF + cat >> "${workspace}/lib/foo.cc" << EOF +#include "foo.h" +EOF + + touch "${workspace}/lib/foo.h" + + cd "${workspace}" + bazel build --spawn_strategy=standalone //:foo &>"$TEST_log" \ + || fail "Build failed but should have succeeded" } function test_tree_artifact_headers_are_invalidated() {