Add 'environ' attribute to module extensions and update lockfile
- Add 'environ' to module extensions
- Store the variables and their values in the lockfile
- Compare the variables and values with the lockfile and re-evaluate or error if they differ
PiperOrigin-RevId: 548964193
Change-Id: Ic2d52fe3332e93095c414d8bca4c9b4312bca8c2
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ActionEnvironmentFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ActionEnvironmentFunction.java
index 8947183..2fdcfd5 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ActionEnvironmentFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ActionEnvironmentFunction.java
@@ -15,6 +15,7 @@
package com.google.devtools.build.lib.skyframe;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.bugreport.BugReport;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.skyframe.AbstractSkyKey;
@@ -23,8 +24,6 @@
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.SkyValue;
import com.google.devtools.build.skyframe.SkyframeLookupResult;
-import java.util.Collections;
-import java.util.LinkedHashMap;
import java.util.Map;
import javax.annotation.Nullable;
@@ -45,7 +44,7 @@
return env.getValue(ClientEnvironmentFunction.key(key));
}
- /** @return the SkyKey to invoke this function for the environment variable {@code variable}. */
+ /** Returns the SkyKey to invoke this function for the environment variable {@code variable}. */
public static Key key(String variable) {
return Key.create(variable);
}
@@ -81,8 +80,8 @@
* if and only if some dependencies from Skyframe still need to be resolved.
*/
@Nullable
- public static Map<String, String> getEnvironmentView(Environment env, Iterable<String> keys)
- throws InterruptedException {
+ public static ImmutableMap<String, String> getEnvironmentView(
+ Environment env, Iterable<String> keys) throws InterruptedException {
ImmutableList.Builder<SkyKey> skyframeKeysBuilder = ImmutableList.builder();
for (String key : keys) {
skyframeKeysBuilder.add(key(key));
@@ -92,8 +91,8 @@
if (env.valuesMissing()) {
return null;
}
- // To return the initial order and support null values, we use a LinkedHashMap.
- LinkedHashMap<String, String> result = new LinkedHashMap<>();
+
+ ImmutableMap.Builder<String, String> result = ImmutableMap.builder();
for (SkyKey key : skyframeKeys) {
ClientEnvironmentValue value = (ClientEnvironmentValue) values.get(key);
if (value == null) {
@@ -102,8 +101,10 @@
"ClientEnvironmentValue " + key + " was missing, this should never happen"));
return null;
}
- result.put(key.argument().toString(), value.getValue());
+ if (value.getValue() != null) {
+ result.put(key.argument().toString(), value.getValue());
+ }
}
- return Collections.unmodifiableMap(result);
+ return result.buildOrThrow();
}
}