Skip to content

Commit 489bcb7

Browse files
authored
Create a simple bool env variable parser (#1696)
This little PR creates a unified way to parse environmental variable bools.
1 parent 102797c commit 489bcb7

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

emsdk.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,18 @@
4747

4848
extra_release_tag = None
4949

50+
51+
def get_env_boolean(name):
52+
env_var = os.getenv(name)
53+
assert env_var in {None, '1', '0'}, f'invalid environment variable setting ${env_var} for ${name}'
54+
return env_var == '1'
55+
56+
5057
# Enable this to do very verbose printing about the different steps that are
5158
# being run. Useful for debugging.
52-
VERBOSE = int(os.getenv('EMSDK_VERBOSE', '0'))
53-
QUIET = int(os.getenv('EMSDK_QUIET', '0'))
54-
if os.getenv('EMSDK_NOTTY'):
59+
VERBOSE = get_env_boolean('EMSDK_VERBOSE')
60+
QUIET = get_env_boolean('EMSDK_QUIET')
61+
if get_env_boolean('EMSDK_NOTTY'):
5562
TTY_OUTPUT = False
5663
else:
5764
TTY_OUTPUT = sys.stdout.isatty()
@@ -112,11 +119,11 @@ def exit_with_error(msg):
112119

113120

114121
# Pick which shell of 4 shells to use
115-
POWERSHELL = bool(os.getenv('EMSDK_POWERSHELL'))
116-
CSH = bool(os.getenv('EMSDK_CSH'))
117-
CMD = bool(os.getenv('EMSDK_CMD'))
118-
BASH = bool(os.getenv('EMSDK_BASH'))
119-
FISH = bool(os.getenv('EMSDK_FISH'))
122+
POWERSHELL = get_env_boolean('EMSDK_POWERSHELL')
123+
CSH = get_env_boolean('EMSDK_CSH')
124+
CMD = get_env_boolean('EMSDK_CMD')
125+
BASH = get_env_boolean('EMSDK_BASH')
126+
FISH = get_env_boolean('EMSDK_FISH')
120127

121128
if WINDOWS and BASH:
122129
MSYS = True
@@ -165,7 +172,7 @@ def exit_with_error(msg):
165172
ENABLE_LLVM_ASSERTIONS = 'auto'
166173

167174
# If true, keeps the downloaded archive files.
168-
KEEP_DOWNLOADS = bool(os.getenv('EMSDK_KEEP_DOWNLOADS'))
175+
KEEP_DOWNLOADS = get_env_boolean('EMSDK_KEEP_DOWNLOADS')
169176

170177

171178
def os_name():

0 commit comments

Comments
 (0)