@@ -1477,6 +1477,77 @@ def find_emscripten_root(active_tools):
1477
1477
return root
1478
1478
1479
1479
1480
+ def fetch_nightly_node_versions ():
1481
+ url = "https://nodejs.org/download/nightly/"
1482
+ with urlopen (url ) as response :
1483
+ html = response .read ().decode ("utf-8" )
1484
+
1485
+ # Regex to capture href values like v7.0.0-nightly2016080175c6d9dd95/
1486
+ pattern = re .compile (r'<a href="(v[0-9]+\.[0-9]+\.[0-9]+-nightly[0-9a-f]+)/">' )
1487
+ matches = pattern .findall (html )
1488
+ return matches
1489
+
1490
+
1491
+ def dir_installed_nightly_node_versions ():
1492
+ path = os .path .abspath ('node' )
1493
+ return [name for name in os .listdir (path ) if os .path .isdir (os .path .join (path , name )) and name .startswith ("nightly-" )]
1494
+
1495
+
1496
+ def extract_newest_node_nightly_version (versions ):
1497
+ def parse (v ):
1498
+ # example: v7.0.0-nightly2016080175c6d9dd95
1499
+ m = re .match (r'v(\d+)\.(\d+)\.(\d+)-nightly(\d+)' , v )
1500
+ if m :
1501
+ major , minor , patch , nightly = m .groups ()
1502
+ return [int (major ), int (minor ), int (patch ), int (nightly )]
1503
+ else :
1504
+ return []
1505
+
1506
+ try :
1507
+ return max (versions , key = lambda v : parse (v ))
1508
+ except Exception :
1509
+ return None
1510
+
1511
+
1512
+ def download_node_nightly (tool ):
1513
+ nightly_versions = fetch_nightly_node_versions ()
1514
+ latest_nightly = extract_newest_node_nightly_version (nightly_versions )
1515
+ print ('Latest Node.js Nightly download available is "' + latest_nightly + '"' )
1516
+
1517
+ output_dir = os .path .abspath ('node/nightly-' + latest_nightly )
1518
+ # Node.js zip structure quirk: Linux and macOS archives have a /bin,
1519
+ # Windows does not. Unify the file structures.
1520
+ if WINDOWS :
1521
+ output_dir += '/bin'
1522
+
1523
+ if os .path .isdir (output_dir ):
1524
+ return True
1525
+
1526
+ url = tool .url .replace ('%version%' , latest_nightly )
1527
+ if WINDOWS :
1528
+ os_ = 'win'
1529
+ elif LINUX :
1530
+ os_ = 'linux'
1531
+ elif MACOS :
1532
+ os_ = 'darwin'
1533
+ else :
1534
+ os_ = ''
1535
+ if platform .machine ().lower () in ["x86_64" , "amd64" ]:
1536
+ arch = 'x64'
1537
+ elif platform .machine ().lower () in ["arm64" , "aarch64" ]:
1538
+ arch = 'arm64'
1539
+ if WINDOWS :
1540
+ zip_suffix = 'zip'
1541
+ else :
1542
+ zip_suffix = 'tar.gz'
1543
+ url = url .replace ('%os%' , os_ )
1544
+ url = url .replace ('%arch%' , arch )
1545
+ url = url .replace ('%zip_suffix%' , zip_suffix )
1546
+ download_and_extract (url , output_dir )
1547
+ open (tool .get_version_file_path (), 'w' ).write ('node-nightly-64bit' )
1548
+ return True
1549
+
1550
+
1480
1551
# returns a tuple (string,string) of config files paths that need to used
1481
1552
# to activate emsdk env depending on $SHELL, defaults to bash.
1482
1553
def get_emsdk_shell_env_configs ():
@@ -1511,7 +1582,10 @@ def generate_em_config(active_tools, permanently_activate, system):
1511
1582
activated_config ['NODE_JS' ] = node_fallback
1512
1583
1513
1584
for name , value in activated_config .items ():
1514
- cfg += name + " = '" + value + "'\n "
1585
+ if value .startswith ('[' ):
1586
+ cfg += name + " = " + value + "\n "
1587
+ else :
1588
+ cfg += name + " = '" + value + "'\n "
1515
1589
1516
1590
emroot = find_emscripten_root (active_tools )
1517
1591
if emroot :
@@ -1606,6 +1680,11 @@ def expand_vars(self, str):
1606
1680
str = str .replace ('%.exe%' , '.exe' if WINDOWS else '' )
1607
1681
if '%llvm_build_bin_dir%' in str :
1608
1682
str = str .replace ('%llvm_build_bin_dir%' , llvm_build_bin_dir (self ))
1683
+ if '%latest_downloaded_node_nightly_dir%' in str :
1684
+ installed_node_nightlys = dir_installed_nightly_node_versions ()
1685
+ latest_node_nightly = extract_newest_node_nightly_version (installed_node_nightlys )
1686
+ if latest_node_nightly :
1687
+ str = str .replace ('%latest_downloaded_node_nightly_dir%' , latest_node_nightly )
1609
1688
1610
1689
return str
1611
1690
@@ -1727,10 +1806,11 @@ def is_installed(self, skip_version_check=False):
1727
1806
return False
1728
1807
1729
1808
if self .download_url () is None :
1730
- # This tool does not contain downloadable elements , so it is installed by default.
1809
+ debug_print ( str ( self ) + ' has no files to download , so is installed by default.' )
1731
1810
return True
1732
1811
1733
1812
content_exists = is_nonempty_directory (self .installation_path ())
1813
+ debug_print (str (self ) + ' installation path is ' + self .installation_path () + ', exists: ' + str (content_exists ) + '.' )
1734
1814
1735
1815
# For e.g. fastcomp clang from git repo, the activated PATH is the
1736
1816
# directory where the compiler is built to, and installation_path is
@@ -1876,12 +1956,14 @@ def install_tool(self):
1876
1956
print ("Installing tool '" + str (self ) + "'.." )
1877
1957
url = self .download_url ()
1878
1958
1879
- if hasattr (self , 'custom_install_script' ) and self .custom_install_script == 'build_llvm' :
1880
- success = build_llvm (self )
1881
- elif hasattr (self , 'custom_install_script' ) and self .custom_install_script == 'build_ninja' :
1882
- success = build_ninja (self )
1883
- elif hasattr (self , 'custom_install_script' ) and self .custom_install_script == 'build_ccache' :
1884
- success = build_ccache (self )
1959
+ custom_install_scripts = {
1960
+ 'build_llvm' : build_llvm ,
1961
+ 'build_ninja' : build_ninja ,
1962
+ 'build_ccache' : build_ccache ,
1963
+ 'download_node_nightly' : download_node_nightly
1964
+ }
1965
+ if hasattr (self , 'custom_install_script' ) and self .custom_install_script in custom_install_scripts :
1966
+ success = custom_install_scripts [self .custom_install_script ](self )
1885
1967
elif hasattr (self , 'git_branch' ):
1886
1968
success = git_clone_checkout_and_pull (url , self .installation_path (), self .git_branch , getattr (self , 'remote_name' , 'origin' ))
1887
1969
elif url .endswith (ARCHIVE_SUFFIXES ):
@@ -1896,7 +1978,7 @@ def install_tool(self):
1896
1978
if hasattr (self , 'custom_install_script' ):
1897
1979
if self .custom_install_script == 'emscripten_npm_install' :
1898
1980
success = emscripten_npm_install (self , self .installation_path ())
1899
- elif self .custom_install_script in ('build_llvm' , 'build_ninja' , 'build_ccache' ):
1981
+ elif self .custom_install_script in ('build_llvm' , 'build_ninja' , 'build_ccache' , 'download_node_nightly' ):
1900
1982
# 'build_llvm' is a special one that does the download on its
1901
1983
# own, others do the download manually.
1902
1984
pass
0 commit comments