Search in sources :

Example 46 with AnalysisResult

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

the class SkylarkAspectsTest method aspectFailingExecution.

@Test
public void aspectFailingExecution() throws Exception {
    scratch.file("test/aspect.bzl", "def _impl(target, ctx):", "   return 1/0", "", "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" + "Traceback (most recent call last):" + LINE_SEPARATOR + "\tFile \"/workspace/test/BUILD\", line 1" + LINE_SEPARATOR + "\t\t//test:aspect.bzl%MyAspect(...)" + LINE_SEPARATOR + "\tFile \"/workspace/test/aspect.bzl\", line 2, in _impl" + LINE_SEPARATOR + "\t\t1 / 0" + LINE_SEPARATOR + "integer division by zero");
}
Also used : ViewCreationFailedException(com.google.devtools.build.lib.analysis.ViewCreationFailedException) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Test(org.junit.Test)

Example 47 with AnalysisResult

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

the class SkylarkAspectsTest method buildTargetAndCheckRuleInfo.

private void buildTargetAndCheckRuleInfo(String... expectedLabels) throws Exception {
    AnalysisResult result = update(ImmutableList.<String>of(), "//test:r2");
    ConfiguredTarget configuredTarget = result.getTargetsToBuild().iterator().next();
    SkylarkNestedSet ruleInfoValue = (SkylarkNestedSet) configuredTarget.getProvider(SkylarkProviders.class).getValue("rule_info");
    assertThat(ruleInfoValue.getSet(String.class)).containsExactlyElementsIn(Arrays.asList(expectedLabels));
}
Also used : ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) SkylarkNestedSet(com.google.devtools.build.lib.syntax.SkylarkNestedSet)

Example 48 with AnalysisResult

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

the class SkylarkAspectsTest method aspectParametersOptional.

@Test
public void aspectParametersOptional() throws Exception {
    scratch.file("test/aspect.bzl", "def _impl(target, ctx):", "   return struct()", "def _rule_impl(ctx):", "   return struct()", "MyAspectOptParam = aspect(", "    implementation=_impl,", "    attrs = { 'my_attr' : attr.string(values=['aaa'], default='aaa') },", ")", "my_rule = rule(", "    implementation=_rule_impl,", "    attrs = { 'deps' : attr.label_list(aspects=[MyAspectOptParam]) },", ")");
    scratch.file("test/BUILD", "load('//test:aspect.bzl', 'my_rule')", "my_rule(name = 'xxx')");
    AnalysisResult result = update(ImmutableList.<String>of(), "//test:xxx");
    assertThat(result.hasError()).isFalse();
}
Also used : AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Test(org.junit.Test)

Example 49 with AnalysisResult

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

the class SkylarkAspectsTest method duplicateOutputGroups.

@Test
public void duplicateOutputGroups() throws Exception {
    scratch.file("test/aspect.bzl", "def _impl(target, ctx):", "  f = ctx.new_file('f.txt')", "  ctx.file_action(f, 'f')", "  return struct(output_groups = { 'duplicate' : depset([f]) })", "", "MyAspect = aspect(implementation=_impl)", "def _rule_impl(ctx):", "  g = ctx.new_file('g.txt')", "  ctx.file_action(g, 'g')", "  return struct(output_groups = { 'duplicate' : depset([g]) })", "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: Output group 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 50 with AnalysisResult

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

the class SkylarkAspectsTest method aspectOnAspectLinearAlias.

/**
   * Linear aspects-on-aspects with alias rule.
   */
@Test
public void aspectOnAspectLinearAlias() 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):", "  value = []", "  if hasattr(ctx.rule.attr.dep, 'a2p'):", "     value += ctx.rule.attr.dep.a2p.value", "  if hasattr(target, 'a1p'):", "     value.append(str(target.label) + str(ctx.aspect_ids) + '=yes')", "  else:", "     value.append(str(target.label) + str(ctx.aspect_ids) + '=no')", "  return struct(a2p = a2p(value = value))", "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')", "alias(name = 'a0', actual = ':r0')", "r1(name = 'r1', dep = ':a0')", "r2(name = 'r2', dep = ':r1')");
    AnalysisResult analysisResult = update("//test:r2");
    ConfiguredTarget target = Iterables.getOnlyElement(analysisResult.getTargetsToBuild());
    SkylarkList<?> result = (SkylarkList<?>) target.get("result");
    // "yes" means that aspect a2 sees a1's providers.
    assertThat(result).containsExactly("//test:r0[\"//test:aspect.bzl%a1\", \"//test:aspect.bzl%a2\"]=yes", "//test:r1[\"//test:aspect.bzl%a2\"]=no");
}
Also used : SkylarkList(com.google.devtools.build.lib.syntax.SkylarkList) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) 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