Search in sources :

Example 1 with AspectDefinition

use of com.google.devtools.build.lib.packages.AspectDefinition in project bazel by bazelbuild.

the class SkylarkAspectsTest method aspectAllowsFragmentsToBeSpecified.

@Test
public void aspectAllowsFragmentsToBeSpecified() 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/aspect.bzl%MyAspect"), "//test:xxx");
    AspectValue aspectValue = Iterables.getOnlyElement(analysisResult.getAspects());
    AspectDefinition aspectDefinition = aspectValue.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();
}
Also used : AspectValue(com.google.devtools.build.lib.skyframe.AspectValue) AspectDefinition(com.google.devtools.build.lib.packages.AspectDefinition) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Test(org.junit.Test)

Example 2 with AspectDefinition

use of com.google.devtools.build.lib.packages.AspectDefinition in project bazel by bazelbuild.

the class AspectDefinitionTest method testMissingFragmentPolicy_PropagatedToConfigurationFragmentPolicy.

@Test
public void testMissingFragmentPolicy_PropagatedToConfigurationFragmentPolicy() throws Exception {
    AspectDefinition missingFragments = new AspectDefinition.Builder(TEST_ASPECT_CLASS).setMissingFragmentPolicy(MissingFragmentPolicy.IGNORE).build();
    assertThat(missingFragments.getConfigurationFragmentPolicy()).isNotNull();
    assertThat(missingFragments.getConfigurationFragmentPolicy().getMissingFragmentPolicy()).isEqualTo(MissingFragmentPolicy.IGNORE);
}
Also used : AspectDefinition(com.google.devtools.build.lib.packages.AspectDefinition) Test(org.junit.Test)

Example 3 with AspectDefinition

use of com.google.devtools.build.lib.packages.AspectDefinition in project bazel by bazelbuild.

the class AspectDefinitionTest method testEmptySkylarkConfigurationFragmentPolicySetup_HasNonNullPolicy.

@Test
public void testEmptySkylarkConfigurationFragmentPolicySetup_HasNonNullPolicy() throws Exception {
    AspectDefinition noPolicy = new AspectDefinition.Builder(TEST_ASPECT_CLASS).requiresConfigurationFragmentsBySkylarkModuleName(ImmutableList.<String>of()).requiresHostConfigurationFragmentsBySkylarkModuleName(ImmutableList.<String>of()).build();
    assertThat(noPolicy.getConfigurationFragmentPolicy()).isNotNull();
}
Also used : AspectDefinition(com.google.devtools.build.lib.packages.AspectDefinition) Test(org.junit.Test)

Example 4 with AspectDefinition

use of com.google.devtools.build.lib.packages.AspectDefinition in project bazel by bazelbuild.

the class AspectDefinitionTest method testAttributeAspect_WrapsAndAddsToMap.

@Test
public void testAttributeAspect_WrapsAndAddsToMap() throws Exception {
    AspectDefinition withAspects = new AspectDefinition.Builder(TEST_ASPECT_CLASS).propagateAlongAttribute("srcs").propagateAlongAttribute("deps").build();
    assertThat(withAspects.propagateAlong(createLabelListAttribute("srcs"))).isTrue();
    assertThat(withAspects.propagateAlong(createLabelListAttribute("deps"))).isTrue();
}
Also used : AspectDefinition(com.google.devtools.build.lib.packages.AspectDefinition) Test(org.junit.Test)

Example 5 with AspectDefinition

use of com.google.devtools.build.lib.packages.AspectDefinition in project bazel by bazelbuild.

the class AspectDefinitionTest method testAspectWithImplicitOrLateboundAttribute_AddsToAttributeMap.

@Test
public void testAspectWithImplicitOrLateboundAttribute_AddsToAttributeMap() throws Exception {
    Attribute implicit = attr("$runtime", BuildType.LABEL).value(Label.parseAbsoluteUnchecked("//run:time")).build();
    LateBoundLabel<String> latebound = new LateBoundLabel<String>() {

        @Override
        public Label resolve(Rule rule, AttributeMap attributes, String configuration) {
            return Label.parseAbsoluteUnchecked("//run:away");
        }
    };
    AspectDefinition simple = new AspectDefinition.Builder(TEST_ASPECT_CLASS).add(implicit).add(attr(":latebound", BuildType.LABEL).value(latebound)).build();
    assertThat(simple.getAttributes()).containsEntry("$runtime", implicit);
    assertThat(simple.getAttributes()).containsKey(":latebound");
    assertThat(simple.getAttributes().get(":latebound").getLateBoundDefault()).isEqualTo(latebound);
}
Also used : AttributeMap(com.google.devtools.build.lib.packages.AttributeMap) Attribute(com.google.devtools.build.lib.packages.Attribute) LateBoundLabel(com.google.devtools.build.lib.packages.Attribute.LateBoundLabel) AspectDefinition(com.google.devtools.build.lib.packages.AspectDefinition) Rule(com.google.devtools.build.lib.packages.Rule) Test(org.junit.Test)

Aggregations

AspectDefinition (com.google.devtools.build.lib.packages.AspectDefinition)15 Test (org.junit.Test)14 AdvertisedProviderSet (com.google.devtools.build.lib.packages.AdvertisedProviderSet)3 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 AnalysisResult (com.google.devtools.build.lib.analysis.BuildView.AnalysisResult)1 AspectParameters (com.google.devtools.build.lib.packages.AspectParameters)1 Attribute (com.google.devtools.build.lib.packages.Attribute)1 LateBoundLabel (com.google.devtools.build.lib.packages.Attribute.LateBoundLabel)1 AttributeMap (com.google.devtools.build.lib.packages.AttributeMap)1 NativeAspectClass (com.google.devtools.build.lib.packages.NativeAspectClass)1 Rule (com.google.devtools.build.lib.packages.Rule)1 AspectValue (com.google.devtools.build.lib.skyframe.AspectValue)1