Skip to content

Commit 8230125

Browse files
authored
Use second argument to os.getenv to simplify code. NFC (#1004)
1 parent 0ea8f8a commit 8230125

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

emsdk.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ def exit_with_error(msg):
8383
elif EMSDK_OS == 'macos':
8484
MACOS = True
8585
else:
86-
assert False
86+
assert False, 'EMSDK_OS must be one of: windows, linux, macos'
8787
else:
88-
if os.name == 'nt' or (os.getenv('SYSTEMROOT') is not None and 'windows' in os.getenv('SYSTEMROOT').lower()) or (os.getenv('COMSPEC') is not None and 'windows' in os.getenv('COMSPEC').lower()):
88+
if os.name == 'nt' or ('windows' in os.getenv('SYSTEMROOT', '').lower()) or ('windows' in os.getenv('COMSPEC', '').lower()):
8989
WINDOWS = True
9090

9191
if os.getenv('MSYSTEM'):
@@ -256,7 +256,9 @@ def is_exe(fpath):
256256

257257
def vswhere(version):
258258
try:
259-
program_files = os.environ['ProgramFiles(x86)'] if 'ProgramFiles(x86)' in os.environ else os.environ['ProgramFiles']
259+
program_files = os.environ.get('ProgramFiles(x86)')
260+
if not program_files:
261+
program_files = os.environ['ProgramFiles']
260262
vswhere_path = os.path.join(program_files, 'Microsoft Visual Studio', 'Installer', 'vswhere.exe')
261263
output = json.loads(subprocess.check_output([vswhere_path, '-latest', '-version', '[%s.0,%s.0)' % (version, version + 1), '-requires', 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64', '-property', 'installationPath', '-format', 'json']))
262264
# Visual Studio 2017 Express is not included in the above search, and it
@@ -291,7 +293,6 @@ def vs_filewhere(installation_path, platform, file):
291293
elif '--vs2019' in sys.argv:
292294
CMAKE_GENERATOR = 'Visual Studio 16'
293295
else:
294-
program_files = os.environ['ProgramFiles(x86)'] if 'ProgramFiles(x86)' in os.environ else os.environ['ProgramFiles']
295296
vs2019_exists = len(vswhere(16)) > 0
296297
vs2017_exists = len(vswhere(15)) > 0
297298
mingw_exists = which('mingw32-make') is not None and which('g++') is not None
@@ -566,7 +567,8 @@ def untargz(source_filename, dest_dir):
566567
def fix_potentially_long_windows_pathname(pathname):
567568
if not WINDOWS:
568569
return pathname
569-
# Test if emsdk calls fix_potentially_long_windows_pathname() with long relative paths (which is problematic)
570+
# Test if emsdk calls fix_potentially_long_windows_pathname() with long
571+
# relative paths (which is problematic)
570572
if not os.path.isabs(pathname) and len(pathname) > 200:
571573
errlog('Warning: Seeing a relative path "' + pathname + '" which is dangerously long for being referenced as a short Windows path name. Refactor emsdk to be able to handle this!')
572574
if pathname.startswith('\\\\?\\'):
@@ -1671,14 +1673,8 @@ def generate_dot_emscripten(active_tools):
16711673

16721674

16731675
def find_msbuild_dir():
1674-
if 'ProgramFiles' in os.environ and os.environ['ProgramFiles']:
1675-
program_files = os.environ['ProgramFiles']
1676-
else:
1677-
program_files = 'C:/Program Files'
1678-
if 'ProgramFiles(x86)' in os.environ and os.environ['ProgramFiles(x86)']:
1679-
program_files_x86 = os.environ['ProgramFiles(x86)']
1680-
else:
1681-
program_files_x86 = 'C:/Program Files (x86)'
1676+
program_files = os.environ.get('ProgramFiles', 'C:/Program Files')
1677+
program_files_x86 = os.environ.get('ProgramFiles(x86)', 'C:/Program Files (x86)')
16821678
MSBUILDX86_DIR = os.path.join(program_files_x86, "MSBuild/Microsoft.Cpp/v4.0/Platforms")
16831679
MSBUILD_DIR = os.path.join(program_files, "MSBuild/Microsoft.Cpp/v4.0/Platforms")
16841680
if os.path.exists(MSBUILDX86_DIR):

0 commit comments

Comments
 (0)