Skip to content

Commit f655151

Browse files
sbc100hedwigz
authored andcommitted
Remove target_environment_may_be helper. NFC (emscripten-core#23160)
We already have the existing, and more widely used, `ENVIRONMENT_MAY_BE_XX` settings.
1 parent f6ab157 commit f655151

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
@@ -1446,7 +1446,7 @@ def phase_linker_setup(options, state, newargs): # noqa: C901, PLR0912, PLR0915
14461446
if 'MODULARIZE' in user_settings:
14471447
exit_with_error('EXPORT_ES6 requires MODULARIZE to be set')
14481448
settings.MODULARIZE = 1
1449-
if shared.target_environment_may_be('node') and not settings.USE_ES6_IMPORT_META:
1449+
if settings.ENVIRONMENT_MAY_BE_NODE and not settings.USE_ES6_IMPORT_META:
14501450
# EXPORT_ES6 + ENVIRONMENT=*node* requires the use of import.meta.url
14511451
if 'USE_ES6_IMPORT_META' in user_settings:
14521452
exit_with_error('EXPORT_ES6 and ENVIRONMENT=*node* requires USE_ES6_IMPORT_META to be set')
@@ -1773,7 +1773,7 @@ def get_full_import_name(name):
17731773
if settings.NODE_CODE_CACHING:
17741774
if settings.WASM_ASYNC_COMPILATION:
17751775
exit_with_error('NODE_CODE_CACHING requires sync compilation (WASM_ASYNC_COMPILATION=0)')
1776-
if not shared.target_environment_may_be('node'):
1776+
if not settings.ENVIRONMENT_MAY_BE_NODE:
17771777
exit_with_error('NODE_CODE_CACHING only works in node, but target environments do not include it')
17781778
if settings.SINGLE_FILE:
17791779
exit_with_error('NODE_CODE_CACHING saves a file on the side and is not compatible with SINGLE_FILE')
@@ -2372,11 +2372,11 @@ def phase_binaryen(target, options, wasm_target):
23722372

23732373

23742374
def node_es6_imports():
2375-
if not settings.EXPORT_ES6 or not shared.target_environment_may_be('node'):
2375+
if not settings.EXPORT_ES6 or not settings.ENVIRONMENT_MAY_BE_NODE:
23762376
return ''
23772377

23782378
# Multi-environment builds uses `await import` in `shell.js`
2379-
if shared.target_environment_may_be('web'):
2379+
if settings.ENVIRONMENT_MAY_BE_WEB:
23802380
return ''
23812381

23822382
# Use static import declaration if we only target Node.js
@@ -2403,8 +2403,8 @@ def modularize():
24032403
# Multi-environment ES6 builds require an async function
24042404
async_emit = ''
24052405
if settings.EXPORT_ES6 and \
2406-
shared.target_environment_may_be('node') and \
2407-
shared.target_environment_may_be('web'):
2406+
settings.ENVIRONMENT_MAY_BE_NODE and \
2407+
settings.ENVIRONMENT_MAY_BE_WEB:
24082408
async_emit = 'async '
24092409

24102410
# TODO: Remove when https://bugs.webkit.org/show_bug.cgi?id=223533 is resolved.
@@ -2452,7 +2452,7 @@ def modularize():
24522452
script_url = 'import.meta.url'
24532453
else:
24542454
script_url = "typeof document != 'undefined' ? document.currentScript?.src : undefined"
2455-
if shared.target_environment_may_be('node'):
2455+
if settings.ENVIRONMENT_MAY_BE_NODE:
24562456
script_url_node = "if (typeof __filename != 'undefined') _scriptName = _scriptName || __filename;"
24572457
if settings.MODULARIZE == 'instance':
24582458
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)