Skip to content

Commit

Permalink
Rename VendorUtil to VendorManager
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorcloudy committed Jun 6, 2024
1 parent dd3e0a5 commit 076de9f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import com.google.devtools.build.lib.bazel.bzlmod.SingleExtensionFunction;
import com.google.devtools.build.lib.bazel.bzlmod.SingleExtensionUsagesFunction;
import com.google.devtools.build.lib.bazel.bzlmod.VendorFileFunction;
import com.google.devtools.build.lib.bazel.bzlmod.VendorUtil;
import com.google.devtools.build.lib.bazel.bzlmod.YankedVersionsFunction;
import com.google.devtools.build.lib.bazel.bzlmod.YankedVersionsUtil;
import com.google.devtools.build.lib.bazel.commands.FetchCommand;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ java_library(

java_library(
name = "vendor",
srcs = ["VendorUtil.java"],
srcs = ["VendorManager.java"],
deps = [
"//src/main/java/com/google/devtools/build/lib/bazel/repository/downloader",
"//src/main/java/com/google/devtools/build/lib/cmdline",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public enum KnownFileHashesMode {
private final ImmutableMap<String, Optional<Checksum>> knownFileHashes;
private final ImmutableMap<ModuleKey, String> previouslySelectedYankedVersions;
@Nullable
private final VendorUtil vendorUtil;
private final VendorManager vendorUtil;
private final KnownFileHashesMode knownFileHashesMode;
private volatile Optional<BazelRegistryJson> bazelRegistryJson;
private volatile StoredEventHandler bazelRegistryJsonEvents;
Expand All @@ -117,7 +117,7 @@ public IndexRegistry(
this.knownFileHashes = knownFileHashes;
this.knownFileHashesMode = knownFileHashesMode;
this.previouslySelectedYankedVersions = previouslySelectedYankedVersions;
this.vendorUtil = vendorDir.map(VendorUtil::new).orElse(null);
this.vendorUtil = vendorDir.map(VendorManager::new).orElse(null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
import java.util.Objects;

/** Utility class for vendoring external repositories. */
public class VendorUtil {
public class VendorManager {

private final static String REGISTRIES_DIR = "_registries";

private final Path vendorDirectory;

public VendorUtil(Path vendorDirectory) {
public VendorManager(Path vendorDirectory) {
this.vendorDirectory = vendorDirectory;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.google.devtools.build.lib.analysis.NoBuildRequestFinishedEvent;
import com.google.devtools.build.lib.bazel.bzlmod.BazelFetchAllValue;
import com.google.devtools.build.lib.bazel.bzlmod.BazelModuleResolutionValue;
import com.google.devtools.build.lib.bazel.bzlmod.VendorUtil;
import com.google.devtools.build.lib.bazel.bzlmod.VendorManager;
import com.google.devtools.build.lib.bazel.commands.RepositoryFetcher.RepositoryFetcherException;
import com.google.devtools.build.lib.bazel.commands.TargetFetcher.TargetFetcherException;
import com.google.devtools.build.lib.bazel.repository.RepositoryOptions;
Expand Down Expand Up @@ -53,7 +53,6 @@
import com.google.devtools.build.lib.util.DetailedExitCode;
import com.google.devtools.build.lib.util.InterruptedFailureDetails;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.skyframe.EvaluationContext;
import com.google.devtools.build.skyframe.EvaluationResult;
import com.google.devtools.build.skyframe.InMemoryGraph;
Expand Down Expand Up @@ -107,15 +106,14 @@
usesConfigurationOptions = true,
help = "resource:vendor.txt",
shortDescription =
"Fetches external repositories into a specific folder specified by the flag "
+ "--vendor_dir.")
"Fetches external repositories into a folder specified by the flag --vendor_dir.")
public final class VendorCommand implements BlazeCommand {
public static final String NAME = "vendor";

private final DownloadManager downloadManager;
private final Supplier<Map<String, String>> clientEnvironmentSupplier;
@Nullable
private VendorUtil vendorUtil = null;
private VendorManager vendorManager = null;

public VendorCommand(
DownloadManager downloadManager, Supplier<Map<String, String>> clientEnvironmentSupplier) {
Expand Down Expand Up @@ -158,7 +156,7 @@ public BlazeCommandResult exec(CommandEnvironment env, OptionsParsingResult opti
VendorOptions vendorOptions = options.getOptions(VendorOptions.class);
LoadingPhaseThreadsOption threadsOption = options.getOptions(LoadingPhaseThreadsOption.class);
Path vendorDirectory = env.getWorkspace().getRelative(options.getOptions(RepositoryOptions.class).vendorDirectory);
this.vendorUtil = new VendorUtil(vendorDirectory);
this.vendorManager = new VendorManager(vendorDirectory);
try {
if (!options.getResidue().isEmpty()) {
result = vendorTargets(env, options, options.getResidue());
Expand Down Expand Up @@ -333,7 +331,7 @@ private ImmutableSet<RepositoryName> collectReposFromTargets(
private void vendor(
CommandEnvironment env, ImmutableList<RepositoryName> reposToVendor)
throws IOException, InterruptedException {
Objects.requireNonNull(vendorUtil);
Objects.requireNonNull(vendorManager);

// 1. Vendor registry files
BazelModuleResolutionValue moduleResolutionValue =
Expand All @@ -360,7 +358,7 @@ private void vendor(
continue;
}

String outputPath = vendorUtil.getVendorPathForUrl(url).getPathString();
String outputPath = vendorManager.getVendorPathForUrl(url).getPathString();
String outputPathLowerCase = outputPath.toLowerCase(Locale.ROOT);
if (vendorPathToUrl.containsKey(outputPathLowerCase)) {
String previousUrl = vendorPathToUrl.get(outputPathLowerCase);
Expand All @@ -373,18 +371,18 @@ private void vendor(
+ " cause conflict on case insensitive file systems, please fix by changing the"
+ " registry URLs!",
previousUrl,
vendorUtil.getVendorPathForUrl(URI.create(previousUrl).toURL()).getPathString(),
vendorManager.getVendorPathForUrl(URI.create(previousUrl).toURL()).getPathString(),
entry.getKey(),
outputPath));
}

Optional<Checksum> checksum = entry.getValue();
if (!vendorUtil.isUrlVendored(url)
if (!vendorManager.isUrlVendored(url)
// Only vendor a registry URL when its checksum exists, otherwise the URL should be
// recorded as "not found" in moduleResolutionValue.getRegistryFileHashes()
&& checksum.isPresent()) {
try {
vendorUtil.vendorRegistryUrl(
vendorManager.vendorRegistryUrl(
url,
downloadManager.downloadAndReadOneUrlForBzlmod(
url, env.getReporter(), clientEnvironmentSupplier.get(), checksum));
Expand All @@ -404,7 +402,7 @@ private void vendor(
env.getDirectories()
.getOutputBase()
.getRelative(LabelConstants.EXTERNAL_REPOSITORY_LOCATION);
vendorUtil.vendorRepos(externalPath, reposToVendor);
vendorManager.vendorRepos(externalPath, reposToVendor);
}

private static BlazeCommandResult createFailedBlazeCommandResult(
Expand Down

0 comments on commit 076de9f

Please sign in to comment.