Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.0.1] Allow cc_binary with dynamic_deps to be extended #24815

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1694,7 +1694,7 @@ public Object call(StarlarkThread thread, Tuple args, Dict<String, Object> kwarg
checkAttributeName(arg);
if (arg.startsWith("_")) {
// allow setting private attributes from initializers in builtins
Label definitionLabel = ruleClass.getRuleDefinitionEnvironmentLabel();
Label definitionLabel = currentRuleClass.getRuleDefinitionEnvironmentLabel();
BuiltinRestriction.failIfLabelOutsideAllowlist(
definitionLabel,
RepositoryMapping.ALWAYS_FALLBACK,
Expand Down
41 changes: 41 additions & 0 deletions src/test/shell/bazel/cc_integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2079,4 +2079,45 @@ EOF
bazel build //pkg:testCodegen &> "$TEST_log" || fail "Build failed"
}

function test_extend_cc_binary_with_dynamic_deps() {
mkdir -p pkg
cat >pkg/BUILD <<'EOF'
load("my_cc_binary.bzl", "my_cc_binary")

constraint_setting(name = "foo")
constraint_value(name = "never_selected", constraint_setting = ":foo")

my_cc_binary(
name = "hello",
srcs = ["main.cpp"],
# Ensure that the select has no effect but can't be simplified.
dynamic_deps = select({":never_selected": ["unused"], "//conditions:default": []}),
)
EOF

cat >pkg/my_cc_binary.bzl << 'EOF'
def _my_cc_binary_impl(ctx):
print("Hello from my_cc_binary")
return ctx.super()

my_cc_binary = rule(
implementation = _my_cc_binary_impl,
parent = native.cc_binary,
)
EOF

cat >pkg/main.cpp <<'EOF'
#include <iostream>

int main() {
std::cout << "Hello from main.cpp" << std::endl;
return 0;
}
EOF

bazel run //pkg:hello &> $TEST_log || fail "Expected success"
expect_log "Hello from my_cc_binary"
expect_log "Hello from main.cpp"
}

run_suite "cc_integration_test"
Loading