From 46ef8a4da2fd01685218d31fe4466a3ab0c9eaa2 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Fri, 13 Dec 2024 16:13:36 -0800 Subject: [PATCH] Remove `target_environment_may_be` helper. NFC (#23160) We already have the existing, and more widely used, `ENVIRONMENT_MAY_BE_XX` settings. --- tools/building.py | 6 +++--- tools/link.py | 14 +++++++------- tools/shared.py | 4 ---- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/tools/building.py b/tools/building.py index 1110f1dfb7bf7..d5b018d758476 100644 --- a/tools/building.py +++ b/tools/building.py @@ -572,7 +572,7 @@ def closure_compiler(filename, advanced=True, extra_closure_args=None): CLOSURE_EXTERNS += [exports_file.name] # Node.js specific externs - if shared.target_environment_may_be('node'): + if settings.ENVIRONMENT_MAY_BE_NODE: NODE_EXTERNS_BASE = path_from_root('third_party/closure-compiler/node-externs') NODE_EXTERNS = os.listdir(NODE_EXTERNS_BASE) NODE_EXTERNS = [os.path.join(NODE_EXTERNS_BASE, name) for name in NODE_EXTERNS @@ -580,13 +580,13 @@ def closure_compiler(filename, advanced=True, extra_closure_args=None): CLOSURE_EXTERNS += [path_from_root('src/closure-externs/node-externs.js')] + NODE_EXTERNS # V8/SpiderMonkey shell specific externs - if shared.target_environment_may_be('shell'): + if settings.ENVIRONMENT_MAY_BE_SHELL: V8_EXTERNS = [path_from_root('src/closure-externs/v8-externs.js')] SPIDERMONKEY_EXTERNS = [path_from_root('src/closure-externs/spidermonkey-externs.js')] CLOSURE_EXTERNS += V8_EXTERNS + SPIDERMONKEY_EXTERNS # Web environment specific externs - if shared.target_environment_may_be('web') or shared.target_environment_may_be('worker'): + if settings.ENVIRONMENT_MAY_BE_WEB or settings.ENVIRONMENT_MAY_BE_WORKER: BROWSER_EXTERNS_BASE = path_from_root('src/closure-externs/browser-externs') if os.path.isdir(BROWSER_EXTERNS_BASE): BROWSER_EXTERNS = os.listdir(BROWSER_EXTERNS_BASE) diff --git a/tools/link.py b/tools/link.py index 76b6e521bb8d4..4444f4e06146c 100644 --- a/tools/link.py +++ b/tools/link.py @@ -1440,7 +1440,7 @@ def phase_linker_setup(options, state, newargs): # noqa: C901, PLR0912, PLR0915 if 'MODULARIZE' in user_settings: exit_with_error('EXPORT_ES6 requires MODULARIZE to be set') settings.MODULARIZE = 1 - if shared.target_environment_may_be('node') and not settings.USE_ES6_IMPORT_META: + if settings.ENVIRONMENT_MAY_BE_NODE and not settings.USE_ES6_IMPORT_META: # EXPORT_ES6 + ENVIRONMENT=*node* requires the use of import.meta.url if 'USE_ES6_IMPORT_META' in user_settings: exit_with_error('EXPORT_ES6 and ENVIRONMENT=*node* requires USE_ES6_IMPORT_META to be set') @@ -1767,7 +1767,7 @@ def get_full_import_name(name): if settings.NODE_CODE_CACHING: if settings.WASM_ASYNC_COMPILATION: exit_with_error('NODE_CODE_CACHING requires sync compilation (WASM_ASYNC_COMPILATION=0)') - if not shared.target_environment_may_be('node'): + if not settings.ENVIRONMENT_MAY_BE_NODE: exit_with_error('NODE_CODE_CACHING only works in node, but target environments do not include it') if settings.SINGLE_FILE: exit_with_error('NODE_CODE_CACHING saves a file on the side and is not compatible with SINGLE_FILE') @@ -2366,11 +2366,11 @@ def phase_binaryen(target, options, wasm_target): def node_es6_imports(): - if not settings.EXPORT_ES6 or not shared.target_environment_may_be('node'): + if not settings.EXPORT_ES6 or not settings.ENVIRONMENT_MAY_BE_NODE: return '' # Multi-environment builds uses `await import` in `shell.js` - if shared.target_environment_may_be('web'): + if settings.ENVIRONMENT_MAY_BE_WEB: return '' # Use static import declaration if we only target Node.js @@ -2397,8 +2397,8 @@ def modularize(): # Multi-environment ES6 builds require an async function async_emit = '' if settings.EXPORT_ES6 and \ - shared.target_environment_may_be('node') and \ - shared.target_environment_may_be('web'): + settings.ENVIRONMENT_MAY_BE_NODE and \ + settings.ENVIRONMENT_MAY_BE_WEB: async_emit = 'async ' # TODO: Remove when https://bugs.webkit.org/show_bug.cgi?id=223533 is resolved. @@ -2446,7 +2446,7 @@ def modularize(): script_url = 'import.meta.url' else: script_url = "typeof document != 'undefined' ? document.currentScript?.src : undefined" - if shared.target_environment_may_be('node'): + if settings.ENVIRONMENT_MAY_BE_NODE: script_url_node = "if (typeof __filename != 'undefined') _scriptName = _scriptName || __filename;" if settings.MODULARIZE == 'instance': src = '''%(node_imports)s diff --git a/tools/shared.py b/tools/shared.py index b6cc824a0f020..c6eb79378495e 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -640,10 +640,6 @@ def get_temp_files(): return tempfiles.TempFiles(TEMP_DIR, save_debug_files=False) -def target_environment_may_be(environment): - return not settings.ENVIRONMENT or environment in settings.ENVIRONMENT.split(',') - - def print_compiler_stage(cmd): """Emulate the '-v/-###' flags of clang/gcc by printing the sub-commands that we run."""