diff --git a/bazel/emscripten_toolchain/link_wrapper.py b/bazel/emscripten_toolchain/link_wrapper.py index ce10dae..3134c8d 100644 --- a/bazel/emscripten_toolchain/link_wrapper.py +++ b/bazel/emscripten_toolchain/link_wrapper.py @@ -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) diff --git a/bazel/emscripten_toolchain/wasm_binary.py b/bazel/emscripten_toolchain/wasm_binary.py index 641c0d6..12aa870 100644 --- a/bazel/emscripten_toolchain/wasm_binary.py +++ b/bazel/emscripten_toolchain/wasm_binary.py @@ -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'))