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

[6.4.0] Always check $config_dependencies visibility at use #19197

Merged
merged 2 commits into from
Aug 7, 2023
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 @@ -26,6 +26,7 @@
import com.google.devtools.build.lib.packages.RawAttributeMapper;
import com.google.devtools.build.lib.packages.Rule;
import com.google.devtools.build.lib.packages.Target;
import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.packages.Type;
import com.google.devtools.build.lib.packages.semantics.BuildLanguageOptions;
import com.google.devtools.build.lib.skyframe.ConfiguredTargetAndData;
Expand Down Expand Up @@ -89,6 +90,7 @@ private void validateDirectPrerequisiteVisibility(

if (!toolCheckAtDefinition
|| !attribute.isImplicit()
|| attribute.getName().equals(RuleClass.CONFIG_SETTING_DEPS_ATTRIBUTE)
|| rule.getRuleClassObject().getRuleDefinitionEnvironmentLabel() == null) {
// Default check: The attribute must be visible from the target.
if (!context.isVisible(prerequisite.getConfiguredTarget())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,42 @@ public void testDataVisibilityPrivateCheckPrivateAtUse() throws Exception {
assertThrows(ViewCreationFailedException.class, () -> update("//use:world"));
}

@Test
public void testConfigSettingVisibilityAlwaysCheckedAtUse() throws Exception {
scratch.file(
"BUILD",
"load('//build_defs:defs.bzl', 'my_rule')",
"my_rule(",
" name = 'my_target',",
" value = select({",
" '//config_setting:my_setting': 'foo',",
" '//conditions:default': 'bar',",
" }),",
")");
scratch.file("build_defs/BUILD");
scratch.file(
"build_defs/defs.bzl",
"def _my_rule_impl(ctx):",
" pass",
"my_rule = rule(",
" implementation = _my_rule_impl,",
" attrs = {",
" 'value': attr.string(mandatory = True),",
" },",
")");
scratch.file(
"config_setting/BUILD",
"config_setting(",
" name = 'my_setting',",
" values = {'cpu': 'does_not_matter'},",
" visibility = ['//:__pkg__'],",
")");
useConfiguration("--incompatible_visibility_private_attributes_at_definition");

update("//:my_target");
assertThat(hasErrors(getConfiguredTarget("//:my_target"))).isFalse();
}

void setupFilesScenario(String wantRead) throws Exception {
scratch.file("src/source.txt", "source");
scratch.file("src/BUILD", "exports_files(['source.txt'], visibility=['//pkg:__pkg__'])");
Expand Down