Make git_repository use shared update attr function.
RELNOTES: None
# limitations under the License.
"""Rules for cloning external git repositories."""
-load("@bazel_tools//tools/build_defs/repo:utils.bzl", "patch", "workspace_and_buildfile")
+load("@bazel_tools//tools/build_defs/repo:utils.bzl", "patch", "update_attrs", "workspace_and_buildfile")
def _clone_or_update(ctx):
if ((not ctx.attr.tag and not ctx.attr.commit and not ctx.attr.branch) or
@@ -117,15 +117,8 @@ def _remove_dot_git(ctx):
"rm -rf '{directory}'".format(directory = ctx.path(".git")),
])
-def _update_commit(orig, keys, override):
- # Merge the override information into the dict, resulting by taking the
- # given keys, as well as the name, from orig (if present there).
- result = {}
- for key in keys:
- if getattr(orig, key) != None:
- result[key] = getattr(orig, key)
- result["name"] = orig.name
- result.update(override)
+def _update_git_attrs(orig, keys, override):
+ result = update_attrs(orig, keys, override)
# if we found the actual commit, remove all other means of specifying it,
# like tag or branch.
@@ -164,13 +157,13 @@ def _new_git_repository_implementation(ctx):
workspace_and_buildfile(ctx)
patch(ctx)
_remove_dot_git(ctx)
- return _update_commit(ctx.attr, _new_git_repository_attrs.keys(), update)
+ return _update_git_attrs(ctx.attr, _new_git_repository_attrs.keys(), update)
def _git_repository_implementation(ctx):
update = _clone_or_update(ctx)
patch(ctx)
_remove_dot_git(ctx)
- return _update_commit(ctx.attr, _common_attrs.keys(), update)
+ return _update_git_attrs(ctx.attr, _common_attrs.keys(), update)
new_git_repository = repository_rule(
implementation = _new_git_repository_implementation,
