aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/skylark
diff options
context:
space:
mode:
authorGravatar Michael Staib <mstaib@google.com>2016-01-20 21:37:05 +0000
committerGravatar Lukacs Berki <lberki@google.com>2016-01-21 10:35:03 +0000
commit8824d5ec1e58ca92fe04df932e7f649a6add715c (patch)
treec78485707baeb88bb1fc11374c9d87151fab74ea /src/test/java/com/google/devtools/build/lib/skylark
parentbd9f25c593a140acb15d3fd3fc7f66d091e1a898 (diff)
Enforce aspect configuration fragment specification when present.
If an aspect has specified its configuration fragment dependencies, use these in place of the rule's. Note that the dynamic configuration support for this is yet to come. Also in this CL: * RuleContext is constructed with a ruleClassNameForLogging, which allows error messages involving aspects to be clearer. RELNOTES[NEW]: Skylark aspects can now specify configuration fragment dependencies with fragments and host_fragments like rules can. -- MOS_MIGRATED_REVID=112614357
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/skylark')
-rw-r--r--src/test/java/com/google/devtools/build/lib/skylark/SkylarkAspectsTest.java120
1 files changed, 117 insertions, 3 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkAspectsTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkAspectsTest.java
index 33ee3af822..2e6935ca58 100644
--- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkAspectsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkAspectsTest.java
@@ -314,7 +314,8 @@ public class SkylarkAspectsTest extends AnalysisTestCase {
// expect to fail.
}
assertContainsEvent(
- "ERROR /workspace/test/BUILD:1:1: in java_library rule //test:xxx: \n"
+ "ERROR /workspace/test/BUILD:1:1: in "
+ + "//test:aspect.bzl%MyAspect aspect on java_library rule //test:xxx: \n"
+ "Traceback (most recent call last):\n"
+ "\tFile \"/workspace/test/BUILD\", line 1\n"
+ "\t\t//test:aspect.bzl%MyAspect(...)\n"
@@ -363,7 +364,8 @@ public class SkylarkAspectsTest extends AnalysisTestCase {
// expect to fail.
}
assertContainsEvent(
- "ERROR /workspace/test/BUILD:1:1: in java_library rule //test:xxx: \n"
+ "ERROR /workspace/test/BUILD:1:1: in //test:aspect.bzl%MyAspect aspect on java_library rule"
+ + " //test:xxx: \n"
+ "\n"
+ "\n"
+ "/workspace/test/aspect.bzl:4:11: Value of provider 'x' is of an illegal type: function");
@@ -388,7 +390,8 @@ public class SkylarkAspectsTest extends AnalysisTestCase {
// expect to fail.
}
assertContainsEvent(
- "ERROR /workspace/test/BUILD:1:1: in java_library rule //test:xxx: \n"
+ "ERROR /workspace/test/BUILD:1:1: in "
+ + "//test:aspect.bzl%MyAspect aspect on java_library rule //test:xxx: \n"
+ "\n"
+ "\n"
+ "The following files have no generating action:\n"
@@ -457,4 +460,115 @@ public class SkylarkAspectsTest extends AnalysisTestCase {
+ "Please create a BUILD file in the same or any parent directory. "
+ "Note that this BUILD file does not need to do anything except exist.");
}
+
+ @Test
+ public void testAspectFragmentAccessSuccess() throws Exception {
+ getConfiguredTargetForAspectFragment(
+ "ctx.fragments.cpp.compiler", "'cpp'", "", "", "");
+ assertNoEvents();
+ }
+
+ @Test
+ public void testAspectHostFragmentAccessSuccess() throws Exception {
+ getConfiguredTargetForAspectFragment(
+ "ctx.host_fragments.cpp.compiler", "", "'cpp'", "", "");
+ assertNoEvents();
+ }
+
+ @Test
+ public void testAspectFragmentAccessError() throws Exception {
+ reporter.removeHandler(failFastHandler);
+ try {
+ getConfiguredTargetForAspectFragment(
+ "ctx.fragments.cpp.compiler", "'java'", "'cpp'", "'cpp'", "");
+ fail("update() should have failed");
+ } catch (ViewCreationFailedException e) {
+ // expected
+ }
+ assertContainsEvent(
+ "//test:aspect.bzl%MyAspect aspect on my_rule has to declare 'cpp' as a "
+ + "required fragment in target configuration in order to access it. Please update the "
+ + "'fragments' argument of the rule definition "
+ + "(for example: fragments = [\"cpp\"])");
+ }
+
+ @Test
+ public void testAspectHostFragmentAccessError() throws Exception {
+ reporter.removeHandler(failFastHandler);
+ try {
+ getConfiguredTargetForAspectFragment(
+ "ctx.host_fragments.cpp.compiler", "'cpp'", "'java'", "", "'cpp'");
+ fail("update() should have failed");
+ } catch (ViewCreationFailedException e) {
+ // expected
+ }
+ assertContainsEvent(
+ "//test:aspect.bzl%MyAspect aspect on my_rule has to declare 'cpp' as a "
+ + "required fragment in host configuration in order to access it. Please update the "
+ + "'host_fragments' argument of the rule definition "
+ + "(for example: host_fragments = [\"cpp\"])");
+ }
+
+ @Test
+ public void testAspectFragmentFallback() throws Exception {
+ // TODO(mstaib): Remove this test when rule fragment fallback is no longer permitted.
+ getConfiguredTargetForAspectFragment(
+ "ctx.fragments.cpp.compiler", "", "", "'cpp'", "");
+ assertNoEvents();
+ }
+
+ @Test
+ public void testAspectHostFragmentFallback() throws Exception {
+ // TODO(mstaib): Remove this test when rule fragment fallback is no longer permitted.
+ getConfiguredTargetForAspectFragment(
+ "ctx.host_fragments.cpp.compiler", "", "", "", "'cpp'");
+ assertNoEvents();
+ }
+
+
+ private ConfiguredTarget getConfiguredTargetForAspectFragment(
+ String fullFieldName,
+ String fragments,
+ String hostFragments,
+ String ruleFragments,
+ String ruleHostFragments)
+ throws Exception {
+ scratch.file(
+ "test/aspect.bzl",
+ "def _aspect_impl(target, ctx):",
+ " return struct(result = str(" + fullFieldName + "))",
+ "",
+ "def _rule_impl(ctx):",
+ " return struct(stuff = '...')",
+ "",
+ "MyAspect = aspect(",
+ " implementation=_aspect_impl,",
+ " attr_aspects=['deps'],",
+ " fragments=[" + fragments + "],",
+ " host_fragments=[" + hostFragments + "],",
+ ")",
+ "my_rule = rule(",
+ " implementation=_rule_impl,",
+ " attrs = { 'attr' : ",
+ " attr.label_list(mandatory=True, allow_files=True, aspects = [MyAspect]) },",
+ " fragments=[" + ruleFragments + "],",
+ " host_fragments=[" + ruleHostFragments + "],",
+ ")");
+ scratch.file(
+ "test/BUILD",
+ "load('/test/aspect', 'my_rule')",
+ "exports_files(['zzz'])",
+ "my_rule(",
+ " name = 'yyy',",
+ " attr = ['zzz'],",
+ ")",
+ "my_rule(",
+ " name = 'xxx',",
+ " attr = ['yyy'],",
+ ")");
+
+ update(ImmutableList.of("test/aspect.bzl%MyAspect"), "//test:xxx");
+
+ return getConfiguredTarget("//test:xxx");
+ }
}