Skip to content

Commit 46ef8a4

Browse files
authored
Remove target_environment_may_be helper. NFC (#23160)
We already have the existing, and more widely used, `ENVIRONMENT_MAY_BE_XX` settings.
1 parent 0dfb071 commit 46ef8a4

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
lines changed

tools/building.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -572,21 +572,21 @@ def closure_compiler(filename, advanced=True, extra_closure_args=None):
572572
CLOSURE_EXTERNS += [exports_file.name]
573573

574574
# Node.js specific externs
575-
if shared.target_environment_may_be('node'):
575+
if settings.ENVIRONMENT_MAY_BE_NODE:
576576
NODE_EXTERNS_BASE = path_from_root('third_party/closure-compiler/node-externs')
577577
NODE_EXTERNS = os.listdir(NODE_EXTERNS_BASE)
578578
NODE_EXTERNS = [os.path.join(NODE_EXTERNS_BASE, name) for name in NODE_EXTERNS
579579
if name.endswith('.js')]
580580
CLOSURE_EXTERNS += [path_from_root('src/closure-externs/node-externs.js')] + NODE_EXTERNS
581581

582582
# V8/SpiderMonkey shell specific externs
583-
if shared.target_environment_may_be('shell'):
583+
if settings.ENVIRONMENT_MAY_BE_SHELL:
584584
V8_EXTERNS = [path_from_root('src/closure-externs/v8-externs.js')]
585585
SPIDERMONKEY_EXTERNS = [path_from_root('src/closure-externs/spidermonkey-externs.js')]
586586
CLOSURE_EXTERNS += V8_EXTERNS + SPIDERMONKEY_EXTERNS
587587

588588
# Web environment specific externs
589-
if shared.target_environment_may_be('web') or shared.target_environment_may_be('worker'):
589+
if settings.ENVIRONMENT_MAY_BE_WEB or settings.ENVIRONMENT_MAY_BE_WORKER:
590590
BROWSER_EXTERNS_BASE = path_from_root('src/closure-externs/browser-externs')
591591
if os.path.isdir(BROWSER_EXTERNS_BASE):
592592
BROWSER_EXTERNS = os.listdir(BROWSER_EXTERNS_BASE)

tools/link.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,7 +1440,7 @@ def phase_linker_setup(options, state, newargs): # noqa: C901, PLR0912, PLR0915
14401440
if 'MODULARIZE' in user_settings:
14411441
exit_with_error('EXPORT_ES6 requires MODULARIZE to be set')
14421442
settings.MODULARIZE = 1
1443-
if shared.target_environment_may_be('node') and not settings.USE_ES6_IMPORT_META:
1443+
if settings.ENVIRONMENT_MAY_BE_NODE and not settings.USE_ES6_IMPORT_META:
14441444
# EXPORT_ES6 + ENVIRONMENT=*node* requires the use of import.meta.url
14451445
if 'USE_ES6_IMPORT_META' in user_settings:
14461446
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):
17671767
if settings.NODE_CODE_CACHING:
17681768
if settings.WASM_ASYNC_COMPILATION:
17691769
exit_with_error('NODE_CODE_CACHING requires sync compilation (WASM_ASYNC_COMPILATION=0)')
1770-
if not shared.target_environment_may_be('node'):
1770+
if not settings.ENVIRONMENT_MAY_BE_NODE:
17711771
exit_with_error('NODE_CODE_CACHING only works in node, but target environments do not include it')
17721772
if settings.SINGLE_FILE:
17731773
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):
23662366

23672367

23682368
def node_es6_imports():
2369-
if not settings.EXPORT_ES6 or not shared.target_environment_may_be('node'):
2369+
if not settings.EXPORT_ES6 or not settings.ENVIRONMENT_MAY_BE_NODE:
23702370
return ''
23712371

23722372
# Multi-environment builds uses `await import` in `shell.js`
2373-
if shared.target_environment_may_be('web'):
2373+
if settings.ENVIRONMENT_MAY_BE_WEB:
23742374
return ''
23752375

23762376
# Use static import declaration if we only target Node.js
@@ -2397,8 +2397,8 @@ def modularize():
23972397
# Multi-environment ES6 builds require an async function
23982398
async_emit = ''
23992399
if settings.EXPORT_ES6 and \
2400-
shared.target_environment_may_be('node') and \
2401-
shared.target_environment_may_be('web'):
2400+
settings.ENVIRONMENT_MAY_BE_NODE and \
2401+
settings.ENVIRONMENT_MAY_BE_WEB:
24022402
async_emit = 'async '
24032403

24042404
# TODO: Remove when https://bugs.webkit.org/show_bug.cgi?id=223533 is resolved.
@@ -2446,7 +2446,7 @@ def modularize():
24462446
script_url = 'import.meta.url'
24472447
else:
24482448
script_url = "typeof document != 'undefined' ? document.currentScript?.src : undefined"
2449-
if shared.target_environment_may_be('node'):
2449+
if settings.ENVIRONMENT_MAY_BE_NODE:
24502450
script_url_node = "if (typeof __filename != 'undefined') _scriptName = _scriptName || __filename;"
24512451
if settings.MODULARIZE == 'instance':
24522452
src = '''%(node_imports)s

tools/shared.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -640,10 +640,6 @@ def get_temp_files():
640640
return tempfiles.TempFiles(TEMP_DIR, save_debug_files=False)
641641

642642

643-
def target_environment_may_be(environment):
644-
return not settings.ENVIRONMENT or environment in settings.ENVIRONMENT.split(',')
645-
646-
647643
def print_compiler_stage(cmd):
648644
"""Emulate the '-v/-###' flags of clang/gcc by printing the sub-commands
649645
that we run."""

0 commit comments

Comments
 (0)