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();
}
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();
}
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);
}
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);
}
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();
}
});
}
Aggregations