aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorGravatar Klaus Aehlig <aehlig@google.com>2018-07-17 01:04:49 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-07-17 01:06:48 -0700
commite39991acbeb5c5cacbb61de004be77436be3664e (patch)
treedc9f374fd8c3f7ba574cf529bbeda58fe036c4a8 /tools
parentd491bf10f42e213292382c98a1dc439537f00f43 (diff)
git_repository: remove .git directory
While we do not expect any targets to actually depend on the contents of the .git subdirectory of an external repository, it is still a non-reproducible part of an external git repository, blocking all attempts to demonstrate reproducibility of that the given rule. Change-Id: Id1e08013a8ca33d4b4c4b053b9423f75d771dfc1 PiperOrigin-RevId: 204872242
Diffstat (limited to 'tools')
-rw-r--r--tools/build_defs/repo/git.bzl11
1 files changed, 11 insertions, 0 deletions
diff --git a/tools/build_defs/repo/git.bzl b/tools/build_defs/repo/git.bzl
index 2616ff6814..5280aee4a8 100644
--- a/tools/build_defs/repo/git.bzl
+++ b/tools/build_defs/repo/git.bzl
@@ -101,6 +101,15 @@ set -ex
]).stdout
return {"commit": actual_commit, "shallow_since": shallow_date}
+def _remove_dot_git(ctx):
+ # Remove the .git directory, if present
+ bash_exe = ctx.os.environ["BAZEL_SH"] if "BAZEL_SH" in ctx.os.environ else "bash"
+ ctx.execute([
+ bash_exe,
+ "-c",
+ "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).
@@ -147,11 +156,13 @@ def _new_git_repository_implementation(ctx):
update = _clone_or_update(ctx)
workspace_and_buildfile(ctx)
patch(ctx)
+ _remove_dot_git(ctx)
return _update_commit(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)
new_git_repository = repository_rule(