Skip to content

Commit 768d66a

Browse files
committed
Build reproducible tarballs from git
1 parent f725e61 commit 768d66a

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

easybuild/tools/filetools.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2707,11 +2707,15 @@ def get_source_tarball_from_git(filename, targetdir, git_config):
27072707
for cmd in cmds:
27082708
run.run_cmd(cmd, log_all=True, simple=True, regexp=False, path=repo_name)
27092709

2710-
# create an archive and delete the git repo directory
2711-
if keep_git_dir:
2712-
tar_cmd = ['tar', 'cfvz', targetpath, repo_name]
2713-
else:
2714-
tar_cmd = ['tar', 'cfvz', targetpath, '--exclude', '.git', repo_name]
2710+
# When CentOS 7 is phased out and tar>1.28 is everywhere, replace find-sort-pipe with tar-flag
2711+
# '--sort=name' and place LC_ALL in front of tar. Also remove flags --null, --no-recursion, and
2712+
# --files-from - from the flags to tar. See https://reproducible-builds.org/docs/archives/
2713+
tar_cmd = ['find', repo_name, '-print0', '-path \'*/.git\' -prune' if not keep_git_dir else '', '|',
2714+
'LC_ALL=C', 'sort', '--zero-terminated', '|',
2715+
'GZIP=--no-name', 'tar', '--create', '--file', targetpath, '--no-recursion',
2716+
'--gzip', '--mtime="1970-01-01 00:00Z"', '--owner=0', '--group=0',
2717+
'--numeric-owner', '--format=gnu', '--null',
2718+
'--no-recursion', '--files-from -']
27152719
run.run_cmd(' '.join(tar_cmd), log_all=True, simple=True, regexp=False)
27162720

27172721
# cleanup (repo_name dir does not exist in dry run mode)

test/framework/filetools.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2784,7 +2784,10 @@ def run_check():
27842784
expected = '\n'.join([
27852785
r' running command "git clone --depth 1 --branch tag_for_tests %(git_repo)s"',
27862786
r" \(in .*/tmp.*\)",
2787-
r' running command "tar cfvz .*/target/test.tar.gz --exclude .git testrepository"',
2787+
r' running command "find testrepository -print0 -path \'*/.git\' -prune | LC_ALL=C sort --zero-terminated'
2788+
r' | GZIP=--no-name tar --create --file /tmp/eb-dm7hbbde/eb-6lulalhw/eb-vqfy4wts/target/test.tar.gz'
2789+
r' --no-recursion --gzip --mtime="1970-01-01 00:00Z" --owner=0 --group=0 --numeric-owner --format=gnu'
2790+
r' --null --no-recursion --files-from -"',
27882791
r" \(in .*/tmp.*\)",
27892792
]) % git_repo
27902793
run_check()
@@ -2793,7 +2796,10 @@ def run_check():
27932796
expected = '\n'.join([
27942797
r' running command "git clone --depth 1 --branch tag_for_tests %(git_repo)s test123"',
27952798
r" \(in .*/tmp.*\)",
2796-
r' running command "tar cfvz .*/target/test.tar.gz --exclude .git test123"',
2799+
r' running command "find test123 -print0 -path \'*/.git\' -prune | LC_ALL=C sort --zero-terminated'
2800+
r' | GZIP=--no-name tar --create --file /tmp/eb-ktdntga4/eb-7z7n1da5/eb-s63ey1jv/target/test.tar.gz'
2801+
r' --no-recursion --gzip --mtime="1970-01-01 00:00Z" --owner=0 --group=0 --numeric-owner --format=gnu'
2802+
r' --null --no-recursion --files-from -"',
27972803
r" \(in .*/tmp.*\)",
27982804
]) % git_repo
27992805
run_check()
@@ -2803,7 +2809,10 @@ def run_check():
28032809
expected = '\n'.join([
28042810
r' running command "git clone --depth 1 --branch tag_for_tests --recursive %(git_repo)s"',
28052811
r" \(in .*/tmp.*\)",
2806-
r' running command "tar cfvz .*/target/test.tar.gz --exclude .git testrepository"',
2812+
r' running command "find testrepository -print0 -path \'*/.git\' -prune | LC_ALL=C sort --zero-terminated'
2813+
r' | GZIP=--no-name tar --create --file /tmp/eb-pjnoh7lx/eb-nxgzay98/eb-s0p413qg/target/test.tar.gz'
2814+
r' --no-recursion --gzip --mtime="1970-01-01 00:00Z" --owner=0 --group=0 --numeric-owner --format=gnu'
2815+
r' --null --no-recursion --files-from -"',
28072816
r" \(in .*/tmp.*\)",
28082817
]) % git_repo
28092818
run_check()
@@ -2812,7 +2821,10 @@ def run_check():
28122821
expected = '\n'.join([
28132822
r' running command "git clone --branch tag_for_tests --recursive %(git_repo)s"',
28142823
r" \(in .*/tmp.*\)",
2815-
r' running command "tar cfvz .*/target/test.tar.gz testrepository"',
2824+
r' running command "find testrepository -print0 | LC_ALL=C sort --zero-terminated | GZIP=--no-name tar'
2825+
r' --create --file /tmp/eb-lmkpjxhn/eb-hciph_6r/eb-7nfb8le2/target/test.tar.gz --no-recursion --gzip'
2826+
r' --mtime="1970-01-01 00:00Z" --owner=0 --group=0 --numeric-owner --format=gnu --null --no-recursion'
2827+
r' --files-from -"',
28162828
r" \(in .*/tmp.*\)",
28172829
]) % git_repo
28182830
run_check()
@@ -2825,7 +2837,10 @@ def run_check():
28252837
r" \(in .*/tmp.*\)",
28262838
r' running command "git checkout 8456f86 && git submodule update --init --recursive"',
28272839
r" \(in testrepository\)",
2828-
r' running command "tar cfvz .*/target/test.tar.gz --exclude .git testrepository"',
2840+
r' running command "find testrepository -print0 -path \'*/.git\' -prune | LC_ALL=C sort --zero-terminated'
2841+
r' | GZIP=--no-name tar --create --file /tmp/eb-94jy8omr/eb-s1dl9w7f/eb-p9cvr1s3/target/test.tar.gz'
2842+
r ' --no-recursion --gzip --mtime="1970-01-01 00:00Z" --owner=0 --group=0 --numeric-owner --format=gnu'
2843+
r ' --null --no-recursion --files-from -"',
28292844
r" \(in .*/tmp.*\)",
28302845
]) % git_repo
28312846
run_check()
@@ -2836,7 +2851,10 @@ def run_check():
28362851
r" \(in .*/tmp.*\)",
28372852
r' running command "git checkout 8456f86"',
28382853
r" \(in testrepository\)",
2839-
r' running command "tar cfvz .*/target/test.tar.gz --exclude .git testrepository"',
2854+
r' running command "find testrepository -print0 -path \'*/.git\' -prune | LC_ALL=C sort --zero-terminated'
2855+
r ' | GZIP=--no-name tar --create --file /tmp/eb-2ptsipme/eb-8nwwv2uc/eb-zxrs_gk_/target/test.tar.gz'
2856+
r ' --no-recursion --gzip --mtime="1970-01-01 00:00Z" --owner=0 --group=0 --numeric-owner --format=gnu'
2857+
r ' --null --no-recursion --files-from -"',
28402858
r" \(in .*/tmp.*\)",
28412859
]) % git_repo
28422860
run_check()

0 commit comments

Comments
 (0)