12
12
import shutil
13
13
import bz2
14
14
import io
15
+ from pathlib import Path
15
16
16
17
from distutils .version import StrictVersion
17
18
18
19
# If not run from node/, cd to node/.
19
- os .chdir (os . path . dirname (__file__ ) or '.' )
20
+ os .chdir (Path (__file__ ). parent )
20
21
21
22
original_argv = sys .argv [1 :]
22
23
25
26
CC = os .environ .get ('CC' , 'cc' if sys .platform == 'darwin' else 'gcc' )
26
27
CXX = os .environ .get ('CXX' , 'c++' if sys .platform == 'darwin' else 'g++' )
27
28
28
- sys .path .insert (0 , os .path .join ('tools' , 'gyp' , 'pylib' ))
29
+ tools_path = Path ('tools' )
30
+
31
+ sys .path .insert (0 , str (tools_path / 'gyp' / 'pylib' ))
29
32
from gyp .common import GetFlavor
30
33
31
34
# imports in tools/configure.d
32
- sys .path .insert (0 , os . path . join ( 'tools' , 'configure.d' ))
35
+ sys .path .insert (0 , str ( tools_path / 'configure.d' ))
33
36
import nodedownload
34
37
35
38
# imports in tools/
53
56
valid_mips_fpu = ('fp32' , 'fp64' , 'fpxx' )
54
57
valid_mips_float_abi = ('soft' , 'hard' )
55
58
valid_intl_modes = ('none' , 'small-icu' , 'full-icu' , 'system-icu' )
56
- with open ('tools/icu/icu_versions.json' ) as f :
57
- icu_versions = json .load (f )
59
+ icu_versions = json .loads ((tools_path / 'icu' / 'icu_versions.json' ).read_text (encoding = 'utf-8' ))
58
60
59
61
shareable_builtins = {'cjs_module_lexer/lexer' : 'deps/cjs-module-lexer/lexer.js' ,
60
62
'cjs_module_lexer/dist/lexer' : 'deps/cjs-module-lexer/dist/lexer.js' ,
845
847
(options , args ) = parser .parse_known_args ()
846
848
847
849
# Expand ~ in the install prefix now, it gets written to multiple files.
848
- options .prefix = os . path . expanduser ( options .prefix or '' )
850
+ options .prefix = str ( Path ( options .prefix or '' ). expanduser () )
849
851
850
852
# set up auto-download list
851
853
auto_downloads = nodedownload .parse (options .download_list )
@@ -1207,7 +1209,7 @@ def configure_zos(o):
1207
1209
o ['variables' ]['node_static_zoslib' ] = b (True )
1208
1210
if options .static_zoslib_gyp :
1209
1211
# Apply to all Node.js components for now
1210
- o ['variables' ]['zoslib_include_dir' ] = os . path . dirname (options .static_zoslib_gyp ) + '/include'
1212
+ o ['variables' ]['zoslib_include_dir' ] = Path (options .static_zoslib_gyp ). parent + '/include'
1211
1213
o ['include_dirs' ] += [o ['variables' ]['zoslib_include_dir' ]]
1212
1214
else :
1213
1215
raise Exception ('--static-zoslib-gyp=<path to zoslib.gyp file> is required.' )
@@ -1609,7 +1611,7 @@ def configure_static(o):
1609
1611
1610
1612
def write (filename , data ):
1611
1613
print_verbose ('creating %s' % filename )
1612
- with open (filename , 'w+' ) as f :
1614
+ with Path (filename ). open ( mode = 'w+' , encoding = 'utf-8 ' ) as f :
1613
1615
f .write (data )
1614
1616
1615
1617
do_not_edit = '# Do not edit. Generated by the configure script.\n '
@@ -1625,8 +1627,8 @@ def glob_to_var(dir_base, dir_sub, patch_dir):
1625
1627
# srcfile uses "slash" as dir separator as its output is consumed by gyp
1626
1628
srcfile = '%s/%s' % (dir_sub , file )
1627
1629
if patch_dir :
1628
- patchfile = '%s/%s/%s' % (dir_base , patch_dir , file )
1629
- if os . path . isfile ( patchfile ):
1630
+ patchfile = Path (dir_base , patch_dir , file )
1631
+ if patchfile . is_file ( ):
1630
1632
srcfile = '%s/%s' % (patch_dir , file )
1631
1633
info ('Using floating patch "%s" from "%s"' % (patchfile , dir_base ))
1632
1634
list .append (srcfile )
@@ -1635,9 +1637,8 @@ def glob_to_var(dir_base, dir_sub, patch_dir):
1635
1637
1636
1638
def configure_intl (o ):
1637
1639
def icu_download (path ):
1638
- depFile = 'tools/icu/current_ver.dep'
1639
- with open (depFile ) as f :
1640
- icus = json .load (f )
1640
+ depFile = tools_path / 'icu' / 'current_ver.dep'
1641
+ icus = json .loads (depFile .read_text (encoding = 'utf-8' ))
1641
1642
# download ICU, if needed
1642
1643
if not os .access (options .download_path , os .W_OK ):
1643
1644
error ('''Cannot write to desired download path.
@@ -1652,13 +1653,13 @@ def icu_download(path):
1652
1653
For the entry %s,
1653
1654
Expected one of these keys: %s''' % (depFile , url , ' ' .join (allAlgos )))
1654
1655
local = url .split ('/' )[- 1 ]
1655
- targetfile = os . path . join (options .download_path , local )
1656
- if not os . path . isfile ( targetfile ):
1656
+ targetfile = Path (options .download_path , local )
1657
+ if not targetfile . is_file ( ):
1657
1658
if attemptdownload :
1658
1659
nodedownload .retrievefile (url , targetfile )
1659
1660
else :
1660
1661
print ('Re-using existing %s' % targetfile )
1661
- if os . path . isfile ( targetfile ):
1662
+ if targetfile . is_file ( ):
1662
1663
print ('Checking file integrity with %s:\r ' % hashAlgo )
1663
1664
gotHash = nodedownload .checkHash (targetfile , hashAlgo )
1664
1665
print ('%s: %s %s' % (hashAlgo , gotHash , targetfile ))
@@ -1744,14 +1745,15 @@ def icu_download(path):
1744
1745
icu_full_path = icu_deps_path
1745
1746
1746
1747
# icu-tmp is used to download and unpack the ICU tarball.
1747
- icu_tmp_path = os . path . join (icu_parent_path , 'icu-tmp' )
1748
+ icu_tmp_path = Path (icu_parent_path , 'icu-tmp' )
1748
1749
1749
1750
# canned ICU. see tools/icu/README.md to update.
1750
1751
canned_icu_dir = 'deps/icu-small'
1751
1752
1752
1753
# use the README to verify what the canned ICU is
1753
- canned_is_full = os .path .isfile (os .path .join (canned_icu_dir , 'README-FULL-ICU.txt' ))
1754
- canned_is_small = os .path .isfile (os .path .join (canned_icu_dir , 'README-SMALL-ICU.txt' ))
1754
+ canned_icu_path = Path (canned_icu_dir )
1755
+ canned_is_full = (canned_icu_path / 'README-FULL-ICU.txt' ).is_file ()
1756
+ canned_is_small = (canned_icu_path / 'README-SMALL-ICU.txt' ).is_file ()
1755
1757
if canned_is_small :
1756
1758
warn ('Ignoring %s - in-repo small icu is no longer supported.' % canned_icu_dir )
1757
1759
@@ -1771,39 +1773,39 @@ def icu_download(path):
1771
1773
icu_config ['variables' ]['icu_full_canned' ] = 1
1772
1774
# --with-icu-source processing
1773
1775
# now, check that they didn't pass --with-icu-source=deps/icu
1774
- elif with_icu_source and os . path . abspath (icu_full_path ) == os . path . abspath (with_icu_source ):
1776
+ elif with_icu_source and Path (icu_full_path ). resolve () == Path (with_icu_source ). resolve ( ):
1775
1777
warn ('Ignoring redundant --with-icu-source=%s' % with_icu_source )
1776
1778
with_icu_source = None
1777
1779
# if with_icu_source is still set, try to use it.
1778
1780
if with_icu_source :
1779
- if os . path . isdir (icu_full_path ):
1781
+ if Path (icu_full_path ). is_dir ( ):
1780
1782
print ('Deleting old ICU source: %s' % icu_full_path )
1781
1783
shutil .rmtree (icu_full_path )
1782
1784
# now, what path was given?
1783
- if os . path . isdir (with_icu_source ):
1785
+ if Path (with_icu_source ). is_dir ( ):
1784
1786
# it's a path. Copy it.
1785
1787
print ('%s -> %s' % (with_icu_source , icu_full_path ))
1786
1788
shutil .copytree (with_icu_source , icu_full_path )
1787
1789
else :
1788
1790
# could be file or URL.
1789
1791
# Set up temporary area
1790
- if os . path . isdir (icu_tmp_path ):
1792
+ if Path (icu_tmp_path ). is_dir ( ):
1791
1793
shutil .rmtree (icu_tmp_path )
1792
- os .mkdir (icu_tmp_path )
1794
+ icu_tmp_path .mkdir ()
1793
1795
icu_tarball = None
1794
- if os . path . isfile (with_icu_source ):
1796
+ if Path (with_icu_source ). is_file ( ):
1795
1797
# it's a file. Try to unpack it.
1796
1798
icu_tarball = with_icu_source
1797
1799
else :
1798
1800
# Can we download it?
1799
- local = os . path . join ( icu_tmp_path , with_icu_source .split ('/' )[- 1 ]) # local part
1801
+ local = icu_tmp_path / with_icu_source .split ('/' )[- 1 ] # local part
1800
1802
icu_tarball = nodedownload .retrievefile (with_icu_source , local )
1801
1803
# continue with "icu_tarball"
1802
1804
nodedownload .unpack (icu_tarball , icu_tmp_path )
1803
1805
# Did it unpack correctly? Should contain 'icu'
1804
- tmp_icu = os . path . join ( icu_tmp_path , 'icu' )
1805
- if os . path . isdir ( tmp_icu ):
1806
- os .rename (tmp_icu , icu_full_path )
1806
+ tmp_icu = icu_tmp_path / 'icu'
1807
+ if tmp_icu . is_dir ( ):
1808
+ tmp_icu .rename (icu_full_path )
1807
1809
shutil .rmtree (icu_tmp_path )
1808
1810
else :
1809
1811
shutil .rmtree (icu_tmp_path )
@@ -1814,22 +1816,22 @@ def icu_download(path):
1814
1816
o ['variables' ]['icu_gyp_path' ] = 'tools/icu/icu-generic.gyp'
1815
1817
# ICU source dir relative to tools/icu (for .gyp file)
1816
1818
o ['variables' ]['icu_path' ] = icu_full_path
1817
- if not os . path . isdir (icu_full_path ):
1819
+ if not Path (icu_full_path ). is_dir ( ):
1818
1820
# can we download (or find) a zipfile?
1819
1821
localzip = icu_download (icu_full_path )
1820
1822
if localzip :
1821
1823
nodedownload .unpack (localzip , icu_parent_path )
1822
1824
else :
1823
1825
warn ('* ECMA-402 (Intl) support didn\' t find ICU in %s..' % icu_full_path )
1824
- if not os . path . isdir (icu_full_path ):
1826
+ if not Path (icu_full_path ). is_dir ( ):
1825
1827
error ('''Cannot build Intl without ICU in %s.
1826
1828
Fix, or disable with "--with-intl=none"''' % icu_full_path )
1827
1829
else :
1828
1830
print_verbose ('* Using ICU in %s' % icu_full_path )
1829
1831
# Now, what version of ICU is it? We just need the "major", such as 54.
1830
1832
# uvernum.h contains it as a #define.
1831
- uvernum_h = os . path . join (icu_full_path , 'source/ common/ unicode/ uvernum.h' )
1832
- if not os . path . isfile ( uvernum_h ):
1833
+ uvernum_h = Path (icu_full_path , 'source' , ' common' , ' unicode' , ' uvernum.h' )
1834
+ if not uvernum_h . is_file ( ):
1833
1835
error ('Could not load %s - is ICU installed?' % uvernum_h )
1834
1836
icu_ver_major = None
1835
1837
matchVerExp = r'^\s*#define\s+U_ICU_VERSION_SHORT\s+"([^"]*)".*'
@@ -1850,17 +1852,15 @@ def icu_download(path):
1850
1852
icu_data_file_l = 'icudt%s%s.dat' % (icu_ver_major , 'l' ) # LE filename
1851
1853
icu_data_file = 'icudt%s%s.dat' % (icu_ver_major , icu_endianness )
1852
1854
# relative to configure
1853
- icu_data_path = os .path .join (icu_full_path ,
1854
- 'source/data/in' ,
1855
- icu_data_file_l ) # LE
1855
+ icu_data_path = Path (icu_full_path , 'source' , 'data' , 'in' , icu_data_file_l ) # LE
1856
1856
compressed_data = '%s.bz2' % (icu_data_path )
1857
- if not os . path . isfile ( icu_data_path ) and os . path . isfile (compressed_data ):
1857
+ if not icu_data_path . is_file ( ) and Path (compressed_data ). is_file ( ):
1858
1858
# unpack. deps/icu is a temporary path
1859
- if os . path . isdir ( icu_tmp_path ):
1859
+ if icu_tmp_path . is_dir ( ):
1860
1860
shutil .rmtree (icu_tmp_path )
1861
- os .mkdir (icu_tmp_path )
1862
- icu_data_path = os . path . join ( icu_tmp_path , icu_data_file_l )
1863
- with open (icu_data_path , 'wb' ) as outf :
1861
+ icu_tmp_path .mkdir ()
1862
+ icu_data_path = icu_tmp_path / icu_data_file_l
1863
+ with icu_data_path . open (mode = 'wb' ) as outf :
1864
1864
inf = bz2 .BZ2File (compressed_data , 'rb' )
1865
1865
try :
1866
1866
shutil .copyfileobj (inf , outf )
@@ -1869,20 +1869,18 @@ def icu_download(path):
1869
1869
# Now, proceed..
1870
1870
1871
1871
# relative to dep..
1872
- icu_data_in = os . path . join ('..' ,'..' , icu_data_path )
1873
- if not os . path . isfile ( icu_data_path ) and icu_endianness != 'l' :
1872
+ icu_data_in = Path ('..' , '..' , icu_data_path )
1873
+ if not icu_data_path . is_file ( ) and icu_endianness != 'l' :
1874
1874
# use host endianness
1875
- icu_data_path = os .path .join (icu_full_path ,
1876
- 'source/data/in' ,
1877
- icu_data_file ) # will be generated
1878
- if not os .path .isfile (icu_data_path ):
1875
+ icu_data_path = Path (icu_full_path , 'source' , 'data' , 'in' , icu_data_file ) # will be generated
1876
+ if not icu_data_path .is_file ():
1879
1877
# .. and we're not about to build it from .gyp!
1880
1878
error ('''ICU prebuilt data file %s does not exist.
1881
1879
See the README.md.''' % icu_data_path )
1882
1880
1883
1881
# this is the input '.dat' file to use .. icudt*.dat
1884
1882
# may be little-endian if from a icu-project.org tarball
1885
- o ['variables' ]['icu_data_in' ] = icu_data_in
1883
+ o ['variables' ]['icu_data_in' ] = str ( icu_data_in )
1886
1884
1887
1885
# map from variable name to subdirs
1888
1886
icu_src = {
@@ -1979,15 +1977,15 @@ def make_bin_override():
1979
1977
os .path .realpath (which_python ) == os .path .realpath (sys .executable )):
1980
1978
return
1981
1979
1982
- bin_override = os . path . abspath ('out/ tools/ bin' )
1980
+ bin_override = Path ('out' , ' tools' , ' bin'). resolve ( )
1983
1981
try :
1984
- os . makedirs ( bin_override )
1982
+ bin_override . mkdir ( parents = True )
1985
1983
except OSError as e :
1986
1984
if e .errno != errno .EEXIST : raise e
1987
1985
1988
- python_link = os . path . join ( bin_override , 'python' )
1986
+ python_link = bin_override / 'python'
1989
1987
try :
1990
- os .unlink (python_link )
1988
+ python_link .unlink ()
1991
1989
except OSError as e :
1992
1990
if e .errno != errno .ENOENT : raise e
1993
1991
os .symlink (sys .executable , python_link )
@@ -2074,7 +2072,7 @@ def make_bin_override():
2074
2072
2075
2073
write ('config.status' , '#!/bin/sh\n set -x\n exec ./configure ' +
2076
2074
' ' .join ([shlex .quote (arg ) for arg in original_argv ]) + '\n ' )
2077
- os . chmod ('config.status' , 0o775 )
2075
+ Path ('config.status' ). chmod ( 0o775 )
2078
2076
2079
2077
2080
2078
config = {
0 commit comments