aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2015-11-05 16:29:16 +0000
committerGravatar John Field <jfield@google.com>2015-11-05 16:52:36 +0000
commit582246164ff8ce7e07654b86d22c2ff64e3fcffb (patch)
tree20588cbf9b0a99bc1fe6ec42f359ccb3547b771d /src
parent08c8aac68cb549a6e35e8a7f4686131d83ba30e4 (diff)
Propagate environment variables set with --test_env command line flag to the test runner for ExperimentalIosTest.
This is the first of two CLs. This CL allows templating and reading of the %(test_env)s variable. After this CL is released, another CL will introduce a the variable into ios_test.sh.bazel_template. -- MOS_MIGRATED_REVID=107141559
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/actions/TemplateExpansionAction.java23
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/TestSupport.java7
2 files changed, 29 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/actions/TemplateExpansionAction.java b/src/main/java/com/google/devtools/build/lib/analysis/actions/TemplateExpansionAction.java
index 554dcbfac6..fc1b8427c6 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/actions/TemplateExpansionAction.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/actions/TemplateExpansionAction.java
@@ -16,6 +16,7 @@ package com.google.devtools.build.lib.analysis.actions;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Joiner;
+import com.google.common.base.Joiner.MapJoiner;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
@@ -35,6 +36,7 @@ import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.List;
+import java.util.Map;
/**
* Action to expand a template and write the expanded content to a file.
@@ -93,7 +95,28 @@ public class TemplateExpansionAction extends AbstractFileWriteAction {
}
};
}
+
+ /**
+ * Returns an immutable Substitution instance for the key and map of values. Corresponding
+ * values in the map will be joined with "=", and pairs will be joined by spaces before
+ * substitution.
+ *
+ * <p>For example, the map <(a,1), (b,2), (c,3)> will become "a=1 b=2 c=3".
+ */
+ public static Substitution ofSpaceSeparatedMap(final String key, final Map<?, ?> value) {
+ return new Substitution() {
+ @Override
+ public String getKey() {
+ return key;
+ }
+ @Override
+ public String getValue() {
+ return Joiner.on(" ").withKeyValueSeparator("=").join(value);
+ }
+ };
+ }
+
@Override
public boolean equals(Object object) {
if (this == object) {
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/TestSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/TestSupport.java
index 06b8f7976c..acf7d156a8 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/TestSupport.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/TestSupport.java
@@ -38,6 +38,7 @@ import com.google.devtools.build.lib.util.FileType;
import java.util.List;
import java.util.Map;
+import java.util.TreeMap;
import javax.annotation.Nullable;
@@ -74,6 +75,8 @@ public class TestSupport {
String runMemleaks =
ruleContext.getFragment(ObjcConfiguration.class).runMemleaks() ? "true" : "false";
+ Map<String, String> testEnv = ruleContext.getConfiguration().getTestEnv();
+
// The substitutions below are common for simulator and lab device.
ImmutableList.Builder<Substitution> substitutions =
new ImmutableList.Builder<Substitution>()
@@ -82,7 +85,9 @@ public class TestSupport {
.add(Substitution.of("%(test_app_name)s", baseNameWithoutIpa(testIpa)))
.add(
Substitution.of("%(plugin_jars)s", Artifact.joinRootRelativePaths(":", plugins())));
-
+
+ substitutions.add(Substitution.ofSpaceSeparatedMap("%(test_env)s", testEnv));
+
// xctestIpa is the app bundle being tested
Optional<Artifact> xctestIpa = xctestIpa();
if (xctestIpa.isPresent()) {