1111import shlex
1212import subprocess
1313import shutil
14+ import bz2
15+
1416from distutils .spawn import find_executable as which
1517
1618# If not run from node/, cd to node/.
409411intl_optgroup .add_option ('--with-intl' ,
410412 action = 'store' ,
411413 dest = 'with_intl' ,
412- default = 'small -icu' ,
414+ default = 'full -icu' ,
413415 choices = valid_intl_modes ,
414416 help = 'Intl mode (valid choices: {0}) [default: %default]' .format (
415417 ', ' .join (valid_intl_modes )))
@@ -1399,38 +1401,35 @@ def write_config(data, name):
13991401 icu_parent_path = 'deps'
14001402
14011403 # The full path to the ICU source directory. Should not include './'.
1402- icu_full_path = 'deps/icu'
1404+ icu_deps_path = 'deps/icu'
1405+ icu_full_path = icu_deps_path
14031406
14041407 # icu-tmp is used to download and unpack the ICU tarball.
14051408 icu_tmp_path = os .path .join (icu_parent_path , 'icu-tmp' )
14061409
14071410 # canned ICU. see tools/icu/README.md to update.
14081411 canned_icu_dir = 'deps/icu-small'
14091412
1413+ # use the README to verify what the canned ICU is
1414+ canned_is_full = os .path .isfile (os .path .join (canned_icu_dir , 'README-FULL-ICU.txt' ))
1415+ canned_is_small = os .path .isfile (os .path .join (canned_icu_dir , 'README-SMALL-ICU.txt' ))
1416+ if canned_is_small :
1417+ warn ('Ignoring %s - in-repo small icu is no longer supported.' % canned_icu_dir )
1418+
14101419 # We can use 'deps/icu-small' - pre-canned ICU *iff*
1411- # - with_intl == small-icu (the default!)
1412- # - with_icu_locales == 'root,en' (the default!)
1413- # - deps/icu-small exists!
1420+ # - canned_is_full AND
14141421 # - with_icu_source is unset (i.e. no other ICU was specified)
1415- # (Note that this is the *DEFAULT CASE*.)
14161422 #
14171423 # This is *roughly* equivalent to
1418- # $ configure --with-intl=small -icu --with-icu-source=deps/icu-small
1424+ # $ configure --with-intl=full -icu --with-icu-source=deps/icu-small
14191425 # .. Except that we avoid copying icu-small over to deps/icu.
14201426 # In this default case, deps/icu is ignored, although make clean will
14211427 # still harmlessly remove deps/icu.
14221428
1423- # are we using default locales?
1424- using_default_locales = ( options .with_icu_locales == icu_default_locales )
1425-
1426- # make sure the canned ICU really exists
1427- canned_icu_available = os .path .isdir (canned_icu_dir )
1428-
1429- if (o ['variables' ]['icu_small' ] == b (True )) and using_default_locales and (not with_icu_source ) and canned_icu_available :
1429+ if (not with_icu_source ) and canned_is_full :
14301430 # OK- we can use the canned ICU.
1431- icu_config ['variables' ]['icu_small_canned' ] = 1
14321431 icu_full_path = canned_icu_dir
1433-
1432+ icu_config [ 'variables' ][ 'icu_full_canned' ] = 1
14341433 # --with-icu-source processing
14351434 # now, check that they didn't pass --with-icu-source=deps/icu
14361435 elif with_icu_source and os .path .abspath (icu_full_path ) == os .path .abspath (with_icu_source ):
@@ -1508,29 +1507,40 @@ def write_config(data, name):
15081507 icu_endianness = sys .byteorder [0 ]
15091508 o ['variables' ]['icu_ver_major' ] = icu_ver_major
15101509 o ['variables' ]['icu_endianness' ] = icu_endianness
1511- icu_data_file_l = 'icudt%s%s.dat' % (icu_ver_major , 'l' )
1510+ icu_data_file_l = 'icudt%s%s.dat' % (icu_ver_major , 'l' ) # LE filename
15121511 icu_data_file = 'icudt%s%s.dat' % (icu_ver_major , icu_endianness )
15131512 # relative to configure
15141513 icu_data_path = os .path .join (icu_full_path ,
15151514 'source/data/in' ,
1516- icu_data_file_l )
1515+ icu_data_file_l ) # LE
1516+ compressed_data = '%s.bz2' % (icu_data_path )
1517+ if not os .path .isfile (icu_data_path ) and os .path .isfile (compressed_data ):
1518+ # unpack. deps/icu is a temporary path
1519+ if os .path .isdir (icu_tmp_path ):
1520+ shutil .rmtree (icu_tmp_path )
1521+ os .mkdir (icu_tmp_path )
1522+ icu_data_path = os .path .join (icu_tmp_path , icu_data_file_l )
1523+ with open (icu_data_path , 'wb' ) as outf :
1524+ with bz2 .BZ2File (compressed_data , 'rb' ) as inf :
1525+ shutil .copyfileobj (inf , outf )
1526+ # Now, proceed..
1527+
15171528 # relative to dep..
1518- icu_data_in = os .path .join ('..' ,'..' , icu_full_path , 'source/data/in' , icu_data_file_l )
1529+ icu_data_in = os .path .join ('..' ,'..' , icu_data_path )
15191530 if not os .path .isfile (icu_data_path ) and icu_endianness != 'l' :
15201531 # use host endianness
15211532 icu_data_path = os .path .join (icu_full_path ,
15221533 'source/data/in' ,
1523- icu_data_file )
1524- # relative to dep..
1525- icu_data_in = os .path .join ('..' , icu_full_path , 'source/data/in' ,
1526- icu_data_file )
1527- # this is the input '.dat' file to use .. icudt*.dat
1528- # may be little-endian if from a icu-project.org tarball
1529- o ['variables' ]['icu_data_in' ] = icu_data_in
1534+ icu_data_file ) # will be generated
15301535 if not os .path .isfile (icu_data_path ):
15311536 # .. and we're not about to build it from .gyp!
15321537 error ('''ICU prebuilt data file %s does not exist.
15331538 See the README.md.''' % icu_data_path )
1539+
1540+ # this is the input '.dat' file to use .. icudt*.dat
1541+ # may be little-endian if from a icu-project.org tarball
1542+ o ['variables' ]['icu_data_in' ] = icu_data_in
1543+
15341544 # map from variable name to subdirs
15351545 icu_src = {
15361546 'stubdata' : 'stubdata' ,
@@ -1547,6 +1557,31 @@ def write_config(data, name):
15471557 var = 'icu_src_%s' % i
15481558 path = '../../%s/source/%s' % (icu_full_path , icu_src [i ])
15491559 icu_config ['variables' ][var ] = glob_to_var ('tools/icu' , path , 'patches/%s/source/%s' % (icu_ver_major , icu_src [i ]) )
1560+ # calculate platform-specific genccode args
1561+ # print("platform %s, flavor %s" % (sys.platform, flavor))
1562+ # if sys.platform == 'darwin':
1563+ # shlib_suffix = '%s.dylib'
1564+ # elif sys.platform.startswith('aix'):
1565+ # shlib_suffix = '%s.a'
1566+ # else:
1567+ # shlib_suffix = 'so.%s'
1568+ if flavor == 'win' :
1569+ icu_config ['variables' ]['icu_asm_ext' ] = 'obj'
1570+ icu_config ['variables' ]['icu_asm_opts' ] = [ '-o ' ]
1571+ elif with_intl == 'small-icu' or options .cross_compiling :
1572+ icu_config ['variables' ]['icu_asm_ext' ] = 'c'
1573+ icu_config ['variables' ]['icu_asm_opts' ] = []
1574+ elif flavor == 'mac' :
1575+ icu_config ['variables' ]['icu_asm_ext' ] = 'S'
1576+ icu_config ['variables' ]['icu_asm_opts' ] = [ '-a' , 'gcc-darwin' ]
1577+ elif sys .platform .startswith ('aix' ):
1578+ icu_config ['variables' ]['icu_asm_ext' ] = 'S'
1579+ icu_config ['variables' ]['icu_asm_opts' ] = [ '-a' , 'xlc' ]
1580+ else :
1581+ # assume GCC-compatible asm is OK
1582+ icu_config ['variables' ]['icu_asm_ext' ] = 'S'
1583+ icu_config ['variables' ]['icu_asm_opts' ] = [ '-a' , 'gcc' ]
1584+
15501585 # write updated icu_config.gypi with a bunch of paths
15511586 write (icu_config_name , do_not_edit +
15521587 pprint .pformat (icu_config , indent = 2 ) + '\n ' )
0 commit comments