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();
}
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");
}
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();
}
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();
}
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'");
}
Aggregations