MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / run_closure_cmd

Function run_closure_cmd

tools/building.py:647–753  ·  view source on GitHub ↗
(cmd, filename, env)

Source from the content-addressed store, hash-verified

645
646
647def run_closure_cmd(cmd, filename, env):
648 cmd += ['--js', filename]
649
650 # Closure compiler is unable to deal with path names that are not 7-bit ASCII:
651 # https://github.com/google/closure-compiler/issues/3784
652 tempfiles = shared.get_temp_files()
653
654 def move_to_safe_7bit_ascii_filename(filename):
655 if os.path.abspath(filename).isascii():
656 return os.path.abspath(filename)
657 safe_filename = tempfiles.get('.js').name # Safe 7-bit filename
658 shutil.copyfile(filename, safe_filename)
659 return os.path.relpath(safe_filename, tempfiles.tmpdir)
660
661 for i in range(len(cmd)):
662 for prefix in ('--externs', '--js'):
663 # Handle the case where the flag and the value are two separate arguments.
664 if cmd[i] == prefix:
665 cmd[i + 1] = move_to_safe_7bit_ascii_filename(cmd[i + 1])
666 # and the case where they are one argument, e.g. --externs=foo.js
667 elif cmd[i].startswith(prefix + '='):
668 # Replace the argument with a version that has a safe filename.
669 filename = cmd[i].split('=', 1)[1]
670 cmd[i] = '='.join([prefix, move_to_safe_7bit_ascii_filename(filename)])
671
672 outfile = tempfiles.get('.cc.js').name # Safe 7-bit filename
673
674 # Specify output file relative to the temp directory to avoid specifying non-7-bit-ASCII path names.
675 cmd += ['--js_output_file', os.path.relpath(outfile, tempfiles.tmpdir)]
676 if not settings.MINIFY_WHITESPACE:
677 cmd += ['--formatting', 'PRETTY_PRINT']
678
679 if settings.WASM2JS:
680 # In WASM2JS mode, the WebAssembly object is polyfilled, which triggers
681 # Closure's built-in type check:
682 # externs.zip//webassembly.js:29:18: WARNING - [JSC_TYPE_MISMATCH] initializing variable
683 # We cannot fix this warning externally, since adding /** @suppress{checkTypes} */
684 # to the polyfill is "in the wrong end". So mute this warning globally to
685 # allow clean Closure output. https://github.com/google/closure-compiler/issues/4108
686 cmd += ['--jscomp_off=checkTypes']
687
688 # WASM2JS codegen routinely generates expressions that are unused, e.g.
689 # WARNING - [JSC_USELESS_CODE] Suspicious code. The result of the 'bitor' operator is not being used.
690 # s(0) | 0;
691 # ^^^^^^^^
692 # Turn off this check in Closure to allow clean Closure output.
693 cmd += ['--jscomp_off=uselessCode']
694
695 shared.print_compiler_stage(cmd)
696
697 # Closure compiler does not work if any of the input files contain characters outside the
698 # 7-bit ASCII range. Therefore make sure the command line we pass does not contain any such
699 # input files by passing all input filenames relative to the cwd. (user temp directory might
700 # be in user's home directory, and user's profile name might contain unicode characters)
701 # https://github.com/google/closure-compiler/issues/4159: Closure outputs stdout/stderr in iso-8859-1 on Windows.
702 proc = run_process(cmd, stderr=PIPE, check=False, env=env, cwd=tempfiles.tmpdir, encoding='iso-8859-1' if WINDOWS else 'utf-8')
703
704 # XXX Closure bug: if Closure is invoked with --create_source_map, Closure should create a

Callers 1

closure_compilerFunction · 0.85

Calls 10

run_processFunction · 0.85
exit_with_errorFunction · 0.85
splitMethod · 0.80
warningMethod · 0.80
getMethod · 0.65
rangeFunction · 0.50
joinMethod · 0.45
errorMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected