@@ -6,13 +6,18 @@ import re
6
6
import shlex
7
7
import subprocess
8
8
import sys
9
+ import shutil
9
10
10
11
CC = os .environ .get ('CC' , 'cc' )
11
12
12
13
root_dir = os .path .dirname (__file__ )
13
14
sys .path .insert (0 , os .path .join (root_dir , 'tools' , 'gyp' , 'pylib' ))
14
15
from gyp .common import GetFlavor
15
16
17
+ # imports in tools/configure.d
18
+ sys .path .insert (0 , os .path .join (root_dir , 'tools' , 'configure.d' ))
19
+ import nodedownload
20
+
16
21
# parse our options
17
22
parser = optparse .OptionParser ()
18
23
@@ -712,6 +717,34 @@ def glob_to_var(dir_base, dir_sub):
712
717
return list
713
718
714
719
def configure_intl (o ):
720
+ icus = [
721
+ {
722
+ 'url' : 'http://download.icu-project.org/files/icu4c/54.1/icu4c-54_1-src.zip' ,
723
+ # from https://ssl.icu-project.org/files/icu4c/54.1/icu4c-src-54_1.md5:
724
+ 'md5' : '6b89d60e2f0e140898ae4d7f72323bca' ,
725
+ },
726
+ ]
727
+ def icu_download (path ):
728
+ # download ICU, if needed
729
+ for icu in icus :
730
+ url = icu ['url' ]
731
+ md5 = icu ['md5' ]
732
+ local = url .split ('/' )[- 1 ]
733
+ targetfile = os .path .join (root_dir , 'deps' , local )
734
+ if not os .path .isfile (targetfile ):
735
+ nodedownload .retrievefile (url , targetfile )
736
+ else :
737
+ print ' Re-using existing %s' % targetfile
738
+ if os .path .isfile (targetfile ):
739
+ sys .stdout .write (' Checking file integrity with MD5:\r ' )
740
+ gotmd5 = nodedownload .md5sum (targetfile )
741
+ print ' MD5: %s %s' % (gotmd5 , targetfile )
742
+ if (md5 == gotmd5 ):
743
+ return targetfile
744
+ else :
745
+ print ' Expected: %s *MISMATCH*' % md5
746
+ print '\n ** Corrupted ZIP? Delete %s to retry download.\n ' % targetfile
747
+ return None
715
748
icu_config = {
716
749
'variables' : {}
717
750
}
@@ -723,7 +756,6 @@ def configure_intl(o):
723
756
write (icu_config_name , do_not_edit +
724
757
pprint .pformat (icu_config , indent = 2 ) + '\n ' )
725
758
726
- # small ICU is off by default.
727
759
# always set icu_small, node.gyp depends on it being defined.
728
760
o ['variables' ]['icu_small' ] = b (False )
729
761
@@ -739,6 +771,8 @@ def configure_intl(o):
739
771
o ['variables' ]['icu_gyp_path' ] = options .with_icu_path
740
772
return
741
773
# --with-intl=<with_intl>
774
+ if with_intl is None :
775
+ with_intl = 'none' # The default mode of Intl
742
776
if with_intl == 'none' or with_intl is None :
743
777
o ['variables' ]['v8_enable_i18n_support' ] = 0
744
778
return # no Intl
@@ -769,20 +803,45 @@ def configure_intl(o):
769
803
# Note: non-ICU implementations could use other 'with_intl'
770
804
# values.
771
805
806
+ icu_parent_path = os .path .join (root_dir , 'deps' )
807
+ icu_full_path = os .path .join (icu_parent_path , 'icu' )
808
+ icu_small_path = os .path .join (icu_parent_path , 'icu-small' )
809
+ icu_small_tag = os .path .join (icu_full_path , 'is-small-icu.txt' )
810
+
811
+ ## Use (or not) an embedded small-icu.
812
+ if with_intl == 'small-icu' :
813
+ if not os .path .isdir (icu_full_path ) and os .path .isdir (icu_small_path ):
814
+ # deps/small-icu -> deps/icu
815
+ print 'Copying small ICU %s to %s' % (icu_small_path , icu_full_path )
816
+ shutil .copytree (icu_small_path , icu_full_path )
817
+ #else:
818
+ # print 'Not copying %s to %s' % (icu_small_path, icu_full_path)
819
+ elif os .path .isfile (icu_small_tag ):
820
+ print 'deleting small-icu %s for --with-intl=%s' % (icu_full_path , with_intl )
821
+ shutil .rmtree (icu_full_path )
822
+
772
823
# ICU mode. (icu-generic.gyp)
773
824
byteorder = sys .byteorder
774
825
o ['variables' ]['icu_gyp_path' ] = 'tools/icu/icu-generic.gyp'
775
826
# ICU source dir relative to root
776
- icu_full_path = os .path .join (root_dir , 'deps/icu' )
777
827
o ['variables' ]['icu_path' ] = icu_full_path
778
828
if not os .path .isdir (icu_full_path ):
779
- print 'Error: ICU path is not a directory: %s' % (icu_full_path )
829
+ print '* ECMA-402 (Intl) support didn\' t find ICU in %s..' % (icu_full_path )
830
+ # can we download (or find) a zipfile?
831
+ localzip = icu_download (icu_full_path )
832
+ if localzip :
833
+ nodedownload .unpack (localzip , icu_parent_path )
834
+ if not os .path .isdir (icu_full_path ):
835
+ print ' Cannot build Intl without ICU in %s.' % (icu_full_path )
836
+ print ' (Fix, or disable with "--with-intl=none" )'
780
837
sys .exit (1 )
838
+ else :
839
+ print '* Using ICU in %s' % (icu_full_path )
781
840
# Now, what version of ICU is it? We just need the "major", such as 54.
782
841
# uvernum.h contains it as a #define.
783
842
uvernum_h = os .path .join (icu_full_path , 'source/common/unicode/uvernum.h' )
784
843
if not os .path .isfile (uvernum_h ):
785
- print 'Error: could not load %s - is ICU installed?' % uvernum_h
844
+ print ' Error: could not load %s - is ICU installed?' % uvernum_h
786
845
sys .exit (1 )
787
846
icu_ver_major = None
788
847
matchVerExp = r'^\s*#define\s+U_ICU_VERSION_SHORT\s+"([^"]*)".*'
@@ -792,7 +851,7 @@ def configure_intl(o):
792
851
if m :
793
852
icu_ver_major = m .group (1 )
794
853
if not icu_ver_major :
795
- print 'Could not read U_ICU_VERSION_SHORT version from %s' % uvernum_h
854
+ print ' Could not read U_ICU_VERSION_SHORT version from %s' % uvernum_h
796
855
sys .exit (1 )
797
856
icu_endianness = sys .byteorder [0 ]; # TODO(srl295): EBCDIC should be 'e'
798
857
o ['variables' ]['icu_ver_major' ] = icu_ver_major
@@ -819,8 +878,8 @@ def configure_intl(o):
819
878
# this is the icudt*.dat file which node will be using (platform endianness)
820
879
o ['variables' ]['icu_data_file' ] = icu_data_file
821
880
if not os .path .isfile (icu_data_path ):
822
- print 'Error: ICU prebuilt data file %s does not exist.' % icu_data_path
823
- print 'See the README.md.'
881
+ print ' Error: ICU prebuilt data file %s does not exist.' % icu_data_path
882
+ print ' See the README.md.'
824
883
# .. and we're not about to build it from .gyp!
825
884
sys .exit (1 )
826
885
# map from variable name to subdirs
0 commit comments