From cd95f3cbd25c58d7fba964ac8b61ef63fb8585c1 Mon Sep 17 00:00:00 2001 From: gregce Date: Mon, 5 Jun 2017 15:33:48 -0400 Subject: Make compatible_with = ["all", "foo"] the same as compatible_with = ["all"]. Assuming "all" fulfills "foo", these should be exactly the same (and maybe we should trigger a redundant listing error). In practice, it's possible to make the first case succeed while the second fails because of environment refining and lack of static constraint checking for selects. See changes for details. Also refactor ConstraintSemantics.checkConstraints to divide and conquer more clearly. PiperOrigin-RevId: 158047217 --- .../lib/analysis/constraints/ConstraintsTest.java | 46 +++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) (limited to 'src/test/java/com/google/devtools/build/lib/analysis') 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 fac4f006b6..1bf3b0f27a 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 @@ -1266,5 +1266,49 @@ public class ConstraintsTest extends AbstractConstraintsTest { + "\nenvironment group: //buildenv/bar:bar:\n" + " environment: //buildenv/bar:c removed by: //hello:lib (/workspace/hello/BUILD:9:1)"); } -} + private void writeRulesForRefiningSubsetTests(String topLevelRestrictedTo) throws Exception { + new EnvironmentGroupMaker("buildenv/foo") + .setEnvironments("a", "b", "all") + .setFulfills("all", "a") + .setFulfills("all", "b") + .setDefaults() + .make(); + scratch.file("hello/BUILD", + "cc_library(", + " name = 'lib',", + " srcs = [],", + " deps = [':dep1'],", + " restricted_to = ['//buildenv/foo:" + topLevelRestrictedTo + "'])", + "cc_library(", + " name = 'dep1',", + " srcs = [],", + // This is technically illegal because "dep1" declares support for both "a" and "b" but + // no dependency under the select can provide "b". This is known as "static select + // constraint checking" and is currently an unimplemented Bazel TODO. + " deps = select({", + " '//config:a': [':dep2'],", + " '//conditions:default': [':dep2'],", + " }),", + " restricted_to = ['//buildenv/foo:all'])", + "cc_library(", + " name = 'dep2',", + " srcs = [],", + " compatible_with = ['//buildenv/foo:a'])"); + } + + @Test + public void refiningReplacesRemovedEnvironmentWithValidFulfillingSubset() throws Exception { + writeRulesForRefiningSubsetTests("a"); + assertThat(getConfiguredTarget("//hello:lib")).isNotNull(); + } + + @Test + public void refiningReplacesRemovedEnvironmentWithInvalidFulfillingSubset() throws Exception { + writeRulesForRefiningSubsetTests("b"); + 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"); + } +} -- cgit v1.2.3