(filename, advanced=True, extra_closure_args=None)
| 548 | |
| 549 | @ToolchainProfiler.profile() |
| 550 | def closure_compiler(filename, advanced=True, extra_closure_args=None): |
| 551 | user_args = [] |
| 552 | env_args = os.environ.get('EMCC_CLOSURE_ARGS') |
| 553 | if env_args: |
| 554 | user_args += shlex.split(env_args) |
| 555 | if extra_closure_args: |
| 556 | user_args += extra_closure_args |
| 557 | |
| 558 | closure_cmd, env = get_closure_compiler_and_env(user_args) |
| 559 | |
| 560 | # Closure externs file contains known symbols to be extern to the minification, Closure |
| 561 | # should not minify these symbol names. |
| 562 | CLOSURE_EXTERNS = [path_from_root('src/closure-externs/closure-externs.js')] |
| 563 | |
| 564 | if settings.MODULARIZE: |
| 565 | CLOSURE_EXTERNS += [path_from_root('src/closure-externs/modularize-externs.js')] |
| 566 | |
| 567 | if settings.AUDIO_WORKLET: |
| 568 | CLOSURE_EXTERNS += [path_from_root('src/closure-externs/audio-worklet-externs.js')] |
| 569 | |
| 570 | # Closure compiler needs to know about all exports that come from the wasm module, because to optimize for small code size, |
| 571 | # the exported symbols are added to global scope via a foreach loop in a way that evades Closure's static analysis. With an explicit |
| 572 | # externs file for the exports, Closure is able to reason about the exports. |
| 573 | if settings.WASM_EXPORTS and not settings.DECLARE_ASM_MODULE_EXPORTS: |
| 574 | # Generate an exports file that records all the exported symbols from the wasm module. |
| 575 | exports = [asmjs_mangle(i) for i in settings.WASM_EXPORTS] + settings.ALIASES |
| 576 | module_exports_suppressions = '\n'.join(['/**\n * @suppress {duplicate, undefinedVars}\n */\nvar %s;\n' % e for e in exports]) |
| 577 | exports_file = shared.get_temp_files().get('.js', prefix='emcc_module_exports_') |
| 578 | exports_file.write(module_exports_suppressions.encode()) |
| 579 | exports_file.close() |
| 580 | |
| 581 | CLOSURE_EXTERNS += [exports_file.name] |
| 582 | |
| 583 | # Node.js specific externs |
| 584 | if settings.ENVIRONMENT_MAY_BE_NODE: |
| 585 | node_extern_dir = path_from_root('third_party/closure-compiler/node-externs') |
| 586 | node_externs = os.listdir(node_extern_dir) |
| 587 | node_externs = [os.path.join(node_extern_dir, name) for name in node_externs if name.endswith('.js')] |
| 588 | CLOSURE_EXTERNS += [path_from_root('src/closure-externs/node-externs.js'), *node_externs] |
| 589 | |
| 590 | # V8/SpiderMonkey shell specific externs |
| 591 | if settings.ENVIRONMENT_MAY_BE_SHELL: |
| 592 | V8_EXTERNS = [path_from_root('src/closure-externs/v8-externs.js')] |
| 593 | SPIDERMONKEY_EXTERNS = [path_from_root('src/closure-externs/spidermonkey-externs.js')] |
| 594 | CLOSURE_EXTERNS += V8_EXTERNS + SPIDERMONKEY_EXTERNS |
| 595 | |
| 596 | # Web environment specific externs |
| 597 | if settings.ENVIRONMENT_MAY_BE_WEB or settings.ENVIRONMENT_MAY_BE_WORKER: |
| 598 | browser_externs_dir = path_from_root('src/closure-externs/browser-externs') |
| 599 | if os.path.isdir(browser_externs_dir): |
| 600 | browser_externs = os.listdir(browser_externs_dir) |
| 601 | browser_externs = [os.path.join(browser_externs_dir, name) for name in browser_externs if name.endswith('.js')] |
| 602 | CLOSURE_EXTERNS += browser_externs |
| 603 | |
| 604 | if settings.DYNCALLS: |
| 605 | CLOSURE_EXTERNS += [path_from_root('src/closure-externs/dyncall-externs.js')] |
| 606 | |
| 607 | args = ['--compilation_level', 'ADVANCED_OPTIMIZATIONS' if advanced else 'SIMPLE_OPTIMIZATIONS'] |
no test coverage detected