diff --git a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BazelLockFileModule.java b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BazelLockFileModule.java index a664ae3437b5c2..4036eb3b994f42 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BazelLockFileModule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BazelLockFileModule.java @@ -106,8 +106,13 @@ public void afterCommand() throws AbruptExitException { combineModuleExtensions(lockfile.getModuleExtensions(), oldExtensionUsages)) .build(); - // Write the new value to the file - updateLockfile(lockfilePath, lockfile); + // Write the new value to the file, but only if needed. This is not just a performance + // optimization: whenever the lockfile is updated, most Skyframe nodes will be marked as dirty + // on the next build, which breaks commands such as `bazel config` that rely on + // com.google.devtools.build.skyframe.MemoizingEvaluator#getDoneValues. + if (!lockfile.equals(oldLockfile)) { + updateLockfile(lockfilePath, lockfile); + } this.moduleResolutionEvent = null; this.extensionResolutionEventsMap.clear(); }