Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Auto-load ICU data from --with-icu-default-data-dir #30825

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,14 @@
'the icu4c source archive. '
'v%d.x or later recommended.' % icu_versions['minimum_icu'])

intl_optgroup.add_option('--with-icu-default-data-dir',
action='store',
dest='with_icu_default_data_dir',
help='Path to the icuXXdt{lb}.dat file. If unspecified, ICU data will '
'only be read if the NODE_ICU_DATA environment variable or the '
'--icu-data-dir runtime argument is used. This option has effect '
'only when Node.js is built with --with-intl=small-icu.')

parser.add_option('--with-ltcg',
action='store_true',
dest='with_ltcg',
Expand Down Expand Up @@ -1391,6 +1399,7 @@ def write_config(data, name):
locs.add('root') # must have root
o['variables']['icu_locales'] = ','.join(str(loc) for loc in locs)
# We will check a bit later if we can use the canned deps/icu-small
o['variables']['icu_default_data'] = options.with_icu_default_data_dir or ''
elif with_intl == 'full-icu':
# full ICU
o['variables']['v8_enable_i18n_support'] = 1
Expand Down
7 changes: 7 additions & 0 deletions node.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@
'conditions': [
[ 'icu_small=="true"', {
'defines': [ 'NODE_HAVE_SMALL_ICU=1' ],
'conditions': [
[ 'icu_default_data!=""', {
'defines': [
'NODE_ICU_DEFAULT_DATA_DIR="<(icu_default_data)"',
],
}],
],
}]],
}],
[ 'node_no_browser_globals=="true"', {
Expand Down
20 changes: 20 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@

#if defined(NODE_HAVE_I18N_SUPPORT)
#include <unicode/uvernum.h>
#include <unicode/utypes.h>
#endif


Expand Down Expand Up @@ -882,6 +883,25 @@ int InitializeNodeWithArgs(std::vector<std::string>* argv,
if (per_process::cli_options->icu_data_dir.empty())
credentials::SafeGetenv("NODE_ICU_DATA",
&per_process::cli_options->icu_data_dir);

#ifdef NODE_ICU_DEFAULT_DATA_DIR
// If neither the CLI option nor the environment variable was specified,
// fall back to the configured default
if (per_process::cli_options->icu_data_dir.empty()) {
// Check whether the NODE_ICU_DEFAULT_DATA_DIR contains the right data
// file and can be read.
static const char full_path[] =
NODE_ICU_DEFAULT_DATA_DIR "/" U_ICUDATA_NAME ".dat";

FILE* f = fopen(full_path, "rb");

if (f != nullptr) {
fclose(f);
per_process::cli_options->icu_data_dir = NODE_ICU_DEFAULT_DATA_DIR;
sgallagher marked this conversation as resolved.
Show resolved Hide resolved
}
}
#endif // NODE_ICU_DEFAULT_DATA_DIR

// Initialize ICU.
// If icu_data_dir is empty here, it will load the 'minimal' data.
if (!i18n::InitializeICUDirectory(per_process::cli_options->icu_data_dir)) {
Expand Down