Skip to content

Commit dce6413

Browse files
srl295evanlucas
authored andcommitted
tools: Check in tools for shrinking ICU size, change default to small-icu
* Change configure default to "small-icu" (Intl on, English only) * add "--without-intl" and "vcbuild without-intl" options, equivalent to --with-intl=none * update BUILDING.md with above changes * Checks in tools that generate the deps/icu-small source directory from ICU source * Tools and process for updating ICU documented in tools/icu/README.md Fixes: #3476 PR-URL: #6088 Reviewed-By: James M Snell <[email protected]>
1 parent ee1e5a2 commit dce6413

File tree

6 files changed

+388
-110
lines changed

6 files changed

+388
-110
lines changed

BUILDING.md

+12-26
Original file line numberDiff line numberDiff line change
@@ -117,29 +117,14 @@ $ make
117117

118118
### `Intl` (ECMA-402) support:
119119

120-
[Intl](https://github.com/nodejs/node/wiki/Intl) support is not
121-
enabled by default.
120+
[Intl](https://github.com/nodejs/node/wiki/Intl) support is
121+
enabled by default, with English data only.
122122

123+
#### Default: `small-icu` (English only) support
123124

124-
#### "small" (English only) support
125-
126-
This option will build with "small" (English only) support, but
127-
the full `Intl` (ECMA-402) APIs. With `--download=all` it will
128-
download the ICU library as needed.
129-
130-
##### Unix / OS X:
131-
132-
```text
133-
$ ./configure --with-intl=small-icu --download=all
134-
```
135-
136-
##### Windows:
137-
138-
```text
139-
> vcbuild small-icu download-all
140-
```
141-
142-
The `small-icu` mode builds with English-only data. You can add full
125+
By default, only English data is included, but
126+
the full `Intl` (ECMA-402) APIs. It does not need to download
127+
any dependencies to function. You can add full
143128
data at runtime.
144129

145130
*Note:* more docs are on
@@ -148,7 +133,8 @@ data at runtime.
148133
#### Build with full ICU support (all locales supported by ICU):
149134

150135
With the `--download=all`, this may download ICU if you don't have an
151-
ICU in `deps/icu`.
136+
ICU in `deps/icu`. (The embedded `small-icu` included in the default
137+
Node.js source does not include all locales.)
152138

153139
##### Unix / OS X:
154140

@@ -164,19 +150,19 @@ $ ./configure --with-intl=full-icu --download=all
164150

165151
#### Building without Intl support
166152

167-
The `Intl` object will not be available. This is the default at
168-
present, so this option is not normally needed.
153+
The `Intl` object will not be available, nor some other APIs such as
154+
`String.normalize`.
169155

170156
##### Unix / OS X:
171157

172158
```text
173-
$ ./configure --with-intl=none
159+
$ ./configure --without-intl
174160
```
175161

176162
##### Windows:
177163

178164
```text
179-
> vcbuild intl-none
165+
> vcbuild without-intl
180166
```
181167

182168
#### Use existing installed ICU (Unix / OS X only):

configure

+47-11
Original file line numberDiff line numberDiff line change
@@ -303,20 +303,28 @@ parser.add_option('--with-etw',
303303
intl_optgroup.add_option('--with-intl',
304304
action='store',
305305
dest='with_intl',
306-
default='none',
306+
default='small-icu',
307307
choices=valid_intl_modes,
308308
help='Intl mode (valid choices: {0}) [default: %default]'.format(
309309
', '.join(valid_intl_modes)))
310310

311+
intl_optgroup.add_option('--without-intl',
312+
action='store_const',
313+
dest='with_intl',
314+
const='none',
315+
help='Disable Intl, same as --with-intl=none')
316+
311317
intl_optgroup.add_option('--with-icu-path',
312318
action='store',
313319
dest='with_icu_path',
314320
help='Path to icu.gyp (ICU i18n, Chromium version only.)')
315321

322+
icu_default_locales='root,en'
323+
316324
intl_optgroup.add_option('--with-icu-locales',
317325
action='store',
318326
dest='with_icu_locales',
319-
default='root,en',
327+
default=icu_default_locales,
320328
help='Comma-separated list of locales for "small-icu". "root" is assumed. '
321329
'[default: %default]')
322330

@@ -880,7 +888,7 @@ do_not_edit = '# Do not edit. Generated by the configure script.\n'
880888

881889
def glob_to_var(dir_base, dir_sub, patch_dir):
882890
list = []
883-
dir_all = os.path.join(dir_base, dir_sub)
891+
dir_all = '%s/%s' % (dir_base, dir_sub)
884892
files = os.walk(dir_all)
885893
for ent in files:
886894
(path, dirs, files) = ent
@@ -968,6 +976,7 @@ def configure_intl(o):
968976
locs = set(options.with_icu_locales.split(','))
969977
locs.add('root') # must have root
970978
o['variables']['icu_locales'] = string.join(locs,',')
979+
# We will check a bit later if we can use the canned deps/icu-small
971980
elif with_intl == 'full-icu':
972981
# full ICU
973982
o['variables']['v8_enable_i18n_support'] = 1
@@ -994,15 +1003,42 @@ def configure_intl(o):
9941003
# this is just the 'deps' dir. Used for unpacking.
9951004
icu_parent_path = os.path.join(root_dir, 'deps')
9961005

997-
# The full path to the ICU source directory.
998-
icu_full_path = os.path.join(icu_parent_path, 'icu')
1006+
# The full path to the ICU source directory. Should not include './'.
1007+
icu_full_path = 'deps/icu'
9991008

10001009
# icu-tmp is used to download and unpack the ICU tarball.
10011010
icu_tmp_path = os.path.join(icu_parent_path, 'icu-tmp')
10021011

1012+
# canned ICU. see tools/icu/README.md to update.
1013+
canned_icu_dir = 'deps/icu-small'
1014+
1015+
# We can use 'deps/icu-small' - pre-canned ICU *iff*
1016+
# - with_intl == small-icu (the default!)
1017+
# - with_icu_locales == 'root,en' (the default!)
1018+
# - deps/icu-small exists!
1019+
# - with_icu_source is unset (i.e. no other ICU was specified)
1020+
# (Note that this is the *DEFAULT CASE*.)
1021+
#
1022+
# This is *roughly* equivalent to
1023+
# $ configure --with-intl=small-icu --with-icu-source=deps/icu-small
1024+
# .. Except that we avoid copying icu-small over to deps/icu.
1025+
# In this default case, deps/icu is ignored, although make clean will
1026+
# still harmlessly remove deps/icu.
1027+
1028+
# are we using default locales?
1029+
using_default_locales = ( options.with_icu_locales == icu_default_locales )
1030+
1031+
# make sure the canned ICU really exists
1032+
canned_icu_available = os.path.isdir(canned_icu_dir)
1033+
1034+
if (o['variables']['icu_small'] == b(True)) and using_default_locales and (not with_icu_source) and canned_icu_available:
1035+
# OK- we can use the canned ICU.
1036+
icu_config['variables']['icu_small_canned'] = 1
1037+
icu_full_path = canned_icu_dir
1038+
10031039
# --with-icu-source processing
1004-
# first, check that they didn't pass --with-icu-source=deps/icu
1005-
if with_icu_source and os.path.abspath(icu_full_path) == os.path.abspath(with_icu_source):
1040+
# now, check that they didn't pass --with-icu-source=deps/icu
1041+
elif with_icu_source and os.path.abspath(icu_full_path) == os.path.abspath(with_icu_source):
10061042
print 'Ignoring redundant --with-icu-source=%s' % (with_icu_source)
10071043
with_icu_source = None
10081044
# if with_icu_source is still set, try to use it.
@@ -1043,7 +1079,7 @@ def configure_intl(o):
10431079

10441080
# ICU mode. (icu-generic.gyp)
10451081
o['variables']['icu_gyp_path'] = 'tools/icu/icu-generic.gyp'
1046-
# ICU source dir relative to root
1082+
# ICU source dir relative to tools/icu (for .gyp file)
10471083
o['variables']['icu_path'] = icu_full_path
10481084
if not os.path.isdir(icu_full_path):
10491085
print '* ECMA-402 (Intl) support didn\'t find ICU in %s..' % (icu_full_path)
@@ -1083,14 +1119,14 @@ def configure_intl(o):
10831119
'source/data/in',
10841120
icu_data_file_l)
10851121
# relative to dep..
1086-
icu_data_in = os.path.join('../../deps/icu/source/data/in', icu_data_file_l)
1122+
icu_data_in = os.path.join('..','..', icu_full_path, 'source/data/in', icu_data_file_l)
10871123
if not os.path.isfile(icu_data_path) and icu_endianness != 'l':
10881124
# use host endianness
10891125
icu_data_path = os.path.join(icu_full_path,
10901126
'source/data/in',
10911127
icu_data_file)
10921128
# relative to dep..
1093-
icu_data_in = os.path.join('icu/source/data/in',
1129+
icu_data_in = os.path.join('..', icu_full_path, 'source/data/in',
10941130
icu_data_file)
10951131
# this is the input '.dat' file to use .. icudt*.dat
10961132
# may be little-endian if from a icu-project.org tarball
@@ -1117,7 +1153,7 @@ def configure_intl(o):
11171153
# with a list of the src files to use
11181154
for i in icu_src:
11191155
var = 'icu_src_%s' % i
1120-
path = '../../deps/icu/source/%s' % icu_src[i]
1156+
path = '../../%s/source/%s' % (icu_full_path, icu_src[i])
11211157
icu_config['variables'][var] = glob_to_var('tools/icu', path, 'patches/%s/source/%s' % (icu_ver_major, icu_src[i]) )
11221158
# write updated icu_config.gypi with a bunch of paths
11231159
write(icu_config_name, do_not_edit +

tools/icu/README.md

+78
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,84 @@
11
Notes about the icu directory.
22
===
33

4+
How to upgrade ICU
5+
---
6+
7+
- Make sure your node workspace is clean (clean `git status`) should be sufficient.
8+
- Configure Node with the specific [ICU version](http://icu-project.org/download) you want to upgrade to, for example:
9+
10+
```
11+
./configure \
12+
--with-intl=small-icu \
13+
--with-icu-source=http://download.icu-project.org/files/icu4c/56.1/icu4c-56_1-src.zip
14+
make
15+
```
16+
17+
(the equivalent `vcbuild.bat` commands should work also.)
18+
19+
- (note- may need to make changes in `icu-generic.gyp` or `tools/icu/patches` for
20+
version specific stuff)
21+
22+
- Verify the node build works
23+
24+
```
25+
make test-ci
26+
```
27+
28+
Also running
29+
```js
30+
new Intl.DateTimeFormat('es',{month:'long'}).format(new Date(9E8));
31+
```
32+
33+
…Should return `January` not `enero`.
34+
(TODO here: improve [testing](https://github.com/nodejs/Intl/issues/16))
35+
36+
37+
- Now, copy `deps/icu` over to `deps/icu-small`
38+
39+
```
40+
python tools/icu/shrink-icu-src.py
41+
```
42+
43+
- Now, do a clean rebuild of node to test:
44+
45+
(TODO: fix this when these options become default)
46+
47+
```
48+
./configure --with-intl=small-icu --with-icu-source=deps/icu-small
49+
make
50+
```
51+
52+
- Test this newly default-generated Node.js
53+
```js
54+
process.versions.icu;
55+
new Intl.DateTimeFormat('es',{month:'long'}).format(new Date(9E8));
56+
```
57+
58+
(should return your updated ICU version number, and also `January` again.)
59+
60+
- You are ready to check in the updated `deps/small-icu`.
61+
This is a big commit, so make this a separate commit from other changes.
62+
63+
- Now, fix the default URL for the `full-icu` build in `/configure`, in
64+
the `configure_intl()` function. It should match the ICU URL used in the
65+
first step. When this is done, the following should build with full ICU.
66+
67+
```
68+
# clean up
69+
rm -rf out deps/icu deps/icu4c*
70+
./configure --with-intl=full-icu --download=all
71+
make
72+
make test-ci
73+
```
74+
75+
- commit the change to `configure`.
76+
77+
-----
78+
79+
Notes about these tools
80+
---
81+
482
The files in this directory were written for the node.js effort. It's
583
the intent of their author (Steven R. Loomis / srl295) to merge them
684
upstream into ICU, pending much discussion within the ICU-PMC.

0 commit comments

Comments
 (0)