Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Commit 957030f

Browse files
committed
Merge branch 'srl-v0.12-autoicu' of https://github.com/srl295/node into srl-v0.12-autoicu
Conflicts: configure
2 parents 8bce4eb + 8a33708 commit 957030f

File tree

2 files changed

+90
-12
lines changed

2 files changed

+90
-12
lines changed

README.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,41 @@ make doc
8383
man doc/node.1
8484
```
8585

86-
### To build `Intl` (ECMA-402) support:
86+
### `Intl` (ECMA-402) support:
8787

88-
*Note:* more docs, including how to reduce disk footprint, are on
88+
The `small-icu` mode is enabled by default. It will build
89+
with English-only data. You can add full data at runtime.
90+
91+
*Note:* more docs are on
8992
[the wiki](https://github.com/joyent/node/wiki/Intl).
9093

94+
#### Build with full ICU support (all locales supported by ICU):
95+
96+
Unix/Macintosh:
97+
98+
```sh
99+
./configure --with-intl=full-icu
100+
```
101+
102+
Windows:
103+
104+
```sh
105+
vcbuild full-icu
106+
```
107+
108+
#### Build with no Intl support `:-(`
109+
110+
```sh
111+
./configure --with-intl=none
112+
```
113+
91114
#### Use existing installed ICU (Unix/Macintosh only):
92115

93116
```sh
94117
pkg-config --modversion icu-i18n && ./configure --with-intl=system-icu
95118
```
96119

97-
#### Build ICU from source:
120+
#### Build with a specific ICU:
98121

99122
First: Unpack latest ICU
100123
[icu4c-**##.#**-src.tgz](http://icu-project.org/download) (or `.zip`)

configure

Lines changed: 64 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import subprocess
88
import sys
99
import urllib
1010
import zipfile
11+
import hashlib
1112

1213
CC = os.environ.get('CC', 'cc')
1314

@@ -250,7 +251,7 @@ parser.add_option('--with-icu-path',
250251
parser.add_option('--with-intl',
251252
action='store',
252253
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)')
254255

255256
parser.add_option('--with-perfctr',
256257
action='store_true',
@@ -758,6 +759,57 @@ def icu_download(path):
758759
return None
759760

760761
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>\nConnecting...\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
761813
icu_config = {
762814
'variables': {}
763815
}
@@ -786,7 +838,7 @@ def configure_intl(o):
786838
return
787839
# --with-intl=<with_intl>
788840
if with_intl is None:
789-
with_intl = 'none' # this is the default 'intl' mode.
841+
with_intl = 'small-icu' # The default mode
790842
if with_intl == 'none' or with_intl is None:
791843
o['variables']['v8_enable_i18n_support'] = 0
792844
return # no Intl
@@ -825,21 +877,24 @@ def configure_intl(o):
825877
icu_full_path = os.path.join(icu_parent_path, 'icu')
826878
o['variables']['icu_path'] = icu_full_path
827879
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)
829881
# can we download (or find) a zipfile?
830882
localzip = icu_download(icu_full_path)
831883
if localzip:
832884
with zipfile.ZipFile(localzip, 'r') as icuzip:
833-
print 'Extracting ICU source zip: %s' % localzip
885+
print ' Extracting ICU source zip: %s' % localzip
834886
icuzip.extractall(icu_parent_path)
835887
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" )'
837890
sys.exit(1)
891+
else:
892+
print '* Using ICU in %s' % (icu_full_path)
838893
# Now, what version of ICU is it? We just need the "major", such as 54.
839894
# uvernum.h contains it as a #define.
840895
uvernum_h = os.path.join(icu_full_path, 'source/common/unicode/uvernum.h')
841896
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
843898
sys.exit(1)
844899
icu_ver_major = None
845900
matchVerExp = r'^\s*#define\s+U_ICU_VERSION_SHORT\s+"([^"]*)".*'
@@ -849,7 +904,7 @@ def configure_intl(o):
849904
if m:
850905
icu_ver_major = m.group(1)
851906
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
853908
sys.exit(1)
854909
icu_endianness = sys.byteorder[0]; # TODO(srl295): EBCDIC should be 'e'
855910
o['variables']['icu_ver_major'] = icu_ver_major
@@ -876,8 +931,8 @@ def configure_intl(o):
876931
# this is the icudt*.dat file which node will be using (platform endianness)
877932
o['variables']['icu_data_file'] = icu_data_file
878933
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.'
881936
# .. and we're not about to build it from .gyp!
882937
sys.exit(1)
883938
# map from variable name to subdirs

0 commit comments

Comments
 (0)