Search in sources :

Example 6 with AnalysisResult

use of com.google.devtools.build.lib.analysis.BuildView.AnalysisResult 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 7 with AnalysisResult

use of com.google.devtools.build.lib.analysis.BuildView.AnalysisResult in project bazel by bazelbuild.

the class SkylarkAspectsTest method aspectFailingReturnsUnsafeObject.

@Test
public void aspectFailingReturnsUnsafeObject() throws Exception {
    scratch.file("test/aspect.bzl", "def foo():", "   return 0", "def _impl(target, ctx):", "   return struct(x = foo)", "", "MyAspect = aspect(implementation=_impl)");
    scratch.file("test/BUILD", "java_library(name = 'xxx',)");
    reporter.removeHandler(failFastHandler);
    try {
        AnalysisResult result = update(ImmutableList.of("test/aspect.bzl%MyAspect"), "//test:xxx");
        assertThat(keepGoing()).isTrue();
        assertThat(result.hasError()).isTrue();
    } catch (ViewCreationFailedException e) {
    // expect to fail.
    }
    assertContainsEvent("ERROR /workspace/test/BUILD:1:1: in //test:aspect.bzl%MyAspect aspect on java_library rule" + " //test:xxx: \n" + "\n" + "\n" + "/workspace/test/aspect.bzl:4:11: Value of provider 'x' is of an illegal type: function");
}
Also used : ViewCreationFailedException(com.google.devtools.build.lib.analysis.ViewCreationFailedException) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Test(org.junit.Test)

Example 8 with AnalysisResult

use of com.google.devtools.build.lib.analysis.BuildView.AnalysisResult in project bazel by bazelbuild.

the class SkylarkAspectsTest method aspectOnAspectInconsistentVisibility.

@Test
public void aspectOnAspectInconsistentVisibility() throws Exception {
    scratch.file("test/aspect.bzl", "a1p = provider()", "def _a1_impl(target,ctx):", "  return struct(a1p = a1p(text = 'random'))", "a1 = aspect(_a1_impl, attr_aspects = ['dep'], provides = ['a1p'])", "a2p = provider()", "def _a2_impl(target,ctx):", "  return struct(a2p = a2p(value = 'random'))", "a2 = aspect(_a2_impl, attr_aspects = ['dep'], required_aspect_providers = ['a1p'])", "def _r1_impl(ctx):", "  pass", "def _r2_impl(ctx):", "  return struct(result = ctx.attr.dep.a2p.value)", "r1 = rule(_r1_impl, attrs = { 'dep' : attr.label(aspects = [a1])})", "r2 = rule(_r2_impl, attrs = { 'dep' : attr.label(aspects = [a2])})");
    scratch.file("test/BUILD", "load(':aspect.bzl', 'r1', 'r2')", "r1(name = 'r0')", "r1(name = 'r1', dep = ':r0')", "r2(name = 'r2', dep = ':r1')", "r1(name = 'r1_1', dep = ':r2')", "r2(name = 'r2_1', dep = ':r1_1')");
    reporter.removeHandler(failFastHandler);
    try {
        AnalysisResult analysisResult = update("//test:r2_1");
        assertThat(analysisResult.hasError()).isTrue();
        assertThat(keepGoing()).isTrue();
    } catch (ViewCreationFailedException e) {
    // expected
    }
    assertContainsEvent("ERROR /workspace/test/BUILD:4:1: Aspect //test:aspect.bzl%a2 is" + " applied twice, both before and after aspect //test:aspect.bzl%a1 " + "(when propagating from //test:r2 to //test:r1 via attribute dep)");
}
Also used : ViewCreationFailedException(com.google.devtools.build.lib.analysis.ViewCreationFailedException) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Test(org.junit.Test)

Example 9 with AnalysisResult

use of com.google.devtools.build.lib.analysis.BuildView.AnalysisResult in project bazel by bazelbuild.

the class SkylarkAspectsTest method aspectWithDeclaredProviders.

@Test
public void aspectWithDeclaredProviders() throws Exception {
    scratch.file("test/aspect.bzl", "foo = provider()", "bar = provider()", "def _impl(target, ctx):", "   return [foo(), bar()]", "MyAspect = aspect(implementation=_impl)");
    scratch.file("test/BUILD", "java_library(name = 'xxx',)");
    AnalysisResult analysisResult = update(ImmutableList.of("test/aspect.bzl%MyAspect"), "//test:xxx");
    assertThat(getLabelsToBuild(analysisResult)).containsExactly("//test:xxx");
    assertThat(getAspectDescriptions(analysisResult)).containsExactly("//test:aspect.bzl%MyAspect(//test:xxx)");
    List<Key> providers = getDeclaredProviderKeys(analysisResult);
    assertThat((providers.get(0))).isEqualTo(new SkylarkKey(Label.parseAbsolute("//test:aspect.bzl"), "foo"));
    assertThat((providers.get(1))).isEqualTo(new SkylarkKey(Label.parseAbsolute("//test:aspect.bzl"), "bar"));
}
Also used : SkylarkKey(com.google.devtools.build.lib.packages.SkylarkClassObjectConstructor.SkylarkKey) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) SkylarkKey(com.google.devtools.build.lib.packages.SkylarkClassObjectConstructor.SkylarkKey) Key(com.google.devtools.build.lib.packages.ClassObjectConstructor.Key) Test(org.junit.Test)

Example 10 with AnalysisResult

use of com.google.devtools.build.lib.analysis.BuildView.AnalysisResult in project bazel by bazelbuild.

the class SkylarkAspectsTest method aspectFailingOrphanArtifacts.

@Test
public void aspectFailingOrphanArtifacts() throws Exception {
    scratch.file("test/aspect.bzl", "def _impl(target, ctx):", "  ctx.new_file('missing_in_action.txt')", "  return struct()", "", "MyAspect = aspect(implementation=_impl)");
    scratch.file("test/BUILD", "java_library(name = 'xxx',)");
    reporter.removeHandler(failFastHandler);
    try {
        AnalysisResult result = update(ImmutableList.of("test/aspect.bzl%MyAspect"), "//test:xxx");
        assertThat(keepGoing()).isTrue();
        assertThat(result.hasError()).isTrue();
    } catch (ViewCreationFailedException e) {
    // expect to fail.
    }
    assertContainsEvent("ERROR /workspace/test/BUILD:1:1: in " + "//test:aspect.bzl%MyAspect aspect on java_library rule //test:xxx: \n" + "\n" + "\n" + "The following files have no generating action:\n" + "test/missing_in_action.txt\n");
}
Also used : ViewCreationFailedException(com.google.devtools.build.lib.analysis.ViewCreationFailedException) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Test(org.junit.Test)

Aggregations

AnalysisResult (com.google.devtools.build.lib.analysis.BuildView.AnalysisResult)69 Test (org.junit.Test)63 ViewCreationFailedException (com.google.devtools.build.lib.analysis.ViewCreationFailedException)21 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)12 EventBus (com.google.common.eventbus.EventBus)8 AspectValue (com.google.devtools.build.lib.skyframe.AspectValue)7 SkylarkProviders (com.google.devtools.build.lib.analysis.SkylarkProviders)6 Artifact (com.google.devtools.build.lib.actions.Artifact)5 TargetParsingException (com.google.devtools.build.lib.cmdline.TargetParsingException)5 SkylarkList (com.google.devtools.build.lib.syntax.SkylarkList)5 Nullable (javax.annotation.Nullable)5 Label (com.google.devtools.build.lib.cmdline.Label)4 OutputGroupProvider (com.google.devtools.build.lib.analysis.OutputGroupProvider)3 SkylarkNestedSet (com.google.devtools.build.lib.syntax.SkylarkNestedSet)3 Key (com.google.devtools.build.lib.packages.ClassObjectConstructor.Key)2 SkylarkKey (com.google.devtools.build.lib.packages.SkylarkClassObjectConstructor.SkylarkKey)2 Stopwatch (com.google.common.base.Stopwatch)1 BuildFailedException (com.google.devtools.build.lib.actions.BuildFailedException)1 AnalysisPhaseCompleteEvent (com.google.devtools.build.lib.analysis.AnalysisPhaseCompleteEvent)1 BuildInfoEvent (com.google.devtools.build.lib.analysis.BuildInfoEvent)1