diff options
author | gregce <gregce@google.com> | 2018-08-08 10:43:59 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-08-08 10:45:57 -0700 |
commit | f2a07a7336445b9b427c144c95663c2f2649a307 (patch) | |
tree | f4408c5b57fa270456deef047f512e6fb59ffa17 /src/test | |
parent | 8ed7d9670e619b6c0d2ef35ace61ede1562b9d56 (diff) |
Improve error messaging for constraints violations.
1) Break up dense lines with clearer pretty-printing.
2) When a violation happens because of a select(), mention
both the target with the select (as before) *and*
the dep that the select() chose.
3) Integrate this messaging into --target_environment violations,
which currently provide no info about the root cause.
Examples:
-------------------------------------
select() + compatible_with violation:
-------------------------------------
Before:
ERROR: /workspace/testapp/BUILD:41:1: in cc_binary rule //testapp:top: the current command-line flags disqualify all supported environments because of incompatible select() paths:
environment: //constraints:p removed by: //testapp:midlib (/workspace/testapp/BUILD:28:1)
After:
ERROR: /workspace/testapp/BUILD:41:1: in cc_binary rule //testapp:top: the current command line flags disqualify all supported environments because of incompatible select() paths:
environment: //constraints:p
removed by: //testapp:midlib (/workspace/testapp/BUILD:28:1)
which has a select() that chooses dep: //testapp:glib
which lacks: //constraints:p.
-------------------------------------
select() + --target_environment=//constraints:p violation:
-------------------------------------
Before:
ERROR: This is a restricted-environment build.
- //testapp:top does not support required environment //constraints:p
After:
ERROR: This is a restricted-environment build.
//testapp:top does not support:
environment: //constraints:p
removed by: //testapp:midlib (/workspace/testapp/BUILD:28:1)
which has a select() that chooses dep: //testapp:g
which lacks: //constraints:p
Fixes: #5795
PiperOrigin-RevId: 207910308
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/analysis/constraints/ConstraintsTest.java | 80 |
1 files changed, 58 insertions, 22 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/constraints/ConstraintsTest.java b/src/test/java/com/google/devtools/build/lib/analysis/constraints/ConstraintsTest.java index 0aa30d4273..a3f82cbc6e 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/constraints/ConstraintsTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/constraints/ConstraintsTest.java @@ -1060,9 +1060,14 @@ public class ConstraintsTest extends AbstractConstraintsTest { reporter.removeHandler(failFastHandler); // Invalid because "--define mode=a" refines :lib to "compatible_with = []" (empty). assertThat(getConfiguredTarget("//hello:lib")).isNull(); - assertContainsEvent("//hello:lib: the current command-line flags disqualify all supported " - + "environments because of incompatible select() paths:\n" - + " environment: //buildenv/foo:b removed by: //hello:lib (/workspace/hello/BUILD:1:1)"); + assertContainsEvent("" + + "//hello:lib: the current command line flags disqualify all supported environments " + + "because of incompatible select() paths:\n" + + " \n" + + " environment: //buildenv/foo:b\n" + + " removed by: //hello:lib (/workspace/hello/BUILD:1:1)\n" + + " which has a select() that chooses dep: //deps:dep_a\n" + + " which lacks: //buildenv/foo:b"); } @Test @@ -1110,9 +1115,14 @@ public class ConstraintsTest extends AbstractConstraintsTest { reporter.removeHandler(failFastHandler); // Invalid because "--define mode=a" refines :lib to "compatible_with = ['//buildenv/foo:a']". assertThat(getConfiguredTarget("//hello:depender")).isNull(); - assertContainsEvent("//hello:depender: the current command-line flags disqualify all supported " - + "environments because of incompatible select() paths:\n" - + " environment: //buildenv/foo:b removed by: //hello:lib (/workspace/hello/BUILD:1:1)"); + assertContainsEvent("" + + "//hello:depender: the current command line flags disqualify all supported environments " + + "because of incompatible select() paths:\n" + + " \n" + + " environment: //buildenv/foo:b\n" + + " removed by: //hello:lib (/workspace/hello/BUILD:1:1)\n" + + " which has a select() that chooses dep: //deps:dep_a\n" + + " which lacks: //buildenv/foo:b"); } @Test @@ -1145,9 +1155,14 @@ public class ConstraintsTest extends AbstractConstraintsTest { reporter.removeHandler(failFastHandler); // Invalid because "--define mode=a" refines :lib to "compatible_with = ['//buildenv/foo:a']". assertThat(getConfiguredTarget("//hello:depender")).isNull(); - assertContainsEvent("//hello:depender: the current command-line flags disqualify all supported " - + "environments because of incompatible select() paths:\n" - + " environment: //buildenv/foo:b removed by: //hello:lib2 (/workspace/hello/BUILD:1:1)"); + assertContainsEvent("" + + "//hello:depender: the current command line flags disqualify all supported environments " + + "because of incompatible select() paths:\n" + + " \n" + + " environment: //buildenv/foo:b\n" + + " removed by: //hello:lib2 (/workspace/hello/BUILD:1:1)\n" + + " which has a select() that chooses dep: //deps:dep_a\n" + + " which lacks: //buildenv/foo:b"); } @Test @@ -1167,9 +1182,14 @@ public class ConstraintsTest extends AbstractConstraintsTest { // Invalid because :lib has an implicit default of ['//buildenv/foo:b'] and "--define mode=a" // refines it to "compatible_with = []" (empty). assertThat(getConfiguredTarget("//hello:lib")).isNull(); - assertContainsEvent("//hello:lib: the current command-line flags disqualify all supported " - + "environments because of incompatible select() paths:\n" - + " environment: //buildenv/foo:b removed by: //hello:lib (/workspace/hello/BUILD:1:1)"); + assertContainsEvent("" + + "//hello:lib: the current command line flags disqualify all supported environments " + + "because of incompatible select() paths:\n" + + " \n" + + " environment: //buildenv/foo:b\n" + + " removed by: //hello:lib (/workspace/hello/BUILD:1:1)\n" + + " which has a select() that chooses dep: //deps:dep_a\n" + + " which lacks: //buildenv/foo:b"); } @Test @@ -1199,9 +1219,14 @@ public class ConstraintsTest extends AbstractConstraintsTest { // Invalid because while the //buildenv/foo refinement successfully refines :lib to // ['//buildenv/foo:a'], the bar refinement refines it to []. assertThat(getConfiguredTarget("//hello:lib")).isNull(); - assertContainsEvent("//hello:lib: the current command-line flags disqualify all supported " - + "environments because of incompatible select() paths:\n" - + " environment: //buildenv/bar:c removed by: //hello:lib (/workspace/hello/BUILD:1:1)"); + assertContainsEvent("" + + "//hello:lib: the current command line flags disqualify all supported environments " + + "because of incompatible select() paths:\n" + + " \n" + + " environment: //buildenv/bar:c\n" + + " removed by: //hello:lib (/workspace/hello/BUILD:1:1)\n" + + " which has a select() that chooses dep: //deps:dep_a\n" + + " which lacks: //buildenv/bar:c"); } /** @@ -1232,12 +1257,23 @@ public class ConstraintsTest extends AbstractConstraintsTest { useConfiguration("--define", "mode=a"); reporter.removeHandler(failFastHandler); assertThat(getConfiguredTarget("//hello:lib")).isNull(); - assertContainsEvent("//hello:lib: the current command-line flags disqualify all supported " - + "environments because of incompatible select() paths:\n" - + "\nenvironment group: //buildenv/foo:foo:\n" - + " environment: //buildenv/foo:a removed by: //hello:lib (/workspace/hello/BUILD:9:1)\n" - + "\nenvironment group: //buildenv/bar:bar:\n" - + " environment: //buildenv/bar:c removed by: //hello:lib (/workspace/hello/BUILD:9:1)"); + assertContainsEvent("" + + "//hello:lib: the current command line flags disqualify all supported environments " + + "because of incompatible select() paths:\n" + + " \n" + + "environment group: //buildenv/foo:foo:\n" + + " \n" + + " environment: //buildenv/foo:a\n" + + " removed by: //hello:lib (/workspace/hello/BUILD:9:1)\n" + + " which has a select() that chooses dep: //hello:all_groups_gone\n" + + " which lacks: //buildenv/foo:a\n" + + " \n" + + "environment group: //buildenv/bar:bar:\n" + + " \n" + + " environment: //buildenv/bar:c\n" + + " removed by: //hello:lib (/workspace/hello/BUILD:9:1)\n" + + " which has a select() that chooses dep: //hello:all_groups_gone\n" + + " which lacks: //buildenv/bar:c"); } private void writeRulesForRefiningSubsetTests(String topLevelRestrictedTo) throws Exception { @@ -1281,7 +1317,7 @@ public class ConstraintsTest extends AbstractConstraintsTest { writeRulesForRefiningSubsetTests("b"); reporter.removeHandler(failFastHandler); assertThat(getConfiguredTarget("//hello:lib")).isNull(); - assertContainsEvent("//hello:lib: the current command-line flags disqualify all supported " + assertContainsEvent("//hello:lib: the current command line flags disqualify all supported " + "environments because of incompatible select() paths"); } } |