aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/skylark
diff options
context:
space:
mode:
authorGravatar Michael Staib <mstaib@google.com>2016-01-15 20:11:11 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2016-01-15 22:30:16 +0000
commitcd48cd56ab576f3ff1c5acaa749582c6bd7043b9 (patch)
treefea553f726bba8739dfa581281c684a2887229fc /src/test/java/com/google/devtools/build/lib/skylark
parentcb5d741ab44c11809cb0cd666bfb20af5f6af114 (diff)
Enable Aspects to specify their configuration fragment dependencies.
Note: This specification currently does not have any effect, but soon... In the default mode, when an aspect does not call any of the configuration fragment methods on its AspectDefinition.Builder, the old behavior will persist; aspects can only access fragments their associated rule has access to, and have no guarantee as to what those fragments are. This mode will become deprecated with a future CL. If an aspect does call a configuration fragment method, it will have a configuration fragment policy. In a future CL, this will mean it will be restricted to accessing only those fragments, but will be understood as requiring access to them for the purposes of dynamic configuration, even if the rule it is attached to or created by does not otherwise require them. Eventually, all aspects will be required to declare their configuration fragments this way. Skylark aspects may also declare configuration fragments as of this CL. Two new parameters are added to the aspect() function, fragments and host_fragments, mirroring the similar parameters for rules. If both of these parameters are empty or unspecified, the default mode is used, as with normal aspects. Also in this CL: * Minor javadoc fixes for AspectDefinition. * Additional tests for AspectDefinition. -- MOS_MIGRATED_REVID=112271713
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/skylark')
-rw-r--r--src/test/java/com/google/devtools/build/lib/skylark/SkylarkAspectsTest.java45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkAspectsTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkAspectsTest.java
index 0e68f6be0b..b629094f40 100644
--- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkAspectsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkAspectsTest.java
@@ -18,6 +18,7 @@ import static com.google.common.truth.Truth.assertThat;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
import com.google.common.eventbus.EventBus;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.analysis.BuildView.AnalysisResult;
@@ -28,7 +29,12 @@ import com.google.devtools.build.lib.analysis.ViewCreationFailedException;
import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
+import com.google.devtools.build.lib.packages.AspectDefinition;
+import com.google.devtools.build.lib.packages.Attribute.ConfigurationTransition;
+import com.google.devtools.build.lib.rules.cpp.CppConfiguration;
+import com.google.devtools.build.lib.rules.java.Jvm;
import com.google.devtools.build.lib.skyframe.AspectValue;
+import com.google.devtools.build.lib.skyframe.AspectValue.AspectKey;
import com.google.devtools.build.lib.syntax.SkylarkNestedSet;
import org.junit.Test;
@@ -88,6 +94,45 @@ public class SkylarkAspectsTest extends BuildViewTestCase {
}
@Test
+ public void testAspectAllowsFragmentsToBeSpecified() throws Exception {
+ scratch.file(
+ "test/aspect.bzl",
+ "def _impl(target, ctx):",
+ " print('This aspect does nothing')",
+ " return struct()",
+ "MyAspect = aspect(implementation=_impl, fragments=['jvm'], host_fragments=['cpp'])");
+ scratch.file("test/BUILD", "java_library(name = 'xxx',)");
+
+ AnalysisResult analysisResult =
+ update(
+ ImmutableList.of("//test:xxx"),
+ ImmutableList.of("test/aspect.bzl%MyAspect"),
+ false,
+ LOADING_PHASE_THREADS,
+ true,
+ new EventBus());
+ AspectValue aspectValue = Iterables.getOnlyElement(analysisResult.getAspects());
+ AspectKey aspectKey = aspectValue.getKey();
+ AspectDefinition aspectDefinition = aspectKey.getAspect().getDefinition();
+ assertThat(
+ aspectDefinition.getConfigurationFragmentPolicy()
+ .isLegalConfigurationFragment(Jvm.class, ConfigurationTransition.NONE))
+ .isTrue();
+ assertThat(
+ aspectDefinition.getConfigurationFragmentPolicy()
+ .isLegalConfigurationFragment(Jvm.class, ConfigurationTransition.HOST))
+ .isFalse();
+ assertThat(
+ aspectDefinition.getConfigurationFragmentPolicy()
+ .isLegalConfigurationFragment(CppConfiguration.class, ConfigurationTransition.NONE))
+ .isFalse();
+ assertThat(
+ aspectDefinition.getConfigurationFragmentPolicy()
+ .isLegalConfigurationFragment(CppConfiguration.class, ConfigurationTransition.HOST))
+ .isTrue();
+ }
+
+ @Test
public void testAspectPropagating() throws Exception {
scratch.file(
"test/aspect.bzl",