@@ -8,6 +8,7 @@ import subprocess
8
8
import sys
9
9
import urllib
10
10
import zipfile
11
+ import hashlib
11
12
12
13
CC = os .environ .get ('CC' , 'cc' )
13
14
@@ -250,7 +251,7 @@ parser.add_option('--with-icu-path',
250
251
parser .add_option ('--with-intl' ,
251
252
action = 'store' ,
252
253
dest = 'with_intl' ,
253
- help = 'Intl mode: none, full-icu, small-icu (default is none )' )
254
+ help = 'Intl mode: none, full-icu, small-icu (default is small-icu )' )
254
255
255
256
parser .add_option ('--with-perfctr' ,
256
257
action = 'store_true' ,
@@ -758,6 +759,57 @@ def icu_download(path):
758
759
return None
759
760
760
761
def configure_intl (o ):
762
+ class ConfigOpener (urllib .FancyURLopener ):
763
+ # append to existing version (UA)
764
+ version = '%s (node.js/configure)' % urllib .URLopener .version
765
+ def icu_download (path ):
766
+ # download ICU, if needed
767
+ icus = [
768
+ {
769
+ 'url' : 'http://download.icu-project.org/files/icu4c/54.1/icu4c-54_1-src.zip' ,
770
+ # from https://ssl.icu-project.org/files/icu4c/54.1/icu4c-src-54_1.md5:
771
+ 'md5' : '6b89d60e2f0e140898ae4d7f72323bca' ,
772
+ },
773
+ ]
774
+ def fmtMb (amt ):
775
+ return "{:.1f}" .format (amt / 1024000. )
776
+ spin = "\\ |/-"
777
+ def reporthook (count , size , total ):
778
+ sys .stdout .write (' ICU: %c %sMB total, %sMB downloaded \r ' %
779
+ (spin [count % 4 ], fmtMb (total ), fmtMb (count * size )))
780
+ for icu in icus :
781
+ url = icu ['url' ]
782
+ md5 = icu ['md5' ]
783
+ local = url .split ('/' )[- 1 ]
784
+ targetfile = os .path .join (root_dir , 'deps' , local )
785
+ if not os .path .isfile (targetfile ):
786
+ try :
787
+ sys .stdout .write (' <%s>\n Connecting...\r ' % url )
788
+ sys .stdout .flush ()
789
+ msg = urllib .urlretrieve (url , targetfile , reporthook = reporthook )
790
+ print '' # clear the line
791
+ except :
792
+ print ' ** Error occurred while downloading\n <%s>' % url
793
+ raise
794
+ else :
795
+ print ' Re-using existing %s' % targetfile
796
+ if os .path .isfile (targetfile ):
797
+ digest = hashlib .md5 ()
798
+ count = 0
799
+ sys .stdout .write (' Checking file integrity with MD5:\r ' )
800
+ with open (targetfile , 'rb' ) as f :
801
+ chunk = f .read (1024 )
802
+ while chunk != "" :
803
+ digest .update (chunk )
804
+ chunk = f .read (1024 )
805
+ gotmd5 = digest .hexdigest ()
806
+ print ' MD5: %s %s' % (gotmd5 , targetfile )
807
+ if (md5 == gotmd5 ):
808
+ return targetfile
809
+ else :
810
+ print ' Expected: %s *MISMATCH*' % md5
811
+ print '\n ** Corrupted ZIP? Delete %s to retry download.\n ' % targetfile
812
+ return None
761
813
icu_config = {
762
814
'variables' : {}
763
815
}
@@ -786,7 +838,7 @@ def configure_intl(o):
786
838
return
787
839
# --with-intl=<with_intl>
788
840
if with_intl is None :
789
- with_intl = 'none ' # this is the default 'intl' mode.
841
+ with_intl = 'small-icu ' # The default mode
790
842
if with_intl == 'none' or with_intl is None :
791
843
o ['variables' ]['v8_enable_i18n_support' ] = 0
792
844
return # no Intl
@@ -825,21 +877,24 @@ def configure_intl(o):
825
877
icu_full_path = os .path .join (icu_parent_path , 'icu' )
826
878
o ['variables' ]['icu_path' ] = icu_full_path
827
879
if not os .path .isdir (icu_full_path ):
828
- print 'ECMA-402 (Intl) needs an ICU in %s' % (icu_full_path )
880
+ print '* ECMA-402 (Intl) support didn \' t find ICU in %s.. ' % (icu_full_path )
829
881
# can we download (or find) a zipfile?
830
882
localzip = icu_download (icu_full_path )
831
883
if localzip :
832
884
with zipfile .ZipFile (localzip , 'r' ) as icuzip :
833
- print 'Extracting ICU source zip: %s' % localzip
885
+ print ' Extracting ICU source zip: %s' % localzip
834
886
icuzip .extractall (icu_parent_path )
835
887
if not os .path .isdir (icu_full_path ):
836
- print 'Cannot continue without ICU in %s.' % (icu_full_path )
888
+ print ' Cannot build Intl without ICU in %s.' % (icu_full_path )
889
+ print ' (Fix, or disable with "--with-intl=none" )'
837
890
sys .exit (1 )
891
+ else :
892
+ print '* Using ICU in %s' % (icu_full_path )
838
893
# Now, what version of ICU is it? We just need the "major", such as 54.
839
894
# uvernum.h contains it as a #define.
840
895
uvernum_h = os .path .join (icu_full_path , 'source/common/unicode/uvernum.h' )
841
896
if not os .path .isfile (uvernum_h ):
842
- print 'Error: could not load %s - is ICU installed?' % uvernum_h
897
+ print ' Error: could not load %s - is ICU installed?' % uvernum_h
843
898
sys .exit (1 )
844
899
icu_ver_major = None
845
900
matchVerExp = r'^\s*#define\s+U_ICU_VERSION_SHORT\s+"([^"]*)".*'
@@ -849,7 +904,7 @@ def configure_intl(o):
849
904
if m :
850
905
icu_ver_major = m .group (1 )
851
906
if not icu_ver_major :
852
- print 'Could not read U_ICU_VERSION_SHORT version from %s' % uvernum_h
907
+ print ' Could not read U_ICU_VERSION_SHORT version from %s' % uvernum_h
853
908
sys .exit (1 )
854
909
icu_endianness = sys .byteorder [0 ]; # TODO(srl295): EBCDIC should be 'e'
855
910
o ['variables' ]['icu_ver_major' ] = icu_ver_major
@@ -876,8 +931,8 @@ def configure_intl(o):
876
931
# this is the icudt*.dat file which node will be using (platform endianness)
877
932
o ['variables' ]['icu_data_file' ] = icu_data_file
878
933
if not os .path .isfile (icu_data_path ):
879
- print 'Error: ICU prebuilt data file %s does not exist.' % icu_data_path
880
- print 'See the README.md.'
934
+ print ' Error: ICU prebuilt data file %s does not exist.' % icu_data_path
935
+ print ' See the README.md.'
881
936
# .. and we're not about to build it from .gyp!
882
937
sys .exit (1 )
883
938
# map from variable name to subdirs
0 commit comments