forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[7.1.0] bzlmod: support git repos in source.json (bazelbuild#21036)
bzlmod: support git repos in source.json Closes bazelbuild#20912. RELNOTES: Added `init_submodules` attribute to `git_override`. Registries now support the `git_repository` type in `source.json`. Change-Id: Ia267131e6d081572a642888ba34e285805bbbe9f PiperOrigin-RevId: 601268823 --------- Co-authored-by: Nachum Goldstein <[email protected]> Co-authored-by: Keith Smiley <[email protected]>
- Loading branch information
1 parent
c6c7693
commit d0b4c39
Showing
9 changed files
with
346 additions
and
60 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
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
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
132 changes: 132 additions & 0 deletions
132
src/main/java/com/google/devtools/build/lib/bazel/bzlmod/GitRepoSpecBuilder.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,132 @@ | ||
// 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.common.collect.ImmutableMap; | ||
import com.google.errorprone.annotations.CanIgnoreReturnValue; | ||
import java.util.List; | ||
|
||
/** | ||
* Builder for a {@link RepoSpec} object that indicates how to materialize a repo corresponding to a | ||
* {@code git_repository} repo rule call. | ||
*/ | ||
public class GitRepoSpecBuilder { | ||
|
||
public static final String GIT_REPO_PATH = "@bazel_tools//tools/build_defs/repo:git.bzl"; | ||
|
||
private final ImmutableMap.Builder<String, Object> attrBuilder; | ||
|
||
public GitRepoSpecBuilder() { | ||
attrBuilder = new ImmutableMap.Builder<>(); | ||
} | ||
|
||
@CanIgnoreReturnValue | ||
public GitRepoSpecBuilder setRepoName(String repoName) { | ||
return setAttr("name", repoName); | ||
} | ||
|
||
@CanIgnoreReturnValue | ||
public GitRepoSpecBuilder setRemote(String remoteRepoUrl) { | ||
return setAttr("remote", remoteRepoUrl); | ||
} | ||
|
||
@CanIgnoreReturnValue | ||
public GitRepoSpecBuilder setCommit(String gitCommitHash) { | ||
return setAttr("commit", gitCommitHash); | ||
} | ||
|
||
@CanIgnoreReturnValue | ||
public GitRepoSpecBuilder setShallowSince(String shallowSince) { | ||
return setAttr("shallow_since", shallowSince); | ||
} | ||
|
||
@CanIgnoreReturnValue | ||
public GitRepoSpecBuilder setTag(String tag) { | ||
return setAttr("tag", tag); | ||
} | ||
|
||
@CanIgnoreReturnValue | ||
public GitRepoSpecBuilder setInitSubmodules(boolean initSubmodules) { | ||
setAttr("init_submodules", initSubmodules); | ||
setAttr("recursive_init_submodules", initSubmodules); | ||
return this; | ||
} | ||
|
||
@CanIgnoreReturnValue | ||
public GitRepoSpecBuilder setVerbose(boolean verbose) { | ||
return setAttr("verbose", verbose); | ||
} | ||
|
||
@CanIgnoreReturnValue | ||
public GitRepoSpecBuilder setStripPrefix(String stripPrefix) { | ||
return setAttr("strip_prefix", stripPrefix); | ||
} | ||
|
||
@CanIgnoreReturnValue | ||
public GitRepoSpecBuilder setPatches(List<String> patches) { | ||
return setAttr("patches", patches); | ||
} | ||
|
||
@CanIgnoreReturnValue | ||
public GitRepoSpecBuilder setPatchTool(String patchTool) { | ||
return setAttr("patch_tool", patchTool); | ||
} | ||
|
||
@CanIgnoreReturnValue | ||
public GitRepoSpecBuilder setPatchArgs(List<String> patchArgs) { | ||
return setAttr("patch_args", patchArgs); | ||
} | ||
|
||
@CanIgnoreReturnValue | ||
public GitRepoSpecBuilder setPatchCmds(List<String> patchCmds) { | ||
return setAttr("patch_cmds", patchCmds); | ||
} | ||
|
||
@CanIgnoreReturnValue | ||
public GitRepoSpecBuilder setPatchCmdsWin(List<String> patchCmdsWin) { | ||
return setAttr("patch_cmds_win", patchCmdsWin); | ||
} | ||
|
||
public RepoSpec build() { | ||
return RepoSpec.builder() | ||
.setBzlFile(GIT_REPO_PATH) | ||
.setRuleClassName("git_repository") | ||
.setAttributes(AttributeValues.create(attrBuilder.buildOrThrow())) | ||
.build(); | ||
} | ||
|
||
@CanIgnoreReturnValue | ||
private GitRepoSpecBuilder setAttr(String name, String value) { | ||
if (value != null && !value.isEmpty()) { | ||
attrBuilder.put(name, value); | ||
} | ||
return this; | ||
} | ||
|
||
@CanIgnoreReturnValue | ||
private GitRepoSpecBuilder setAttr(String name, boolean value) { | ||
attrBuilder.put(name, value); | ||
return this; | ||
} | ||
|
||
@CanIgnoreReturnValue | ||
private GitRepoSpecBuilder setAttr(String name, List<String> value) { | ||
if (value != null && !value.isEmpty()) { | ||
attrBuilder.put(name, value); | ||
} | ||
return this; | ||
} | ||
} |
Oops, something went wrong.