aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/skyframe/AspectFunction.java
diff options
context:
space:
mode:
authorGravatar Lukacs Berki <lberki@google.com>2016-08-30 12:26:18 +0000
committerGravatar Klaus Aehlig <aehlig@google.com>2016-08-31 08:09:03 +0000
commitea988b691aa9c1ceb67d05885b947ca58c13cbf7 (patch)
treeade5d14eb2bba1d326798b1176877159a632a64e /src/main/java/com/google/devtools/build/lib/skyframe/AspectFunction.java
parent1b2071f1809e8fd91a238b3b08fc1b32bf24b89b (diff)
Make aspects attached to aliases work when their actual= attribute is a select.
Fixes https://github.com/bazelbuild/e4b/issues/6 . -- MOS_MIGRATED_REVID=131698950
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.java40
1 files changed, 26 insertions, 14 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 d94be28632..4035242c4e 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
@@ -44,7 +44,7 @@ import com.google.devtools.build.lib.packages.RuleClassProvider;
import com.google.devtools.build.lib.packages.SkylarkAspect;
import com.google.devtools.build.lib.packages.SkylarkAspectClass;
import com.google.devtools.build.lib.packages.Target;
-import com.google.devtools.build.lib.packages.TargetUtils;
+import com.google.devtools.build.lib.rules.AliasProvider;
import com.google.devtools.build.lib.skyframe.AspectValue.AspectKey;
import com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction.ConfiguredValueCreationException;
import com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction.DependencyEvaluationException;
@@ -165,6 +165,7 @@ public final class AspectFunction implements SkyFunction {
throw new AspectFunctionException(
new BuildFileContainsErrorsException(key.getLabel().getPackageIdentifier()));
}
+
Target target;
try {
target = pkg.getTarget(key.getLabel().getName());
@@ -172,11 +173,6 @@ public final class AspectFunction implements SkyFunction {
throw new AspectFunctionException(e);
}
- Label aliasLabel = TargetUtils.getAliasTarget(target);
- if (aliasLabel != null) {
- return createAliasAspect(env, target, aliasLabel, aspect, key);
- }
-
if (!(target instanceof Rule)) {
env.getListener().handle(Event.error(
target.getLocation(),
@@ -186,7 +182,7 @@ public final class AspectFunction implements SkyFunction {
"aspects must be attached to rules"));
}
- final ConfiguredTargetValue configuredTargetValue;
+ ConfiguredTargetValue configuredTargetValue;
try {
configuredTargetValue =
(ConfiguredTargetValue) env.getValueOrThrow(
@@ -202,12 +198,18 @@ public final class AspectFunction implements SkyFunction {
// precomputed.
return null;
}
- RuleConfiguredTarget associatedTarget =
- (RuleConfiguredTarget) configuredTargetValue.getConfiguredTarget();
- if (associatedTarget == null) {
+
+ if (configuredTargetValue.getConfiguredTarget() == null) {
return null;
}
+ if (configuredTargetValue.getConfiguredTarget().getProvider(AliasProvider.class) != null) {
+ return createAliasAspect(env, target, aspect, key,
+ configuredTargetValue.getConfiguredTarget());
+ }
+
+ RuleConfiguredTarget associatedTarget =
+ (RuleConfiguredTarget) configuredTargetValue.getConfiguredTarget();
SkyframeDependencyResolver resolver = view.createDependencyResolver(env);
// When getting the dependencies of this hybrid aspect+base target, use the aspect's
@@ -277,15 +279,24 @@ public final class AspectFunction implements SkyFunction {
private static SkyValue createAliasAspect(
Environment env,
Target originalTarget,
- Label aliasLabel,
Aspect aspect,
- AspectKey originalKey)
- throws InterruptedException {
- SkyKey depKey = AspectValue.key(aliasLabel,
+ AspectKey originalKey,
+ ConfiguredTarget configuredTarget) throws InterruptedException {
+ ImmutableList<Label> aliasChain = configuredTarget.getProvider(AliasProvider.class)
+ .getAliasChain();
+ // Find the next alias in the chain: either the next alias (if there are two) or the name of
+ // the real configured target.
+ Label aliasLabel = aliasChain.size() > 1 ? aliasChain.get(1) : configuredTarget.getLabel();
+
+ SkyKey depKey = AspectValue.key(
+ aliasLabel,
originalKey.getAspectConfiguration(),
originalKey.getBaseConfiguration(),
originalKey.getAspectClass(),
originalKey.getParameters());
+
+ // Compute the AspectValue of the target the alias refers to (which can itself be either an
+ // alias or a real target)
AspectValue real = (AspectValue) env.getValue(depKey);
if (env.valuesMissing()) {
return null;
@@ -295,6 +306,7 @@ public final class AspectFunction implements SkyFunction {
.addTransitive(real.getTransitivePackages())
.add(originalTarget.getPackage())
.build();
+
return new AspectValue(
originalKey,
aspect,