@@ -1464,6 +1464,21 @@ def load_em_config():
1464
1464
pass
1465
1465
1466
1466
1467
+ def find_emscripten_root (active_tools ):
1468
+ """Find the currently active emscripten root.
1469
+
1470
+ If there is more than one tool that defines EMSCRIPTEN_ROOT (this
1471
+ should not happen under normal circumstances), assume the last one takes
1472
+ precedence.
1473
+ """
1474
+ root = None
1475
+ for tool in active_tools :
1476
+ config = tool .activated_config ()
1477
+ if 'EMSCRIPTEN_ROOT' in config :
1478
+ root = config ['EMSCRIPTEN_ROOT' ]
1479
+ return root
1480
+
1481
+
1467
1482
def generate_em_config (active_tools , permanently_activate , system ):
1468
1483
cfg = 'import os\n '
1469
1484
cfg += "emsdk_path = os.path.dirname(os.getenv('EM_CONFIG')).replace('\\ \\ ', '/')\n "
@@ -1484,10 +1499,17 @@ def generate_em_config(active_tools, permanently_activate, system):
1484
1499
for name , value in activated_config .items ():
1485
1500
cfg += name + " = '" + value + "'\n "
1486
1501
1487
- cfg += '''\
1488
- COMPILER_ENGINE = NODE_JS
1489
- JS_ENGINES = [NODE_JS]
1490
- '''
1502
+ emroot = find_emscripten_root (active_tools )
1503
+ if emroot :
1504
+ version = parse_emscripten_version (emroot )
1505
+ # Older emscripten versions of emscripten depend on certain config
1506
+ # keys that are no longer used.
1507
+ # See https://github.com/emscripten-core/emscripten/pull/9469
1508
+ if version < [1 , 38 , 46 ]:
1509
+ cfg += 'COMPILER_ENGINE = NODE_JS\n '
1510
+ # See https://github.com/emscripten-core/emscripten/pull/9542
1511
+ if version < [1 , 38 , 48 ]:
1512
+ cfg += 'JS_ENGINES = [NODE_JS]\n '
1491
1513
1492
1514
cfg = cfg .replace ("'" + EMSDK_PATH , "emsdk_path + '" )
1493
1515
@@ -2488,39 +2510,38 @@ def get_env_vars_to_add(tools_to_activate, system, user):
2488
2510
env_vars_to_add += [('EMSDK' , EMSDK_PATH )]
2489
2511
2490
2512
for tool in tools_to_activate :
2491
- config = tool .activated_config ()
2492
- if 'EMSCRIPTEN_ROOT' in config :
2493
- # For older emscripten versions that don't use an embedded cache by
2494
- # default we need to export EM_CACHE.
2495
- #
2496
- # Sadly, we can't put this in the config file since those older versions
2497
- # also didn't read the `CACHE` key from the config file:
2498
- #
2499
- # History:
2500
- # - 'CACHE' config started being honored in 1.39.16
2501
- # https://github.com/emscripten-core/emscripten/pull/11091
2502
- # - Default to embedded cache also started in 1.39.16
2503
- # https://github.com/emscripten-core/emscripten/pull/11126
2504
- # - Emscripten supports automatically locating the embedded
2505
- # config in 1.39.13:
2506
- # https://github.com/emscripten-core/emscripten/pull/10935
2507
- #
2508
- # Since setting EM_CACHE in the environment effects the entire machine
2509
- # we want to avoid this except when installing these older emscripten
2510
- # versions that really need it.
2511
- version = parse_emscripten_version (config ['EMSCRIPTEN_ROOT' ])
2512
- if version < [1 , 39 , 16 ]:
2513
- em_cache_dir = os .path .join (config ['EMSCRIPTEN_ROOT' ], 'cache' )
2514
- env_vars_to_add += [('EM_CACHE' , em_cache_dir )]
2515
- if version < [1 , 39 , 13 ]:
2516
- env_vars_to_add += [('EM_CONFIG' , os .path .normpath (EM_CONFIG_PATH ))]
2517
-
2518
- envs = tool .activated_environment ()
2519
- for env in envs :
2513
+ for env in tool .activated_environment ():
2520
2514
key , value = parse_key_value (env )
2521
2515
value = to_native_path (tool .expand_vars (value ))
2522
2516
env_vars_to_add += [(key , value )]
2523
2517
2518
+ emroot = find_emscripten_root (tools_to_activate )
2519
+ if emroot :
2520
+ # For older emscripten versions that don't use an embedded cache by
2521
+ # default we need to export EM_CACHE.
2522
+ #
2523
+ # Sadly, we can't put this in the config file since those older versions
2524
+ # also didn't read the `CACHE` key from the config file:
2525
+ #
2526
+ # History:
2527
+ # - 'CACHE' config started being honored in 1.39.16
2528
+ # https://github.com/emscripten-core/emscripten/pull/11091
2529
+ # - Default to embedded cache also started in 1.39.16
2530
+ # https://github.com/emscripten-core/emscripten/pull/11126
2531
+ # - Emscripten supports automatically locating the embedded
2532
+ # config in 1.39.13:
2533
+ # https://github.com/emscripten-core/emscripten/pull/10935
2534
+ #
2535
+ # Since setting EM_CACHE in the environment effects the entire machine
2536
+ # we want to avoid this except when installing these older emscripten
2537
+ # versions that really need it.
2538
+ version = parse_emscripten_version (emroot )
2539
+ if version < [1 , 39 , 16 ]:
2540
+ em_cache_dir = os .path .join (emroot , 'cache' )
2541
+ env_vars_to_add += [('EM_CACHE' , em_cache_dir )]
2542
+ if version < [1 , 39 , 13 ]:
2543
+ env_vars_to_add += [('EM_CONFIG' , os .path .normpath (EM_CONFIG_PATH ))]
2544
+
2524
2545
return env_vars_to_add
2525
2546
2526
2547
0 commit comments