Skip to content

Commit 9d720a1

Browse files
author
Stewart Miles
committed
Fixed export_unity_package.py on macOS.
Python's tarfile and gzip on macOS generates a .tar.gz that can't be read by Unity on Windows. This changes export_unity_package.py to use BSD tar distributed with macOS to generate tarballs instead which not only can be expanded on Windows but also speeds up the archiving process. Fixed #351 Change-Id: Ifc82666c6496f9a11088b6a7ea01e9cbad593846
1 parent 025c0a3 commit 9d720a1

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

source/ExportUnityPackage/export_unity_package.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2475,7 +2475,11 @@ def create_archive(archive_filename, input_directory, timestamp):
24752475
os.makedirs(archive_dir)
24762476

24772477
# Create a tar.gz archive.
2478-
if platform.system() == "Linux":
2478+
tar_available = (platform.system() == "Linux" or
2479+
platform.system() == "Darwin")
2480+
gnu_tar_available = platform.system() == "Linux"
2481+
# Whether a reproducible tar.gz is required.
2482+
if tar_available:
24792483
# tarfile is 10x slower than the tar command so use the command line
24802484
# tool where it's available and can generate a reproducible archive.
24812485
list_filename = os.path.join(tempfile.mkdtemp(), "input_files.txt")
@@ -2487,13 +2491,26 @@ def create_archive(archive_filename, input_directory, timestamp):
24872491

24882492
tar_args = ["tar"]
24892493
tar_args.extend(["-c", "-z", "-f", archive_filename])
2490-
if FLAGS.timestamp:
2491-
tar_args.append("--mtime=@%d" % FLAGS.timestamp)
2492-
# Hard code the user and group of files in the tar file so that
2493-
# the process is reproducible.
2494-
tar_args.extend(["--owner=%s" % FLAGS.owner,
2495-
"--group=%s" % FLAGS.group])
2496-
tar_args.append("--no-recursion")
2494+
if gnu_tar_available:
2495+
if FLAGS.timestamp:
2496+
tar_args.append("--mtime=@%d" % FLAGS.timestamp)
2497+
# Hard code the user and group of files in the tar file so that
2498+
# the process is reproducible.
2499+
tar_args.extend(["--owner=%s" % FLAGS.owner,
2500+
"--group=%s" % FLAGS.group])
2501+
tar_args.append("--no-recursion")
2502+
else: # Assume BSD tar.
2503+
# Set the modification time of each file since BSD tar doesn't have
2504+
# an option to override this.
2505+
if FLAGS.timestamp:
2506+
for filename in input_filenames:
2507+
os.utime(filename, (FLAGS.timestamp, FLAGS.timestamp))
2508+
# Don't recurse directories.
2509+
tar_args.append("-n")
2510+
# If timestamp, group or owner are present strip all fields from
2511+
# the tar so that it's reproducible.
2512+
if FLAGS.timestamp or FLAGS.owner or FLAGS.group:
2513+
tar_args.extend(["--options", "mtree:!all"])
24972514
tar_args.extend(["-T", list_filename])
24982515
# Disable timestamp in the gzip header.
24992516
tar_env = os.environ.copy()

0 commit comments

Comments
 (0)