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