Skip to content

Commit

Permalink
Fix quote include paths for external genfiles/bin dirs with the sibli…
Browse files Browse the repository at this point in the history
…ng repository layout.

PiperOrigin-RevId: 359369701
  • Loading branch information
Googler authored and copybara-github committed Feb 24, 2021
1 parent 7398e33 commit 698f112
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
47 changes: 47 additions & 0 deletions src/test/shell/bazel/cc_integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdio.h>
void sayhello() {
printf("hello\n");
}
EOF

cat >> $(create_workspace_with_default_repos WORKSPACE) <<EOF
local_repository(name = 'repo', path='$REPO_PATH')
EOF

bazel build @repo//foo:bar \
> "$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"

0 comments on commit 698f112

Please sign in to comment.