diff options
author | 2016-11-17 16:52:10 +0000 | |
---|---|---|
committer | 2016-11-17 18:18:43 +0000 | |
commit | 2ca06f5beb9571215b12158d0dd945b72b00d38a (patch) | |
tree | cf2b0ab6847af757a604dfbcee30e02cf0a2da28 /src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java | |
parent | 4f3d4756c0ea7169048ce5ead748c33fc14713cd (diff) |
Introduce support for 'expand_if_all_available' for flag_groups in CROSSTOOL
With the recent addition of structured variables to CROSSTOOL we now need a way
how to conditionally expand various flag_groups depending on the presence of
particular build variable or its fields. This cl adds this support to flag
groups.
--
MOS_MIGRATED_REVID=139466070
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java index 71658dd0e7..5161ae5f4e 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java @@ -416,6 +416,115 @@ public class CcToolchainFeaturesTest { } @Test + public void testExpandIfAllAvailableWithStructsExpandsIfPresent() throws Exception { + assertThat( + getCommandLineForFlagGroups( + "flag_group {" + + " expand_if_all_available: 'struct'" + + " flag: '-A%{struct.foo}'" + + " flag: '-B%{struct.bar}'" + + "}", + createStructureVariables( + "struct", + new Variables.StructureBuilder() + .addField("foo", "fooValue") + .addField("bar", "barValue")))) + .containsExactly("-AfooValue", "-BbarValue"); + } + + @Test + public void testExpandIfAllAvailableWithStructsDoesntExpandIfMissing() throws Exception { + assertThat( + getCommandLineForFlagGroups( + "flag_group {" + + " expand_if_all_available: 'nonexistent'" + + " flag: '-A%{struct.foo}'" + + " flag: '-B%{struct.bar}'" + + "}", + createStructureVariables( + "struct", + new Variables.StructureBuilder() + .addField("foo", "fooValue") + .addField("bar", "barValue")))) + .isEmpty(); + } + + @Test + public void testExpandIfAllAvailableWithStructsDoesntCrashIfMissing() throws Exception { + assertThat( + getCommandLineForFlagGroups( + "flag_group {" + + " expand_if_all_available: 'nonexistent'" + + " flag: '-A%{nonexistent.foo}'" + + " flag: '-B%{nonexistent.bar}'" + + "}", + createVariables())) + .isEmpty(); + } + + @Test + public void testExpandIfAllAvailableWithStructFieldDoesntCrashIfMissing() throws Exception { + assertThat( + getCommandLineForFlagGroups( + "flag_group {" + + " expand_if_all_available: 'nonexistent.nonexistant_field'" + + " flag: '-A%{nonexistent.foo}'" + + " flag: '-B%{nonexistent.bar}'" + + "}", + createVariables())) + .isEmpty(); + } + + @Test + public void testExpandIfAllAvailableWithStructFieldExpandsIfPresent() throws Exception { + assertThat( + getCommandLineForFlagGroups( + "flag_group {" + + " expand_if_all_available: 'struct.foo'" + + " flag: '-A%{struct.foo}'" + + " flag: '-B%{struct.bar}'" + + "}", + createStructureVariables( + "struct", + new Variables.StructureBuilder() + .addField("foo", "fooValue") + .addField("bar", "barValue")))) + .containsExactly("-AfooValue", "-BbarValue"); + } + + @Test + public void testExpandIfAllAvailableWithStructFieldDoesntExpandIfMissing() throws Exception { + assertThat( + getCommandLineForFlagGroups( + "flag_group {" + + " expand_if_all_available: 'struct.foo'" + + " flag: '-A%{struct.foo}'" + + " flag: '-B%{struct.bar}'" + + "}", + createStructureVariables( + "struct", new Variables.StructureBuilder().addField("bar", "barValue")))) + .isEmpty(); + } + + @Test + public void testExpandIfAllAvailableWithStructFieldScopesRight() throws Exception { + assertThat( + getCommandLineForFlagGroups( + "flag_group {" + + " flag_group {" + + " expand_if_all_available: 'struct.foo'" + + " flag: '-A%{struct.foo}'" + + " }" + + " flag_group { " + + " flag: '-B%{struct.bar}'" + + " }" + + "}", + createStructureVariables( + "struct", new Variables.StructureBuilder().addField("bar", "barValue")))) + .containsExactly("-BbarValue"); + } + + @Test public void testLegacyListVariableExpansion() throws Exception { assertThat(getCommandLineForFlag("%{v}", createVariables("v", "1", "v", "2"))) .containsExactly("1", "2"); |