Skip to content

Commit 8d9e14e

Browse files
committed
make reproducible archives only of git repos without .git dir and reset timestamps with touch
1 parent 88de22e commit 8d9e14e

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

easybuild/tools/filetools.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2540,12 +2540,12 @@ def copy(paths, target_path, force_in_dry_run=False, **kwargs):
25402540
raise EasyBuildError("Specified path to copy is not an existing file or directory: %s", path)
25412541

25422542

2543-
def get_source_tarball_from_git(filename, targetdir, git_config):
2543+
def get_source_tarball_from_git(filename, target_dir, git_config):
25442544
"""
25452545
Downloads a git repository, at a specific tag or commit, recursively or not, and make an archive with it
25462546
25472547
:param filename: name of the archive to save the code to (must be .tar.gz)
2548-
:param targetdir: target directory where to save the archive to
2548+
:param target_dir: target directory where to save the archive to
25492549
:param git_config: dictionary containing url, repo_name, recursive, and one of tag or commit
25502550
"""
25512551
# sanity check on git_config value being passed
@@ -2584,8 +2584,7 @@ def get_source_tarball_from_git(filename, targetdir, git_config):
25842584
raise EasyBuildError("git_config currently only supports filename ending in .tar.gz")
25852585

25862586
# prepare target directory and clone repository
2587-
mkdir(targetdir, parents=True)
2588-
targetpath = os.path.join(targetdir, filename)
2587+
mkdir(target_dir, parents=True)
25892588

25902589
# compose 'git clone' command, and run it
25912590
if extra_config_params:
@@ -2668,21 +2667,36 @@ def get_source_tarball_from_git(filename, targetdir, git_config):
26682667
for cmd in cmds:
26692668
run_shell_cmd(cmd, work_dir=work_dir, hidden=True, verbose_dry_run=True)
26702669

2671-
# When CentOS 7 is phased out and tar>1.28 is everywhere, replace find-sort-pipe with tar-flag
2672-
# '--sort=name' and place LC_ALL in front of tar. Also remove flags --null, --no-recursion, and
2673-
# --files-from - from the flags to tar. See https://reproducible-builds.org/docs/archives/
2674-
tar_cmd = ['find', repo_name, '-print0', '-path \'*/.git\' -prune' if not keep_git_dir else '', '|',
2675-
'LC_ALL=C', 'sort', '--zero-terminated', '|',
2676-
'GZIP=--no-name', 'tar', '--create', '--file', targetpath, '--no-recursion',
2677-
'--gzip', '--mtime="1970-01-01 00:00Z"', '--owner=0', '--group=0',
2678-
'--numeric-owner', '--format=gnu', '--null',
2679-
'--no-recursion', '--files-from -']
2670+
# Create archive
2671+
archive_path = os.path.join(target_dir, filename)
2672+
2673+
if keep_git_dir:
2674+
# create archive of git repo including .git directory
2675+
tar_cmd = ['tar', 'cfvz', archive_path, repo_name]
2676+
else:
2677+
# create reproducible archive
2678+
# see https://reproducible-builds.org/docs/archives/
2679+
# TODO: when CentOS 7 is phased out and tar>1.28 is everywhere, replace sort step
2680+
# in the pipe with tar-flag '--sort=name' and place LC_ALL in front of tar.
2681+
tar_cmd = [
2682+
# print names of all files and folders excluding .git directory
2683+
'find', repo_name, '-name ".git"', '-prune', '-o', '-print0',
2684+
# reset access and modification timestamps
2685+
'-exec', 'touch', '-t 197001010100', '{}', '\;', '|',
2686+
# sort file list
2687+
'LC_ALL=C', 'sort', '--zero-terminated', '|',
2688+
# create tarball in GNU format with ownership reset
2689+
'tar', '--create', '--no-recursion', '--owner=0', '--group=0', '--numeric-owner', '--format=gnu',
2690+
'--null', '--files-from', '-', '|',
2691+
# compress tarball with gzip without original file name and timestamp
2692+
'gzip', '--no-name', '>', archive_path
2693+
]
26802694
run_shell_cmd(' '.join(tar_cmd), work_dir=tmpdir, hidden=True, verbose_dry_run=True)
26812695

26822696
# cleanup (repo_name dir does not exist in dry run mode)
26832697
remove(tmpdir)
26842698

2685-
return targetpath
2699+
return archive_path
26862700

26872701

26882702
def move_file(path, target_path, force_in_dry_run=False):

0 commit comments

Comments
 (0)