diff --git a/src/main/java/com/google/devtools/build/lib/bazel/BazelRepositoryModule.java b/src/main/java/com/google/devtools/build/lib/bazel/BazelRepositoryModule.java index 469d55934431dd..00986a8166df6c 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/BazelRepositoryModule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/BazelRepositoryModule.java @@ -266,7 +266,8 @@ public void workspaceInit( .addSkyFunction(SkyFunctions.MODULE_FILE, moduleFileFunction) .addSkyFunction(SkyFunctions.BAZEL_DEP_GRAPH, new BazelDepGraphFunction()) .addSkyFunction( - SkyFunctions.BAZEL_LOCK_FILE, new BazelLockFileFunction(directories.getWorkspace())) + SkyFunctions.BAZEL_LOCK_FILE, + new BazelLockFileFunction(directories.getWorkspace(), directories.getOutputBase())) .addSkyFunction(SkyFunctions.BAZEL_FETCH_ALL, new BazelFetchAllFunction()) .addSkyFunction(SkyFunctions.BAZEL_MOD_TIDY, new BazelModTidyFunction()) .addSkyFunction(SkyFunctions.BAZEL_MODULE_INSPECTION, new BazelModuleInspectorFunction()) diff --git a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BUILD b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BUILD index 9127d464f26a9a..f2014412f5c9db 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BUILD +++ b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BUILD @@ -125,6 +125,7 @@ java_library( ":resolution_impl", "//src/main/java/com/google/devtools/build/lib:runtime", "//src/main/java/com/google/devtools/build/lib/bazel/repository:repository_options", + "//src/main/java/com/google/devtools/build/lib/bazel/repository/downloader", "//src/main/java/com/google/devtools/build/lib/cmdline", "//src/main/java/com/google/devtools/build/lib/skyframe:precomputed_value", "//src/main/java/com/google/devtools/build/lib/skyframe:skyframe_cluster", diff --git a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BazelLockFileFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BazelLockFileFunction.java index c89d830af424d4..d0caf8642b6c2b 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BazelLockFileFunction.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BazelLockFileFunction.java @@ -55,29 +55,42 @@ public class BazelLockFileFunction implements SkyFunction { private static final BazelLockFileValue EMPTY_LOCKFILE = BazelLockFileValue.builder().build(); private final Path rootDirectory; + private final Path outputBase; - public BazelLockFileFunction(Path rootDirectory) { + public BazelLockFileFunction(Path rootDirectory, Path outputBase) { this.rootDirectory = rootDirectory; + this.outputBase = outputBase; } @Override @Nullable public SkyValue compute(SkyKey skyKey, Environment env) throws BazelLockfileFunctionException, InterruptedException { + boolean forPersistentLockfile = skyKey == BazelLockFileValue.PERSISTENT_KEY; RootedPath lockfilePath = - RootedPath.toRootedPath(Root.fromPath(rootDirectory), LabelConstants.MODULE_LOCKFILE_NAME); + RootedPath.toRootedPath( + Root.fromPath(forPersistentLockfile ? outputBase : rootDirectory), + LabelConstants.MODULE_LOCKFILE_NAME); - // Add dependency on the lockfile to recognize changes to it + // Add dependency on the lockfiles to recognize changes to it if (env.getValue(FileValue.key(lockfilePath)) == null) { return null; } - try (SilentCloseable c = Profiler.instance().profile(ProfilerTask.BZLMOD, "parse lockfile")) { - return getLockfileValue(lockfilePath, LOCKFILE_MODE.get(env)); + try (SilentCloseable c = + Profiler.instance() + .profile( + ProfilerTask.BZLMOD, + forPersistentLockfile ? "parse persistent lockfile" : "parse lockfile")) { + return getLockfileValue( + lockfilePath, forPersistentLockfile ? LockfileMode.UPDATE : LOCKFILE_MODE.get(env)); } catch (IOException | JsonSyntaxException | NullPointerException | IllegalArgumentException e) { + if (forPersistentLockfile) { + return EMPTY_LOCKFILE; + } String actionSuffix; if (POSSIBLE_MERGE_CONFLICT_PATTERN.matcher(e.getMessage()).find()) { actionSuffix = 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 43b1cfb9b75c84..1fb2ab003a87ce 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 @@ -26,6 +26,7 @@ import com.google.common.flogger.GoogleLogger; import com.google.devtools.build.lib.bazel.repository.RepositoryOptions; import com.google.devtools.build.lib.bazel.repository.RepositoryOptions.LockfileMode; +import com.google.devtools.build.lib.bazel.repository.downloader.Checksum; import com.google.devtools.build.lib.cmdline.LabelConstants; import com.google.devtools.build.lib.runtime.BlazeModule; import com.google.devtools.build.lib.runtime.CommandEnvironment; @@ -39,6 +40,7 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; +import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Predicate; @@ -50,6 +52,7 @@ public class BazelLockFileModule extends BlazeModule { private SkyframeExecutor executor; private Path workspaceRoot; + private Path outputBase; private LockfileMode optionsLockfileMode; private static final GoogleLogger logger = GoogleLogger.forEnclosingClass(); @@ -61,6 +64,7 @@ public class BazelLockFileModule extends BlazeModule { public void beforeCommand(CommandEnvironment env) { executor = env.getSkyframeExecutor(); workspaceRoot = env.getWorkspace(); + outputBase = env.getOutputBase(); optionsLockfileMode = env.getOptions().getOptions(RepositoryOptions.class).lockfileMode; } @@ -70,6 +74,7 @@ public void afterCommand() { BazelModuleResolutionValue moduleResolutionValue; BazelDepGraphValue depGraphValue; BazelLockFileValue oldLockfile; + BazelLockFileValue oldPersistentLockfile; try { PrecomputedValue lockfileModeValue = (PrecomputedValue) evaluator.getExistingValue(LOCKFILE_MODE.getKey()); @@ -89,11 +94,16 @@ public void afterCommand() { (BazelModuleResolutionValue) evaluator.getExistingValue(BazelModuleResolutionValue.KEY); depGraphValue = (BazelDepGraphValue) evaluator.getExistingValue(BazelDepGraphValue.KEY); oldLockfile = (BazelLockFileValue) evaluator.getExistingValue(BazelLockFileValue.KEY); + oldPersistentLockfile = + (BazelLockFileValue) evaluator.getExistingValue(BazelLockFileValue.PERSISTENT_KEY); } catch (InterruptedException e) { // Not thrown in Bazel. throw new IllegalStateException(e); } - if (moduleResolutionValue == null || depGraphValue == null || oldLockfile == null) { + if (moduleResolutionValue == null + || depGraphValue == null + || oldLockfile == null + || oldPersistentLockfile == null) { // An error during the actual build prevented the evaluation of these values and has already // been reported at this point. return; @@ -120,28 +130,75 @@ public void afterCommand() { newExtensionInfos.put(key.argument(), value.lockFileInfo().get()); } }); - var combinedExtensionInfos = - combineModuleExtensions( - oldLockfile.getModuleExtensions(), - newExtensionInfos, - /* hasUsages= */ depGraphValue.getExtensionUsagesTable()::containsRow); - - // Create an updated version of the lockfile, keeping only the extension results from the old - // lockfile that are still up-to-date and adding the newly resolved extension results. - BazelLockFileValue newLockfile = - BazelLockFileValue.builder() - .setRegistryFileHashes( - ImmutableSortedMap.copyOf(moduleResolutionValue.getRegistryFileHashes())) - .setSelectedYankedVersions(moduleResolutionValue.getSelectedYankedVersions()) - .setModuleExtensions(combinedExtensionInfos) - .build(); - - // 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 (!newLockfile.equals(oldLockfile)) { - updateLockfile(workspaceRoot, newLockfile); + + Thread updateLockfile = + Thread.startVirtualThread( + () -> { + var nonReproducibleExtensionInfos = + combineModuleExtensions( + oldPersistentLockfile.getModuleExtensions(), + newExtensionInfos, + /* hasUsages= */ depGraphValue.getExtensionUsagesTable()::containsRow, + /* reproducible= */ false); + + // Create an updated version of the lockfile, keeping only the extension results from + // the old + // lockfile that are still up-to-date and adding the newly resolved extension results. + BazelLockFileValue newLockfile = + BazelLockFileValue.builder() + .setRegistryFileHashes( + ImmutableSortedMap.copyOf(moduleResolutionValue.getRegistryFileHashes())) + .setSelectedYankedVersions(moduleResolutionValue.getSelectedYankedVersions()) + .setModuleExtensions(nonReproducibleExtensionInfos) + .build(); + + // Write the new values to the files, 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 (!newLockfile.equals(oldLockfile)) { + updateLockfile(workspaceRoot, newLockfile); + } + }); + + Thread updatePersistentLockfile = + Thread.startVirtualThread( + () -> { + var reproducibleExtensionInfos = + combineModuleExtensions( + oldLockfile.getModuleExtensions(), + newExtensionInfos, + /* hasUsages= */ depGraphValue.getExtensionUsagesTable()::containsRow, + /* reproducible= */ true); + + var persistentRegistryFileHashes = + ImmutableMap.>builder() + .putAll(oldPersistentLockfile.getRegistryFileHashes()) + .putAll( + Maps.filterValues( + moduleResolutionValue.getRegistryFileHashes(), Optional::isPresent)) + .buildKeepingLast(); + BazelLockFileValue newPersistentLockfile = + BazelLockFileValue.builder() + .setRegistryFileHashes( + ImmutableSortedMap.copyOf(persistentRegistryFileHashes)) + .setSelectedYankedVersions(ImmutableMap.of()) + .setModuleExtensions(reproducibleExtensionInfos) + .build(); + + if (!newPersistentLockfile.equals(oldPersistentLockfile)) { + updateLockfile(outputBase, newPersistentLockfile); + } + }); + + try { + updateLockfile.join(); + updatePersistentLockfile.join(); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + logger.atSevere().withCause(e).log( + "Interrupted while updating MODULE.bazel.lock file: %s", e.getMessage()); } } @@ -156,12 +213,13 @@ public void afterCommand() { Map> oldExtensionInfos, Map newExtensionInfos, - Predicate hasUsages) { + Predicate hasUsages, + boolean reproducible) { Map> updatedExtensionMap = new HashMap<>(); // Keep those per factor extension results that are still used according to the static - // information given in the extension declaration (dependence on os and arch, reproducibility). + // information given in the extension declaration (dependence on os and arch). // Other information such as transitive .bzl hash and usages hash are *not* checked here. for (var entry : oldExtensionInfos.entrySet()) { var moduleExtensionId = entry.getKey(); @@ -176,7 +234,7 @@ public void afterCommand() { continue; } var newFactors = newExtensionInfo.extensionFactors(); - // Factor results can be individually marked as reproducible and should be dropped if so. + // Factor results can be individually marked as reproducible. ImmutableSortedMap perFactorResultsToKeep = ImmutableSortedMap.copyOf( @@ -185,7 +243,8 @@ public void afterCommand() { existingFactors -> newFactors.hasSameDependenciesAs(existingFactors) && !(newFactors.equals(existingFactors) - && newExtensionInfo.moduleExtension().isReproducible()))); + && newExtensionInfo.moduleExtension().isReproducible() + == reproducible))); if (perFactorResultsToKeep.isEmpty()) { continue; } @@ -195,7 +254,7 @@ public void afterCommand() { // Add the new resolved extensions for (var extensionIdAndInfo : newExtensionInfos.entrySet()) { LockFileModuleExtension extension = extensionIdAndInfo.getValue().moduleExtension(); - if (extension.isReproducible()) { + if (extension.isReproducible() != reproducible) { continue; } @@ -227,12 +286,12 @@ public void afterCommand() { /** * Updates the data stored in the lockfile (MODULE.bazel.lock) * - * @param workspaceRoot Root of the workspace where the lockfile is located + * @param lockfileRoot Root under which the lockfile is located * @param updatedLockfile The updated lockfile data to save */ - private static void updateLockfile(Path workspaceRoot, BazelLockFileValue updatedLockfile) { + private static void updateLockfile(Path lockfileRoot, BazelLockFileValue updatedLockfile) { RootedPath lockfilePath = - RootedPath.toRootedPath(Root.fromPath(workspaceRoot), LabelConstants.MODULE_LOCKFILE_NAME); + RootedPath.toRootedPath(Root.fromPath(lockfileRoot), LabelConstants.MODULE_LOCKFILE_NAME); try { FileSystemUtils.writeContent( lockfilePath.asPath(), diff --git a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BazelLockFileValue.java b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BazelLockFileValue.java index c615d21623ecbf..a3ccb70e046f73 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BazelLockFileValue.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BazelLockFileValue.java @@ -42,6 +42,9 @@ public abstract class BazelLockFileValue implements SkyValue { @SerializationConstant public static final SkyKey KEY = () -> SkyFunctions.BAZEL_LOCK_FILE; + @SerializationConstant + public static final SkyKey PERSISTENT_KEY = () -> SkyFunctions.BAZEL_LOCK_FILE; + static Builder builder() { return new AutoValue_BazelLockFileValue.Builder() .setLockFileVersion(LOCK_FILE_VERSION) diff --git a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/RegistryFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/RegistryFunction.java index 6d0ef0fa0653bc..67495aa5bf291a 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/RegistryFunction.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/RegistryFunction.java @@ -15,7 +15,10 @@ package com.google.devtools.build.lib.bazel.bzlmod; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.google.devtools.build.lib.bazel.repository.RepositoryOptions.LockfileMode; +import com.google.devtools.build.lib.bazel.repository.downloader.Checksum; import com.google.devtools.build.lib.rules.repository.RepositoryDelegatorFunction; import com.google.devtools.build.lib.server.FailureDetails; import com.google.devtools.build.lib.skyframe.PrecomputedValue.Precomputed; @@ -64,8 +67,13 @@ public SkyValue compute(SkyKey skyKey, Environment env) RegistryFunction.LAST_INVALIDATION.get(env); } - BazelLockFileValue lockfile = (BazelLockFileValue) env.getValue(BazelLockFileValue.KEY); - if (lockfile == null) { + var lockfiles = + env.getValuesAndExceptions( + ImmutableList.of(BazelLockFileValue.KEY, BazelLockFileValue.PERSISTENT_KEY)); + BazelLockFileValue lockfile = (BazelLockFileValue) lockfiles.get(BazelLockFileValue.KEY); + BazelLockFileValue persistentLockfile = + (BazelLockFileValue) lockfiles.get(BazelLockFileValue.PERSISTENT_KEY); + if (lockfile == null || persistentLockfile == null) { return null; } @@ -74,7 +82,10 @@ public SkyValue compute(SkyKey skyKey, Environment env) return registryFactory.createRegistry( key.url().replace("%workspace%", workspaceRoot.getPathString()), lockfileMode, - lockfile.getRegistryFileHashes(), + ImmutableMap.>builder() + .putAll(persistentLockfile.getRegistryFileHashes()) + .putAll(lockfile.getRegistryFileHashes()) + .buildKeepingLast(), lockfile.getSelectedYankedVersions(), vendorDir); } catch (URISyntaxException e) { diff --git a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/SingleExtensionEvalFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/SingleExtensionEvalFunction.java index bd9904922e6da5..886172d5e71e98 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/SingleExtensionEvalFunction.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/SingleExtensionEvalFunction.java @@ -140,13 +140,23 @@ public SkyValue compute(SkyKey skyKey, Environment env) LockFileModuleExtension lockedExtension = null; LockfileMode lockfileMode = BazelLockFileFunction.LOCKFILE_MODE.get(env); if (!lockfileMode.equals(LockfileMode.OFF)) { - BazelLockFileValue lockfile = (BazelLockFileValue) env.getValue(BazelLockFileValue.KEY); - if (lockfile == null) { + var lockfiles = + env.getValuesAndExceptions( + ImmutableList.of(BazelLockFileValue.KEY, BazelLockFileValue.PERSISTENT_KEY)); + BazelLockFileValue lockfile = (BazelLockFileValue) lockfiles.get(BazelLockFileValue.KEY); + BazelLockFileValue persistentLockfile = + (BazelLockFileValue) lockfiles.get(BazelLockFileValue.PERSISTENT_KEY); + if (lockfile == null || persistentLockfile == null) { return null; } var lockedExtensionMap = lockfile.getModuleExtensions().get(extensionId); lockedExtension = lockedExtensionMap == null ? null : lockedExtensionMap.get(extension.getEvalFactors()); + if (lockedExtension == null) { + lockedExtensionMap = persistentLockfile.getModuleExtensions().get(extensionId); + lockedExtension = + lockedExtensionMap == null ? null : lockedExtensionMap.get(extension.getEvalFactors()); + } if (lockedExtension != null) { try { SingleExtensionValue singleExtensionValue = @@ -335,7 +345,9 @@ private SingleExtensionValue tryGettingValueFromLockFile( Optional.of(new LockFileModuleExtension.WithFactors(evalFactors, lockedExtension)), env); } - if (lockfileMode.equals(LockfileMode.ERROR)) { + // Reproducible extensions are always locked in the persistent lockfile to provide best-effort + // speedups, but should never result in an error if out-of-date. + if (lockfileMode.equals(LockfileMode.ERROR) && !lockedExtension.isReproducible()) { throw new SingleExtensionEvalFunctionException( ExternalDepsException.withMessage( Code.BAD_LOCKFILE, diff --git a/src/main/java/com/google/devtools/build/lib/cmdline/LabelConstants.java b/src/main/java/com/google/devtools/build/lib/cmdline/LabelConstants.java index 8a3a1a80f1683b..70de267617e67a 100644 --- a/src/main/java/com/google/devtools/build/lib/cmdline/LabelConstants.java +++ b/src/main/java/com/google/devtools/build/lib/cmdline/LabelConstants.java @@ -48,6 +48,8 @@ public class LabelConstants { public static final PathFragment VENDOR_FILE_NAME = PathFragment.create("VENDOR.bazel"); public static final PathFragment MODULE_LOCKFILE_NAME = PathFragment.create("MODULE.bazel.lock"); + public static final PathFragment MODULE_REPRODUCIBLE_LOCKFILE_NAME = + PathFragment.create("MODULE.bazel.reproducible_lock"); // With this prefix, non-main repositories are symlinked under // $output_base/execution_root/__main__/external diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/packages/BazelPackageLoader.java b/src/main/java/com/google/devtools/build/lib/skyframe/packages/BazelPackageLoader.java index 953768ae9a0ffc..8d23f3ed0be00e 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/packages/BazelPackageLoader.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/packages/BazelPackageLoader.java @@ -198,7 +198,8 @@ public BazelPackageLoader buildImpl() { EXTERNAL_PACKAGE_HELPER)) .put( SkyFunctions.BAZEL_LOCK_FILE, - new BazelLockFileFunction(directories.getWorkspace())) + new BazelLockFileFunction( + directories.getWorkspace(), directories.getOutputBase())) .put(SkyFunctions.BAZEL_DEP_GRAPH, new BazelDepGraphFunction()) .put(SkyFunctions.BAZEL_MODULE_RESOLUTION, new BazelModuleResolutionFunction()) .put(SkyFunctions.REPO_SPEC, repoSpecFunction) diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisMock.java b/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisMock.java index fdad032997c68d..5564d16bea2a69 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisMock.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisMock.java @@ -226,7 +226,9 @@ public ImmutableMap getSkyFunctions(BlazeDirectori directories.getWorkspace(), getBuiltinModules(directories))) .put(SkyFunctions.BAZEL_DEP_GRAPH, new BazelDepGraphFunction()) - .put(SkyFunctions.BAZEL_LOCK_FILE, new BazelLockFileFunction(directories.getWorkspace())) + .put( + SkyFunctions.BAZEL_LOCK_FILE, + new BazelLockFileFunction(directories.getWorkspace(), directories.getOutputBase())) .put(SkyFunctions.BAZEL_MODULE_RESOLUTION, new BazelModuleResolutionFunction()) .put(SkyFunctions.SINGLE_EXTENSION, new SingleExtensionFunction()) .put( diff --git a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BazelDepGraphFunctionTest.java b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BazelDepGraphFunctionTest.java index dd669ae718fdd9..e6401a25fe970d 100644 --- a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BazelDepGraphFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BazelDepGraphFunctionTest.java @@ -126,7 +126,7 @@ public void setup() throws Exception { rootDirectory, ImmutableMap.of())) .put(SkyFunctions.PRECOMPUTED, new PrecomputedFunction()) - .put(SkyFunctions.BAZEL_LOCK_FILE, new BazelLockFileFunction(rootDirectory)) + .put(SkyFunctions.BAZEL_LOCK_FILE, new BazelLockFileFunction(rootDirectory, directories.getOutputBase())) .put(SkyFunctions.BAZEL_DEP_GRAPH, new BazelDepGraphFunction()) .put(SkyFunctions.BAZEL_MODULE_RESOLUTION, resolutionFunctionMock) .put( diff --git a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BazelLockFileModuleTest.java b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BazelLockFileModuleTest.java index b20318aad413b8..0eb9ca3aed513a 100644 --- a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BazelLockFileModuleTest.java +++ b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BazelLockFileModuleTest.java @@ -63,7 +63,7 @@ public void combineModuleExtensionsReproducibleFactorAdded() { assertThat( BazelLockFileModule.combineModuleExtensions( - oldExtensionInfos, newExtensionInfos, id -> true)) + oldExtensionInfos, newExtensionInfos, id -> true, /* reproducible= */ false)) .isEqualTo(oldExtensionInfos); } @@ -77,7 +77,7 @@ public void combineModuleExtensionsFactorBecomesReproducible() { assertThat( BazelLockFileModule.combineModuleExtensions( - oldExtensionInfos, newExtensionInfos, id -> true)) + oldExtensionInfos, newExtensionInfos, id -> true, /* reproducible= */ false)) .isEmpty(); } @@ -92,7 +92,7 @@ public void combineModuleExtensionsFactorBecomesNonReproducible() { assertThat( BazelLockFileModule.combineModuleExtensions( - oldExtensionInfos, newExtensionInfos, id -> true)) + oldExtensionInfos, newExtensionInfos, id -> true, /* reproducible= */ false)) .isEqualTo( ImmutableMap.of(extensionId, ImmutableMap.of(evalFactors, nonReproducibleResult))); } diff --git a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BazelModuleResolutionFunctionTest.java b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BazelModuleResolutionFunctionTest.java index ef59c79260d547..ec45cc99390bf5 100644 --- a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BazelModuleResolutionFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BazelModuleResolutionFunctionTest.java @@ -140,7 +140,7 @@ public void setup() throws Exception { ImmutableMap.of())) .put(SkyFunctions.PRECOMPUTED, new PrecomputedFunction()) .put(SkyFunctions.BAZEL_DEP_GRAPH, new BazelDepGraphFunction()) - .put(SkyFunctions.BAZEL_LOCK_FILE, new BazelLockFileFunction(rootDirectory)) + .put(SkyFunctions.BAZEL_LOCK_FILE, new BazelLockFileFunction(rootDirectory, directories.getOutputBase())) .put(SkyFunctions.BAZEL_MODULE_RESOLUTION, new BazelModuleResolutionFunction()) .put( SkyFunctions.REGISTRY, diff --git a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BzlmodRepoRuleFunctionTest.java b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BzlmodRepoRuleFunctionTest.java index e799387928da63..d3dfdc9bce0266 100644 --- a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BzlmodRepoRuleFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BzlmodRepoRuleFunctionTest.java @@ -127,7 +127,7 @@ public void setup() throws Exception { BzlmodRepoRuleValue.BZLMOD_REPO_RULE, new BzlmodRepoRuleFunction(ruleClassProvider, directories)) .put(SkyFunctions.BAZEL_DEP_GRAPH, new BazelDepGraphFunction()) - .put(SkyFunctions.BAZEL_LOCK_FILE, new BazelLockFileFunction(rootDirectory)) + .put(SkyFunctions.BAZEL_LOCK_FILE, new BazelLockFileFunction(rootDirectory, directories.getOutputBase())) .put(SkyFunctions.BAZEL_MODULE_RESOLUTION, new BazelModuleResolutionFunction()) .put( SkyFunctions.MODULE_FILE, diff --git a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/DiscoveryTest.java b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/DiscoveryTest.java index 245c0640746e89..ff47e34678f91d 100644 --- a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/DiscoveryTest.java +++ b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/DiscoveryTest.java @@ -189,7 +189,7 @@ private void setUpWithBuiltinModules(ImmutableMap b SyscallCache.NO_CACHE, externalFilesHelper)) .put(DiscoveryValue.FUNCTION_NAME, new DiscoveryFunction()) - .put(SkyFunctions.BAZEL_LOCK_FILE, new BazelLockFileFunction(rootDirectory)) + .put(SkyFunctions.BAZEL_LOCK_FILE, new BazelLockFileFunction(rootDirectory, directories.getOutputBase())) .put( SkyFunctions.MODULE_FILE, new ModuleFileFunction( diff --git a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionResolutionTest.java b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionResolutionTest.java index 7c6ad9a3ae4cb3..ad0abdd3094401 100644 --- a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionResolutionTest.java +++ b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionResolutionTest.java @@ -237,7 +237,7 @@ public void setup() throws Exception { .put( BzlmodRepoRuleValue.BZLMOD_REPO_RULE, new BzlmodRepoRuleFunction(ruleClassProvider, directories)) - .put(SkyFunctions.BAZEL_LOCK_FILE, new BazelLockFileFunction(rootDirectory)) + .put(SkyFunctions.BAZEL_LOCK_FILE, new BazelLockFileFunction(rootDirectory, directories.getOutputBase())) .put(SkyFunctions.BAZEL_DEP_GRAPH, new BazelDepGraphFunction()) .put(SkyFunctions.BAZEL_MODULE_RESOLUTION, new BazelModuleResolutionFunction()) .put(SkyFunctions.SINGLE_EXTENSION_USAGES, new SingleExtensionUsagesFunction()) diff --git a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileFunctionTest.java b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileFunctionTest.java index 36f315a5d7042d..50ab71df36fb09 100644 --- a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileFunctionTest.java @@ -148,7 +148,9 @@ private void setUpWithBuiltinModules(ImmutableMap b new TimestampGranularityMonitor(BlazeClock.instance())), SyscallCache.NO_CACHE, externalFilesHelper)) - .put(SkyFunctions.BAZEL_LOCK_FILE, new BazelLockFileFunction(rootDirectory)) + .put( + SkyFunctions.BAZEL_LOCK_FILE, + new BazelLockFileFunction(rootDirectory, directories.getOutputBase())) .put( SkyFunctions.MODULE_FILE, new ModuleFileFunction( diff --git a/src/test/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorTest.java b/src/test/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorTest.java index 79e3752f0a8b9b..4f3ce86fe329e2 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorTest.java @@ -240,7 +240,9 @@ public void setupDelegator() throws Exception { rootPath, ImmutableMap.of())) .put(SkyFunctions.BAZEL_DEP_GRAPH, new BazelDepGraphFunction()) - .put(SkyFunctions.BAZEL_LOCK_FILE, new BazelLockFileFunction(rootDirectory)) + .put( + SkyFunctions.BAZEL_LOCK_FILE, + new BazelLockFileFunction(rootDirectory, directories.getOutputBase())) .put(SkyFunctions.BAZEL_MODULE_RESOLUTION, new BazelModuleResolutionFunction()) .put( BzlmodRepoRuleValue.BZLMOD_REPO_RULE, diff --git a/src/test/py/bazel/bzlmod/bazel_lockfile_test.py b/src/test/py/bazel/bzlmod/bazel_lockfile_test.py index ce01663da7246c..e38f788f3b7115 100644 --- a/src/test/py/bazel/bzlmod/bazel_lockfile_test.py +++ b/src/test/py/bazel/bzlmod/bazel_lockfile_test.py @@ -60,6 +60,12 @@ def setUp(self): # TODO(pcloudy): investigate why this is needed, MODULE.bazel.lock is not # deterministic? os.remove(self.Path('MODULE.bazel.lock')) + _, stdout, _ = self.RunBazel(['info', 'output_base']) + output_base = pathlib.Path(stdout[0].strip()) + try: + os.remove(output_base.joinpath('MODULE.bazel.lock')) + except FileNotFoundError: + pass def tearDown(self): self.main_registry.stop()