From e39991acbeb5c5cacbb61de004be77436be3664e Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Tue, 17 Jul 2018 01:04:49 -0700 Subject: 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 --- tools/build_defs/repo/git.bzl | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tools') 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( -- cgit v1.2.3