Search in sources :

Example 11 with AspectDefinition

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

the class AspectDefinitionTest method testRequireProvider_AddsTwoSetsOfRequiredProvidersAndNames.

@Test
public void testRequireProvider_AddsTwoSetsOfRequiredProvidersAndNames() throws Exception {
    AspectDefinition requiresProviders = new AspectDefinition.Builder(TEST_ASPECT_CLASS).requireProviderSets(ImmutableList.of(ImmutableSet.<Class<?>>of(String.class, Integer.class), ImmutableSet.<Class<?>>of(Boolean.class))).build();
    AdvertisedProviderSet expectedOkSet1 = AdvertisedProviderSet.builder().addNative(String.class).addNative(Integer.class).build();
    AdvertisedProviderSet expectedOkSet2 = AdvertisedProviderSet.builder().addNative(Boolean.class).build();
    AdvertisedProviderSet expectedFailSet = AdvertisedProviderSet.builder().addNative(Float.class).build();
    assertThat(requiresProviders.getRequiredProviders().isSatisfiedBy(AdvertisedProviderSet.ANY)).isTrue();
    assertThat(requiresProviders.getRequiredProviders().isSatisfiedBy(expectedOkSet1)).isTrue();
    assertThat(requiresProviders.getRequiredProviders().isSatisfiedBy(expectedOkSet2)).isTrue();
    assertThat(requiresProviders.getRequiredProviders().isSatisfiedBy(expectedFailSet)).isFalse();
    assertThat(requiresProviders.getRequiredProviders().isSatisfiedBy(AdvertisedProviderSet.EMPTY)).isFalse();
}
Also used : AdvertisedProviderSet(com.google.devtools.build.lib.packages.AdvertisedProviderSet) AspectDefinition(com.google.devtools.build.lib.packages.AspectDefinition) Test(org.junit.Test)

Example 12 with AspectDefinition

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

the class AspectDefinitionTest method testRequiresConfigurationFragmentNames_PropagatedToConfigurationFragmentPolicy.

@Test
public void testRequiresConfigurationFragmentNames_PropagatedToConfigurationFragmentPolicy() throws Exception {
    AspectDefinition requiresFragments = new AspectDefinition.Builder(TEST_ASPECT_CLASS).requiresConfigurationFragmentsBySkylarkModuleName(ImmutableList.of("test_fragment")).build();
    assertThat(requiresFragments.getConfigurationFragmentPolicy()).isNotNull();
    assertThat(requiresFragments.getConfigurationFragmentPolicy().isLegalConfigurationFragment(TestFragment.class, ConfigurationTransition.NONE)).isTrue();
}
Also used : AspectDefinition(com.google.devtools.build.lib.packages.AspectDefinition) Test(org.junit.Test)

Example 13 with AspectDefinition

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

the class AspectDefinitionTest method testRequiresConfigurationFragments_PropagatedToConfigurationFragmentPolicy.

@Test
public void testRequiresConfigurationFragments_PropagatedToConfigurationFragmentPolicy() throws Exception {
    AspectDefinition requiresFragments = new AspectDefinition.Builder(TEST_ASPECT_CLASS).requiresConfigurationFragments(Integer.class, String.class).build();
    assertThat(requiresFragments.getConfigurationFragmentPolicy()).isNotNull();
    assertThat(requiresFragments.getConfigurationFragmentPolicy().getRequiredConfigurationFragments()).containsExactly(Integer.class, String.class);
}
Also used : AspectDefinition(com.google.devtools.build.lib.packages.AspectDefinition) Test(org.junit.Test)

Example 14 with AspectDefinition

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

the class AspectDefinitionTest method testRequiresHostConfigurationFragments_PropagatedToConfigurationFragmentPolicy.

@Test
public void testRequiresHostConfigurationFragments_PropagatedToConfigurationFragmentPolicy() throws Exception {
    AspectDefinition requiresFragments = new AspectDefinition.Builder(TEST_ASPECT_CLASS).requiresHostConfigurationFragments(Integer.class, String.class).build();
    assertThat(requiresFragments.getConfigurationFragmentPolicy()).isNotNull();
    assertThat(requiresFragments.getConfigurationFragmentPolicy().getRequiredConfigurationFragments()).containsExactly(Integer.class, String.class);
}
Also used : AspectDefinition(com.google.devtools.build.lib.packages.AspectDefinition) Test(org.junit.Test)

Example 15 with AspectDefinition

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

the class AspectCollectionTest method createAspect.

/**
   * Creates an aspect wiht a class named {@code className} advertizing a provider
   * {@code className} that requires any of providers {@code requiredAspects}.
   */
private Aspect createAspect(final String className, String... requiredAspects) {
    ImmutableList.Builder<ImmutableSet<SkylarkProviderIdentifier>> requiredProvidersBuilder = ImmutableList.builder();
    for (String requiredAspect : requiredAspects) {
        requiredProvidersBuilder.add(ImmutableSet.of((SkylarkProviderIdentifier.forLegacy(requiredAspect))));
    }
    final ImmutableList<ImmutableSet<SkylarkProviderIdentifier>> requiredProviders = requiredProvidersBuilder.build();
    return Aspect.forNative(new NativeAspectClass() {

        @Override
        public String getName() {
            return className;
        }

        @Override
        public AspectDefinition getDefinition(AspectParameters aspectParameters) {
            return AspectDefinition.builder(this).requireAspectsWithProviders(requiredProviders).advertiseProvider(ImmutableList.of(SkylarkProviderIdentifier.forLegacy(className))).build();
        }
    });
}
Also used : NativeAspectClass(com.google.devtools.build.lib.packages.NativeAspectClass) AspectParameters(com.google.devtools.build.lib.packages.AspectParameters) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableList(com.google.common.collect.ImmutableList) AspectDefinition(com.google.devtools.build.lib.packages.AspectDefinition)

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