diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/RepoFetchingSkyKeyComputeState.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/RepoFetchingSkyKeyComputeState.java index 55473ddf64b0df..a709603c830f05 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/RepoFetchingSkyKeyComputeState.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/RepoFetchingSkyKeyComputeState.java @@ -17,6 +17,8 @@ import com.google.devtools.build.lib.rules.repository.RepositoryDirectoryValue; import com.google.devtools.build.skyframe.SkyFunction; import com.google.devtools.build.skyframe.SkyFunction.Environment.SkyKeyComputeState; +import java.util.Map; +import java.util.TreeMap; import java.util.concurrent.BlockingQueue; import java.util.concurrent.Future; import java.util.concurrent.SynchronousQueue; @@ -51,11 +53,13 @@ enum Signal { /** The channel for the worker thread to send a signal to the host Skyframe thread. */ final BlockingQueue signalQueue = new SynchronousQueue<>(); + /** * The channel for the host Skyframe thread to send fresh {@link SkyFunction.Environment} objects * back to the worker thread. */ final BlockingQueue delegateEnvQueue = new SynchronousQueue<>(); + /** * This future holds on to the worker thread in order to cancel it when necessary; it also serves * to tell whether a worker thread is already running. @@ -66,6 +70,14 @@ enum Signal { // we might block in `close()`, which is potentially bad (see its javadoc). @Nullable volatile Future workerFuture = null; + /** + * This is where the {@code markerData} for the whole invocation is collected. + * + *

{@link com.google.devtools.build.lib.rules.repository.RepositoryDelegatorFunction} creates a + * new map on each restart, so we can't simply plumb that in. + */ + final Map markerData = new TreeMap<>(); + SkyFunction.Environment signalForFreshEnv() throws InterruptedException { signalQueue.put(Signal.RESTART); return delegateEnvQueue.take(); diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkRepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkRepositoryFunction.java index fc3a7e146c128b..491f226c7fdc49 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkRepositoryFunction.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkRepositoryFunction.java @@ -112,6 +112,7 @@ protected boolean verifySemanticsMarkerData(Map markerData, Envi // false is the safe thing to do. return false; } + return describeSemantics(starlarkSemantics).equals(markerData.get(SEMANTICS)); } @@ -158,7 +159,7 @@ public RepositoryDirectoryValue.Builder fetch( () -> { try { return fetchInternal( - rule, outputDirectory, directories, workerEnv, markerData, key); + rule, outputDirectory, directories, workerEnv, state.markerData, key); } finally { state.signalQueue.put(Signal.DONE); } @@ -174,7 +175,9 @@ public RepositoryDirectoryValue.Builder fetch( return null; case DONE: try { - return workerFuture.get(); + RepositoryDirectoryValue.Builder result = workerFuture.get(); + markerData.putAll(state.markerData); + return result; } catch (ExecutionException e) { Throwables.throwIfInstanceOf(e.getCause(), RepositoryFunctionException.class); Throwables.throwIfUnchecked(e.getCause());