Skip to content

Commit

Permalink
Always output a tarball from cc_binary to simplify logic. (#936)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
walkingeyerobot and Mitch Foley committed Dec 1, 2021
1 parent 846f683 commit c7305b4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 31 deletions.
17 changes: 7 additions & 10 deletions bazel/emscripten_toolchain/link_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,14 @@
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)
24 changes: 3 additions & 21 deletions bazel/emscripten_toolchain/wasm_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import argparse
import os
import subprocess
import sys


def ensure(f):
Expand All @@ -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'))
Expand Down

0 comments on commit c7305b4

Please sign in to comment.