Skip to content

Commit

Permalink
Remove target_environment_may_be helper. NFC (#23160)
Browse files Browse the repository at this point in the history
We already have the existing, and more widely used,
`ENVIRONMENT_MAY_BE_XX` settings.
  • Loading branch information
sbc100 authored Dec 14, 2024
1 parent 0dfb071 commit 46ef8a4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
6 changes: 3 additions & 3 deletions tools/building.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,21 +572,21 @@ 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
if name.endswith('.js')]
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)
Expand Down
14 changes: 7 additions & 7 deletions tools/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions tools/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit 46ef8a4

Please sign in to comment.