Bug 1288567 - Use deterministic tar archive generation; r=dustin

We recently implemented code in mozpack for performing deterministic
tar file creation. It normalizes things like uids, gids, and mtimes
that creep into archives.

MozReview-Commit-ID: 1tn5eXkqACQ

--HG--
extra : rebase_source : 6b069a3a50c9103ae4f6185b26d6a37658179f42
This commit is contained in:
Gregory Szorc 2016-07-22 10:29:58 -07:00
Родитель edbd669eca
Коммит fd01511ec7
1 изменённых файлов: 16 добавлений и 3 удалений

Просмотреть файл

@ -6,7 +6,11 @@ from __future__ import absolute_import, print_function, unicode_literals
import hashlib
import os
import tarfile
from mozpack.archive import (
create_tar_gz_from_files,
)
GECKO = os.path.realpath(os.path.join(__file__, '..', '..', '..', '..'))
DOCKER_ROOT = os.path.join(GECKO, 'testing', 'docker')
@ -65,8 +69,17 @@ def create_context_tar(context_dir, out_path, prefix):
Returns the SHA-256 hex digest of the created archive.
"""
with tarfile.open(out_path, 'w:gz') as tar:
tar.add(context_dir, arcname=prefix)
archive_files = {}
for root, dirs, files in os.walk(context_dir):
for f in files:
source_path = os.path.join(root, f)
rel = source_path[len(context_dir) + 1:]
archive_path = os.path.join(prefix, rel)
archive_files[archive_path] = source_path
with open(out_path, 'wb') as fh:
create_tar_gz_from_files(fh, archive_files, '%s.tar.gz' % prefix)
h = hashlib.sha256()
with open(out_path, 'rb') as fh: