Skip to content

Commit

Permalink
Merge pull request bazelbuild#7 from Wyverald/override
Browse files Browse the repository at this point in the history
Incomplete Override impl & replace Fetcher with RepoSpec
  • Loading branch information
meteorcloudy authored May 5, 2021
2 parents 8dcbcbb + fb1b2d9 commit 5bcc8b7
Show file tree
Hide file tree
Showing 42 changed files with 447 additions and 576 deletions.
1 change: 0 additions & 1 deletion src/main/java/com/google/devtools/build/lib/bazel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/analysis:analysis_cluster",
"//src/main/java/com/google/devtools/build/lib/analysis:blaze_directories",
"//src/main/java/com/google/devtools/build/lib/analysis:config/build_configuration",
"//src/main/java/com/google/devtools/build/lib/bazel/bzlmod:fetch",
"//src/main/java/com/google/devtools/build/lib/bazel/bzlmod:registry",
"//src/main/java/com/google/devtools/build/lib/bazel/bzlmod:resolution",
"//src/main/java/com/google/devtools/build/lib/bazel/commands",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.google.devtools.build.lib.analysis.RuleDefinition;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
import com.google.devtools.build.lib.bazel.bzlmod.DiscoveryFunction;
import com.google.devtools.build.lib.bazel.bzlmod.FetcherFactory;
import com.google.devtools.build.lib.bazel.bzlmod.ModuleFileFunction;
import com.google.devtools.build.lib.bazel.bzlmod.RegistryFactory;
import com.google.devtools.build.lib.bazel.bzlmod.RegistryFactoryImpl;
Expand Down Expand Up @@ -214,11 +213,10 @@ public void workspaceInit(
managedDirectoriesKnowledge,
BazelSkyframeExecutorConstants.EXTERNAL_PACKAGE_HELPER);
builder.addSkyFunction(SkyFunctions.REPOSITORY_DIRECTORY, repositoryDelegatorFunction);
FetcherFactory fetcherFactory = new FetcherFactory(directories.getWorkspace());
RegistryFactory registryFactory = new RegistryFactoryImpl(
new HttpDownloader(), clientEnvironmentSupplier, fetcherFactory);
new HttpDownloader(), clientEnvironmentSupplier);
builder.addSkyFunction(SkyFunctions.MODULE_FILE, new ModuleFileFunction(
fetcherFactory, registryFactory, directories.getWorkspace()));
registryFactory, directories.getWorkspace()));
builder.addSkyFunction(SkyFunctions.DISCOVERY, new DiscoveryFunction());
builder.addSkyFunction(SkyFunctions.SELECTION, new SelectionFunction());
filesystem = runtime.getFileSystem();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.bazel.bzlmod.repo.RepoSpec;

import java.net.URL;

@AutoValue
Expand All @@ -23,8 +25,8 @@ public static ArchiveOverride create(ImmutableList<URL> urls, ImmutableList<URL>
public abstract int getPatchStrip();

@Override
public EarlyFetcher toEarlyFetcher(FetcherFactory fetcherFactory) {
return fetcherFactory.createArchiveFetcher(getUrls(), getPatches(), getIntegrity(),
getStripPrefix(), getPatchStrip());
public RepoSpec getRepoSpec(String repoName) {
return IndexRegistry.getRepoSpecForArchive(
repoName, getUrls(), getPatches(), getIntegrity(), getStripPrefix(), getPatchStrip());
}
}
22 changes: 4 additions & 18 deletions src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,6 @@ java_library(
],
)

java_library(
name = "fetch",
srcs = [
"ArchiveFetcher.java",
"EarlyFetcher.java",
"Fetcher.java",
"FetcherFactory.java",
"LocalPathFetcher.java",
],
deps = [
":common",
"//src/main/java/com/google/devtools/build/lib/vfs",
"//third_party:guava",
]
)

java_library(
name = "registry",
srcs = [
Expand All @@ -45,7 +29,7 @@ java_library(
],
deps = [
":common",
":fetch",
"//src/main/java/com/google/devtools/build/lib/bazel/bzlmod/repo:repo_spec_values",
"//src/main/java/com/google/devtools/build/lib/bazel/repository/downloader",
"//src/main/java/com/google/devtools/build/lib/events",
"//src/main/java/com/google/devtools/build/lib/vfs",
Expand Down Expand Up @@ -74,12 +58,14 @@ java_library(
],
deps = [
":common",
":fetch",
":registry",
"//src/main/java/com/google/devtools/build/lib/actions:file_metadata",
"//src/main/java/com/google/devtools/build/lib/bazel/bzlmod/repo:repo_spec_values",
"//src/main/java/com/google/devtools/build/lib/cmdline:cmdline-primitives",
"//src/main/java/com/google/devtools/build/lib/concurrent",
"//src/main/java/com/google/devtools/build/lib/events",
"//src/main/java/com/google/devtools/build/lib/packages",
"//src/main/java/com/google/devtools/build/lib/rules:repository/repository_directory_value",
"//src/main/java/com/google/devtools/build/lib/skyframe:precomputed_value",
"//src/main/java/com/google/devtools/build/lib/skyframe:sky_functions",
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec:autocodec-annotation",
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.google.devtools.build.lib.bazel.bzlmod;

import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.bazel.bzlmod.repo.RepoSpec;
import com.google.devtools.build.lib.bazel.repository.downloader.HttpDownloader;
import com.google.devtools.build.lib.events.ExtendedEventHandler;
import com.google.gson.FieldNamingPolicy;
Expand All @@ -13,21 +16,22 @@
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

public class IndexRegistry implements Registry {

private static final String HTTP_ARCHIVE_RULE_CLASS =
"@bazel_tools//tools/build_defs/repo:http.bzl%http_archive";

private final URI uri;
private final HttpDownloader httpDownloader;
private final Map<String, String> clientEnv;
private final FetcherFactory fetcherFactory;
private final Gson gson;

IndexRegistry(URI uri, HttpDownloader httpDownloader, Map<String, String> clientEnv,
FetcherFactory fetcherFactory) {
IndexRegistry(URI uri, HttpDownloader httpDownloader, Map<String, String> clientEnv) {
this.uri = uri;
this.httpDownloader = httpDownloader;
this.clientEnv = clientEnv;
this.fetcherFactory = fetcherFactory;
this.gson = new GsonBuilder()
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
.create();
Expand Down Expand Up @@ -85,7 +89,7 @@ private <T> Optional<T> grabJson(String relativePath, Class<T> klass,
}

@Override
public Fetcher getFetcher(ModuleKey key, ExtendedEventHandler eventHandler)
public RepoSpec getRepoSpec(ModuleKey key, String repoName, ExtendedEventHandler eventHandler)
throws IOException, InterruptedException {
Optional<BazelRegistryJson> bazelRegistryJson =
grabJson("bazel_registry.json", BazelRegistryJson.class, eventHandler);
Expand All @@ -96,6 +100,9 @@ public Fetcher getFetcher(ModuleKey key, ExtendedEventHandler eventHandler)
throw new FileNotFoundException(
String.format("Module %s's source information not found in registry %s", key, getUrl()));
}
if (sourceJson.get().integrity == null) {
throw new IOException(String.format("Missing integrity for module %s", key));
}
URL sourceUrl = sourceJson.get().url;
ImmutableList.Builder<URL> urls = new ImmutableList.Builder<>();
if (bazelRegistryJson.isPresent() && bazelRegistryJson.get().mirrors != null) {
Expand Down Expand Up @@ -125,12 +132,27 @@ public Fetcher getFetcher(ModuleKey key, ExtendedEventHandler eventHandler)
String.format("modules/%s/%s/patches/%s", key.getName(), key.getVersion(), name)));
}
}

return fetcherFactory.createArchiveFetcher(
return getRepoSpecForArchive(
repoName,
urls.build(),
patchUrls.build(),
sourceJson.get().integrity,
sourceJson.get().stripPrefix,
Strings.nullToEmpty(sourceJson.get().stripPrefix),
sourceJson.get().patchStrip);
}

public static RepoSpec getRepoSpecForArchive(String repoName, ImmutableList<URL> urls,
ImmutableList<URL> patches, String integrity, String stripPrefix, int patchStrip) {
ImmutableMap.Builder<String, Object> attrBuilder = ImmutableMap.builder();
attrBuilder.put("name", repoName)
.put("urls", urls.stream().map(URL::toString).collect(Collectors.toList()))
// TODO: implement integrity attribute in http_archive
.put("sha256", integrity.substring(7))
.put(
"remote_patches",
patches.stream().map(URL::toString).collect(Collectors.toList()))
.put("patch_args", ImmutableList.of("-p" + patchStrip))
.put("strip_prefix", stripPrefix);
return new RepoSpec(HTTP_ARCHIVE_RULE_CLASS, attrBuilder.build());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.google.devtools.build.lib.bazel.bzlmod;

import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.bazel.bzlmod.repo.RepoSpec;

@AutoValue
public abstract class LocalPathOverride implements NonRegistryOverride {
Expand All @@ -11,7 +13,7 @@ public static LocalPathOverride create(String path) {
public abstract String getPath();

@Override
public EarlyFetcher toEarlyFetcher(FetcherFactory fetcherFactory) {
return fetcherFactory.createLocalPathFetcher(getPath());
public RepoSpec getRepoSpec(String repoName) {
return new RepoSpec("local_repository", ImmutableMap.of("name", repoName, "path", getPath()));
}
}
Loading

0 comments on commit 5bcc8b7

Please sign in to comment.