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