Search in sources :

Example 56 with AnalysisResult

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

the class SkylarkAspectsTest method duplicateSkylarkProviders.

@Test
public void duplicateSkylarkProviders() throws Exception {
    scratch.file("test/aspect.bzl", "def _impl(target, ctx):", "  return struct(duplicate = 'x')", "", "MyAspect = aspect(implementation=_impl)", "def _rule_impl(ctx):", "  return struct(duplicate = 'y')", "my_rule = rule(_rule_impl)", "def _noop(ctx):", "  pass", "rbase = rule(_noop, attrs = { 'dep' : attr.label(aspects = [MyAspect]) })");
    scratch.file("test/BUILD", "load(':aspect.bzl', 'my_rule', 'rbase')", "my_rule(name = 'xxx')", "rbase(name = 'yyy', dep = ':xxx')");
    reporter.removeHandler(failFastHandler);
    try {
        AnalysisResult result = update("//test:yyy");
        assertThat(keepGoing()).isTrue();
        assertThat(result.hasError()).isTrue();
    } catch (ViewCreationFailedException e) {
    // expect to fail.
    }
    assertContainsEvent("ERROR /workspace/test/BUILD:3:1: Provider duplicate provided twice");
}
Also used : ViewCreationFailedException(com.google.devtools.build.lib.analysis.ViewCreationFailedException) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Test(org.junit.Test)

Example 57 with AnalysisResult

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

the class SkylarkAspectsTest method aspectParametersTypeMismatch.

@Test
public void aspectParametersTypeMismatch() throws Exception {
    scratch.file("test/aspect.bzl", "def _impl(target, ctx):", "   return struct()", "def _rule_impl(ctx):", "   return struct()", "MyAspectMismatch = aspect(", "    implementation=_impl,", "    attrs = { 'my_attr' : attr.string(values=['aaa']) },", ")", "my_rule = rule(", "    implementation=_rule_impl,", "    attrs = { 'deps' : attr.label_list(aspects=[MyAspectMismatch]),", "              'my_attr' : attr.int() },", ")");
    scratch.file("test/BUILD", "load('//test:aspect.bzl', 'my_rule')", "my_rule(name = 'xxx', my_attr = 4)");
    reporter.removeHandler(failFastHandler);
    try {
        AnalysisResult result = update(ImmutableList.<String>of(), "//test:xxx");
        assertThat(keepGoing()).isTrue();
        assertThat(result.hasError()).isTrue();
    } catch (Exception e) {
    // expect to fail.
    }
    assertContainsEvent("Aspect //test:aspect.bzl%MyAspectMismatch requires rule my_rule to specify attribute " + "'my_attr' with type string.");
}
Also used : AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) ViewCreationFailedException(com.google.devtools.build.lib.analysis.ViewCreationFailedException) TargetParsingException(com.google.devtools.build.lib.cmdline.TargetParsingException) Test(org.junit.Test)

Example 58 with AnalysisResult

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

the class SkylarkAspectsTest method topLevelAspectsAndExtraActions.

@Test
public void topLevelAspectsAndExtraActions() throws Exception {
    scratch.file("test/aspect.bzl", "def _aspect_impl(target,ctx):", "  f = ctx.new_file('dummy.txt')", "  ctx.action(outputs = [f], command='echo xxx > $(location f)', mnemonic='AspectAction')", "  return struct()", "my_aspect = aspect(implementation = _aspect_impl)");
    scratch.file("test/BUILD", "extra_action(", "    name = 'xa',", "    cmd = 'echo $(EXTRA_ACTION_FILE) > $(output file.xa)',", "    out_templates = ['file.xa'],", ")", "action_listener(", "    name = 'al',", "    mnemonics = [ 'AspectAction' ],", "    extra_actions = [ ':xa' ])", "java_library(name = 'xxx')");
    useConfiguration("--experimental_action_listener=//test:al");
    AnalysisResult analysisResult = update(ImmutableList.<String>of("test/aspect.bzl%my_aspect"), "//test:xxx");
    assertThat(Iterables.transform(analysisResult.getAdditionalArtifactsToBuild(), new Function<Artifact, String>() {

        @Override
        public String apply(Artifact artifact) {
            return artifact.getFilename();
        }
    })).contains("file.xa");
}
Also used : AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 59 with AnalysisResult

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

the class SkylarkAspectsTest method aspectOnAspectInconsistentVisibilityIndirect.

@Test
public void aspectOnAspectInconsistentVisibilityIndirect() 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])})", "def _r0_impl(ctx):", "  pass", "r0 = rule(_r0_impl, attrs = { 'dep' : attr.label()})");
    scratch.file("test/BUILD", "load(':aspect.bzl', 'r0', 'r1', 'r2')", "r0(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')", "r0(name = 'r0_2', dep = ':r2_1')");
    reporter.removeHandler(failFastHandler);
    try {
        AnalysisResult analysisResult = update("//test:r0_2");
        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 60 with AnalysisResult

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

the class SkylarkAspectsTest method duplicateOutputGroupsFromTwoAspects.

@Test
public void duplicateOutputGroupsFromTwoAspects() throws Exception {
    scratch.file("test/aspect.bzl", "def _a1_impl(target, ctx):", "  f = ctx.new_file(target.label.name + '_a1.txt')", "  ctx.file_action(f, 'f')", "  return struct(output_groups = { 'a1_group' : depset([f]) })", "", "a1 = aspect(implementation=_a1_impl, attr_aspects = ['dep'])", "def _rule_impl(ctx):", "  if not ctx.attr.dep:", "     return struct()", "  og = {k:ctx.attr.dep.output_groups[k] for k in ctx.attr.dep.output_groups}", "  return struct(output_groups = og)", "my_rule1 = rule(_rule_impl, attrs = { 'dep' : attr.label(aspects = [a1]) })", "def _a2_impl(target, ctx):", "  g = ctx.new_file(target.label.name + '_a2.txt')", "  ctx.file_action(g, 'f')", "  return struct(output_groups = { 'a1_group' : depset([g]) })", "", "a2 = aspect(implementation=_a2_impl, attr_aspects = ['dep'])", "my_rule2 = rule(_rule_impl, attrs = { 'dep' : attr.label(aspects = [a2]) })");
    scratch.file("test/BUILD", "load(':aspect.bzl', 'my_rule1', 'my_rule2')", "my_rule1(name = 'base')", "my_rule1(name = 'xxx', dep = ':base')", "my_rule2(name = 'yyy', dep = ':xxx')");
    reporter.removeHandler(failFastHandler);
    try {
        AnalysisResult analysisResult = update("//test:yyy");
        assertThat(analysisResult.hasError()).isTrue();
        assertThat(keepGoing()).isTrue();
    } catch (ViewCreationFailedException e) {
    // expected.
    }
    assertContainsEvent("ERROR /workspace/test/BUILD:3:1: Output group a1_group provided twice");
}
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