Search in sources :

Example 16 with AnalysisResult

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

the class SkylarkAspectsTest method toplevelAspectOnFile.

@Test
public void toplevelAspectOnFile() throws Exception {
    scratch.file("test/aspect.bzl", "def _impl(target, ctx):", "   print('This aspect does nothing')", "   return struct()", "MyAspect = aspect(implementation=_impl)");
    scratch.file("test/BUILD", "exports_files(['file.txt'])");
    scratch.file("test/file.txt", "");
    AnalysisResult analysisResult = update(ImmutableList.of("test/aspect.bzl%MyAspect"), "//test:file.txt");
    assertThat(analysisResult.hasError()).isFalse();
    assertThat(analysisResult.getAspects()).isEmpty();
}
Also used : AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Test(org.junit.Test)

Example 17 with AnalysisResult

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

the class SkylarkAspectsTest method outputGroupsFromTwoAspects.

@Test
public void outputGroupsFromTwoAspects() 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 = { 'a2_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')");
    AnalysisResult analysisResult = update("//test:yyy");
    OutputGroupProvider outputGroupProvider = Iterables.getOnlyElement(analysisResult.getTargetsToBuild()).getProvider(OutputGroupProvider.class);
    assertThat(getOutputGroupContents(outputGroupProvider, "a1_group")).containsExactly("test/base_a1.txt");
    assertThat(getOutputGroupContents(outputGroupProvider, "a2_group")).containsExactly("test/xxx_a2.txt");
}
Also used : OutputGroupProvider(com.google.devtools.build.lib.analysis.OutputGroupProvider) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Test(org.junit.Test)

Example 18 with AnalysisResult

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

the class SkylarkAspectsTest method aspectParameters.

@Test
public void aspectParameters() throws Exception {
    scratch.file("test/aspect.bzl", "def _impl(target, ctx):", "   return struct()", "def _rule_impl(ctx):", "   return struct()", "MyAspect = aspect(", "    implementation=_impl,", "    attrs = { 'my_attr' : attr.string(values=['aaa']) },", ")", "my_rule = rule(", "    implementation=_rule_impl,", "    attrs = { 'deps' : attr.label_list(aspects=[MyAspect]),", "              'my_attr' : attr.string() },", ")");
    scratch.file("test/BUILD", "load('//test:aspect.bzl', 'my_rule')", "my_rule(name = 'xxx', my_attr = 'aaa')");
    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 19 with AnalysisResult

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

the class SkylarkAspectsTest method sharedAttributeDefintionWithAspects.

@Test
public void sharedAttributeDefintionWithAspects() throws Exception {
    scratch.file("test/aspect.bzl", "def _aspect_impl(target,ctx):", "  return struct()", "my_aspect = aspect(implementation = _aspect_impl)", "_ATTR = { 'deps' : attr.label_list(aspects = [my_aspect]) }", "def _dummy_impl(ctx):", "  pass", "r1 = rule(_dummy_impl, attrs =  _ATTR)", "r2 = rule(_dummy_impl, attrs =  _ATTR)");
    scratch.file("test/BUILD", "load(':aspect.bzl', 'r1', 'r2')", "r1(name = 't1')", "r2(name = 't2', deps = [':t1'])");
    AnalysisResult analysisResult = update("//test:t2");
    assertThat(analysisResult.hasError()).isFalse();
}
Also used : AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Test(org.junit.Test)

Example 20 with AnalysisResult

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

the class SkylarkAspectsTest method aspectAdvertisingProviders.

@Test
public void aspectAdvertisingProviders() throws Exception {
    scratch.file("test/aspect.bzl", "def _impl(target, ctx):", "   return struct()", "my_aspect = aspect(_impl, provides = ['foo'])", "a_dict = { 'foo' : attr.label_list(aspects = [my_aspect]) }");
    scratch.file("test/BUILD", "java_library(name = 'xxx',)");
    reporter.removeHandler(failFastHandler);
    try {
        AnalysisResult analysisResult = update(ImmutableList.of("//test:aspect.bzl%my_aspect"), "//test:xxx");
        assertThat(keepGoing()).isTrue();
        assertThat(analysisResult.hasError()).isTrue();
    } catch (ViewCreationFailedException e) {
    // expect exception
    }
    assertContainsEvent("Aspect '//test:aspect.bzl%my_aspect', applied to '//test:xxx', " + "does not provide advertised provider 'foo'");
}
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