@@ -32,10 +32,17 @@ binaryen_git_repo = 'https://github.com/WebAssembly/binaryen.git'
32
32
VERBOSE = bool (os .getenv ('EMSDK_VERBOSE' )) if os .getenv ('EMSDK_VERBOSE' ) != None else False
33
33
34
34
WINDOWS = False
35
- if os .name == 'nt' :
35
+ if os .name == 'nt' or 'WINDOWS' in os . getenv ( 'SYSTEMROOT' ) or 'WINDOWS' in os . getenv ( 'COMSPEC' ) :
36
36
WINDOWS = True
37
37
ENVPATH_SEPARATOR = ';'
38
38
39
+ MSYS = False
40
+ if os .getenv ('MSYSTEM' ):
41
+ if os .getenv ('MSYSTEM' ) == 'MSYS' :
42
+ MSYS = True
43
+ else :
44
+ print ('Warning: MSYSTEM environment variable is present, and is set to "' + os .getenv ('MSYSTEM' ) + '". This shell has not been tested with emsdk and may not work.' ) # https://stackoverflow.com/questions/37460073/msys-vs-mingw-internal-environment-variables
45
+
39
46
OSX = False
40
47
if platform .mac_ver ()[0 ] != '' :
41
48
OSX = True
@@ -73,7 +80,7 @@ emscripten_config_directory = os.path.expanduser("~/")
73
80
if os .path .exists (os .path .join (emsdk_path (), '.emscripten' )):
74
81
emscripten_config_directory = emsdk_path ()
75
82
76
- EMSDK_SET_ENV = 'emsdk_set_env.bat' if WINDOWS else 'emsdk_set_env.sh'
83
+ EMSDK_SET_ENV = 'emsdk_set_env.bat' if ( WINDOWS and not MSYS ) else 'emsdk_set_env.sh'
77
84
78
85
# Finds the given executable 'program' in PATH. Operates like the Unix tool 'which'.
79
86
def which (program ):
@@ -910,7 +917,7 @@ def download_and_unzip(zipfile, dest_dir, download_even_if_exists=False, filenam
910
917
return untargz (dst_file , dest_dir , unpack_even_if_exists = download_even_if_exists )
911
918
912
919
def to_native_path (p ):
913
- if WINDOWS :
920
+ if WINDOWS and not MSYS :
914
921
return to_unix_path (p ).replace ('/' , '\\ ' )
915
922
else :
916
923
return to_unix_path (p )
@@ -1208,11 +1215,14 @@ class Tool:
1208
1215
for cfg in activated_cfg :
1209
1216
cfg = cfg .strip ()
1210
1217
(key , value ) = parse_key_value (cfg )
1211
- if not key in dot_emscripten : return False
1218
+ if not key in dot_emscripten :
1219
+ if VERBOSE : print (str (self ) + ' is not active, because key="' + key + '" does not exist in .emscripten' )
1220
+ return False
1212
1221
1213
1222
# If running in embedded mode, all paths are stored dynamically relative to the emsdk root, so normalize those first.
1214
1223
dot_emscripten_key = dot_emscripten [key ].replace ("' + emsdk_path + '" , emsdk_path ())
1215
1224
if dot_emscripten_key != value :
1225
+ if VERBOSE : print (str (self ) + ' is not active, because key="' + key + '" has value "' + dot_emscripten_key + '" but should have value "' + value + '"' )
1216
1226
return False
1217
1227
return True
1218
1228
@@ -1221,6 +1231,7 @@ class Tool:
1221
1231
if hasattr (self , 'activated_env' ):
1222
1232
(key , value ) = parse_key_value (self .activated_environment ())
1223
1233
if not key in os .environ or to_unix_path (os .environ [key ]) != to_unix_path (value ):
1234
+ if VERBOSE : print (str (self ) + ' is not active, because environment variable key="' + key + '" has value "' + str (os .getenv (key )) + '" but should have value "' + value + '"' )
1224
1235
return False
1225
1236
# if WINDOWS:
1226
1237
# env_var = win_get_active_environment_variable(key)
@@ -1232,6 +1243,7 @@ class Tool:
1232
1243
for p in path :
1233
1244
path_items = os .environ ['PATH' ].replace ('\\ ' , '/' ).split (ENVPATH_SEPARATOR )
1234
1245
if not normalized_contains (path_items , p ):
1246
+ if VERBOSE : print (str (self ) + ' is not active, because environment variable PATH item "' + p + '" is not present (PATH=' + os .environ ['PATH' ] + ')' )
1235
1247
return False
1236
1248
return True
1237
1249
@@ -1808,13 +1820,20 @@ def normalized_contains(lst, elem):
1808
1820
return True
1809
1821
return False
1810
1822
1823
+ def to_msys_path (p ):
1824
+ p = to_unix_path (p )
1825
+ new_path = re .sub (r'([a-zA-Z]):/(.*)' , r'/\1/\2' , p )
1826
+ if len (new_path ) > 3 and new_path [0 ] == '/' and new_path [2 ] == '/' :
1827
+ new_path = new_path [0 ] + new_path [1 ].lower () + new_path [2 :]
1828
+ return new_path
1829
+
1811
1830
# Looks at the current PATH and adds and removes entries so that the PATH reflects
1812
1831
# the set of given active tools.
1813
1832
def adjusted_path (tools_to_activate , log_additions = False , system_path_only = False ):
1814
1833
# These directories should be added to PATH
1815
1834
path_add = get_required_path (tools_to_activate )
1816
1835
# These already exist.
1817
- if WINDOWS :
1836
+ if WINDOWS and not MSYS :
1818
1837
existing_path = win_get_environment_variable ('PATH' , system = True )
1819
1838
if not system_path_only :
1820
1839
current_user_path = win_get_environment_variable ('PATH' , system = False )
@@ -1830,17 +1849,24 @@ def adjusted_path(tools_to_activate, log_additions=False, system_path_only=False
1830
1849
elif (system_root + '\\ system32\\ wbem' ) in p .lower (): p = '%SystemRoot%\\ System32\\ Wbem'
1831
1850
elif (system_root + '\\ system32\\ windowspowershell\v 1.0' ) in p .lower (): p = '%SystemRoot%\\ System32\\ WindowsPowerShell\v 1.0\\ '
1832
1851
existing_path [i ] = p
1833
-
1834
1852
else :
1835
1853
existing_path = os .environ ['PATH' ].split (ENVPATH_SEPARATOR )
1836
1854
emsdk_root_path = to_unix_path (emsdk_path ())
1837
1855
1838
1856
existing_emsdk_tools = [item for item in existing_path if to_unix_path (item ).startswith (emsdk_root_path )]
1839
1857
new_emsdk_tools = [item for item in path_add if not normalized_contains (existing_emsdk_tools , item )]
1858
+
1840
1859
# Existing non-emsdk tools
1841
1860
existing_path = [item for item in existing_path if not to_unix_path (item ).startswith (emsdk_root_path )]
1842
1861
new_path = [item for item in path_add if not normalized_contains (existing_path , item )]
1843
- return (ENVPATH_SEPARATOR .join (unique_items (new_path + existing_path )), new_emsdk_tools )
1862
+ whole_path = unique_items (new_path + existing_path )
1863
+ if MSYS :
1864
+ # XXX Hack: If running native Windows Python in MSYS prompt where PATH entries look like "/c/Windows/System32", os.environ['PATH']
1865
+ # in Python will transform to show them as "C:\\Windows\\System32", so need to reconvert path delimiter back to forward slashes.
1866
+ whole_path = map (to_msys_path , whole_path )
1867
+ new_emsdk_tools = map (to_msys_path , new_emsdk_tools )
1868
+
1869
+ return ((':' if MSYS else ENVPATH_SEPARATOR ).join (whole_path ), new_emsdk_tools )
1844
1870
1845
1871
def construct_env (tools_to_activate , permanent ):
1846
1872
global emscripten_config_directory
@@ -1854,7 +1880,7 @@ def construct_env(tools_to_activate, permanent):
1854
1880
# else:
1855
1881
1856
1882
if os .environ ['PATH' ] != newpath : # Don't bother setting the path if there are no changes.
1857
- if WINDOWS : env_string += 'SET PATH=' + newpath + '\n '
1883
+ if WINDOWS and not MSYS : env_string += 'SET PATH=' + newpath + '\n '
1858
1884
else : env_string += 'export PATH="' + newpath + '"\n '
1859
1885
if len (added_path ) > 0 :
1860
1886
print ('Adding directories to PATH:' )
@@ -1886,7 +1912,7 @@ def construct_env(tools_to_activate, permanent):
1886
1912
if len (env_vars_to_add ) > 0 :
1887
1913
print ('Setting environment variables:' )
1888
1914
for key , value in env_vars_to_add :
1889
- if WINDOWS :
1915
+ if WINDOWS and not MSYS :
1890
1916
if permanent :
1891
1917
env_string += 'SETX ' + key + ' "' + value + '"\n '
1892
1918
else :
0 commit comments