use of com.google.devtools.build.lib.packages.AdvertisedProviderSet in project bazel by bazelbuild.
the class TransitiveTraversalValue method forTarget.
static TransitiveTraversalValue forTarget(Target target, @Nullable String firstErrorMessage) {
if (target instanceof Rule) {
Rule rule = (Rule) target;
RuleClass ruleClass = rule.getRuleClassObject();
if (firstErrorMessage == null && !ruleClass.isSkylark()) {
TransitiveTraversalValue value = VALUES_BY_RULE_CLASS.get(ruleClass);
if (value != null) {
return value;
}
AdvertisedProviderSet providers = ruleClass.getAdvertisedProviders();
value = new TransitiveTraversalValue(providers, null);
// May already be there from another RuleClass or a concurrent put.
value = VALUE_INTERNER.intern(value);
// May already be there from a concurrent put.
VALUES_BY_RULE_CLASS.putIfAbsent(ruleClass, value);
return value;
} else {
// same providers.
return TransitiveTraversalValue.create(rule.getRuleClassObject().getAdvertisedProviders(), firstErrorMessage);
}
}
if (firstErrorMessage == null) {
return EMPTY_VALUE;
} else {
return new TransitiveTraversalValue(AdvertisedProviderSet.EMPTY, firstErrorMessage);
}
}
use of com.google.devtools.build.lib.packages.AdvertisedProviderSet in project bazel by bazelbuild.
the class AspectDefinitionTest method testRequireProvider_AddsToSetOfRequiredProvidersAndNames.
@Test
public void testRequireProvider_AddsToSetOfRequiredProvidersAndNames() throws Exception {
AspectDefinition requiresProviders = new AspectDefinition.Builder(TEST_ASPECT_CLASS).requireProviders(String.class, Integer.class).build();
AdvertisedProviderSet expectedOkSet = AdvertisedProviderSet.builder().addNative(String.class).addNative(Integer.class).addNative(Boolean.class).build();
assertThat(requiresProviders.getRequiredProviders().isSatisfiedBy(expectedOkSet)).isTrue();
AdvertisedProviderSet expectedFailSet = AdvertisedProviderSet.builder().addNative(String.class).build();
assertThat(requiresProviders.getRequiredProviders().isSatisfiedBy(expectedFailSet)).isFalse();
assertThat(requiresProviders.getRequiredProviders().isSatisfiedBy(AdvertisedProviderSet.ANY)).isTrue();
assertThat(requiresProviders.getRequiredProviders().isSatisfiedBy(AdvertisedProviderSet.EMPTY)).isFalse();
}
use of com.google.devtools.build.lib.packages.AdvertisedProviderSet in project bazel by bazelbuild.
the class AspectDefinitionTest method testRequireAspectClass_DefaultAcceptsNothing.
@Test
public void testRequireAspectClass_DefaultAcceptsNothing() {
AspectDefinition noAspects = new AspectDefinition.Builder(TEST_ASPECT_CLASS).build();
AdvertisedProviderSet expectedFailSet = AdvertisedProviderSet.builder().addNative(Float.class).build();
assertThat(noAspects.getRequiredProvidersForAspects().isSatisfiedBy(AdvertisedProviderSet.ANY)).isFalse();
assertThat(noAspects.getRequiredProvidersForAspects().isSatisfiedBy(AdvertisedProviderSet.EMPTY)).isFalse();
assertThat(noAspects.getRequiredProvidersForAspects().isSatisfiedBy(expectedFailSet)).isFalse();
}
use of com.google.devtools.build.lib.packages.AdvertisedProviderSet 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.AdvertisedProviderSet in project bazel by bazelbuild.
the class SkylarkRuleClassFunctionsTest method aspectProvides.
@Test
public void aspectProvides() throws Exception {
evalAndExport("def _impl(target, ctx):", " pass", "y = provider()", "my_aspect = aspect(_impl, provides = ['x', y])");
SkylarkAspect myAspect = (SkylarkAspect) lookup("my_aspect");
AdvertisedProviderSet advertisedProviders = myAspect.getDefinition(AspectParameters.EMPTY).getAdvertisedProviders();
assertThat(advertisedProviders.canHaveAnyProvider()).isFalse();
assertThat(advertisedProviders.getSkylarkProviders()).containsExactly(legacy("x"), declared("y"));
}
Aggregations