From ac71f1097c71fd2016d3cb83fdf2c8a63dbae5a5 Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Fri, 26 Apr 2024 17:39:06 +0200 Subject: [PATCH] Revert "user-specific path in lockfile" changes Revert "Remove user specific path from the lockfile (Fixes #19621)" This reverts commit 173bd2bdfad18f971c1ede0a95c205db0f891e11. Revert "Remove user specific absolute path from lockfile" This reverts commit 736a06813d698eea0a266d09f4664a11c1ff672e. --- .../lib/bazel/BazelRepositoryModule.java | 4 +-- .../devtools/build/lib/bazel/bzlmod/BUILD | 1 - .../bazel/bzlmod/BazelLockFileFunction.java | 7 ++-- .../lib/bazel/bzlmod/BazelLockFileModule.java | 3 +- .../lib/bazel/bzlmod/GsonTypeAdapterUtil.java | 23 +++++------- .../build/lib/bazel/bzlmod/IndexRegistry.java | 18 ++++------ .../lib/bazel/bzlmod/RegistryFactoryImpl.java | 12 ++----- .../lib/bazel/bzlmod/RegistryFunction.java | 9 +++-- .../bazel/bzlmod/YankedVersionsFunction.java | 2 +- .../lib/skyframe/BzlmodRepoRuleFunction.java | 34 +----------------- .../skyframe/packages/BazelPackageLoader.java | 7 ++-- .../build/lib/analysis/util/AnalysisMock.java | 4 ++- .../bzlmod/BazelDepGraphFunctionTest.java | 4 ++- .../BazelModuleResolutionFunctionTest.java | 4 ++- .../bzlmod/BzlmodRepoRuleFunctionTest.java | 4 ++- .../build/lib/bazel/bzlmod/DiscoveryTest.java | 4 ++- .../lib/bazel/bzlmod/IndexRegistryTest.java | 5 +-- .../bzlmod/ModuleExtensionResolutionTest.java | 4 ++- .../bazel/bzlmod/ModuleFileFunctionTest.java | 4 ++- .../lib/bazel/bzlmod/RegistryFactoryTest.java | 12 ++----- .../repository/RepositoryDelegatorTest.java | 4 ++- .../py/bazel/bzlmod/bazel_lockfile_test.py | 35 ++++++++----------- 22 files changed, 81 insertions(+), 123 deletions(-) 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 8378eedc6e6368..58ce1c66eef484 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 @@ -270,8 +270,8 @@ SkyFunctions.BAZEL_LOCK_FILE, new BazelLockFileFunction(directories.getWorkspace .addSkyFunction( SkyFunctions.REGISTRY, new RegistryFunction( - new RegistryFactoryImpl( - directories.getWorkspace(), downloadManager, clientEnvironmentSupplier))) + new RegistryFactoryImpl(downloadManager, clientEnvironmentSupplier), + directories.getWorkspace())) .addSkyFunction(SkyFunctions.REPO_SPEC, new RepoSpecFunction()) .addSkyFunction(SkyFunctions.YANKED_VERSIONS, new YankedVersionsFunction()) .addSkyFunction( 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 0fc9f3bede3114..18efd5f7ed8d32 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 @@ -85,7 +85,6 @@ java_library( "//src/main/java/com/google/devtools/build/lib/events", "//src/main/java/com/google/devtools/build/lib/profiler", "//src/main/java/com/google/devtools/build/lib/util:os", - "//src/main/java/com/google/devtools/build/lib/vfs", "//src/main/java/com/google/devtools/build/lib/vfs:pathfragment", "//src/main/java/com/google/devtools/build/skyframe:skyframe-objects", "//third_party:gson", 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 444426549226aa..b575026f8d7032 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 @@ -70,7 +70,7 @@ public SkyValue compute(SkyKey skyKey, Environment env) } try (SilentCloseable c = Profiler.instance().profile(ProfilerTask.BZLMOD, "parse lockfile")) { - return getLockfileValue(lockfilePath, rootDirectory, LOCKFILE_MODE.get(env)); + return getLockfileValue(lockfilePath, LOCKFILE_MODE.get(env)); } catch (IOException | JsonSyntaxException | NullPointerException e) { throw new BazelLockfileFunctionException( ExternalDepsException.withMessage( @@ -83,7 +83,7 @@ public SkyValue compute(SkyKey skyKey, Environment env) } public static BazelLockFileValue getLockfileValue( - RootedPath lockfilePath, Path rootDirectory, LockfileMode lockfileMode) + RootedPath lockfilePath, LockfileMode lockfileMode) throws IOException, BazelLockfileFunctionException { try { String json = FileSystemUtils.readContent(lockfilePath.asPath(), UTF_8); @@ -94,8 +94,7 @@ public static BazelLockFileValue getLockfileValue( lockfilePath .asPath() .getParentDirectory() - .getRelative(LabelConstants.MODULE_DOT_BAZEL_FILE_NAME), - rootDirectory) + .getRelative(LabelConstants.MODULE_DOT_BAZEL_FILE_NAME)) .fromJson(json, BazelLockFileValue.class); } else { // This is an old version, its information can't be used. 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 fa82c78a75a095..1d9f21189101db 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 @@ -255,8 +255,7 @@ private static void updateLockfile(Path workspaceRoot, BazelLockFileValue update lockfilePath .asPath() .getParentDirectory() - .getRelative(LabelConstants.MODULE_DOT_BAZEL_FILE_NAME), - workspaceRoot) + .getRelative(LabelConstants.MODULE_DOT_BAZEL_FILE_NAME)) .toJson(updatedLockfile) + "\n"); } catch (IOException e) { diff --git a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/GsonTypeAdapterUtil.java b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/GsonTypeAdapterUtil.java index 912b455287352e..92b85a3ba9a0c4 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/GsonTypeAdapterUtil.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/GsonTypeAdapterUtil.java @@ -384,23 +384,23 @@ protected abstract static class RootModuleFileEscapingLocation { public abstract int column(); - public Location toLocation(String moduleFilePath, String workspaceRoot) { + public Location toLocation(String moduleFilePath) { String file; if (file().equals(ROOT_MODULE_FILE_LABEL)) { file = moduleFilePath; } else { - file = file().replace("%workspace%", workspaceRoot); + file = file(); } return Location.fromFileLineColumn(file, line(), column()); } public static RootModuleFileEscapingLocation fromLocation( - Location location, String moduleFilePath, String workspaceRoot) { + Location location, String moduleFilePath) { String file; if (location.file().equals(moduleFilePath)) { file = ROOT_MODULE_FILE_LABEL; } else { - file = location.file().replace(workspaceRoot, "%workspace%"); + file = location.file(); } return new AutoValue_GsonTypeAdapterUtil_RootModuleFileEscapingLocation( file, location.line(), location.column()); @@ -410,11 +410,9 @@ public static RootModuleFileEscapingLocation fromLocation( private static final class LocationTypeAdapterFactory implements TypeAdapterFactory { private final String moduleFilePath; - private final String workspaceRoot; - public LocationTypeAdapterFactory(Path moduleFilePath, Path workspaceRoot) { + public LocationTypeAdapterFactory(Path moduleFilePath) { this.moduleFilePath = moduleFilePath.getPathString(); - this.workspaceRoot = workspaceRoot.getPathString(); } @Nullable @@ -433,15 +431,12 @@ public TypeAdapter create(Gson gson, TypeToken typeToken) { public void write(JsonWriter jsonWriter, Location location) throws IOException { relativizedLocationTypeAdapter.write( jsonWriter, - RootModuleFileEscapingLocation.fromLocation( - location, moduleFilePath, workspaceRoot)); + RootModuleFileEscapingLocation.fromLocation(location, moduleFilePath)); } @Override public Location read(JsonReader jsonReader) throws IOException { - return relativizedLocationTypeAdapter - .read(jsonReader) - .toLocation(moduleFilePath, workspaceRoot); + return relativizedLocationTypeAdapter.read(jsonReader).toLocation(moduleFilePath); } }; } @@ -528,10 +523,10 @@ public Optional read(JsonReader jsonReader) throws IOException { } } - public static Gson createLockFileGson(Path moduleFilePath, Path workspaceRoot) { + public static Gson createLockFileGson(Path moduleFilePath) { return newGsonBuilder() .setPrettyPrinting() - .registerTypeAdapterFactory(new LocationTypeAdapterFactory(moduleFilePath, workspaceRoot)) + .registerTypeAdapterFactory(new LocationTypeAdapterFactory(moduleFilePath)) .registerTypeAdapterFactory(new OptionalChecksumTypeAdapterFactory()) .create(); } diff --git a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/IndexRegistry.java b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/IndexRegistry.java index e76ba5c80a8fb8..e5c3ba9639c9d3 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/IndexRegistry.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/IndexRegistry.java @@ -64,9 +64,6 @@ public enum KnownFileHashesMode { ENFORCE } - /** The unresolved version of the url. Ex: has %workspace% placeholder */ - private final String unresolvedUri; - private final URI uri; private final DownloadManager downloadManager; private final Map clientEnv; @@ -80,13 +77,11 @@ public enum KnownFileHashesMode { public IndexRegistry( URI uri, - String unresolvedUri, DownloadManager downloadManager, Map clientEnv, ImmutableMap> knownFileHashes, KnownFileHashesMode knownFileHashesMode) { this.uri = uri; - this.unresolvedUri = unresolvedUri; this.downloadManager = downloadManager; this.clientEnv = clientEnv; this.gson = @@ -99,7 +94,7 @@ public IndexRegistry( @Override public String getUrl() { - return unresolvedUri; + return uri.toString(); } private String constructUrl(String base, String... segments) { @@ -176,7 +171,7 @@ public Optional getModuleFile(ModuleKey key, ExtendedEventHandler ev throws IOException, InterruptedException { String url = constructUrl( - uri.toString(), "modules", key.getName(), key.getVersion().toString(), "MODULE.bazel"); + getUrl(), "modules", key.getName(), key.getVersion().toString(), "MODULE.bazel"); Optional maybeContent = grabFile(url, eventHandler, /* useChecksum= */ true); return maybeContent.map(content -> ModuleFile.create(content, url)); } @@ -259,7 +254,8 @@ public RepoSpec getRepoSpec(ModuleKey key, ExtendedEventHandler eventHandler) Optional jsonString = grabJsonFile(jsonUrl, eventHandler, /* useChecksum= */ true); if (jsonString.isEmpty()) { throw new FileNotFoundException( - String.format("Module %s's %s not found in registry %s", key, SOURCE_JSON_FILENAME, uri)); + String.format( + "Module %s's %s not found in registry %s", key, SOURCE_JSON_FILENAME, getUrl())); } SourceJson sourceJson = parseJson(jsonString.get(), jsonUrl, SourceJson.class); switch (sourceJson.type) { @@ -300,7 +296,7 @@ private Optional getBazelRegistryJson(ExtendedEventHandler ev var storedEventHandler = new StoredEventHandler(); bazelRegistryJson = grabJson( - constructUrl(uri.toString(), "bazel_registry.json"), + constructUrl(getUrl(), "bazel_registry.json"), BazelRegistryJson.class, storedEventHandler, /* useChecksum= */ true); @@ -377,7 +373,7 @@ private RepoSpec createArchiveRepoSpec( for (Map.Entry entry : sourceJson.patches.entrySet()) { remotePatches.put( constructUrl( - unresolvedUri, + getUrl(), "modules", key.getName(), key.getVersion().toString(), @@ -415,7 +411,7 @@ public Optional> getYankedVersions( throws IOException, InterruptedException { Optional metadataJson = grabJson( - constructUrl(uri.toString(), "modules", moduleName, "metadata.json"), + constructUrl(getUrl(), "modules", moduleName, "metadata.json"), MetadataJson.class, eventHandler, // metadata.json is not immutable diff --git a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/RegistryFactoryImpl.java b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/RegistryFactoryImpl.java index 3d1b18c63f2782..16d833bbb1d2d8 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/RegistryFactoryImpl.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/RegistryFactoryImpl.java @@ -20,7 +20,6 @@ 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.bazel.repository.downloader.DownloadManager; -import com.google.devtools.build.lib.vfs.Path; import java.net.URI; import java.net.URISyntaxException; import java.util.Map; @@ -29,26 +28,22 @@ /** Prod implementation of {@link RegistryFactory}. */ public class RegistryFactoryImpl implements RegistryFactory { - private final Path workspacePath; private final DownloadManager downloadManager; private final Supplier> clientEnvironmentSupplier; public RegistryFactoryImpl( - Path workspacePath, - DownloadManager downloadManager, - Supplier> clientEnvironmentSupplier) { - this.workspacePath = workspacePath; + DownloadManager downloadManager, Supplier> clientEnvironmentSupplier) { this.downloadManager = downloadManager; this.clientEnvironmentSupplier = clientEnvironmentSupplier; } @Override public Registry createRegistry( - String unresolvedUrl, + String url, ImmutableMap> knownFileHashes, LockfileMode lockfileMode) throws URISyntaxException { - URI uri = new URI(unresolvedUrl.replace("%workspace%", workspacePath.getPathString())); + URI uri = new URI(url); if (uri.getScheme() == null) { throw new URISyntaxException( uri.toString(), @@ -73,7 +68,6 @@ public Registry createRegistry( }; return new IndexRegistry( uri, - unresolvedUrl, downloadManager, clientEnvironmentSupplier.get(), knownFileHashes, 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 9f60ed89352032..10a85b8ef54bc7 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 @@ -17,6 +17,7 @@ import com.google.devtools.build.lib.bazel.repository.RepositoryOptions.LockfileMode; import com.google.devtools.build.lib.server.FailureDetails; +import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.skyframe.SkyFunction; import com.google.devtools.build.skyframe.SkyFunctionException; import com.google.devtools.build.skyframe.SkyKey; @@ -27,9 +28,11 @@ /** A simple SkyFunction that creates a {@link Registry} with a given URL. */ public class RegistryFunction implements SkyFunction { private final RegistryFactory registryFactory; + private final Path workspaceRoot; - public RegistryFunction(RegistryFactory registryFactory) { + public RegistryFunction(RegistryFactory registryFactory, Path workspaceRoot) { this.registryFactory = registryFactory; + this.workspaceRoot = workspaceRoot; } @Override @@ -46,7 +49,9 @@ public SkyValue compute(SkyKey skyKey, Environment env) RegistryKey key = (RegistryKey) skyKey.argument(); try { return registryFactory.createRegistry( - key.getUrl(), lockfile.getRegistryFileHashes(), lockfileMode); + key.getUrl().replace("%workspace%", workspaceRoot.getPathString()), + lockfile.getRegistryFileHashes(), + lockfileMode); } catch (URISyntaxException e) { throw new RegistryException( ExternalDepsException.withCauseAndMessage( diff --git a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/YankedVersionsFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/YankedVersionsFunction.java index 6420600709c0e2..a61b15ac40b7c5 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/YankedVersionsFunction.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/YankedVersionsFunction.java @@ -64,7 +64,7 @@ public SkyValue compute(SkyKey skyKey, Environment env) throws InterruptedExcept Event.warn( String.format( "Could not read metadata file for module %s from registry %s: %s", - key.getModuleName(), key.getRegistryUrl(), e.getMessage()))); + key.getModuleKey().getName(), key.getRegistryUrl(), e.getMessage()))); // This is failing open: If we can't read the metadata file, we allow yanked modules to be // fetched. return YankedVersionsValue.create(Optional.empty()); diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/BzlmodRepoRuleFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/BzlmodRepoRuleFunction.java index 9298ac9e6f1c7d..0601ffebbf6882 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/BzlmodRepoRuleFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/BzlmodRepoRuleFunction.java @@ -14,7 +14,6 @@ package com.google.devtools.build.lib.skyframe; -import static com.google.common.collect.ImmutableMap.toImmutableMap; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -22,7 +21,6 @@ import com.google.common.collect.ImmutableSet; import com.google.devtools.build.lib.analysis.BlazeDirectories; import com.google.devtools.build.lib.bazel.bzlmod.ArchiveRepoSpecBuilder; -import com.google.devtools.build.lib.bazel.bzlmod.AttributeValues; import com.google.devtools.build.lib.bazel.bzlmod.BazelDepGraphValue; import com.google.devtools.build.lib.bazel.bzlmod.BzlmodRepoRuleCreator; import com.google.devtools.build.lib.bazel.bzlmod.BzlmodRepoRuleValue; @@ -51,7 +49,6 @@ import com.google.devtools.build.skyframe.SkyFunctionException.Transience; import com.google.devtools.build.skyframe.SkyKey; import com.google.devtools.build.skyframe.SkyValue; -import java.util.Map; import java.util.Map.Entry; import java.util.Optional; import java.util.Set; @@ -193,7 +190,7 @@ private BzlmodRepoRuleValue createRuleFromSpec( var attributes = ImmutableMap.builder() - .putAll(resolveRemotePatchesUrl(repoSpec).attributes()) + .putAll(repoSpec.attributes().attributes()) .put("name", repositoryName.getName()) .buildOrThrow(); try { @@ -217,35 +214,6 @@ private BzlmodRepoRuleValue createRuleFromSpec( } } - /* Resolves repo specs containing remote patches that are stored with %workspace% place holder*/ - @SuppressWarnings("unchecked") - private AttributeValues resolveRemotePatchesUrl(RepoSpec repoSpec) { - if (repoSpec - .getRuleClass() - .equals(ArchiveRepoSpecBuilder.HTTP_ARCHIVE_PATH + "%http_archive")) { - return AttributeValues.create( - repoSpec.attributes().attributes().entrySet().stream() - .collect( - toImmutableMap( - Map.Entry::getKey, - e -> { - if (e.getKey().equals("remote_patches")) { - Map remotePatches = (Map) e.getValue(); - return remotePatches.keySet().stream() - .collect( - toImmutableMap( - key -> - key.replace( - "%workspace%", - directories.getWorkspace().getPathString()), - remotePatches::get)); - } - return e.getValue(); - }))); - } - return repoSpec.attributes(); - } - // Starlark rules loaded from bazel_tools that may define Bazel module repositories and thus must // be loaded without relying on any other modules. private static final Set BOOTSTRAP_RULE_CLASSES = 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 344048abe5413c..36e72039fdcb95 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 @@ -139,8 +139,7 @@ public BazelPackageLoader buildImpl() { HttpDownloader httpDownloader = new HttpDownloader(); DownloadManager downloadManager = new DownloadManager(repositoryCache, httpDownloader); RegistryFactory registryFactory = - new RegistryFactoryImpl( - directories.getWorkspace(), downloadManager, Suppliers.ofInstance(ImmutableMap.of())); + new RegistryFactoryImpl(downloadManager, Suppliers.ofInstance(ImmutableMap.of())); // Allow tests to override the following functions to use fake registry or custom built-in // modules @@ -160,7 +159,9 @@ public BazelPackageLoader buildImpl() { } if (!this.extraSkyFunctions.containsKey(SkyFunctions.REGISTRY)) { addExtraSkyFunctions( - ImmutableMap.of(SkyFunctions.REGISTRY, new RegistryFunction(registryFactory))); + ImmutableMap.of( + SkyFunctions.REGISTRY, + new RegistryFunction(registryFactory, directories.getWorkspace()))); } addExtraSkyFunctions( 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 56c441fd966016..c7a16c496bf52e 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 @@ -183,7 +183,9 @@ public ImmutableMap getSkyFunctions(BlazeDirectori SkyFunctions.SINGLE_EXTENSION_EVAL, new SingleExtensionEvalFunction(directories, ImmutableMap::of, downloadManager)) .put(SkyFunctions.SINGLE_EXTENSION_USAGES, new SingleExtensionUsagesFunction()) - .put(SkyFunctions.REGISTRY, new RegistryFunction(FakeRegistry.DEFAULT_FACTORY)) + .put( + SkyFunctions.REGISTRY, + new RegistryFunction(FakeRegistry.DEFAULT_FACTORY, directories.getWorkspace())) .put(SkyFunctions.REPO_SPEC, new RepoSpecFunction()) .put(SkyFunctions.YANKED_VERSIONS, new YankedVersionsFunction()) .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 a8d61f8fa61ed5..3327f1fc54497f 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 @@ -129,7 +129,9 @@ public void setup() throws Exception { .put(SkyFunctions.BAZEL_LOCK_FILE, new BazelLockFileFunction(rootDirectory)) .put(SkyFunctions.BAZEL_DEP_GRAPH, new BazelDepGraphFunction()) .put(SkyFunctions.BAZEL_MODULE_RESOLUTION, resolutionFunctionMock) - .put(SkyFunctions.REGISTRY, new RegistryFunction(new FakeRegistry.Factory())) + .put( + SkyFunctions.REGISTRY, + new RegistryFunction(new FakeRegistry.Factory(), directories.getWorkspace())) .put(SkyFunctions.REPO_SPEC, new RepoSpecFunction()) .put(SkyFunctions.YANKED_VERSIONS, new YankedVersionsFunction()) .put( 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 2c4a7b3099c6d6..38ee7f4d338e29 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 @@ -146,7 +146,9 @@ public void setup() throws Exception { .put(SkyFunctions.BAZEL_DEP_GRAPH, new BazelDepGraphFunction()) .put(SkyFunctions.BAZEL_LOCK_FILE, new BazelLockFileFunction(rootDirectory)) .put(SkyFunctions.BAZEL_MODULE_RESOLUTION, new BazelModuleResolutionFunction()) - .put(SkyFunctions.REGISTRY, new RegistryFunction(registryFactory)) + .put( + SkyFunctions.REGISTRY, + new RegistryFunction(registryFactory, directories.getWorkspace())) .put(SkyFunctions.REPO_SPEC, new RepoSpecFunction()) .put(SkyFunctions.YANKED_VERSIONS, new YankedVersionsFunction()) .put( 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 444ba83ce719d1..9c98532eec437b 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 @@ -134,7 +134,9 @@ public void setup() throws Exception { ruleClassProvider.getBazelStarlarkEnvironment(), workspaceRoot, ImmutableMap.of())) - .put(SkyFunctions.REGISTRY, new RegistryFunction(registryFactory)) + .put( + SkyFunctions.REGISTRY, + new RegistryFunction(registryFactory, directories.getWorkspace())) .put(SkyFunctions.REPO_SPEC, new RepoSpecFunction()) .put(SkyFunctions.YANKED_VERSIONS, new YankedVersionsFunction()) .put( 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 eb3278b1525646..15a5fb4e2b572c 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 @@ -205,7 +205,9 @@ private void setUpWithBuiltinModules(ImmutableMap b .put( BzlmodRepoRuleValue.BZLMOD_REPO_RULE, new BzlmodRepoRuleFunction(ruleClassProvider, directories)) - .put(SkyFunctions.REGISTRY, new RegistryFunction(registryFactory)) + .put( + SkyFunctions.REGISTRY, + new RegistryFunction(registryFactory, directories.getWorkspace())) .put(SkyFunctions.REPO_SPEC, new RepoSpecFunction()) .put(SkyFunctions.YANKED_VERSIONS, new YankedVersionsFunction()) .put( diff --git a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/IndexRegistryTest.java b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/IndexRegistryTest.java index 6ce3d2051117a5..de48900f6fd665 100644 --- a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/IndexRegistryTest.java +++ b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/IndexRegistryTest.java @@ -37,7 +37,6 @@ import com.google.devtools.build.lib.bazel.repository.downloader.DownloadManager; import com.google.devtools.build.lib.bazel.repository.downloader.HttpDownloader; import com.google.devtools.build.lib.testutil.FoundationTestCase; -import com.google.devtools.build.lib.vfs.Path; import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; @@ -85,12 +84,10 @@ public ImmutableMap> getRecordedHashes() { public void setUp() throws Exception { eventRecorder = new EventRecorder(); eventBus.register(eventRecorder); - Path workspaceRoot = scratch.dir("/ws"); repositoryCache = new RepositoryCache(); downloadManager = new DownloadManager(repositoryCache, new HttpDownloader()); registryFactory = - new RegistryFactoryImpl( - workspaceRoot, downloadManager, Suppliers.ofInstance(ImmutableMap.of())); + new RegistryFactoryImpl(downloadManager, Suppliers.ofInstance(ImmutableMap.of())); } @Test 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 66070625ecaaf0..a28afa87be931c 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 @@ -250,7 +250,9 @@ public void setup() throws Exception { .put( SkyFunctions.SINGLE_EXTENSION_EVAL, new SingleExtensionEvalFunction(directories, ImmutableMap::of, downloadManager)) - .put(SkyFunctions.REGISTRY, new RegistryFunction(registryFactory)) + .put( + SkyFunctions.REGISTRY, + new RegistryFunction(registryFactory, directories.getWorkspace())) .put(SkyFunctions.REPO_SPEC, new RepoSpecFunction()) .put(SkyFunctions.YANKED_VERSIONS, new YankedVersionsFunction()) .put( 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 01e4dcfa853a2a..a17632d356a09b 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 @@ -178,7 +178,9 @@ private void setUpWithBuiltinModules(ImmutableMap b .put( BzlmodRepoRuleValue.BZLMOD_REPO_RULE, new BzlmodRepoRuleFunction(ruleClassProvider, directories)) - .put(SkyFunctions.REGISTRY, new RegistryFunction(registryFactory)) + .put( + SkyFunctions.REGISTRY, + new RegistryFunction(registryFactory, directories.getWorkspace())) .put(SkyFunctions.REPO_SPEC, new RepoSpecFunction()) .put(SkyFunctions.YANKED_VERSIONS, new YankedVersionsFunction()) .put( diff --git a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/RegistryFactoryTest.java b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/RegistryFactoryTest.java index 99b37b8b509926..db975081459785 100644 --- a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/RegistryFactoryTest.java +++ b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/RegistryFactoryTest.java @@ -24,8 +24,6 @@ import com.google.devtools.build.lib.bazel.repository.cache.RepositoryCache; import com.google.devtools.build.lib.bazel.repository.downloader.DownloadManager; import com.google.devtools.build.lib.bazel.repository.downloader.HttpDownloader; -import com.google.devtools.build.lib.testutil.FoundationTestCase; -import com.google.devtools.build.lib.vfs.Path; import java.net.URISyntaxException; import org.junit.Test; import org.junit.runner.RunWith; @@ -33,14 +31,12 @@ /** Tests for {@link RegistryFactory}. */ @RunWith(JUnit4.class) -public class RegistryFactoryTest extends FoundationTestCase { +public class RegistryFactoryTest { @Test - public void badSchemes() throws Exception { - Path workspaceRoot = scratch.dir("/ws"); + public void badSchemes() { RegistryFactory registryFactory = new RegistryFactoryImpl( - workspaceRoot, new DownloadManager(new RepositoryCache(), new HttpDownloader()), Suppliers.ofInstance(ImmutableMap.of())); Throwable exception = @@ -60,11 +56,9 @@ public void badSchemes() throws Exception { } @Test - public void badPath() throws Exception { - Path workspaceRoot = scratch.dir("/ws"); + public void badPath() { RegistryFactory registryFactory = new RegistryFactoryImpl( - workspaceRoot, new DownloadManager(new RepositoryCache(), new HttpDownloader()), Suppliers.ofInstance(ImmutableMap.of())); Throwable exception = 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 0c88fc5db85402..71cca88dfa2cc4 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 @@ -248,7 +248,9 @@ public void setupDelegator() throws Exception { .put( BzlmodRepoRuleValue.BZLMOD_REPO_RULE, new BzlmodRepoRuleFunction(ruleClassProvider, directories)) - .put(SkyFunctions.REGISTRY, new RegistryFunction(registryFactory)) + .put( + SkyFunctions.REGISTRY, + new RegistryFunction(registryFactory, directories.getWorkspace())) .put(SkyFunctions.REPO_SPEC, new RepoSpecFunction()) .put(SkyFunctions.YANKED_VERSIONS, new YankedVersionsFunction()) .put( diff --git a/src/test/py/bazel/bzlmod/bazel_lockfile_test.py b/src/test/py/bazel/bzlmod/bazel_lockfile_test.py index 1c5bfe8c07fc3c..85855249de19a0 100644 --- a/src/test/py/bazel/bzlmod/bazel_lockfile_test.py +++ b/src/test/py/bazel/bzlmod/bazel_lockfile_test.py @@ -1312,9 +1312,10 @@ def testExtensionEvaluationOnlyRerunOnRelevantUsagesChanges(self): '', 'def _ext_1_impl(ctx):', ' print("Ext 1 is being evaluated")', - ' num_tags = len([', - ' tag for mod in ctx.modules for tag in mod.tags.tag', - ' ])', + ( + ' num_tags = len([tag for mod in ctx.modules for tag in' + ' mod.tags.tag])' + ), ' repo_rule(name="dep", value="Ext 1 saw %s tags" % num_tags)', '', 'ext_1 = module_extension(', @@ -1324,9 +1325,10 @@ def testExtensionEvaluationOnlyRerunOnRelevantUsagesChanges(self): '', 'def _ext_2_impl(ctx):', ' print("Ext 2 is being evaluated")', - ' num_tags = len([', - ' tag for mod in ctx.modules for tag in mod.tags.tag', - ' ])', + ( + ' num_tags = len([tag for mod in ctx.modules for tag in' + ' mod.tags.tag])' + ), ' repo_rule(name="dep", value="Ext 2 saw %s tags" % num_tags)', '', 'ext_2 = module_extension(', @@ -1336,9 +1338,10 @@ def testExtensionEvaluationOnlyRerunOnRelevantUsagesChanges(self): '', 'def _ext_3_impl(ctx):', ' print("Ext 3 is being evaluated")', - ' num_tags = len([', - ' tag for mod in ctx.modules for tag in mod.tags.tag', - ' ])', + ( + ' num_tags = len([tag for mod in ctx.modules for tag in' + ' mod.tags.tag])' + ), ' repo_rule(name="dep", value="Ext 3 saw %s tags" % num_tags)', '', 'ext_3 = module_extension(', @@ -1513,17 +1516,9 @@ def testLockfileWithNoUserSpecificPath(self): ['build', '--registry=file:///%workspace%/registry', '//:lala'] ) - with open('MODULE.bazel.lock', 'r') as json_file: - lockfile = json.load(json_file) - ss_dep = lockfile['moduleDepGraph']['ss@1.3-1'] - remote_patches = ss_dep['repoSpec']['attributes']['remote_patches'] - ext_usage_location = ss_dep['extensionUsages'][0]['location']['file'] - - self.assertNotIn(self.my_registry.getURL(), ext_usage_location) - self.assertIn('%workspace%', ext_usage_location) - for key in remote_patches.keys(): - self.assertNotIn(self.my_registry.getURL(), key) - self.assertIn('%workspace%', key) + with open('MODULE.bazel.lock', 'r') as f: + self.assertNotIn(self.my_registry.getURL(), f.read()) + finally: self.my_registry.stop()