2019-09-06 14:43:50 -07:00
|
|
|
#!/usr/bin/env python3
|
2017-02-15 16:41:53 -08:00
|
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
2006-05-09 09:20:42 -07:00
|
|
|
|
2008-12-24 10:33:31 -08:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
# Documentation files included with distributions.
|
2006-05-09 09:20:42 -07:00
|
|
|
|
2019-09-04 19:36:23 -07:00
|
|
|
GAME_NAME = sys.argv[1]
|
|
|
|
FILES = sys.argv[2:]
|
2006-05-09 09:20:42 -07:00
|
|
|
|
2008-12-24 10:33:31 -08:00
|
|
|
# Run a command, displaying it before executing it.
|
2006-05-09 09:20:42 -07:00
|
|
|
|
2019-09-04 19:36:23 -07:00
|
|
|
|
2008-12-24 10:33:31 -08:00
|
|
|
def run_command(command):
|
2013-12-31 01:51:20 -08:00
|
|
|
print("> " + command)
|
|
|
|
os.system(command)
|
2006-05-09 09:20:42 -07:00
|
|
|
|
2019-09-04 19:36:23 -07:00
|
|
|
|
2008-12-24 10:33:31 -08:00
|
|
|
# Find the version to build:
|
2006-05-09 09:20:42 -07:00
|
|
|
|
2008-12-24 10:33:31 -08:00
|
|
|
version = os.getenv("VERSION")
|
2006-05-09 09:20:42 -07:00
|
|
|
|
2008-12-24 10:33:31 -08:00
|
|
|
if version is None:
|
2014-10-05 03:09:42 -07:00
|
|
|
sys.stderr.write("Version not specified for release\n")
|
2014-01-06 22:34:47 -08:00
|
|
|
sys.exit(1)
|
2019-09-17 16:36:00 -07:00
|
|
|
if version[0] is "v":
|
|
|
|
# Strip the leading "v" from versioning
|
|
|
|
version = version[1:]
|
2008-12-24 10:33:31 -08:00
|
|
|
|
2014-01-07 17:45:41 -08:00
|
|
|
path = os.path.dirname(FILES[0])
|
|
|
|
basename = os.path.basename(FILES[0])
|
2008-12-24 10:33:31 -08:00
|
|
|
|
2014-01-07 17:45:41 -08:00
|
|
|
base_dir = GAME_NAME + "-" + version
|
2014-01-06 22:34:47 -08:00
|
|
|
full_path = path + "/" + base_dir
|
2008-12-24 10:33:31 -08:00
|
|
|
|
2014-01-06 22:34:47 -08:00
|
|
|
# Create directory and add files
|
2008-12-24 10:33:31 -08:00
|
|
|
|
Introduce measures to start building Zips deterministically.
This at least lays some groundwork for doing so, by gathering archive
members by wildcard expansion rather than zip's -r parameter (which
uses file system order -- essentially random), combined with LC_ALL=C
so that locale sorting orders don't matter either. zip's -X option is
also used so no Unix metadata (UIDs, GIDs, modes) are saved in the
archive.
To really complete the effect, faketime should be used to deal with
file timestamps. Requiring faketime to do `make dist` seems too
extreme to me, so I'm leaving it out, but the general idea is to run a
command such as:
faketime -f "$(TZ=UTC date -d "@$(git show -q --format=format:%ct)" \
"+%Y-%m-%d %H:%M:%S")" \
make dist
This does also assume that zip's default compression algorithm never
changes (eg, from DEFLATE to BZip2 or LZMA), or never releases an
improved version (eg, a better DEFLATE). It's not perfect, but this
should be good enough.
2017-02-22 11:44:50 -08:00
|
|
|
run_command("mkdir {}".format(full_path))
|
2014-01-07 17:45:41 -08:00
|
|
|
for file in FILES:
|
Introduce measures to start building Zips deterministically.
This at least lays some groundwork for doing so, by gathering archive
members by wildcard expansion rather than zip's -r parameter (which
uses file system order -- essentially random), combined with LC_ALL=C
so that locale sorting orders don't matter either. zip's -X option is
also used so no Unix metadata (UIDs, GIDs, modes) are saved in the
archive.
To really complete the effect, faketime should be used to deal with
file timestamps. Requiring faketime to do `make dist` seems too
extreme to me, so I'm leaving it out, but the general idea is to run a
command such as:
faketime -f "$(TZ=UTC date -d "@$(git show -q --format=format:%ct)" \
"+%Y-%m-%d %H:%M:%S")" \
make dist
This does also assume that zip's default compression algorithm never
changes (eg, from DEFLATE to BZip2 or LZMA), or never releases an
improved version (eg, a better DEFLATE). It's not perfect, but this
should be good enough.
2017-02-22 11:44:50 -08:00
|
|
|
run_command("cp {} {}".format(file, full_path))
|
2008-12-24 10:33:31 -08:00
|
|
|
|
2014-01-06 22:34:47 -08:00
|
|
|
orig_dir = os.getcwd()
|
2006-05-09 09:20:42 -07:00
|
|
|
|
2014-01-06 22:34:47 -08:00
|
|
|
os.chdir(path)
|
Introduce measures to start building Zips deterministically.
This at least lays some groundwork for doing so, by gathering archive
members by wildcard expansion rather than zip's -r parameter (which
uses file system order -- essentially random), combined with LC_ALL=C
so that locale sorting orders don't matter either. zip's -X option is
also used so no Unix metadata (UIDs, GIDs, modes) are saved in the
archive.
To really complete the effect, faketime should be used to deal with
file timestamps. Requiring faketime to do `make dist` seems too
extreme to me, so I'm leaving it out, but the general idea is to run a
command such as:
faketime -f "$(TZ=UTC date -d "@$(git show -q --format=format:%ct)" \
"+%Y-%m-%d %H:%M:%S")" \
make dist
This does also assume that zip's default compression algorithm never
changes (eg, from DEFLATE to BZip2 or LZMA), or never releases an
improved version (eg, a better DEFLATE). It's not perfect, but this
should be good enough.
2017-02-22 11:44:50 -08:00
|
|
|
run_command("rm -f {}.zip".format(base_dir))
|
|
|
|
run_command("zip -X {0}.zip {0} {0}/*".format(base_dir))
|
|
|
|
run_command("rm -rf {}".format(base_dir))
|
2014-01-06 22:34:47 -08:00
|
|
|
os.chdir(orig_dir)
|