Skip to content

Commit 56824cb

Browse files
authored
Fix EMSDK_OS override. NFC (#1651)
It is sometimes useful when debugging to be able to things like install the windows binaries on linux using: ``` $ EMSDK_OS=windows ./emsdk install latest ``` Without these changes this zipfile extraction fails due to the use of `//?/` windows filename prefix.
1 parent c0bb220 commit 56824cb

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

emsdk.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ def exit_with_error(msg):
7777
MACOS = False
7878
LINUX = False
7979

80-
if 'EMSDK_OS' in os.environ:
81-
EMSDK_OS = os.environ['EMSDK_OS']
82-
if EMSDK_OS == 'windows':
80+
os_override = os.environ.get('EMSDK_OS')
81+
if os_override:
82+
if os_override == 'windows':
8383
WINDOWS = True
84-
elif EMSDK_OS == 'linux':
84+
elif os_override == 'linux':
8585
LINUX = True
86-
elif EMSDK_OS == 'macos':
86+
elif os_override == 'macos':
8787
MACOS = True
8888
else:
8989
assert False, 'EMSDK_OS must be one of: windows, linux, macos'
@@ -524,7 +524,7 @@ def untargz(source_filename, dest_dir):
524524
# See https://msdn.microsoft.com/en-us/library/aa365247.aspx#maxpath and http://stackoverflow.com/questions/3555527/python-win32-filename-length-workaround
525525
# In that mode, forward slashes cannot be used as delimiters.
526526
def fix_potentially_long_windows_pathname(pathname):
527-
if not WINDOWS or MSYS:
527+
if (not WINDOWS or MSYS) or os_override:
528528
return pathname
529529
# Test if emsdk calls fix_potentially_long_windows_pathname() with long
530530
# relative paths (which is problematic)
@@ -574,6 +574,7 @@ def unzip(source_filename, dest_dir):
574574

575575
unzip_to_dir = dest_dir
576576
if common_subdir:
577+
debug_print(f'common_subdir: {common_subdir}')
577578
unzip_to_dir = os.path.join(os.path.dirname(dest_dir), 'unzip_temp')
578579

579580
# Now do the actual decompress.
@@ -589,8 +590,7 @@ def unzip(source_filename, dest_dir):
589590
# Move the extracted file to its final location without the base
590591
# directory name, if we are stripping that away.
591592
if common_subdir:
592-
if not member.filename.startswith(common_subdir):
593-
raise Exception('Unexpected filename "' + member.filename + '"!')
593+
assert member.filename.startswith(common_subdir), f'unexpected filename {member.filename}'
594594
stripped_filename = '.' + member.filename[len(common_subdir):]
595595
final_dst_filename = os.path.join(dest_dir, stripped_filename)
596596
# Check if a directory
@@ -1598,7 +1598,7 @@ def try_download(url):
15981598

15991599

16001600
def to_native_path(p):
1601-
if WINDOWS and not MSYS:
1601+
if (WINDOWS and not MSYS) and not os_override:
16021602
return to_unix_path(p).replace('/', '\\')
16031603
else:
16041604
return to_unix_path(p)

0 commit comments

Comments
 (0)