|
13 | 13 | // limitations under the License. |
14 | 14 | package com.google.devtools.build.lib.analysis; |
15 | 15 |
|
| 16 | +import static com.google.common.base.Preconditions.checkNotNull; |
16 | 17 | import static com.google.devtools.build.lib.packages.NonconfigurableAttributeMapper.attributeOrNull; |
17 | 18 |
|
18 | 19 | import com.google.devtools.build.lib.analysis.AliasProvider.TargetMode; |
19 | 20 | import com.google.devtools.build.lib.analysis.RuleContext.PrerequisiteValidator; |
20 | 21 | import com.google.devtools.build.lib.analysis.configuredtargets.PackageGroupConfiguredTarget; |
21 | 22 | import com.google.devtools.build.lib.cmdline.Label; |
22 | 23 | import com.google.devtools.build.lib.cmdline.PackageIdentifier; |
| 24 | +import com.google.devtools.build.lib.packages.Aspect; |
23 | 25 | import com.google.devtools.build.lib.packages.Attribute; |
24 | 26 | import com.google.devtools.build.lib.packages.FunctionSplitTransitionAllowlist; |
25 | 27 | import com.google.devtools.build.lib.packages.InputFile; |
26 | 28 | import com.google.devtools.build.lib.packages.NonconfigurableAttributeMapper; |
27 | 29 | import com.google.devtools.build.lib.packages.RawAttributeMapper; |
28 | 30 | import com.google.devtools.build.lib.packages.Rule; |
29 | 31 | import com.google.devtools.build.lib.packages.RuleClass; |
| 32 | +import com.google.devtools.build.lib.packages.StarlarkAspectClass; |
30 | 33 | import com.google.devtools.build.lib.packages.Type; |
31 | 34 | import com.google.devtools.build.lib.packages.semantics.BuildLanguageOptions; |
32 | 35 | import com.google.devtools.build.lib.skyframe.ConfiguredTargetAndData; |
@@ -105,16 +108,33 @@ private void validateDirectPrerequisiteVisibility( |
105 | 108 | if (!toolCheckAtDefinition |
106 | 109 | || !attribute.isImplicit() |
107 | 110 | || attribute.getName().equals(RuleClass.CONFIG_SETTING_DEPS_ATTRIBUTE) |
108 | | - || rule.getRuleClassObject().getRuleDefinitionEnvironmentLabel() == null) { |
| 111 | + || !context.isStarlarkRuleOrAspect()) { |
109 | 112 | // Default check: The attribute must be visible from the target. |
110 | 113 | if (!context.isVisible(prerequisite.getConfiguredTarget())) { |
111 | 114 | handleVisibilityConflict(context, prerequisite, rule.getLabel()); |
112 | 115 | } |
113 | 116 | } else { |
114 | | - // For implicit attributes, check if the prerequisite is visible from the location of the |
115 | | - // rule definition |
116 | | - Label implicitDefinition = rule.getRuleClassObject().getRuleDefinitionEnvironmentLabel(); |
117 | | - if (!RuleContext.isVisible(implicitDefinition, prerequisite.getConfiguredTarget())) { |
| 117 | + // For implicit attributes of Starlark rules or aspects, check if the prerequisite is visible |
| 118 | + // from the location of the definition that declares the attribute. Only perform this check |
| 119 | + // for the current aspect. |
| 120 | + Label implicitDefinition = null; |
| 121 | + Aspect mainAspect = context.getMainAspect(); |
| 122 | + if (mainAspect != null) { |
| 123 | + // Only verify visibility of implicit dependencies of the current aspect. Implicit |
| 124 | + // dependencies of other aspects as well as the rule itself are checked when they are |
| 125 | + // evaluated. |
| 126 | + if (mainAspect.getDefinition().getAttributes().containsKey(attrName)) { |
| 127 | + StarlarkAspectClass aspectClass = (StarlarkAspectClass) mainAspect.getAspectClass(); |
| 128 | + // Never null since we already checked that the aspect is Starlark-defined. |
| 129 | + implicitDefinition = checkNotNull(aspectClass.getExtensionLabel()); |
| 130 | + } |
| 131 | + } else { |
| 132 | + // Never null since we already checked that the rule is a Starlark rule. |
| 133 | + implicitDefinition = |
| 134 | + checkNotNull(rule.getRuleClassObject().getRuleDefinitionEnvironmentLabel()); |
| 135 | + } |
| 136 | + if (implicitDefinition != null |
| 137 | + && !RuleContext.isVisible(implicitDefinition, prerequisite.getConfiguredTarget())) { |
118 | 138 | handleVisibilityConflict(context, prerequisite, implicitDefinition); |
119 | 139 | } |
120 | 140 | } |
|
0 commit comments