Search in sources :

Example 36 with AnalysisResult

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

the class BuildViewTest method testHelpfulErrorForWrongPackageLabels.

@Test
public void testHelpfulErrorForWrongPackageLabels() throws Exception {
    reporter.removeHandler(failFastHandler);
    scratch.file("x/BUILD", "cc_library(name='x', srcs=['x.cc'])");
    scratch.file("y/BUILD", "cc_library(name='y', srcs=['y.cc'], deps=['//x:z'])");
    AnalysisResult result = update(defaultFlags().with(Flag.KEEP_GOING), "//y:y");
    assertThat(result.hasError()).isTrue();
    assertContainsEvent("no such target '//x:z': " + "target 'z' not declared in package 'x' " + "defined by /workspace/x/BUILD and referenced by '//y:y'");
}
Also used : AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Test(org.junit.Test)

Example 37 with AnalysisResult

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

the class SkylarkAspectsTest method topLevelAspectIsNotAnAspect.

@Test
public void topLevelAspectIsNotAnAspect() throws Exception {
    scratch.file("test/aspect.bzl", "MyAspect = 4");
    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("MyAspect from //test:aspect.bzl is not an aspect");
}
Also used : ViewCreationFailedException(com.google.devtools.build.lib.analysis.ViewCreationFailedException) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Test(org.junit.Test)

Example 38 with AnalysisResult

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

the class SkylarkAspectsTest method aspectOnAspectLinear.

/**
   * Simple straightforward linear aspects-on-aspects.
   */
@Test
public void aspectOnAspectLinear() 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')", "r1(name = 'r1', dep = ':r0')", "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)

Example 39 with AnalysisResult

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

the class SkylarkAspectsTest method aspectWithOutputGroupsAsList.

@Test
public void aspectWithOutputGroupsAsList() throws Exception {
    scratch.file("test/aspect.bzl", "def _impl(target, ctx):", "   g = target.output_group('_hidden_top_level" + INTERNAL_SUFFIX + "')", "   return struct(output_groups = { 'my_result' : [ f for f in g] })", "", "MyAspect = aspect(", "   implementation=_impl,", ")");
    scratch.file("test/BUILD", "java_library(", "     name = 'xxx',", "     srcs = ['A.java'],", ")");
    AnalysisResult analysisResult = update(ImmutableList.of("test/aspect.bzl%MyAspect"), "//test:xxx");
    assertThat(transform(analysisResult.getTargetsToBuild(), new Function<ConfiguredTarget, String>() {

        @Nullable
        @Override
        public String apply(ConfiguredTarget configuredTarget) {
            return configuredTarget.getLabel().toString();
        }
    })).containsExactly("//test:xxx");
    AspectValue aspectValue = analysisResult.getAspects().iterator().next();
    OutputGroupProvider outputGroupProvider = aspectValue.getConfiguredAspect().getProvider(OutputGroupProvider.class);
    assertThat(outputGroupProvider).isNotNull();
    NestedSet<Artifact> names = outputGroupProvider.getOutputGroup("my_result");
    assertThat(names).isNotEmpty();
    NestedSet<Artifact> expectedSet = getConfiguredTarget("//test:xxx").getProvider(OutputGroupProvider.class).getOutputGroup(OutputGroupProvider.HIDDEN_TOP_LEVEL);
    assertThat(names).containsExactlyElementsIn(expectedSet);
}
Also used : AspectValue(com.google.devtools.build.lib.skyframe.AspectValue) OutputGroupProvider(com.google.devtools.build.lib.analysis.OutputGroupProvider) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Nullable(javax.annotation.Nullable) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 40 with AnalysisResult

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

the class SkylarkAspectsTest method aspectCommandLineRepoLabel.

@Test
public void aspectCommandLineRepoLabel() throws Exception {
    scratch.overwriteFile("WORKSPACE", scratch.readFile("WORKSPACE"), "local_repository(name='local', path='local/repo')");
    scratch.file("local/repo/aspect.bzl", "def _impl(target, ctx):", "   print('This aspect does nothing')", "   return struct()", "MyAspect = aspect(implementation=_impl)");
    scratch.file("local/repo/BUILD");
    scratch.file("test/BUILD", "java_library(name = 'xxx',)");
    AnalysisResult analysisResult = update(ImmutableList.of("@local//:aspect.bzl%MyAspect"), "//test:xxx");
    assertThat(getLabelsToBuild(analysisResult)).containsExactly("//test:xxx");
    assertThat(getAspectDescriptions(analysisResult)).containsExactly("@local//:aspect.bzl%MyAspect(//test:xxx)");
}
Also used : 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