diff options
author | Chris Parsons <cparsons@google.com> | 2016-01-07 16:56:37 +0000 |
---|---|---|
committer | Damien Martin-Guillerez <dmarting@google.com> | 2016-01-07 20:20:06 +0000 |
commit | efe22ec3338a82a0e4c3f5c256f5f86a27fc4f4e (patch) | |
tree | 989a7243eaf6ff39fe46a9cdcc933f04ed76c424 /src/test/java | |
parent | 6ecf17a26b1907362c45410c6399533e48f8c467 (diff) |
Extend crosstool configuration to allow features to specify (expandable) environment variables to pass to actions
--
MOS_MIGRATED_REVID=111608329
Diffstat (limited to 'src/test/java')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/packages/util/MockCcSupport.java | 39 | ||||
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java | 38 |
2 files changed, 76 insertions, 1 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/packages/util/MockCcSupport.java b/src/test/java/com/google/devtools/build/lib/packages/util/MockCcSupport.java index 5313c403e5..0f61571d82 100644 --- a/src/test/java/com/google/devtools/build/lib/packages/util/MockCcSupport.java +++ b/src/test/java/com/google/devtools/build/lib/packages/util/MockCcSupport.java @@ -132,6 +132,45 @@ public abstract class MockCcSupport { + " }" + "}"; + /** + * A feature configuration snippet useful for testing environment variables. + */ + public static final String ENV_VAR_FEATURE_CONFIGURATION = + "" + + "feature {" + + " name: 'env_feature'" + + " implies: 'static_env_feature'" + + " implies: 'module_maps'" + + "}" + + "feature {" + + " name: 'static_env_feature'" + + " env_set {" + + " action: 'c-compile'" + + " action: 'c++-compile'" + + " action: 'c++-header-parsing'" + + " action: 'c++-header-preprocessing'" + + " action: 'c++-module-compile'" + + " env_entry {" + + " key: 'cat'" + + " value: 'meow'" + + " }" + + " }" + + "}" + + "feature {" + + " name: 'module_maps'" + + " env_set {" + + " action: 'c-compile'" + + " action: 'c++-compile'" + + " action: 'c++-header-parsing'" + + " action: 'c++-header-preprocessing'" + + " action: 'c++-module-compile'" + + " env_entry {" + + " key: 'module'" + + " value: 'module_name:%{module_name}'" + + " }" + + " }" + + "}"; + public static final String THIN_LTO_CONFIGURATION = "" + "feature { " 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 f06f34bf82..7c3a435bc4 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 @@ -39,6 +39,7 @@ import org.junit.runners.JUnit4; import java.util.Arrays; import java.util.Collection; import java.util.List; +import java.util.Map; import java.util.Set; /** @@ -139,7 +140,42 @@ public class CcToolchainFeaturesTest { CppCompileAction.CPP_COMPILE, createVariables()); assertThat(commandLine).containsExactly("-a-c++-compile", "-b-c++-compile").inOrder(); } - + + @Test + public void testEnvVars() throws Exception { + FeatureConfiguration configuration = buildFeatures( + "feature {", + " name: 'a'", + " env_set {", + " action: 'c++-compile'", + " env_entry { key: 'foo', value: 'bar' }", + " env_entry { key: 'cat', value: 'meow' }", + " }", + " flag_set {", + " action: 'c++-compile'", + " flag_group { flag: '-a-c++-compile' }", + " }", + "}", + "feature {", + " name: 'b'", + " env_set {", + " action: 'c++-compile'", + " env_entry { key: 'dog', value: 'woof' }", + " }", + "}", + "feature {", + " name: 'c'", + " env_set {", + " action: 'c++-compile'", + " env_entry { key: 'doNotInclude', value: 'doNotIncludePlease' }", + " }", + "}").getFeatureConfiguration("a", "b"); + Map<String, String> env = configuration.getEnvironmentVariables( + CppCompileAction.CPP_COMPILE, createVariables()); + assertThat(env).containsExactly("foo", "bar", "cat", "meow", "dog", "woof").inOrder(); + assertThat(env).doesNotContainEntry("doNotInclude", "doNotIncludePlease"); + } + private String getExpansionOfFlag(String value) throws Exception { return getExpansionOfFlag(value, createVariables()); } |