Always output a tarball from cc_binary to simplify logic. (#936)

* Always output a tarball from cc_binary to simplify logic. This will change the result of --config=wasm builds that were previously outputting a single file.

* better to use early return here

* Always output a tarball from cc_binary to simplify logic. This will change the result of --config=wasm builds that were previously outputting a single file.

* better to use early return here

Co-authored-by: Mitch Foley <mitchfoley@chromium.org>
This commit is contained in:
walkingeyerobot
2021-12-01 18:26:16 -05:00
committed by GitHub
parent 846f683bea
commit c7305b4045
2 changed files with 10 additions and 31 deletions

View File

@@ -153,17 +153,14 @@ if os.path.exists(wasm_base + '.debug.wasm') and os.path.exists(wasm_base):
wasm_base,
'--add-section=external_debug_info=debugsection.tmp'])
# If we have more than one output file then create tarball
if len(files) > 1:
cmd = ['tar', 'cf', 'tmp.tar'] + files
subprocess.check_call(cmd, cwd=outdir)
os.rename(os.path.join(outdir, 'tmp.tar'), output_file)
elif len(files) == 1:
# Otherwise, if only have a single output than move it to the expected name
if files[0] != os.path.basename(output_file):
os.rename(os.path.join(outdir, files[0]), output_file)
else:
# Make sure we have at least one output file.
if not len(files):
print('emcc.py did not appear to output any known files!')
sys.exit(1)
# cc_binary must output exactly one file; put all the output files in a tarball.
cmd = ['tar', 'cf', 'tmp.tar'] + files
subprocess.check_call(cmd, cwd=outdir)
os.rename(os.path.join(outdir, 'tmp.tar'), output_file)
sys.exit(0)

View File

@@ -21,7 +21,6 @@ WebAssembly binary into a larger web application.
import argparse
import os
import subprocess
import sys
def ensure(f):
@@ -44,26 +43,9 @@ def main():
basename = os.path.basename(args.archive)
stem = basename.split('.')[0]
# Check the type of the input file
mimetype_bytes = subprocess.check_output(['file', '-Lb', '--mime-type', '--mime-encoding', args.archive])
mimetype = mimetype_bytes.decode(sys.stdout.encoding)
# If we have a tar, extract all files. If we have just a single file, copy it.
if 'tar' in mimetype:
subprocess.check_call(
['tar', 'xf', args.archive, '-C', args.output_path])
elif 'binary' in mimetype:
subprocess.check_call([
'cp',
args.archive,
os.path.join(args.output_path, stem + '.wasm')])
elif 'text' in mimetype:
subprocess.check_call([
'cp',
args.archive,
os.path.join(args.output_path, stem + '.js')])
else:
subprocess.check_call(['cp', args.archive, args.output_path])
# Extract all files from the tarball.
subprocess.check_call(
['tar', 'xf', args.archive, '-C', args.output_path])
# At least one of these two files should exist at this point.
ensure(os.path.join(args.output_path, stem + '.js'))