From 7d5efb60c3ffc4f2ab863e2803de73f2063b54ee 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 | 2 +- .../devtools/build/lib/bazel/bzlmod/BUILD | 1 - .../bazel/bzlmod/BazelLockFileFunction.java | 9 ++--- .../lib/bazel/bzlmod/BazelLockFileModule.java | 3 +- .../lib/bazel/bzlmod/GsonTypeAdapterUtil.java | 23 +++++------- .../build/lib/bazel/bzlmod/IndexRegistry.java | 24 +++++-------- .../lib/bazel/bzlmod/RegistryFactoryImpl.java | 12 ++----- .../lib/skyframe/BzlmodRepoRuleFunction.java | 34 +----------------- .../skyframe/packages/BazelPackageLoader.java | 3 +- .../lib/bazel/bzlmod/IndexRegistryTest.java | 5 +-- .../lib/bazel/bzlmod/RegistryFactoryTest.java | 12 ++----- .../py/bazel/bzlmod/bazel_lockfile_test.py | 35 ++++++++----------- 12 files changed, 46 insertions(+), 117 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 ef04d6c6d86361..f4e90749cb565e 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 @@ -273,7 +273,7 @@ SkyFunctions.BAZEL_LOCK_FILE, new BazelLockFileFunction(directories.getWorkspace SkyFunctions.REGISTRY, new RegistryFunction( new RegistryFactoryImpl( - directories.getWorkspace(), downloadManager, clientEnvironmentSupplier))) + downloadManager, clientEnvironmentSupplier))) .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 e82d1f72b285b5..dce6f16844d590 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 @@ -88,7 +88,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 5e34b4c3e83481..4c8aa872646c60 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 @@ -17,7 +17,6 @@ import static java.nio.charset.StandardCharsets.UTF_8; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.devtools.build.lib.actions.FileValue; import com.google.devtools.build.lib.bazel.repository.RepositoryOptions.LockfileMode; @@ -78,7 +77,7 @@ public SkyValue compute(SkyKey skyKey, Environment env) BazelLockFileValue lockfileValue; try (SilentCloseable c = Profiler.instance().profile(ProfilerTask.BZLMOD, "parse lockfile")) { - lockfileValue = getLockfileValue(lockfilePath, rootDirectory); + lockfileValue = getLockfileValue(lockfilePath); } catch (IOException | JsonSyntaxException | NullPointerException e) { throw new BazelLockfileFunctionException( ExternalDepsException.withMessage( @@ -101,8 +100,7 @@ public SkyValue compute(SkyKey skyKey, Environment env) return lockfileValue; } - public static BazelLockFileValue getLockfileValue(RootedPath lockfilePath, Path rootDirectory) - throws IOException { + public static BazelLockFileValue getLockfileValue(RootedPath lockfilePath) throws IOException { BazelLockFileValue bazelLockFileValue; try { String json = FileSystemUtils.readContent(lockfilePath.asPath(), UTF_8); @@ -114,8 +112,7 @@ public static BazelLockFileValue getLockfileValue(RootedPath lockfilePath, Path 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, needs to be updated 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 9d6cd27b326c96..481e5387395e6c 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 @@ -252,8 +252,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 64e07c8f9428f1..3d346798852bb3 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); } }; } @@ -527,10 +522,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 8a190f8b17aef2..ef75486d57bd52 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 @@ -58,9 +58,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; @@ -74,13 +71,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 = @@ -93,7 +88,7 @@ public IndexRegistry( @Override public String getUrl() { - return unresolvedUri; + return uri.toString(); } private String constructUrl(String base, String... segments) { @@ -165,7 +160,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)); } @@ -246,15 +241,12 @@ public RepoSpec getRepoSpec(ModuleKey key, ExtendedEventHandler eventHandler) throws IOException, InterruptedException { String jsonUrl = constructUrl( - uri.toString(), - "modules", - key.getName(), - key.getVersion().toString(), - SOURCE_JSON_FILENAME); + getUrl(), "modules", key.getName(), key.getVersion().toString(), SOURCE_JSON_FILENAME); 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) { @@ -291,7 +283,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); @@ -368,7 +360,7 @@ private RepoSpec createArchiveRepoSpec( for (Map.Entry entry : sourceJson.patches.entrySet()) { remotePatches.put( constructUrl( - unresolvedUri, + getUrl(), "modules", key.getName(), key.getVersion().toString(), @@ -406,7 +398,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/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..b2cda0679a0a65 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 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 5fc42e2e5f997c..b5ad0dffaca4f6 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 @@ -36,7 +36,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/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/py/bazel/bzlmod/bazel_lockfile_test.py b/src/test/py/bazel/bzlmod/bazel_lockfile_test.py index a2457b9d544a37..f2cefa126bc794 100644 --- a/src/test/py/bazel/bzlmod/bazel_lockfile_test.py +++ b/src/test/py/bazel/bzlmod/bazel_lockfile_test.py @@ -1357,9 +1357,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(', @@ -1369,9 +1370,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(', @@ -1381,9 +1383,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(', @@ -1561,17 +1564,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()