mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-27 23:34:57 -04:00
dist: Add some determinism support to bdist_apps
It's necessary to set PYTHONHASHSEED=0 as well as SOURCE_DATE_EPOCH for deterministic compilation, and moreover, the generated zip files do still have timestamps in them.
This commit is contained in:
parent
54638bfc10
commit
68daa238b1
6
direct/src/dist/FreezeTool.py
vendored
6
direct/src/dist/FreezeTool.py
vendored
@ -958,7 +958,7 @@ class Freezer:
|
|||||||
|
|
||||||
# Scan the directory, looking for .py files.
|
# Scan the directory, looking for .py files.
|
||||||
modules = []
|
modules = []
|
||||||
for basename in os.listdir(pathname):
|
for basename in sorted(os.listdir(pathname)):
|
||||||
if basename.endswith('.py') and basename != '__init__.py':
|
if basename.endswith('.py') and basename != '__init__.py':
|
||||||
modules.append(basename[:-3])
|
modules.append(basename[:-3])
|
||||||
|
|
||||||
@ -992,7 +992,7 @@ class Freezer:
|
|||||||
modulePath = self.getModulePath(topName)
|
modulePath = self.getModulePath(topName)
|
||||||
if modulePath:
|
if modulePath:
|
||||||
for dirname in modulePath:
|
for dirname in modulePath:
|
||||||
for basename in os.listdir(dirname):
|
for basename in sorted(os.listdir(dirname)):
|
||||||
if os.path.exists(os.path.join(dirname, basename, '__init__.py')):
|
if os.path.exists(os.path.join(dirname, basename, '__init__.py')):
|
||||||
parentName = '%s.%s' % (topName, basename)
|
parentName = '%s.%s' % (topName, basename)
|
||||||
newParentName = '%s.%s' % (newTopName, basename)
|
newParentName = '%s.%s' % (newTopName, basename)
|
||||||
@ -2587,7 +2587,7 @@ class PandaModuleFinder(modulefinder.ModuleFinder):
|
|||||||
except OSError:
|
except OSError:
|
||||||
self.msg(2, "can't list directory", dir)
|
self.msg(2, "can't list directory", dir)
|
||||||
continue
|
continue
|
||||||
for name in names:
|
for name in sorted(names):
|
||||||
mod = None
|
mod = None
|
||||||
for suff in self.suffixes:
|
for suff in self.suffixes:
|
||||||
n = len(suff)
|
n = len(suff)
|
||||||
|
30
direct/src/dist/commands.py
vendored
30
direct/src/dist/commands.py
vendored
@ -1045,6 +1045,7 @@ class build_apps(setuptools.Command):
|
|||||||
|
|
||||||
rootdir = os.getcwd()
|
rootdir = os.getcwd()
|
||||||
for dirname, subdirlist, filelist in os.walk(rootdir):
|
for dirname, subdirlist, filelist in os.walk(rootdir):
|
||||||
|
subdirlist.sort()
|
||||||
dirpath = os.path.relpath(dirname, rootdir)
|
dirpath = os.path.relpath(dirname, rootdir)
|
||||||
if skip_directory(dirpath):
|
if skip_directory(dirpath):
|
||||||
self.announce('skipping directory {}'.format(dirpath))
|
self.announce('skipping directory {}'.format(dirpath))
|
||||||
@ -1414,7 +1415,8 @@ class bdist_apps(setuptools.Command):
|
|||||||
zf.write(build_dir, base_dir)
|
zf.write(build_dir, base_dir)
|
||||||
|
|
||||||
for dirpath, dirnames, filenames in os.walk(build_dir):
|
for dirpath, dirnames, filenames in os.walk(build_dir):
|
||||||
for name in sorted(dirnames):
|
dirnames.sort()
|
||||||
|
for name in dirnames:
|
||||||
path = os.path.normpath(os.path.join(dirpath, name))
|
path = os.path.normpath(os.path.join(dirpath, name))
|
||||||
zf.write(path, path.replace(build_dir, base_dir, 1))
|
zf.write(path, path.replace(build_dir, base_dir, 1))
|
||||||
for name in filenames:
|
for name in filenames:
|
||||||
@ -1429,16 +1431,39 @@ class bdist_apps(setuptools.Command):
|
|||||||
build_cmd = self.get_finalized_command('build_apps')
|
build_cmd = self.get_finalized_command('build_apps')
|
||||||
binary_names = list(build_cmd.console_apps.keys()) + list(build_cmd.gui_apps.keys())
|
binary_names = list(build_cmd.console_apps.keys()) + list(build_cmd.gui_apps.keys())
|
||||||
|
|
||||||
|
source_date = os.environ.get('SOURCE_DATE_EPOCH', '').strip()
|
||||||
|
if source_date:
|
||||||
|
max_mtime = int(source_date)
|
||||||
|
else:
|
||||||
|
max_mtime = None
|
||||||
|
|
||||||
def tarfilter(tarinfo):
|
def tarfilter(tarinfo):
|
||||||
if tarinfo.isdir() or os.path.basename(tarinfo.name) in binary_names:
|
if tarinfo.isdir() or os.path.basename(tarinfo.name) in binary_names:
|
||||||
tarinfo.mode = 0o755
|
tarinfo.mode = 0o755
|
||||||
else:
|
else:
|
||||||
tarinfo.mode = 0o644
|
tarinfo.mode = 0o644
|
||||||
|
|
||||||
|
# This isn't interesting information to retain for distribution.
|
||||||
|
tarinfo.uid = 0
|
||||||
|
tarinfo.gid = 0
|
||||||
|
tarinfo.uname = ""
|
||||||
|
tarinfo.gname = ""
|
||||||
|
|
||||||
|
if max_mtime is not None and tarinfo.mtime >= max_mtime:
|
||||||
|
tarinfo.mtime = max_mtime
|
||||||
|
|
||||||
return tarinfo
|
return tarinfo
|
||||||
|
|
||||||
with tarfile.open('{}.tar.{}'.format(basename, tar_compression), 'w|{}'.format(tar_compression)) as tf:
|
filename = '{}.tar.{}'.format(basename, tar_compression)
|
||||||
|
with tarfile.open(filename, 'w|{}'.format(tar_compression)) as tf:
|
||||||
tf.add(build_dir, base_dir, filter=tarfilter)
|
tf.add(build_dir, base_dir, filter=tarfilter)
|
||||||
|
|
||||||
|
if tar_compression == 'gz' and max_mtime is not None:
|
||||||
|
# Python provides no elegant way to overwrite the gzip timestamp.
|
||||||
|
with open(filename, 'r+b') as fp:
|
||||||
|
fp.seek(4)
|
||||||
|
fp.write(struct.pack("<L", max_mtime))
|
||||||
|
|
||||||
def create_nsis(self, basename, build_dir, is_64bit):
|
def create_nsis(self, basename, build_dir, is_64bit):
|
||||||
# Get a list of build applications
|
# Get a list of build applications
|
||||||
build_cmd = self.get_finalized_command('build_apps')
|
build_cmd = self.get_finalized_command('build_apps')
|
||||||
@ -1500,6 +1525,7 @@ class bdist_apps(setuptools.Command):
|
|||||||
nsi_dir = p3d.Filename.fromOsSpecific(build_cmd.build_base)
|
nsi_dir = p3d.Filename.fromOsSpecific(build_cmd.build_base)
|
||||||
build_root_dir = p3d.Filename.fromOsSpecific(build_dir)
|
build_root_dir = p3d.Filename.fromOsSpecific(build_dir)
|
||||||
for root, dirs, files in os.walk(build_dir):
|
for root, dirs, files in os.walk(build_dir):
|
||||||
|
dirs.sort()
|
||||||
for name in files:
|
for name in files:
|
||||||
basefile = p3d.Filename.fromOsSpecific(os.path.join(root, name))
|
basefile = p3d.Filename.fromOsSpecific(os.path.join(root, name))
|
||||||
file = p3d.Filename(basefile)
|
file = p3d.Filename(basefile)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user