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 4184f42154b8d0..5bb316dc4a4955 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 @@ -47,6 +47,7 @@ import com.google.devtools.build.lib.bazel.bzlmod.NonRegistryOverride; import com.google.devtools.build.lib.bazel.bzlmod.RegistryFactory; import com.google.devtools.build.lib.bazel.bzlmod.RegistryFactoryImpl; +import com.google.devtools.build.lib.bazel.bzlmod.RegistryFunction; import com.google.devtools.build.lib.bazel.bzlmod.RepoSpecFunction; import com.google.devtools.build.lib.bazel.bzlmod.SingleExtensionEvalFunction; import com.google.devtools.build.lib.bazel.bzlmod.SingleExtensionUsagesFunction; @@ -243,9 +244,6 @@ public void workspaceInit( clientEnvironmentSupplier, directories, BazelSkyframeExecutorConstants.EXTERNAL_PACKAGE_HELPER); - RegistryFactory registryFactory = - new RegistryFactoryImpl( - directories.getWorkspace(), downloadManager, clientEnvironmentSupplier); singleExtensionEvalFunction = new SingleExtensionEvalFunction(directories, clientEnvironmentSupplier, downloadManager); @@ -259,7 +257,6 @@ public void workspaceInit( SkyFunctions.MODULE_FILE, new ModuleFileFunction( runtime.getRuleClassProvider().getBazelStarlarkEnvironment(), - registryFactory, directories.getWorkspace(), builtinModules)) .addSkyFunction(SkyFunctions.BAZEL_DEP_GRAPH, new BazelDepGraphFunction()) @@ -271,8 +268,13 @@ SkyFunctions.BAZEL_LOCK_FILE, new BazelLockFileFunction(directories.getWorkspace .addSkyFunction(SkyFunctions.BAZEL_MODULE_RESOLUTION, new BazelModuleResolutionFunction()) .addSkyFunction(SkyFunctions.SINGLE_EXTENSION_EVAL, singleExtensionEvalFunction) .addSkyFunction(SkyFunctions.SINGLE_EXTENSION_USAGES, new SingleExtensionUsagesFunction()) - .addSkyFunction(SkyFunctions.REPO_SPEC, new RepoSpecFunction(registryFactory)) - .addSkyFunction(SkyFunctions.YANKED_VERSIONS, new YankedVersionsFunction(registryFactory)) + .addSkyFunction( + SkyFunctions.REGISTRY, + new RegistryFunction( + new RegistryFactoryImpl( + directories.getWorkspace(), downloadManager, clientEnvironmentSupplier))) + .addSkyFunction(SkyFunctions.REPO_SPEC, new RepoSpecFunction()) + .addSkyFunction(SkyFunctions.YANKED_VERSIONS, new YankedVersionsFunction()) .addSkyFunction( SkyFunctions.MODULE_EXTENSION_REPO_MAPPING_ENTRIES, new ModuleExtensionRepoMappingEntriesFunction()); 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 aeec3b5567ba48..32146c81dcede7 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 @@ -87,7 +87,7 @@ java_library( "//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", - "//third_party:caffeine", + "//src/main/java/com/google/devtools/build/skyframe:skyframe-objects", "//third_party:gson", "//third_party:guava", ], @@ -139,6 +139,7 @@ java_library( "ModuleThreadContext.java", "MultipleVersionOverride.java", "NonRegistryOverride.java", + "RegistryKey.java", "RegistryOverride.java", "RepoSpecKey.java", "SingleExtensionEvalValue.java", @@ -191,6 +192,7 @@ java_library( "ModuleExtensionEvaluationProgress.java", "ModuleExtensionRepoMappingEntriesFunction.java", "ModuleFileFunction.java", + "RegistryFunction.java", "RepoSpecFunction.java", "Selection.java", "SingleExtensionEvalFunction.java", diff --git a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileFunction.java index 65b34b304e99e5..9c6a260bf92877 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileFunction.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileFunction.java @@ -15,6 +15,7 @@ package com.google.devtools.build.lib.bazel.bzlmod; +import static com.google.common.collect.ImmutableList.toImmutableList; import static com.google.common.collect.ImmutableMap.toImmutableMap; import static java.nio.charset.StandardCharsets.UTF_8; @@ -55,8 +56,6 @@ import com.google.devtools.build.skyframe.SkyValue; import com.google.errorprone.annotations.FormatMethod; import java.io.IOException; -import java.net.URISyntaxException; -import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Objects; @@ -87,7 +86,6 @@ public class ModuleFileFunction implements SkyFunction { new Precomputed<>("module_overrides"); private final BazelStarlarkEnvironment starlarkEnv; - private final RegistryFactory registryFactory; private final Path workspaceRoot; private final ImmutableMap builtinModules; @@ -107,11 +105,9 @@ public class ModuleFileFunction implements SkyFunction { */ public ModuleFileFunction( BazelStarlarkEnvironment starlarkEnv, - RegistryFactory registryFactory, Path workspaceRoot, ImmutableMap builtinModules) { this.starlarkEnv = starlarkEnv; - this.registryFactory = registryFactory; this.workspaceRoot = workspaceRoot; this.builtinModules = builtinModules; } @@ -478,14 +474,18 @@ private GetModuleFileResult getModuleFile( "unrecognized override type %s for module %s", override.getClass().getSimpleName(), key)); } - List registryObjects = new ArrayList<>(registries.size()); - for (String registryUrl : registries) { - try { - registryObjects.add(registryFactory.getRegistryWithUrl(registryUrl)); - } catch (URISyntaxException e) { - throw errorf(Code.INVALID_REGISTRY_URL, e, "Invalid registry URL"); - } + + List registryKeys = + registries.stream().map(RegistryKey::create).collect(toImmutableList()); + var registryResult = env.getValuesAndExceptions(registryKeys); + if (env.valuesMissing()) { + return null; } + List registryObjects = + registryKeys.stream() + .map(registryResult::get) + .map(Registry.class::cast) + .collect(toImmutableList()); // Now go through the list of registries and use the first one that contains the requested // module. diff --git a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/Registry.java b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/Registry.java index 2355bc62819234..619149d7621a36 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/Registry.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/Registry.java @@ -17,11 +17,12 @@ import com.google.common.collect.ImmutableMap; import com.google.devtools.build.lib.events.ExtendedEventHandler; +import com.google.devtools.build.skyframe.SkyValue; import java.io.IOException; import java.util.Optional; /** A database where module metadata is stored. */ -public interface Registry { +public interface Registry extends SkyValue { /** The URL that uniquely identifies the registry. */ String getUrl(); diff --git a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/RegistryFactory.java b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/RegistryFactory.java index b6ea236065f0b3..03ba85dc2dd4fc 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/RegistryFactory.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/RegistryFactory.java @@ -20,6 +20,10 @@ /** A factory type for {@link Registry}. */ public interface RegistryFactory { - /** Returns the unique registry associated with the given URL. */ - Registry getRegistryWithUrl(String url) throws URISyntaxException; + /** + * Creates a registry associated with the given URL. + * + *

Outside of tests, only {@link RegistryFunction} should call this method. + */ + Registry createRegistry(String url) throws URISyntaxException; } 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 cacea9d7bf7e01..d943e69ef4d44f 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 @@ -15,8 +15,6 @@ package com.google.devtools.build.lib.bazel.bzlmod; -import com.github.benmanes.caffeine.cache.Cache; -import com.github.benmanes.caffeine.cache.Caffeine; import com.google.devtools.build.lib.bazel.repository.downloader.DownloadManager; import com.google.devtools.build.lib.vfs.Path; import java.net.URI; @@ -29,7 +27,6 @@ public class RegistryFactoryImpl implements RegistryFactory { private final Path workspacePath; private final DownloadManager downloadManager; private final Supplier> clientEnvironmentSupplier; - private final Cache registries = Caffeine.newBuilder().build(); public RegistryFactoryImpl( Path workspacePath, @@ -41,7 +38,7 @@ public RegistryFactoryImpl( } @Override - public Registry getRegistryWithUrl(String unresolvedUrl) throws URISyntaxException { + public Registry createRegistry(String unresolvedUrl) throws URISyntaxException { URI uri = new URI(unresolvedUrl.replace("%workspace%", workspacePath.getPathString())); if (uri.getScheme() == null) { throw new URISyntaxException( @@ -55,17 +52,10 @@ public Registry getRegistryWithUrl(String unresolvedUrl) throws URISyntaxExcepti "Registry URL path is not valid -- did you mean to use file:///foo/bar " + "or file:///c:/foo/bar for Windows?"); } - switch (uri.getScheme()) { - case "http": - case "https": - case "file": - return registries.get( - unresolvedUrl, - unused -> - new IndexRegistry( - uri, unresolvedUrl, downloadManager, clientEnvironmentSupplier.get())); - default: - throw new URISyntaxException(uri.toString(), "Unrecognized registry URL protocol"); - } + return switch (uri.getScheme()) { + case "http", "https", "file" -> + new IndexRegistry(uri, unresolvedUrl, downloadManager, clientEnvironmentSupplier.get()); + default -> throw new URISyntaxException(uri.toString(), "Unrecognized registry URL protocol"); + }; } } 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 new file mode 100644 index 00000000000000..e99fc2bbcbbbf5 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/RegistryFunction.java @@ -0,0 +1,57 @@ +// Copyright 2021 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package com.google.devtools.build.lib.bazel.bzlmod; + +import com.google.devtools.build.lib.server.FailureDetails; +import com.google.devtools.build.skyframe.SkyFunction; +import com.google.devtools.build.skyframe.SkyFunctionException; +import com.google.devtools.build.skyframe.SkyKey; +import com.google.devtools.build.skyframe.SkyValue; +import java.net.URISyntaxException; +import javax.annotation.Nullable; + +/** A simple SkyFunction that creates a {@link Registry} with a given URL. */ +public class RegistryFunction implements SkyFunction { + private final RegistryFactory registryFactory; + + public RegistryFunction(RegistryFactory registryFactory) { + this.registryFactory = registryFactory; + } + + @Override + @Nullable + public SkyValue compute(SkyKey skyKey, Environment env) + throws InterruptedException, RegistryException { + RegistryKey key = (RegistryKey) skyKey.argument(); + try { + return registryFactory.createRegistry(key.getUrl()); + } catch (URISyntaxException e) { + throw new RegistryException( + ExternalDepsException.withCauseAndMessage( + FailureDetails.ExternalDeps.Code.INVALID_REGISTRY_URL, + e, + "Invalid registry URL: %s", + key.getUrl())); + } + } + + static final class RegistryException extends SkyFunctionException { + + RegistryException(ExternalDepsException cause) { + super(cause, Transience.TRANSIENT); + } + } +} diff --git a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/RegistryKey.java b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/RegistryKey.java new file mode 100644 index 00000000000000..f87773ef4680b0 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/RegistryKey.java @@ -0,0 +1,46 @@ +// Copyright 2021 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package com.google.devtools.build.lib.bazel.bzlmod; + +import com.google.auto.value.AutoValue; +import com.google.devtools.build.lib.skyframe.SkyFunctions; +import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; +import com.google.devtools.build.skyframe.SkyFunctionName; +import com.google.devtools.build.skyframe.SkyKey; + +/** The key for {@link RegistryFunction}. */ +@AutoCodec +@AutoValue +abstract class RegistryKey implements SkyKey { + private static final SkyKeyInterner interner = SkyKey.newInterner(); + + abstract String getUrl(); + + @AutoCodec.Instantiator + static RegistryKey create(String url) { + return interner.intern(new AutoValue_RegistryKey(url)); + } + + @Override + public SkyFunctionName functionName() { + return SkyFunctions.REGISTRY; + } + + @Override + public SkyKeyInterner getSkyKeyInterner() { + return interner; + } +} diff --git a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/RepoSpecFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/RepoSpecFunction.java index 81b23c3700e700..b9f436999f629b 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/RepoSpecFunction.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/RepoSpecFunction.java @@ -24,7 +24,6 @@ import com.google.devtools.build.skyframe.SkyKey; import com.google.devtools.build.skyframe.SkyValue; import java.io.IOException; -import java.net.URISyntaxException; import javax.annotation.Nullable; /** @@ -32,23 +31,22 @@ * fetching required information from its {@link Registry}. */ public class RepoSpecFunction implements SkyFunction { - private final RegistryFactory registryFactory; - - public RepoSpecFunction(RegistryFactory registryFactory) { - this.registryFactory = registryFactory; - } @Override @Nullable public SkyValue compute(SkyKey skyKey, Environment env) throws InterruptedException, RepoSpecException { RepoSpecKey key = (RepoSpecKey) skyKey.argument(); + + Registry registry = (Registry) env.getValue(RegistryKey.create(key.getRegistryUrl())); + if (registry == null) { + return null; + } + try (SilentCloseable c = Profiler.instance() .profile(ProfilerTask.BZLMOD, () -> "compute repo spec: " + key.getModuleKey())) { - return registryFactory - .getRegistryWithUrl(key.getRegistryUrl()) - .getRepoSpec(key.getModuleKey(), env.getListener()); + return registry.getRepoSpec(key.getModuleKey(), env.getListener()); } catch (IOException e) { throw new RepoSpecException( ExternalDepsException.withCauseAndMessage( @@ -56,10 +54,6 @@ public SkyValue compute(SkyKey skyKey, Environment env) e, "Unable to get module repo spec for %s from registry", key.getModuleKey())); - } catch (URISyntaxException e) { - // This should never happen since we obtain the registry URL from an already constructed - // registry. - throw new IllegalStateException(e); } } 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 f6b14365f23b69..89cd60a5da3bdd 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 @@ -23,7 +23,6 @@ import com.google.devtools.build.skyframe.SkyKey; import com.google.devtools.build.skyframe.SkyValue; import java.io.IOException; -import java.net.URISyntaxException; import java.util.Optional; import javax.annotation.Nullable; @@ -32,24 +31,23 @@ * fetching required information from its {@link Registry}. */ public class YankedVersionsFunction implements SkyFunction { - private final RegistryFactory registryFactory; - - public YankedVersionsFunction(RegistryFactory registryFactory) { - this.registryFactory = registryFactory; - } @Override @Nullable public SkyValue compute(SkyKey skyKey, Environment env) throws InterruptedException { var key = (YankedVersionsValue.Key) skyKey.argument(); + + Registry registry = (Registry) env.getValue(RegistryKey.create(key.getRegistryUrl())); + if (registry == null) { + return null; + } + try (SilentCloseable c = Profiler.instance() .profile( ProfilerTask.BZLMOD, () -> "getting yanked versions: " + key.getModuleName())) { return YankedVersionsValue.create( - registryFactory - .getRegistryWithUrl(key.getRegistryUrl()) - .getYankedVersions(key.getModuleName(), env.getListener())); + registry.getYankedVersions(key.getModuleName(), env.getListener())); } catch (IOException e) { env.getListener() .handle( @@ -59,10 +57,6 @@ public SkyValue compute(SkyKey skyKey, Environment env) throws InterruptedExcept // This is failing open: If we can't read the metadata file, we allow yanked modules to be // fetched. return YankedVersionsValue.create(Optional.empty()); - } catch (URISyntaxException e) { - // This should never happen since we obtain the registry URL from an already constructed - // registry. - throw new IllegalStateException(e); } } } diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyFunctions.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyFunctions.java index 81cd98d84947ea..4105d312d6d48e 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyFunctions.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyFunctions.java @@ -162,6 +162,7 @@ public final class SkyFunctions { SkyFunctionName.createHermetic("BAZEL_LOCK_FILE"); public static final SkyFunctionName BAZEL_FETCH_ALL = SkyFunctionName.createHermetic("BAZEL_FETCH_ALL"); + public static final SkyFunctionName REGISTRY = SkyFunctionName.createNonHermetic("REGISTRY"); public static final SkyFunctionName REPO_SPEC = SkyFunctionName.createNonHermetic("REPO_SPEC"); public static final SkyFunctionName YANKED_VERSIONS = SkyFunctionName.createNonHermetic("YANKED_VERSIONS"); 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 7e4c8b5811cf2a..86b835bf3b51a2 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 @@ -143,8 +143,7 @@ public BazelPackageLoader buildImpl() { SkyFunctions.MODULE_FILE, new ModuleFileFunction( ruleClassProvider.getBazelStarlarkEnvironment(), - registryFactory, - directories.getWorkspace(), + directories.getWorkspace(), ImmutableMap.of()))); } 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 e254db42c024ce..e163c74356ecab 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 @@ -25,6 +25,7 @@ import com.google.devtools.build.lib.bazel.bzlmod.ModuleExtensionRepoMappingEntriesFunction; import com.google.devtools.build.lib.bazel.bzlmod.ModuleFileFunction; import com.google.devtools.build.lib.bazel.bzlmod.NonRegistryOverride; +import com.google.devtools.build.lib.bazel.bzlmod.RegistryFunction; import com.google.devtools.build.lib.bazel.bzlmod.RepoSpecFunction; import com.google.devtools.build.lib.bazel.bzlmod.SingleExtensionEvalFunction; import com.google.devtools.build.lib.bazel.bzlmod.SingleExtensionUsagesFunction; @@ -170,7 +171,6 @@ public ImmutableMap getSkyFunctions(BlazeDirectori SkyFunctions.MODULE_FILE, new ModuleFileFunction( createRuleClassProvider().getBazelStarlarkEnvironment(), - FakeRegistry.DEFAULT_FACTORY, directories.getWorkspace(), getBuiltinModules(directories))) .put(SkyFunctions.BAZEL_DEP_GRAPH, new BazelDepGraphFunction()) @@ -180,8 +180,9 @@ public ImmutableMap getSkyFunctions(BlazeDirectori SkyFunctions.SINGLE_EXTENSION_EVAL, new SingleExtensionEvalFunction(directories, ImmutableMap::of, downloadManager)) .put(SkyFunctions.SINGLE_EXTENSION_USAGES, new SingleExtensionUsagesFunction()) - .put(SkyFunctions.REPO_SPEC, new RepoSpecFunction(FakeRegistry.DEFAULT_FACTORY)) - .put(SkyFunctions.YANKED_VERSIONS, new YankedVersionsFunction(FakeRegistry.DEFAULT_FACTORY)) + .put(SkyFunctions.REGISTRY, new RegistryFunction(FakeRegistry.DEFAULT_FACTORY)) + .put(SkyFunctions.REPO_SPEC, new RepoSpecFunction()) + .put(SkyFunctions.YANKED_VERSIONS, new YankedVersionsFunction()) .put( SkyFunctions.MODULE_EXTENSION_REPO_MAPPING_ENTRIES, new ModuleExtensionRepoMappingEntriesFunction()) @@ -298,7 +299,6 @@ public ImmutableMap getSkyFunctions( SkyFunctions.MODULE_FILE, new ModuleFileFunction( createRuleClassProvider().getBazelStarlarkEnvironment(), - FakeRegistry.DEFAULT_FACTORY, directories.getWorkspace(), getBuiltinModules(directories))) .buildOrThrow(); 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 d9b5d4e4f12bd9..4c707b943f4e4e 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 @@ -80,15 +80,12 @@ public class BazelDepGraphFunctionTest extends FoundationTestCase { private MemoizingEvaluator evaluator; - private RecordingDifferencer differencer; private EvaluationContext evaluationContext; - private FakeRegistry.Factory registryFactory; private BazelModuleResolutionFunctionMock resolutionFunctionMock; @Before public void setup() throws Exception { - differencer = new SequencedRecordingDifferencer(); - registryFactory = new FakeRegistry.Factory(); + RecordingDifferencer differencer = new SequencedRecordingDifferencer(); evaluationContext = EvaluationContext.newBuilder().setParallelism(8).setEventHandler(reporter).build(); @@ -127,15 +124,15 @@ public void setup() throws Exception { SkyFunctions.MODULE_FILE, new ModuleFileFunction( TestRuleClassProvider.getRuleClassProvider().getBazelStarlarkEnvironment(), - registryFactory, rootDirectory, ImmutableMap.of())) .put(SkyFunctions.PRECOMPUTED, new PrecomputedFunction()) .put(SkyFunctions.BAZEL_LOCK_FILE, new BazelLockFileFunction(rootDirectory)) .put(SkyFunctions.BAZEL_DEP_GRAPH, new BazelDepGraphFunction()) .put(SkyFunctions.BAZEL_MODULE_RESOLUTION, resolutionFunctionMock) - .put(SkyFunctions.REPO_SPEC, new RepoSpecFunction(registryFactory)) - .put(SkyFunctions.YANKED_VERSIONS, new YankedVersionsFunction(registryFactory)) + .put(SkyFunctions.REGISTRY, new RegistryFunction(new FakeRegistry.Factory())) + .put(SkyFunctions.REPO_SPEC, new RepoSpecFunction()) + .put(SkyFunctions.YANKED_VERSIONS, new YankedVersionsFunction()) .put( SkyFunctions.MODULE_EXTENSION_REPO_MAPPING_ENTRIES, new ModuleExtensionRepoMappingEntriesFunction()) diff --git a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BazelLockFileFunctionTest.java b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BazelLockFileFunctionTest.java index 881a4140dbe2a3..0aaf96ef375b99 100644 --- a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BazelLockFileFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BazelLockFileFunctionTest.java @@ -87,13 +87,11 @@ public class BazelLockFileFunctionTest extends FoundationTestCase { private MemoizingEvaluator evaluator; private RecordingDifferencer differencer; private EvaluationContext evaluationContext; - private FakeRegistry.Factory registryFactory; private static SkyFunctionName updateLockfileFunction; @Before public void setup() throws Exception { differencer = new SequencedRecordingDifferencer(); - registryFactory = new FakeRegistry.Factory(); evaluationContext = EvaluationContext.newBuilder().setParallelism(8).setEventHandler(reporter).build(); @@ -155,12 +153,12 @@ public void setup() throws Exception { SkyFunctions.MODULE_FILE, new ModuleFileFunction( ruleClassProvider.getBazelStarlarkEnvironment(), - registryFactory, rootDirectory, ImmutableMap.of())) .put(SkyFunctions.BAZEL_LOCK_FILE, new BazelLockFileFunction(rootDirectory)) - .put(SkyFunctions.REPO_SPEC, new RepoSpecFunction(registryFactory)) - .put(SkyFunctions.YANKED_VERSIONS, new YankedVersionsFunction(registryFactory)) + .put(SkyFunctions.REGISTRY, new RegistryFunction(new FakeRegistry.Factory())) + .put(SkyFunctions.REPO_SPEC, new RepoSpecFunction()) + .put(SkyFunctions.YANKED_VERSIONS, new YankedVersionsFunction()) .put( SkyFunctions.MODULE_EXTENSION_REPO_MAPPING_ENTRIES, new ModuleExtensionRepoMappingEntriesFunction()) 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 96506393849605..7fd91f6fd46e1d 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 @@ -113,15 +113,15 @@ public void setup() throws Exception { SkyFunctions.MODULE_FILE, new ModuleFileFunction( TestRuleClassProvider.getRuleClassProvider().getBazelStarlarkEnvironment(), - registryFactory, rootDirectory, 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_MODULE_RESOLUTION, new BazelModuleResolutionFunction()) - .put(SkyFunctions.REPO_SPEC, new RepoSpecFunction(registryFactory)) - .put(SkyFunctions.YANKED_VERSIONS, new YankedVersionsFunction(registryFactory)) + .put(SkyFunctions.REGISTRY, new RegistryFunction(registryFactory)) + .put(SkyFunctions.REPO_SPEC, new RepoSpecFunction()) + .put(SkyFunctions.YANKED_VERSIONS, new YankedVersionsFunction()) .put( SkyFunctions.MODULE_EXTENSION_REPO_MAPPING_ENTRIES, new ModuleExtensionRepoMappingEntriesFunction()) 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 cbedac624d4543..e3c1569fef0675 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 @@ -131,11 +131,11 @@ public void setup() throws Exception { SkyFunctions.MODULE_FILE, new ModuleFileFunction( ruleClassProvider.getBazelStarlarkEnvironment(), - registryFactory, workspaceRoot, ImmutableMap.of())) - .put(SkyFunctions.REPO_SPEC, new RepoSpecFunction(registryFactory)) - .put(SkyFunctions.YANKED_VERSIONS, new YankedVersionsFunction(registryFactory)) + .put(SkyFunctions.REGISTRY, new RegistryFunction(registryFactory)) + .put(SkyFunctions.REPO_SPEC, new RepoSpecFunction()) + .put(SkyFunctions.YANKED_VERSIONS, new YankedVersionsFunction()) .put( SkyFunctions.MODULE_EXTENSION_REPO_MAPPING_ENTRIES, new ModuleExtensionRepoMappingEntriesFunction()) 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 ffaea9de3c0efd..742b5d6ca72655 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 @@ -172,7 +172,6 @@ private void setUpWithBuiltinModules(ImmutableMap b SkyFunctions.MODULE_FILE, new ModuleFileFunction( ruleClassProvider.getBazelStarlarkEnvironment(), - registryFactory, workspaceRoot, builtinModules)) .put(SkyFunctions.PRECOMPUTED, new PrecomputedFunction()) @@ -188,8 +187,9 @@ private void setUpWithBuiltinModules(ImmutableMap b .put( BzlmodRepoRuleValue.BZLMOD_REPO_RULE, new BzlmodRepoRuleFunction(ruleClassProvider, directories)) - .put(SkyFunctions.REPO_SPEC, new RepoSpecFunction(registryFactory)) - .put(SkyFunctions.YANKED_VERSIONS, new YankedVersionsFunction(registryFactory)) + .put(SkyFunctions.REGISTRY, new RegistryFunction(registryFactory)) + .put(SkyFunctions.REPO_SPEC, new RepoSpecFunction()) + .put(SkyFunctions.YANKED_VERSIONS, new YankedVersionsFunction()) .put( SkyFunctions.MODULE_EXTENSION_REPO_MAPPING_ENTRIES, new ModuleExtensionRepoMappingEntriesFunction()) diff --git a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/FakeRegistry.java b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/FakeRegistry.java index eae5c80b9bb9e3..b48529ad7120f8 100644 --- a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/FakeRegistry.java +++ b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/FakeRegistry.java @@ -118,7 +118,7 @@ public FakeRegistry newFakeRegistry(String rootPath) { } @Override - public Registry getRegistryWithUrl(String url) { + public Registry createRegistry(String url) { return Preconditions.checkNotNull(registries.get(url), "unknown registry url: %s", url); } } 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 872a53cf019026..2401275b5c74b3 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 @@ -71,7 +71,7 @@ public void testHttpUrl() throws Exception { server.serve("/myreg/modules/foo/1.0/MODULE.bazel", "lol"); server.start(); - Registry registry = registryFactory.getRegistryWithUrl(server.getUrl() + "/myreg"); + Registry registry = registryFactory.createRegistry(server.getUrl() + "/myreg"); assertThat(registry.getModuleFile(createModuleKey("foo", "1.0"), reporter)) .hasValue( ModuleFile.create( @@ -87,7 +87,7 @@ public void testHttpUrlWithNetrcCreds() throws Exception { NetrcParser.parseAndClose( new ByteArrayInputStream( "machine [::1] login rinne password rinnepass\n".getBytes(UTF_8))); - Registry registry = registryFactory.getRegistryWithUrl(server.getUrl() + "/myreg"); + Registry registry = registryFactory.createRegistry(server.getUrl() + "/myreg"); UnrecoverableHttpException e = assertThrows( @@ -112,7 +112,7 @@ public void testFileUrl() throws Exception { } Registry registry = - registryFactory.getRegistryWithUrl( + registryFactory.createRegistry( new File(tempFolder.getRoot(), "fakereg").toURI().toString()); assertThat(registry.getModuleFile(createModuleKey("foo", "1.0"), reporter)) .hasValue(ModuleFile.create("lol".getBytes(UTF_8), file.toURI().toString())); @@ -149,7 +149,7 @@ public void testGetArchiveRepoSpec() throws Exception { "}"); server.start(); - Registry registry = registryFactory.getRegistryWithUrl(server.getUrl()); + Registry registry = registryFactory.createRegistry(server.getUrl()); assertThat(registry.getRepoSpec(createModuleKey("foo", "1.0"), reporter)) .isEqualTo( new ArchiveRepoSpecBuilder() @@ -193,7 +193,7 @@ public void testGetLocalPathRepoSpec() throws Exception { "}"); server.start(); - Registry registry = registryFactory.getRegistryWithUrl(server.getUrl()); + Registry registry = registryFactory.createRegistry(server.getUrl()); assertThat(registry.getRepoSpec(createModuleKey("foo", "1.0"), reporter)) .isEqualTo( RepoSpec.builder() @@ -215,7 +215,7 @@ public void testGetRepoInvalidRegistryJsonSpec() throws Exception { " \"strip_prefix\": \"pref\"", "}"); - Registry registry = registryFactory.getRegistryWithUrl(server.getUrl()); + Registry registry = registryFactory.createRegistry(server.getUrl()); assertThat(registry.getRepoSpec(createModuleKey("foo", "1.0"), reporter)) .isEqualTo( new ArchiveRepoSpecBuilder() @@ -246,7 +246,7 @@ public void testGetRepoInvalidModuleJsonSpec() throws Exception { "}"); server.start(); - Registry registry = registryFactory.getRegistryWithUrl(server.getUrl()); + Registry registry = registryFactory.createRegistry(server.getUrl()); assertThrows( IOException.class, () -> registry.getRepoSpec(createModuleKey("foo", "1.0"), reporter)); } @@ -273,7 +273,7 @@ public void testGetYankedVersion() throws Exception { + " }\n" + "}"); server.start(); - Registry registry = registryFactory.getRegistryWithUrl(server.getUrl()); + Registry registry = registryFactory.createRegistry(server.getUrl()); Optional> yankedVersion = registry.getYankedVersions("red-pill", reporter); assertThat(yankedVersion) @@ -294,7 +294,7 @@ public void testArchiveWithExplicitType() throws Exception { "}"); server.start(); - Registry registry = registryFactory.getRegistryWithUrl(server.getUrl()); + Registry registry = registryFactory.createRegistry(server.getUrl()); assertThat(registry.getRepoSpec(createModuleKey("archive_type", "1.0"), reporter)) .isEqualTo( new ArchiveRepoSpecBuilder() 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 286b2969703413..39156c5bf0e0de 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 @@ -204,7 +204,6 @@ public void setup() throws Exception { SkyFunctions.MODULE_FILE, new ModuleFileFunction( ruleClassProvider.getBazelStarlarkEnvironment(), - registryFactory, workspaceRoot, // Required to load @_builtins. ImmutableMap.of("bazel_tools", LocalPathOverride.create(bazelToolsPath)))) @@ -271,8 +270,9 @@ public void setup() throws Exception { .put(SkyFunctions.BAZEL_MODULE_RESOLUTION, new BazelModuleResolutionFunction()) .put(SkyFunctions.SINGLE_EXTENSION_USAGES, new SingleExtensionUsagesFunction()) .put(SkyFunctions.SINGLE_EXTENSION_EVAL, singleExtensionEvalFunction) - .put(SkyFunctions.REPO_SPEC, new RepoSpecFunction(registryFactory)) - .put(SkyFunctions.YANKED_VERSIONS, new YankedVersionsFunction(registryFactory)) + .put(SkyFunctions.REGISTRY, new RegistryFunction(registryFactory)) + .put(SkyFunctions.REPO_SPEC, new RepoSpecFunction()) + .put(SkyFunctions.YANKED_VERSIONS, new YankedVersionsFunction()) .put( SkyFunctions.MODULE_EXTENSION_REPO_MAPPING_ENTRIES, new ModuleExtensionRepoMappingEntriesFunction()) 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 0905b2cd9ead3c..8e8ea8b0eacfad 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 @@ -141,7 +141,6 @@ private void setUpWithBuiltinModules(ImmutableMap b SkyFunctions.MODULE_FILE, new ModuleFileFunction( ruleClassProvider.getBazelStarlarkEnvironment(), - registryFactory, rootDirectory, builtinModules)) .put(SkyFunctions.PRECOMPUTED, new PrecomputedFunction()) @@ -157,8 +156,9 @@ private void setUpWithBuiltinModules(ImmutableMap b .put( BzlmodRepoRuleValue.BZLMOD_REPO_RULE, new BzlmodRepoRuleFunction(ruleClassProvider, directories)) - .put(SkyFunctions.REPO_SPEC, new RepoSpecFunction(registryFactory)) - .put(SkyFunctions.YANKED_VERSIONS, new YankedVersionsFunction(registryFactory)) + .put(SkyFunctions.REGISTRY, new RegistryFunction(registryFactory)) + .put(SkyFunctions.REPO_SPEC, new RepoSpecFunction()) + .put(SkyFunctions.YANKED_VERSIONS, new YankedVersionsFunction()) .put( SkyFunctions.MODULE_EXTENSION_REPO_MAPPING_ENTRIES, new ModuleExtensionRepoMappingEntriesFunction()) 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 4afd11da79f749..c42597e96569e8 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 @@ -44,11 +44,11 @@ public void badSchemes() throws Exception { Suppliers.ofInstance(ImmutableMap.of())); Throwable exception = assertThrows( - URISyntaxException.class, () -> registryFactory.getRegistryWithUrl("/home/www")); + URISyntaxException.class, () -> registryFactory.createRegistry("/home/www")); assertThat(exception).hasMessageThat().contains("Registry URL has no scheme"); exception = assertThrows( - URISyntaxException.class, () -> registryFactory.getRegistryWithUrl("foo://bar")); + URISyntaxException.class, () -> registryFactory.createRegistry("foo://bar")); assertThat(exception).hasMessageThat().contains("Unrecognized registry URL protocol"); } @@ -63,7 +63,7 @@ public void badPath() throws Exception { Throwable exception = assertThrows( URISyntaxException.class, - () -> registryFactory.getRegistryWithUrl("file:c:/path/to/workspace/registry")); + () -> registryFactory.createRegistry("file:c:/path/to/workspace/registry")); assertThat(exception).hasMessageThat().contains("Registry URL path is not valid"); } } 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 efad3adc00d419..abf5c618b75a5d 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 @@ -36,6 +36,7 @@ import com.google.devtools.build.lib.bazel.bzlmod.FakeRegistry; import com.google.devtools.build.lib.bazel.bzlmod.ModuleExtensionRepoMappingEntriesFunction; import com.google.devtools.build.lib.bazel.bzlmod.ModuleFileFunction; +import com.google.devtools.build.lib.bazel.bzlmod.RegistryFunction; import com.google.devtools.build.lib.bazel.bzlmod.RepoSpecFunction; import com.google.devtools.build.lib.bazel.bzlmod.YankedVersionsFunction; import com.google.devtools.build.lib.bazel.bzlmod.YankedVersionsUtil; @@ -238,7 +239,6 @@ public void setupDelegator() throws Exception { SkyFunctions.MODULE_FILE, new ModuleFileFunction( ruleClassProvider.getBazelStarlarkEnvironment(), - registryFactory, rootPath, ImmutableMap.of())) .put(SkyFunctions.BAZEL_DEP_GRAPH, new BazelDepGraphFunction()) @@ -247,8 +247,9 @@ public void setupDelegator() throws Exception { .put( BzlmodRepoRuleValue.BZLMOD_REPO_RULE, new BzlmodRepoRuleFunction(ruleClassProvider, directories)) - .put(SkyFunctions.REPO_SPEC, new RepoSpecFunction(registryFactory)) - .put(SkyFunctions.YANKED_VERSIONS, new YankedVersionsFunction(registryFactory)) + .put(SkyFunctions.REGISTRY, new RegistryFunction(registryFactory)) + .put(SkyFunctions.REPO_SPEC, new RepoSpecFunction()) + .put(SkyFunctions.YANKED_VERSIONS, new YankedVersionsFunction()) .put( SkyFunctions.MODULE_EXTENSION_REPO_MAPPING_ENTRIES, new ModuleExtensionRepoMappingEntriesFunction())