forked from nodejs/node-v0.x-archive
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: i18n: Autodownload ICU, Add a test.
This is to implement nodejs#7676 (comment) * make `--with-intl=none` the default * Download, verify (md5), unpack ICU's zip if not there * update docs * add a test There's a "list" of URLs being used, but right now only the first is picked up. The logic works something like this: * if there is no directory `deps/icu`, * if no zip file (currently `icu4c-54_1-src.zip`), * download zip file (icu-project.org -> sf.net) * verify the MD5 sum of the zipfile * if bad, print error and exit * unpack the zipfile into `deps/icu` * if `deps/icu` now exists, use it, else fail with help text Also: * refactor some code into tools/configure.d/nodedownload.py * add `intl-none` option for `vcbuild.bat` To rebuild `deps/icu-small` - (not currently checked in) ``` bash tools/icu/prepare-icu-source.sh ``` Reduce space by about 1MB with ICU 54 (over without this patch). Also trims a few other source files, but only conditional on the exact ICU version used. This is to future-proof - a file that is unneeded now may be needed in future ICUs.
- Loading branch information
Showing
10 changed files
with
415 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,8 @@ ipch/ | |
email.md | ||
deps/v8-* | ||
deps/icu | ||
deps/icu*.zip | ||
deps/icu*.tgz | ||
./node_modules | ||
.svn/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright Joyent, Inc. and other Node contributors. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a | ||
// copy of this software and associated documentation files (the | ||
// "Software"), to deal in the Software without restriction, including | ||
// without limitation the rights to use, copy, modify, merge, publish, | ||
// distribute, sublicense, and/or sell copies of the Software, and to permit | ||
// persons to whom the Software is furnished to do so, subject to the | ||
// following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included | ||
// in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
// USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
var common = require('../common'); | ||
var assert = require('assert'); | ||
|
||
var enablei18n = process.config.variables.v8_enable_i18n_support; | ||
if (enablei18n === undefined) { | ||
enablei18n = false; | ||
} | ||
|
||
var haveIntl = ( global.Intl != undefined ); | ||
|
||
if (!haveIntl) { | ||
assert.equal(enablei18n, false, '"Intl" object is NOT present but v8_enable_i18n_support is ' + enablei18n); | ||
console.log('Skipping Intl tests because Intl object not present.'); | ||
} else { | ||
assert.equal(enablei18n, true, '"Intl" object is present but v8_enable_i18n_support is ' + enablei18n + '. Is this test out of date?'); | ||
|
||
// Check with toLocaleString | ||
var date0 = new Date(0); | ||
var GMT = 'Etc/GMT'; | ||
var optsGMT = {timeZone: GMT}; | ||
var localeString0 = date0.toLocaleString(['en'], optsGMT); | ||
var expectString0 = '1/1/1970, 12:00:00 AM'; // epoch | ||
assert.equal(localeString0, expectString0); | ||
|
||
// check with a Formatter | ||
var dtf = new Intl.DateTimeFormat(['en'], {timeZone: GMT, month: 'short', year: '2-digit'}); | ||
var localeString1 = dtf.format(date0); | ||
assert.equal(localeString1, 'Jan 70'); | ||
|
||
// number format | ||
assert.equal(new Intl.NumberFormat(['en']).format(12345.67890), '12,345.679'); | ||
|
||
var coll = new Intl.Collator(['en'],{sensitivity:'base',ignorePunctuation:true}); | ||
|
||
assert.equal(coll.compare('blackbird', 'black-bird'), 0, 'ignore punctuation failed'); | ||
|
||
assert.equal(coll.compare('blackbird', 'red-bird'), -1, 'compare less failed'); | ||
assert.equal(coll.compare('bluebird', 'blackbird'), 1, 'compare greater failed'); | ||
assert.equal(coll.compare('Bluebird', 'bluebird'), 0, 'ignore case failed'); | ||
assert.equal(coll.compare('\ufb03', 'ffi'), 0, 'ffi ligature (contraction) failed'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env python | ||
# Moved some utilities here from ../../configure | ||
|
||
import urllib | ||
import hashlib | ||
import sys | ||
import zipfile | ||
|
||
def formatSize(amt): | ||
"""Format a size as a string in MB""" | ||
return "{:.1f}".format(amt / 1024000.) | ||
|
||
def spin(c): | ||
"""print out a spinner based on 'c'""" | ||
# spin = "\\|/-" | ||
spin = ".:|'" | ||
return (spin[c % len(spin)]) | ||
|
||
class ConfigOpener(urllib.FancyURLopener): | ||
"""fancy opener used by retrievefile. Set a UA""" | ||
# append to existing version (UA) | ||
version = '%s node.js/configure' % urllib.URLopener.version | ||
|
||
def reporthook(count, size, total): | ||
"""internal hook used by retrievefile""" | ||
sys.stdout.write(' Fetch: %c %sMB total, %sMB downloaded \r' % | ||
(spin(count), | ||
formatSize(total), | ||
formatSize(count*size))) | ||
|
||
def retrievefile(url, targetfile): | ||
"""fetch file 'url' as 'targetfile'. Return targetfile or throw.""" | ||
try: | ||
sys.stdout.write(' <%s>\nConnecting...\r' % url) | ||
sys.stdout.flush() | ||
msg = ConfigOpener().retrieve(url, targetfile, reporthook=reporthook) | ||
print '' # clear the line | ||
return targetfile | ||
except: | ||
print ' ** Error occurred while downloading\n <%s>' % url | ||
raise | ||
|
||
def md5sum(targetfile): | ||
"""md5sum a file. Return the hex digest.""" | ||
digest = hashlib.md5() | ||
with open(targetfile, 'rb') as f: | ||
chunk = f.read(1024) | ||
while chunk != "": | ||
digest.update(chunk) | ||
chunk = f.read(1024) | ||
return digest.hexdigest() | ||
|
||
def unpack(packedfile, parent_path): | ||
"""Unpack packedfile into parent_path. Assumes .zip.""" | ||
with zipfile.ZipFile(packedfile, 'r') as icuzip: | ||
print ' Extracting source zip: %s' % packedfile | ||
icuzip.extractall(parent_path) |
Oops, something went wrong.