aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/rules/config
diff options
context:
space:
mode:
authorGravatar juliexxia <juliexxia@google.com>2017-09-20 23:53:15 +0200
committerGravatar László Csomor <laszlocsomor@google.com>2017-09-21 11:04:23 +0200
commit0e7051a55ab0396feeea7b6f9750594a02ef9c34 (patch)
tree356f27e43c9ba8381012fa3806431569a262e39a /src/test/java/com/google/devtools/build/lib/rules/config
parent4c3ef116e3aba72a0fc643b670e2cd872e85028d (diff)
Allow config_settings to match on constraint_values to a target_platform. This is on the way to making select() work with constraint_values re: #305.
PiperOrigin-RevId: 169454982
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/rules/config')
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/config/ConfigSettingTest.java132
1 files changed, 130 insertions, 2 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/rules/config/ConfigSettingTest.java b/src/test/java/com/google/devtools/build/lib/rules/config/ConfigSettingTest.java
index 9def906044..f45a85edca 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/config/ConfigSettingTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/config/ConfigSettingTest.java
@@ -239,9 +239,11 @@ public class ConfigSettingTest extends BuildViewTestCase {
*/
@Test
public void emptySettings() throws Exception {
- checkError("foo", "empty",
+ checkError(
+ "foo",
+ "empty",
"in config_setting rule //foo:empty: "
- + "Either values or flag_values must be specified and non-empty",
+ + "Either values, flag_values or constraint_values must be specified and non-empty",
"config_setting(",
" name = 'empty',",
" values = {})");
@@ -1122,4 +1124,130 @@ public class ConfigSettingTest extends BuildViewTestCase {
" default_value = 'valid',",
")");
}
+
+ @Test
+ public void constraintValue() throws Exception {
+ scratch.file(
+ "test/BUILD",
+ "constraint_setting(name = 'notable_building')",
+ "constraint_value(name = 'empire_state', constraint_setting = 'notable_building')",
+ "constraint_value(name = 'space_needle', constraint_setting = 'notable_building')",
+ "platform(",
+ " name = 'new_york_platform',",
+ " constraint_values = [':empire_state'],",
+ ")",
+ "platform(",
+ " name = 'seattle_platform',",
+ " constraint_values = [':space_needle'],",
+ ")",
+ "config_setting(",
+ " name = 'match',",
+ " constraint_values = [':empire_state'],",
+ ");");
+
+ useConfiguration("--experimental_platforms=//test:new_york_platform");
+ assertThat(getConfigMatchingProvider("//test:match").matches()).isTrue();
+ useConfiguration("--experimental_platforms=//test:seattle_platform");
+ assertThat(getConfigMatchingProvider("//test:match").matches()).isFalse();
+ useConfiguration("");
+ assertThat(getConfigMatchingProvider("//test:match").matches()).isFalse();
+ }
+
+ @Test
+ public void multipleConstraintValues() throws Exception {
+ scratch.file(
+ "test/BUILD",
+ "constraint_setting(name = 'notable_building')",
+ "constraint_value(name = 'empire_state', constraint_setting = 'notable_building')",
+ "constraint_setting(name = 'museum')",
+ "constraint_value(name = 'cloisters', constraint_setting = 'museum')",
+ "constraint_setting(name = 'theme_park')",
+ "constraint_value(name = 'coney_island', constraint_setting = 'theme_park')",
+ "platform(",
+ " name = 'manhattan_platform',",
+ " constraint_values = [",
+ " ':empire_state',",
+ " ':cloisters',",
+ " ],",
+ ")",
+ "platform(",
+ " name = 'museum_platform',",
+ " constraint_values = [':cloisters'],",
+ ")",
+ "platform(",
+ " name = 'new_york_platform',",
+ " constraint_values = [",
+ " ':empire_state',",
+ " ':cloisters',",
+ " ':coney_island',",
+ " ],",
+ ")",
+ "config_setting(",
+ " name = 'match',",
+ " constraint_values = [':empire_state', ':cloisters'],",
+ ");");
+ useConfiguration("--experimental_platforms=//test:manhattan_platform");
+ assertThat(getConfigMatchingProvider("//test:match").matches()).isTrue();
+ useConfiguration("--experimental_platforms=//test:museum_platform");
+ assertThat(getConfigMatchingProvider("//test:match").matches()).isFalse();
+ useConfiguration("--experimental_platforms=//test:new_york_platform");
+ assertThat(getConfigMatchingProvider("//test:match").matches()).isTrue();
+ }
+
+ @Test
+ public void definesAndConstraints() throws Exception {
+ scratch.file(
+ "test/BUILD",
+ "constraint_setting(name = 'notable_building')",
+ "constraint_value(name = 'empire_state', constraint_setting = 'notable_building')",
+ "constraint_value(name = 'space_needle', constraint_setting = 'notable_building')",
+ "platform(",
+ " name = 'new_york_platform',",
+ " constraint_values = [':empire_state'],",
+ ")",
+ "platform(",
+ " name = 'seattle_platform',",
+ " constraint_values = [':space_needle'],",
+ ")",
+ "config_setting(",
+ " name = 'match',",
+ " constraint_values = [':empire_state'],",
+ " values = {",
+ " 'define': 'a=c',",
+ " },",
+ " define_values = {",
+ " 'b': 'd',",
+ " },",
+ ");");
+
+ useConfiguration(
+ "--experimental_platforms=//test:new_york_platform", "--define", "a=c", "--define", "b=d");
+ assertThat(getConfigMatchingProvider("//test:match").matches()).isTrue();
+ useConfiguration("--experimental_platforms=//test:new_york_platform");
+ assertThat(getConfigMatchingProvider("//test:match").matches()).isFalse();
+ useConfiguration("--define", "a=c");
+ assertThat(getConfigMatchingProvider("//test:match").matches()).isFalse();
+ useConfiguration("--define", "a=c", "--experimental_platforms=//test:new_york_platform");
+ assertThat(getConfigMatchingProvider("//test:match").matches()).isFalse();
+ }
+
+ /**
+ * Tests that a config_setting doesn't allow a constraint_values list with more than one
+ * constraint value per constraint setting.
+ */
+ @Test
+ public void multipleValuesPerSetting() throws Exception {
+ checkError("foo", "bad",
+ "in :target_platforms attribute of config_setting rule //foo:bad: "
+ + "error while parsing configuration settings: "
+ + "the target platform contains multiple values '//foo:space_needle' "
+ + "and '//foo:empire_state' that map to the same setting '//foo:notable_building'",
+ "constraint_setting(name = 'notable_building')",
+ "constraint_value(name = 'empire_state', constraint_setting = 'notable_building')",
+ "constraint_value(name = 'space_needle', constraint_setting = 'notable_building')",
+ "config_setting(",
+ " name = 'bad',",
+ " constraint_values = [':empire_state', ':space_needle'],",
+ ");");
+ }
}