@@ -191,15 +191,13 @@ def to_unix_path(p):
191
191
return p .replace ('\\ ' , '/' )
192
192
193
193
194
- def emsdk_path ():
195
- return to_unix_path (os .path .dirname (os .path .realpath (__file__ )))
196
-
194
+ EMSDK_PATH = to_unix_path (os .path .dirname (os .path .realpath (__file__ )))
197
195
198
196
EMSDK_SET_ENV = ""
199
197
if POWERSHELL :
200
- EMSDK_SET_ENV = os .path .join (emsdk_path () , 'emsdk_set_env.ps1' )
198
+ EMSDK_SET_ENV = os .path .join (EMSDK_PATH , 'emsdk_set_env.ps1' )
201
199
else :
202
- EMSDK_SET_ENV = os .path .join (emsdk_path () , 'emsdk_set_env.bat' )
200
+ EMSDK_SET_ENV = os .path .join (EMSDK_PATH , 'emsdk_set_env.bat' )
203
201
204
202
205
203
# Parses https://github.com/emscripten-core/emscripten/tree/d6aced8 to a pair (https://github.com/emscripten-core/emscripten, d6aced8)
@@ -486,7 +484,7 @@ def sdk_path(path):
486
484
if os .path .isabs (path ):
487
485
return path
488
486
489
- return to_unix_path (os .path .join (emsdk_path () , path ))
487
+ return to_unix_path (os .path .join (EMSDK_PATH , path ))
490
488
491
489
492
490
# Removes a single file, suppressing exceptions on failure.
@@ -1615,7 +1613,7 @@ def to_native_path(p):
1615
1613
# Finds and returns a list of the directories that need to be added to PATH for
1616
1614
# the given set of tools.
1617
1615
def get_required_path (active_tools ):
1618
- path_add = [to_native_path (emsdk_path () )]
1616
+ path_add = [to_native_path (EMSDK_PATH )]
1619
1617
for tool in active_tools :
1620
1618
if hasattr (tool , 'activated_path' ):
1621
1619
path = to_native_path (tool .expand_vars (tool .activated_path ))
@@ -1625,11 +1623,8 @@ def get_required_path(active_tools):
1625
1623
1626
1624
# Returns the absolute path to the file '.emscripten' for the current user on
1627
1625
# this system.
1628
- def dot_emscripten_path ():
1629
- return os .path .join (emsdk_path (), ".emscripten" )
1630
-
1631
-
1632
- dot_emscripten = {}
1626
+ EM_CONFIG_PATH = os .path .join (EMSDK_PATH , ".emscripten" )
1627
+ EM_CONFIG_DICT = {}
1633
1628
1634
1629
1635
1630
def parse_key_value (line ):
@@ -1644,23 +1639,23 @@ def parse_key_value(line):
1644
1639
return (key , '' )
1645
1640
1646
1641
1647
- def load_dot_emscripten ():
1648
- dot_emscripten .clear ()
1642
+ def load_em_config ():
1643
+ EM_CONFIG_DICT .clear ()
1649
1644
lines = []
1650
1645
try :
1651
- lines = open (dot_emscripten_path () , "r" ).read ().split ('\n ' )
1646
+ lines = open (EM_CONFIG_PATH , "r" ).read ().split ('\n ' )
1652
1647
except :
1653
1648
pass
1654
1649
for line in lines :
1655
1650
try :
1656
1651
key , value = parse_key_value (line )
1657
1652
if value != '' :
1658
- dot_emscripten [key ] = value
1653
+ EM_CONFIG_DICT [key ] = value
1659
1654
except :
1660
1655
pass
1661
1656
1662
1657
1663
- def generate_dot_emscripten (active_tools ):
1658
+ def generate_em_config (active_tools ):
1664
1659
cfg = 'import os\n '
1665
1660
cfg += "emsdk_path = os.path.dirname(os.getenv('EM_CONFIG')).replace('\\ \\ ', '/')\n "
1666
1661
@@ -1685,17 +1680,17 @@ def generate_dot_emscripten(active_tools):
1685
1680
JS_ENGINES = [NODE_JS]
1686
1681
'''
1687
1682
1688
- cfg = cfg .replace ("'" + emsdk_path () , "emsdk_path + '" )
1683
+ cfg = cfg .replace ("'" + EMSDK_PATH , "emsdk_path + '" )
1689
1684
1690
- if os .path .exists (dot_emscripten_path () ):
1691
- backup_path = dot_emscripten_path () + ".old"
1692
- move_with_overwrite (dot_emscripten_path () , backup_path )
1685
+ if os .path .exists (EM_CONFIG_PATH ):
1686
+ backup_path = EM_CONFIG_PATH + ".old"
1687
+ move_with_overwrite (EM_CONFIG_PATH , backup_path )
1693
1688
1694
- with open (dot_emscripten_path () , "w" ) as text_file :
1689
+ with open (EM_CONFIG_PATH , "w" ) as text_file :
1695
1690
text_file .write (cfg )
1696
1691
1697
1692
# Clear old emscripten content.
1698
- rmfile (os .path .join (emsdk_path () , ".emscripten_sanity" ))
1693
+ rmfile (os .path .join (EMSDK_PATH , ".emscripten_sanity" ))
1699
1694
1700
1695
path_add = get_required_path (active_tools )
1701
1696
if not WINDOWS :
@@ -1927,16 +1922,16 @@ def is_active(self):
1927
1922
return len (deps ) > 0
1928
1923
1929
1924
for key , value in activated_cfg .items ():
1930
- if key not in dot_emscripten :
1925
+ if key not in EM_CONFIG_DICT :
1931
1926
debug_print (str (self ) + ' is not active, because key="' + key + '" does not exist in .emscripten' )
1932
1927
return False
1933
1928
1934
1929
# all paths are stored dynamically relative to the emsdk root, so
1935
1930
# normalize those first.
1936
- dot_emscripten_key = dot_emscripten [key ].replace ("emsdk_path + '" , "'" + emsdk_path () )
1937
- dot_emscripten_key = dot_emscripten_key .strip ("'" )
1938
- if dot_emscripten_key != value :
1939
- debug_print (str (self ) + ' is not active, because key="' + key + '" has value "' + dot_emscripten_key + '" but should have value "' + value + '"' )
1931
+ config_value = EM_CONFIG_DICT [key ].replace ("emsdk_path + '" , "'" + EMSDK_PATH )
1932
+ config_value = config_value .strip ("'" )
1933
+ if config_value != value :
1934
+ debug_print (str (self ) + ' is not active, because key="' + key + '" has value "' + config_value + '" but should have value "' + value + '"' )
1940
1935
return False
1941
1936
return True
1942
1937
@@ -2013,7 +2008,7 @@ def install_sdk(self):
2013
2008
if getattr (self , 'custom_install_script' , None ) == 'emscripten_npm_install' :
2014
2009
# upstream tools have hardcoded paths that are not stored in emsdk_manifest.json registry
2015
2010
install_path = 'upstream' if 'releases-upstream' in self .version else 'fastcomp'
2016
- emscripten_dir = os .path .join (emsdk_path () , install_path , 'emscripten' )
2011
+ emscripten_dir = os .path .join (EMSDK_PATH , install_path , 'emscripten' )
2017
2012
# Older versions of the sdk did not include the node_modules directory
2018
2013
# and require `npm ci` to be run post-install
2019
2014
if not os .path .exists (os .path .join (emscripten_dir , 'node_modules' )):
@@ -2278,14 +2273,14 @@ def python_2_3_sorted(arr, cmp):
2278
2273
2279
2274
2280
2275
def is_emsdk_sourced_from_github ():
2281
- return os .path .exists (os .path .join (emsdk_path () , '.git' ))
2276
+ return os .path .exists (os .path .join (EMSDK_PATH , '.git' ))
2282
2277
2283
2278
2284
2279
def update_emsdk ():
2285
2280
if is_emsdk_sourced_from_github ():
2286
2281
errlog ('You seem to have bootstrapped Emscripten SDK by cloning from GitHub. In this case, use "git pull" instead of "emsdk update" to update emsdk. (Not doing that automatically in case you have local changes)' )
2287
2282
sys .exit (1 )
2288
- if not download_and_unzip (emsdk_zip_download_url , emsdk_path () , clobber = False ):
2283
+ if not download_and_unzip (emsdk_zip_download_url , EMSDK_PATH , clobber = False ):
2289
2284
sys .exit (1 )
2290
2285
2291
2286
@@ -2547,7 +2542,7 @@ def process_tool_list(tools_to_activate):
2547
2542
2548
2543
2549
2544
def write_set_env_script (env_string ):
2550
- assert ( CMD or POWERSHELL )
2545
+ assert CMD or POWERSHELL
2551
2546
open (EMSDK_SET_ENV , 'w' ).write (env_string )
2552
2547
2553
2548
@@ -2562,7 +2557,7 @@ def set_active_tools(tools_to_activate, permanently_activate, system):
2562
2557
print ('Setting the following tools as active:\n ' + '\n ' .join (map (lambda x : str (x ), tools )))
2563
2558
print ('' )
2564
2559
2565
- generate_dot_emscripten (tools_to_activate )
2560
+ generate_em_config (tools_to_activate )
2566
2561
2567
2562
# Construct a .bat or .ps1 script that will be invoked to set env. vars and PATH
2568
2563
# We only do this on cmd or powershell since emsdk.bat/ps1 is able to modify the
@@ -2630,12 +2625,11 @@ def adjusted_path(tools_to_activate, system=False, user=False):
2630
2625
existing_path = win_get_environment_variable ('PATH' , system = system , user = user , fallback = True ).split (ENVPATH_SEPARATOR )
2631
2626
else :
2632
2627
existing_path = os .environ ['PATH' ].split (ENVPATH_SEPARATOR )
2633
- emsdk_root_path = to_unix_path (emsdk_path ())
2634
2628
2635
2629
existing_emsdk_tools = []
2636
2630
existing_nonemsdk_path = []
2637
2631
for entry in existing_path :
2638
- if to_unix_path (entry ).startswith (emsdk_root_path ):
2632
+ if to_unix_path (entry ).startswith (EMSDK_PATH ):
2639
2633
existing_emsdk_tools .append (entry )
2640
2634
else :
2641
2635
existing_nonemsdk_path .append (entry )
@@ -2678,7 +2672,7 @@ def get_env_vars_to_add(tools_to_activate, system, user):
2678
2672
info ('' )
2679
2673
2680
2674
# A core variable EMSDK points to the root of Emscripten SDK directory.
2681
- env_vars_to_add += [('EMSDK' , to_unix_path ( emsdk_path ()) )]
2675
+ env_vars_to_add += [('EMSDK' , EMSDK_PATH )]
2682
2676
2683
2677
for tool in tools_to_activate :
2684
2678
config = tool .activated_config ()
@@ -2706,7 +2700,7 @@ def get_env_vars_to_add(tools_to_activate, system, user):
2706
2700
em_cache_dir = os .path .join (config ['EMSCRIPTEN_ROOT' ], 'cache' )
2707
2701
env_vars_to_add += [('EM_CACHE' , em_cache_dir )]
2708
2702
if version < [1 , 39 , 13 ]:
2709
- env_vars_to_add += [('EM_CONFIG' , os .path .normpath (dot_emscripten_path () ))]
2703
+ env_vars_to_add += [('EM_CONFIG' , os .path .normpath (EM_CONFIG_PATH ))]
2710
2704
2711
2705
envs = tool .activated_environment ()
2712
2706
for env in envs :
@@ -3020,7 +3014,7 @@ def extract_string_arg(name):
3020
3014
activating = cmd == 'activate'
3021
3015
args = [expand_sdk_name (a , activating = activating ) for a in args ]
3022
3016
3023
- load_dot_emscripten ()
3017
+ load_em_config ()
3024
3018
load_sdk_manifest ()
3025
3019
3026
3020
# Apply any overrides to git branch names to clone from.
0 commit comments