diff options
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/actions/ActionEnvironment.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/actions/ActionEnvironment.java | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/actions/ActionEnvironment.java b/src/main/java/com/google/devtools/build/lib/actions/ActionEnvironment.java index ba39e801ee..d074c399de 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/ActionEnvironment.java +++ b/src/main/java/com/google/devtools/build/lib/actions/ActionEnvironment.java @@ -42,7 +42,8 @@ public final class ActionEnvironment { */ // TODO(ulfjack): Migrate all production code to use the proper action environment, and then make // this @VisibleForTesting or rename it to clarify. - public static final ActionEnvironment EMPTY = new ActionEnvironment(ImmutableMap.of()); + public static final ActionEnvironment EMPTY = + new ActionEnvironment(ImmutableMap.of(), ImmutableSet.of()); /** * Splits the given map into a map of variables with a fixed value, and a set of variables that @@ -62,24 +63,31 @@ public final class ActionEnvironment { inheritedEnv.add(key); } } - return new ActionEnvironment(fixedEnv, inheritedEnv); + return create(fixedEnv, inheritedEnv); } private final ImmutableMap<String, String> fixedEnv; private final ImmutableSet<String> inheritedEnv; + private ActionEnvironment(Map<String, String> fixedEnv, Set<String> inheritedEnv) { + this.fixedEnv = ImmutableMap.copyOf(fixedEnv); + this.inheritedEnv = ImmutableSet.copyOf(inheritedEnv); + } + /** * Creates a new action environment. The order in which the environments are combined is * undefined, so callers need to take care that the key set of the {@code fixedEnv} map and the * set of {@code inheritedEnv} elements are disjoint. */ - public ActionEnvironment(Map<String, String> fixedEnv, Set<String> inheritedEnv) { - this.fixedEnv = ImmutableMap.copyOf(fixedEnv); - this.inheritedEnv = ImmutableSet.copyOf(inheritedEnv); + public static ActionEnvironment create(Map<String, String> fixedEnv, Set<String> inheritedEnv) { + if (fixedEnv.isEmpty() && inheritedEnv.isEmpty()) { + return EMPTY; + } + return new ActionEnvironment(fixedEnv, inheritedEnv); } - public ActionEnvironment(Map<String, String> fixedEnv) { - this(fixedEnv, ImmutableSet.of()); + public static ActionEnvironment create(Map<String, String> fixedEnv) { + return new ActionEnvironment(fixedEnv, ImmutableSet.of()); } public ImmutableMap<String, String> getFixedEnv() { |