diff options
author | dslomov <dslomov@google.com> | 2017-04-25 17:46:17 +0200 |
---|---|---|
committer | Vladimir Moskva <vladmos@google.com> | 2017-04-25 20:38:54 +0200 |
commit | 99ea6b466b9562bb720de1ab264687295f7da0e4 (patch) | |
tree | f9baae383a6342ec234209dba859335735f27679 /src/main/java/com/google/devtools/build/lib/skyframe/AspectFunction.java | |
parent | 641318ac48dd4f110184c42b4b75485ee61416a8 (diff) |
Native aspects can opt-in to apply to files.
Only works for top-level targets.
RELNOTES: None.
PiperOrigin-RevId: 154176914
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skyframe/AspectFunction.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/skyframe/AspectFunction.java | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/AspectFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/AspectFunction.java index d00c48efa0..5a2f964b89 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/AspectFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/AspectFunction.java @@ -41,7 +41,6 @@ import com.google.devtools.build.lib.packages.AspectDescriptor; import com.google.devtools.build.lib.packages.Attribute; import com.google.devtools.build.lib.packages.BuildFileContainsErrorsException; import com.google.devtools.build.lib.packages.NativeAspectClass; -import com.google.devtools.build.lib.packages.NoSuchTargetException; import com.google.devtools.build.lib.packages.NoSuchThingException; import com.google.devtools.build.lib.packages.Package; import com.google.devtools.build.lib.packages.Rule; @@ -180,21 +179,6 @@ public final class AspectFunction implements SkyFunction { new BuildFileContainsErrorsException(key.getLabel().getPackageIdentifier())); } - Target target; - try { - target = pkg.getTarget(key.getLabel().getName()); - } catch (NoSuchTargetException e) { - throw new AspectFunctionException(e); - } - - if (!(target instanceof Rule)) { - env.getListener().handle(Event.error( - target.getLocation(), - String.format("%s is attached to %s %s but aspects must be attached to rules", - aspect.getAspectClass().getName(), target.getTargetKind(), target.getName()))); - throw new AspectFunctionException(new AspectCreationException( - "aspects must be attached to rules")); - } ConfiguredTargetValue configuredTargetValue; try { @@ -218,13 +202,24 @@ public final class AspectFunction implements SkyFunction { return null; } + ConfiguredTarget associatedTarget = configuredTargetValue.getConfiguredTarget(); + + Target target = associatedTarget.getTarget(); + if (!aspect.getDefinition().applyToFiles() && !(target instanceof Rule)) { + env.getListener().handle(Event.error( + target.getLocation(), + String.format("%s is attached to %s %s but aspects must be attached to rules", + aspect.getAspectClass().getName(), target.getTargetKind(), target.getName()))); + throw new AspectFunctionException(new AspectCreationException( + "aspects must be attached to rules")); + } + + if (configuredTargetValue.getConfiguredTarget().getProvider(AliasProvider.class) != null) { return createAliasAspect(env, target, aspect, key, configuredTargetValue.getConfiguredTarget()); } - ConfiguredTarget associatedTarget = - configuredTargetValue.getConfiguredTarget(); ImmutableList.Builder<Aspect> aspectPathBuilder = ImmutableList.builder(); |