Skip to content

Commit 37fa12d

Browse files
committed
build: unbreak windows build of ICU source URL
- configure: don't assume ICU source is a path, it's sometimes a URL Also: - cleanup comments in configure.py and nodedownload.py - feat: add a way to set ICU url on windows - update docs for maintaining ICU per above url Fixes: #55214
1 parent cebf21d commit 37fa12d

File tree

4 files changed

+42
-23
lines changed

4 files changed

+42
-23
lines changed

configure.py

+24-10
Original file line numberDiff line numberDiff line change
@@ -1798,7 +1798,8 @@ def glob_to_var(dir_base, dir_sub, patch_dir):
17981798
return file_list
17991799

18001800
def configure_intl(o):
1801-
def icu_download(path):
1801+
def icu_download():
1802+
"""Download or verify ICU from the deps file (current_ver.dep)"""
18021803
depFile = tools_path / 'icu' / 'current_ver.dep'
18031804
icus = json.loads(depFile.read_text(encoding='utf-8'))
18041805
# download ICU, if needed
@@ -1848,6 +1849,17 @@ def icu_download(path):
18481849

18491850
with_intl = options.with_intl
18501851
with_icu_source = options.with_icu_source
1852+
if not with_icu_source:
1853+
with_icu_source_path = None
1854+
# no --with-icu-source
1855+
elif with_icu_source.startswith('http://') or with_icu_source.startswith('https://'):
1856+
# --with-icu-source isn't a path.
1857+
with_icu_source_path = None
1858+
else:
1859+
# convert to a resolved path for the dep check (below)
1860+
with_icu_source = Path(with_icu_source).resolve()
1861+
# pre-convert to a path for later checks.
1862+
with_icu_source_path = Path(with_icu_source)
18511863
have_icu_path = bool(options.with_icu_path)
18521864
if have_icu_path and with_intl != 'none':
18531865
error('Cannot specify both --with-icu-path and --with-intl')
@@ -1936,16 +1948,16 @@ def icu_download(path):
19361948
icu_config['variables']['icu_full_canned'] = 1
19371949
# --with-icu-source processing
19381950
# now, check that they didn't pass --with-icu-source=deps/icu
1939-
elif with_icu_source and Path(icu_full_path).resolve() == Path(with_icu_source).resolve():
1940-
warn(f'Ignoring redundant --with-icu-source={with_icu_source}')
1951+
elif with_icu_source and Path(icu_full_path).resolve() == with_icu_source:
1952+
warn(f'Ignoring redundant --with-icu-source={options.with_icu_source}')
19411953
with_icu_source = None
19421954
# if with_icu_source is still set, try to use it.
19431955
if with_icu_source:
19441956
if Path(icu_full_path).is_dir():
19451957
print(f'Deleting old ICU source: {icu_full_path}')
19461958
shutil.rmtree(icu_full_path)
19471959
# now, what path was given?
1948-
if Path(with_icu_source).is_dir():
1960+
if with_icu_source_path and with_icu_source_path.is_dir():
19491961
# it's a path. Copy it.
19501962
print(f'{with_icu_source} -> {icu_full_path}')
19511963
shutil.copytree(with_icu_source, icu_full_path)
@@ -1956,13 +1968,15 @@ def icu_download(path):
19561968
shutil.rmtree(icu_tmp_path)
19571969
icu_tmp_path.mkdir()
19581970
icu_tarball = None
1959-
if Path(with_icu_source).is_file():
1971+
if with_icu_source_path and with_icu_source_path.is_file():
19601972
# it's a file. Try to unpack it.
1961-
icu_tarball = with_icu_source
1962-
else:
1963-
# Can we download it?
1973+
icu_tarball = str(with_icu_source.as_posix()) # resolved path
1974+
elif not with_icu_source_path:
1975+
# Can we download it? (not a path)
19641976
local = icu_tmp_path / with_icu_source.split('/')[-1] # local part
19651977
icu_tarball = nodedownload.retrievefile(with_icu_source, local)
1978+
else:
1979+
error(f'Cannot find ICU, not a file, dir, or URL: --with-icu-source={options.with_icu_source}')
19661980
# continue with "icu_tarball"
19671981
nodedownload.unpack(icu_tarball, icu_tmp_path)
19681982
# Did it unpack correctly? Should contain 'icu'
@@ -1972,15 +1986,15 @@ def icu_download(path):
19721986
shutil.rmtree(icu_tmp_path)
19731987
else:
19741988
shutil.rmtree(icu_tmp_path)
1975-
error(f'--with-icu-source={with_icu_source} did not result in an "icu" dir.')
1989+
error(f'--with-icu-source={options.with_icu_source} did not result in an "icu" dir.')
19761990

19771991
# ICU mode. (icu-generic.gyp)
19781992
o['variables']['icu_gyp_path'] = 'tools/icu/icu-generic.gyp'
19791993
# ICU source dir relative to tools/icu (for .gyp file)
19801994
o['variables']['icu_path'] = icu_full_path
19811995
if not Path(icu_full_path).is_dir():
19821996
# can we download (or find) a zipfile?
1983-
localzip = icu_download(icu_full_path)
1997+
localzip = icu_download()
19841998
if localzip:
19851999
nodedownload.unpack(localzip, icu_parent_path)
19862000
else:

doc/contributing/maintaining/maintaining-icu.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,17 @@ Node.js is built.
109109
* Configure Node.js with the specific [ICU version](http://site.icu-project.org/download)
110110
you want to upgrade to, for example:
111111
112+
(posix)
112113
```bash
113114
./configure \
114115
--with-intl=full-icu \
115116
--with-icu-source=https://github.com/unicode-org/icu/releases/download/release-67-1/icu4c-67_1-src.tgz
116117
make
117118
```
118-
119-
> _Note_ in theory, the equivalent `vcbuild.bat` commands should work also,
120-
> but the commands below are makefile-centric.
119+
(vcbuild)
120+
```shell
121+
vcbuild.bat full-icu with-icu-source https://github.com/unicode-org/icu/releases/download/release-67-1/icu4c-67_1-src.tgz test
122+
```
121123

122124
* If there are ICU version-specific changes needed, you may need to make changes
123125
in `tools/icu/icu-generic.gyp` or add patch files to `tools/icu/patches`.

tools/configure.d/nodedownload.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,19 @@ def checkHash(targetfile, hashAlgo):
7070

7171
def unpack(packedfile, parent_path):
7272
"""Unpacks packedfile into parent_path. Assumes .zip. Returns parent_path"""
73+
packedsuffix = packedfile.lower().split('.')[-1] # .zip, .tgz etc
7374
if zipfile.is_zipfile(packedfile):
74-
with contextlib.closing(zipfile.ZipFile(packedfile, 'r')) as icuzip:
75-
print(' Extracting zipfile: %s' % packedfile)
76-
icuzip.extractall(parent_path)
77-
return parent_path
75+
print(' Extracting zip file: %s' % packedfile)
76+
with contextlib.closing(zipfile.ZipFile(packedfile, 'r')) as icuzip:
77+
icuzip.extractall(parent_path)
78+
return parent_path
7879
elif tarfile.is_tarfile(packedfile):
79-
with contextlib.closing(tarfile.TarFile.open(packedfile, 'r')) as icuzip:
80-
print(' Extracting tarfile: %s' % packedfile)
81-
icuzip.extractall(parent_path)
82-
return parent_path
80+
# this will support gz, bz2, xz, etc. See tarfile.open()
81+
print(' Extracting tar file: %s' % packedfile)
82+
with contextlib.closing(tarfile.TarFile.open(packedfile, 'r')) as icuzip:
83+
icuzip.extractall(parent_path)
84+
return parent_path
8385
else:
84-
packedsuffix = packedfile.lower().split('.')[-1] # .zip, .tgz etc
8586
raise Exception('Error: Don\'t know how to unpack %s with extension %s' % (packedfile, packedsuffix))
8687

8788
# List of possible "--download=" types.

vcbuild.bat

+3-1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ if /i "%1"=="full-icu" set i18n_arg=%1&goto arg-ok
135135
if /i "%1"=="intl-none" set i18n_arg=none&goto arg-ok
136136
if /i "%1"=="without-intl" set i18n_arg=none&goto arg-ok
137137
if /i "%1"=="download-all" set download_arg="--download=all"&goto arg-ok
138+
if /i "%1"=="with-icu-source" set with_icu_source=%2&goto arg-ok-2
138139
if /i "%1"=="ignore-flaky" set test_args=%test_args% --flaky-tests=dontcare&goto arg-ok
139140
if /i "%1"=="dll" set dll=1&goto arg-ok
140141
if /i "%1"=="enable-vtune" set enable_vtune_arg=1&goto arg-ok
@@ -201,6 +202,7 @@ if defined enable_static set configure_flags=%configure_flags% --enable-stati
201202
if defined no_NODE_OPTIONS set configure_flags=%configure_flags% --without-node-options
202203
if defined link_module set configure_flags=%configure_flags% %link_module%
203204
if defined i18n_arg set configure_flags=%configure_flags% --with-intl=%i18n_arg%
205+
if defined with_icu_source set configure_flags=%configure_flags% --with-icu-source=%with_icu_source%
204206
if defined config_flags set configure_flags=%configure_flags% %config_flags%
205207
if defined target_arch set configure_flags=%configure_flags% --dest-cpu=%target_arch%
206208
if defined debug_nghttp2 set configure_flags=%configure_flags% --debug-nghttp2
@@ -801,7 +803,7 @@ set exit_code=1
801803
goto exit
802804

803805
:help
804-
echo vcbuild.bat [debug/release] [msi] [doc] [test/test-all/test-addons/test-doc/test-js-native-api/test-node-api/test-internet/test-tick-processor/test-known-issues/test-node-inspect/test-check-deopts/test-npm/test-v8/test-v8-intl/test-v8-benchmarks/test-v8-all] [ignore-flaky] [static/dll] [noprojgen] [projgen] [clang-cl] [small-icu/full-icu/without-intl] [nobuild] [nosnapshot] [nonpm] [nocorepack] [ltcg] [licensetf] [sign] [x64/arm64] [vs2022] [download-all] [enable-vtune] [lint/lint-ci/lint-js/lint-md] [lint-md-build] [format-md] [package] [build-release] [upload] [no-NODE-OPTIONS] [link-module path-to-module] [debug-http2] [debug-nghttp2] [clean] [cctest] [no-cctest] [openssl-no-asm]
806+
echo vcbuild.bat [debug/release] [msi] [doc] [test/test-all/test-addons/test-doc/test-js-native-api/test-node-api/test-internet/test-tick-processor/test-known-issues/test-node-inspect/test-check-deopts/test-npm/test-v8/test-v8-intl/test-v8-benchmarks/test-v8-all] [ignore-flaky] [static/dll] [noprojgen] [projgen] [clang-cl] [small-icu/full-icu/without-intl] [with-icu-source path-or-URL] [nobuild] [nosnapshot] [nonpm] [nocorepack] [ltcg] [licensetf] [sign] [x64/arm64] [vs2022] [download-all] [enable-vtune] [lint/lint-ci/lint-js/lint-md] [lint-md-build] [format-md] [package] [build-release] [upload] [no-NODE-OPTIONS] [link-module path-to-module] [debug-http2] [debug-nghttp2] [clean] [cctest] [no-cctest] [openssl-no-asm]
805807
echo Examples:
806808
echo vcbuild.bat : builds release build
807809
echo vcbuild.bat debug : builds debug build

0 commit comments

Comments
 (0)