From 698f112b4f0c98f385273f039642a27349d56456 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 24 Feb 2021 14:23:14 -0800 Subject: [PATCH] Fix quote include paths for external genfiles/bin dirs with the sibling repository layout. PiperOrigin-RevId: 359369701 --- .../lib/rules/cpp/CcCompilationHelper.java | 8 +++- src/test/shell/bazel/cc_integration_test.sh | 47 +++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) 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 ddfeddadcaa5b1..934783a3b462e6 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 @@ -1013,9 +1013,13 @@ private CcCompilationContext initializeCcCompilationContext(RuleContext ruleCont PathFragment repositoryPath = repositoryName.getExecPath(siblingRepositoryLayout); ccCompilationContextBuilder.addQuoteIncludeDir(repositoryPath); ccCompilationContextBuilder.addQuoteIncludeDir( - ruleContext.getGenfilesFragment().getRelative(repositoryPath)); + siblingRepositoryLayout + ? ruleContext.getGenfilesFragment() + : ruleContext.getGenfilesFragment().getRelative(repositoryPath)); ccCompilationContextBuilder.addQuoteIncludeDir( - ruleContext.getBinFragment().getRelative(repositoryPath)); + siblingRepositoryLayout + ? ruleContext.getBinFragment() + : ruleContext.getBinFragment().getRelative(repositoryPath)); ccCompilationContextBuilder.addSystemIncludeDirs(systemIncludeDirs); ccCompilationContextBuilder.addFrameworkIncludeDirs(frameworkIncludeDirs); diff --git a/src/test/shell/bazel/cc_integration_test.sh b/src/test/shell/bazel/cc_integration_test.sh index c42aabb3043a75..fb872d2cd5e209 100755 --- a/src/test/shell/bazel/cc_integration_test.sh +++ b/src/test/shell/bazel/cc_integration_test.sh @@ -1201,4 +1201,51 @@ EOF assert_equals "$(sed 's/\\//g' bazel-bin/package/aspect_out-0.params)" \ "$(cat package/expected_args)" } + +function test_include_external_genrule_header() { + REPO_PATH=$TEST_TMPDIR/repo + mkdir -p "$REPO_PATH" + create_workspace_with_default_repos "$REPO_PATH/WORKSPACE" + mkdir "$REPO_PATH/foo" + cat > "$REPO_PATH/foo/BUILD" <<'EOF' +cc_library( + name = "bar", + srcs = [ + "bar.cc", + "inc.h", + ], +) + +genrule( + name = "inc_h", + srcs = ["inc.txt"], + outs = ["inc.h"], + cmd = "cp $< $@", +) +EOF + cat > "$REPO_PATH/foo/bar.cc" <<'EOF' +#include "foo/inc.h" + +int main() { + sayhello(); +} +EOF + cat > "$REPO_PATH/foo/inc.txt" <<'EOF' +#include + +void sayhello() { + printf("hello\n"); +} +EOF + + cat >> $(create_workspace_with_default_repos WORKSPACE) < "$TEST_log" || fail "expected build success" + bazel build --experimental_sibling_repository_layout @repo//foo:bar \ + > "$TEST_log" || fail "expected build success" +} + run_suite "cc_integration_test"