@@ -30,7 +30,6 @@ from swift_build_support.swift_build_support import (
3030 diagnostics ,
3131 products ,
3232 shell ,
33- tar ,
3433 targets ,
3534 workspace
3635)
@@ -89,6 +88,25 @@ def print_xcodebuild_versions(file=sys.stdout):
8988 file .flush ()
9089
9190
91+ def tar (source , destination ):
92+ """
93+ Create a gzip archive of the file at 'source' at the given
94+ 'destination' path.
95+ """
96+ # We do not use `tarfile` here because:
97+ # - We wish to support LZMA2 compression while also supporting Python 2.7.
98+ # - We wish to explicitly set the owner and group of the archive.
99+ args = ['tar' , '-c' , '-z' , '-f' , destination ]
100+
101+ if platform .system () != 'Darwin' and platform .system () != 'Windows' :
102+ args += ['--owner=0' , '--group=0' ]
103+
104+ # Discard stderr output such as 'tar: Failed to open ...'. We'll detect
105+ # these cases using the exit code, which should cause 'shell.call' to
106+ # raise.
107+ shell .call (args + [source ], stderr = shell .DEVNULL )
108+
109+
92110class BuildScriptInvocation (object ):
93111
94112 """Represent a single build script invocation."""
@@ -1169,8 +1187,8 @@ def main_normal():
11691187 # run `tar` without the leading '/' (we remove it ourselves to keep
11701188 # `tar` from emitting a warning).
11711189 with shell .pushd (args .install_symroot ):
1172- tar . tar (source = prefix .lstrip ('/' ),
1173- destination = args .symbols_package )
1190+ tar (source = prefix .lstrip ('/' ),
1191+ destination = args .symbols_package )
11741192
11751193 return 0
11761194
0 commit comments