-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#13316) This CL implements ModuleFileFunction, a SkyFunction that takes the name and version of a module, finds and evaluates its MODULE.bazel file and returns the evaluated result. This is not hooked into the main SkyFrame route yet (RepositoryDelegatorFunction has yet to call this). PiperOrigin-RevId: 380141062
- Loading branch information
1 parent
a0b65df
commit efa35e3
Showing
22 changed files
with
1,622 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ArchiveOverride.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// 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.common.collect.ImmutableList; | ||
|
||
/** Specifies that a module should be retrieved from an archive. */ | ||
@AutoValue | ||
public abstract class ArchiveOverride implements NonRegistryOverride { | ||
|
||
public static ArchiveOverride create( | ||
ImmutableList<String> urls, | ||
ImmutableList<String> patches, | ||
String integrity, | ||
String stripPrefix, | ||
int patchStrip) { | ||
return new AutoValue_ArchiveOverride(urls, patches, integrity, stripPrefix, patchStrip); | ||
} | ||
|
||
/** The URLs pointing at the archives. Can be HTTP(S) or file URLs. */ | ||
public abstract ImmutableList<String> getUrls(); | ||
|
||
/** The patches to apply after extracting the archive. Should be a list of labels. */ | ||
public abstract ImmutableList<String> getPatches(); | ||
|
||
/** The subresource integirty metadata of the archive. */ | ||
public abstract String getIntegrity(); | ||
|
||
/** The prefix to strip from paths in the archive. */ | ||
public abstract String getStripPrefix(); | ||
|
||
/** The number of path segments to strip from the paths in the supplied patches. */ | ||
public abstract int getPatchStrip(); | ||
} |
68 changes: 68 additions & 0 deletions
68
src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BUILD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
load("@rules_java//java:defs.bzl", "java_library") | ||
|
||
package( | ||
default_visibility = ["//src:__subpackages__"], | ||
) | ||
|
||
licenses(["notice"]) | ||
|
||
filegroup( | ||
name = "srcs", | ||
srcs = glob(["*"]), | ||
visibility = ["//src:__subpackages__"], | ||
) | ||
|
||
java_library( | ||
name = "common", | ||
srcs = ["ModuleKey.java"], | ||
deps = ["//third_party:auto_value"], | ||
) | ||
|
||
java_library( | ||
name = "registry", | ||
srcs = [ | ||
"Registry.java", | ||
"RegistryFactory.java", | ||
], | ||
deps = [ | ||
":common", | ||
"//src/main/java/com/google/devtools/build/lib/events", | ||
], | ||
) | ||
|
||
java_library( | ||
name = "resolution", | ||
srcs = [ | ||
"ArchiveOverride.java", | ||
"GitOverride.java", | ||
"LocalPathOverride.java", | ||
"Module.java", | ||
"ModuleFileFunction.java", | ||
"ModuleFileGlobals.java", | ||
"ModuleFileValue.java", | ||
"NonRegistryOverride.java", | ||
"RegistryOverride.java", | ||
"SingleVersionOverride.java", | ||
], | ||
deps = [ | ||
":common", | ||
":registry", | ||
"//src/main/java/com/google/devtools/build/lib/actions:file_metadata", | ||
"//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/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", | ||
"//src/main/java/com/google/devtools/build/lib/starlarkbuildapi/repository", | ||
"//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", | ||
"//src/main/java/com/google/devtools/build/skyframe:skyframe-objects", | ||
"//src/main/java/net/starlark/java/eval", | ||
"//src/main/java/net/starlark/java/syntax", | ||
"//third_party:auto_value", | ||
"//third_party:guava", | ||
"//third_party:jsr305", | ||
], | ||
) |
40 changes: 40 additions & 0 deletions
40
src/main/java/com/google/devtools/build/lib/bazel/bzlmod/GitOverride.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// 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.common.collect.ImmutableList; | ||
|
||
/** Specifies that a module should be retrieved from a Git repository. */ | ||
@AutoValue | ||
public abstract class GitOverride implements NonRegistryOverride { | ||
public static GitOverride create( | ||
String remote, String commit, ImmutableList<String> patches, int patchStrip) { | ||
return new AutoValue_GitOverride(remote, commit, patches, patchStrip); | ||
} | ||
|
||
/** The URL pointing to the git repository. */ | ||
public abstract String getRemote(); | ||
|
||
/** The commit hash to use. */ | ||
public abstract String getCommit(); | ||
|
||
/** The patches to apply after fetching from Git. Should be a list of labels. */ | ||
public abstract ImmutableList<String> getPatches(); | ||
|
||
/** The number of path segments to strip from the paths in the supplied patches. */ | ||
public abstract int getPatchStrip(); | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/google/devtools/build/lib/bazel/bzlmod/LocalPathOverride.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// 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; | ||
|
||
/** Specifies that a module should be retrieved from a local directory. */ | ||
@AutoValue | ||
public abstract class LocalPathOverride implements NonRegistryOverride { | ||
public static LocalPathOverride create(String path) { | ||
return new AutoValue_LocalPathOverride(path); | ||
} | ||
|
||
/** The path to the local directory where the module contents should be found. */ | ||
public abstract String getPath(); | ||
} |
79 changes: 79 additions & 0 deletions
79
src/main/java/com/google/devtools/build/lib/bazel/bzlmod/Module.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// 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.common.collect.ImmutableMap; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Represents a node in the external dependency graph. | ||
* | ||
* <p>In particular, it represents a specific version of a module; there can be multiple {@link | ||
* Module}s in a dependency graph with the same name but with different versions (such as after | ||
* discovery but before selection, or when there's a multiple_version_override in play). | ||
*/ | ||
@AutoValue | ||
public abstract class Module { | ||
|
||
/** The name of the module. Can be empty if this is the root module. */ | ||
public abstract String getName(); | ||
|
||
/** The version of the module. Must be empty iff the module has a {@link NonRegistryOverride}. */ | ||
public abstract String getVersion(); | ||
|
||
/** | ||
* The direct dependencies of this module. The key type is the repo name of the dep, and the value | ||
* type is the ModuleKey (name+version) of the dep. | ||
*/ | ||
public abstract ImmutableMap<String, ModuleKey> getDeps(); | ||
|
||
/** | ||
* The registry where this module came from. Must be null iff the module has a {@link | ||
* NonRegistryOverride}. | ||
*/ | ||
@Nullable | ||
public abstract Registry getRegistry(); | ||
|
||
/** Returns a {@link Builder} that starts out with the same fields as this object. */ | ||
public abstract Builder toBuilder(); | ||
|
||
/** Returns a new, empty {@link Builder}. */ | ||
static Builder builder() { | ||
return new AutoValue_Module.Builder(); | ||
} | ||
|
||
/** Builder type for {@link Module}. */ | ||
@AutoValue.Builder | ||
public abstract static class Builder { | ||
public abstract Builder setName(String value); | ||
|
||
public abstract Builder setVersion(String value); | ||
|
||
public abstract Builder setDeps(ImmutableMap<String, ModuleKey> value); | ||
|
||
public abstract Builder setRegistry(Registry value); | ||
|
||
abstract ImmutableMap.Builder<String, ModuleKey> depsBuilder(); | ||
|
||
public Builder addDep(String depRepoName, ModuleKey depKey) { | ||
depsBuilder().put(depRepoName, depKey); | ||
return this; | ||
} | ||
|
||
public abstract Module build(); | ||
} | ||
} |
Oops, something went wrong.