Skip to content

Commit

Permalink
Add option to git_repository to provide build file / content
Browse files Browse the repository at this point in the history
This PR moves the extra features of new_git_repository to git_repository
and makes new_git_repository and alias to git_repository.  A side effect
is that new_git_repository should disappear from documentation.

Discussion: https://groups.google.com/g/bazel-dev/c/sfeRE3Ucj7E

Future work:
- Wait until Bazel 6.x goes out, then remove the new_git_repository alias

Closes bazelbuild#16064.

PiperOrigin-RevId: 467925617
Change-Id: I94508f559f84721f7bb880323d1dd53c6e19682b
  • Loading branch information
limdor authored and aiuto committed Oct 12, 2022
1 parent 15d4728 commit 1d59d41
Showing 1 changed file with 7 additions and 27 deletions.
34 changes: 7 additions & 27 deletions tools/build_defs/repo/git.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ _common_attrs = {
"applied. If this attribute is not set, patch_cmds will be executed on Windows, " +
"which requires Bash binary to exist.",
),
}

_new_git_repository_attrs = dict(_common_attrs.items() + {
"build_file": attr.label(
allow_single_file = True,
doc =
Expand Down Expand Up @@ -165,37 +162,17 @@ _new_git_repository_attrs = dict(_common_attrs.items() + {
"Either `workspace_file` or `workspace_file_content` can be " +
"specified, or neither, but not both.",
),
}.items())

def _new_git_repository_implementation(ctx):
if ((not ctx.attr.build_file and not ctx.attr.build_file_content) or
(ctx.attr.build_file and ctx.attr.build_file_content)):
fail("Exactly one of build_file and build_file_content must be provided.")
update = _clone_or_update_repo(ctx)
workspace_and_buildfile(ctx)
patch(ctx)
ctx.delete(ctx.path(".git"))
return _update_git_attrs(ctx.attr, _new_git_repository_attrs.keys(), update)
}

def _git_repository_implementation(ctx):
if ctx.attr.build_file and ctx.attr.build_file_content:
fail("Only one of build_file and build_file_content can be provided.")
update = _clone_or_update_repo(ctx)
workspace_and_buildfile(ctx)
patch(ctx)
ctx.delete(ctx.path(".git"))
return _update_git_attrs(ctx.attr, _common_attrs.keys(), update)

new_git_repository = repository_rule(
implementation = _new_git_repository_implementation,
attrs = _new_git_repository_attrs,
doc = """Clone an external git repository.
Clones a Git repository, checks out the specified tag, or commit, and
makes its targets available for binding. Also determine the id of the
commit actually checked out and its date, and return a dict with parameters
that provide a reproducible version of this rule (which a tag not necessarily
is).
""",
)

git_repository = repository_rule(
implementation = _git_repository_implementation,
attrs = _common_attrs,
Expand All @@ -208,3 +185,6 @@ that provide a reproducible version of this rule (which a tag not necessarily
is).
""",
)

# TODO(bazel_7.x): Remove before bazel 7.x
new_git_repository = git_repository

0 comments on commit 1d59d41

Please sign in to comment.