GeezerVison is showing github.com — build: auto-load ICU data from --with-icu-default-data-dir · nodejs/node@67a2a47
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: configure.py +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 443 | 443 | 'the icu4c source archive. ' | 444 | 444 | 'v%d.x or later recommended.' % icu_versions['minimum_icu']) | 445 | 445 |
| | 446 | +intl_optgroup.add_option('--with-icu-default-data-dir', | | 447 | + action='store', | | 448 | + dest='with_icu_default_data_dir', | | 449 | + help='Path to the icuXXdt{lb}.dat file. If unspecified, ICU data will ' | | 450 | + 'only be read if the NODE_ICU_DATA environment variable or the ' | | 451 | + '--icu-data-dir runtime argument is used. This option has effect ' | | 452 | + 'only when Node.js is built with --with-intl=small-icu.') | | 453 | + | 446 | 454 | parser.add_option('--with-ltcg', | 447 | 455 | action='store_true', | 448 | 456 | dest='with_ltcg', | @@ -1370,6 +1378,7 @@ def write_config(data, name): | 1370 | 1378 | locs.add('root') # must have root | 1371 | 1379 | o['variables']['icu_locales'] = ','.join(str(loc) for loc in locs) | 1372 | 1380 | # We will check a bit later if we can use the canned deps/icu-small | | 1381 | + o['variables']['icu_default_data'] = options.with_icu_default_data_dir or '' | 1373 | 1382 | elif with_intl == 'full-icu': | 1374 | 1383 | # full ICU | 1375 | 1384 | o['variables']['v8_enable_i18n_support'] = 1 | |
Collapse file Copy file name to clipboardExpand all lines: node.gypi +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 103 | 103 | 'conditions': [ | 104 | 104 | [ 'icu_small=="true"', { | 105 | 105 | 'defines': [ 'NODE_HAVE_SMALL_ICU=1' ], | | 106 | + 'conditions': [ | | 107 | + [ 'icu_default_data!=""', { | | 108 | + 'defines': [ | | 109 | + 'NODE_ICU_DEFAULT_DATA_DIR="<(icu_default_data)"', | | 110 | + ], | | 111 | + }], | | 112 | + ], | 106 | 113 | }]], | 107 | 114 | }], | 108 | 115 | [ 'node_no_browser_globals=="true"', { | |
Collapse file Copy file name to clipboardExpand all lines: src/node.cc +20Lines changed: 20 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 79 | 79 |
| 80 | 80 | #if defined(NODE_HAVE_I18N_SUPPORT) | 81 | 81 | #include <unicode/uvernum.h> | | 82 | +#include <unicode/utypes.h> | 82 | 83 | #endif | 83 | 84 |
| 84 | 85 |
| @@ -831,6 +832,25 @@ int InitializeNodeWithArgs(std::vector<std::string>* argv, | 831 | 832 | if (per_process::cli_options->icu_data_dir.empty()) | 832 | 833 | credentials::SafeGetenv("NODE_ICU_DATA", | 833 | 834 | &per_process::cli_options->icu_data_dir); | | 835 | + | | 836 | +#ifdef NODE_ICU_DEFAULT_DATA_DIR | | 837 | + // If neither the CLI option nor the environment variable was specified, | | 838 | + // fall back to the configured default | | 839 | + if (per_process::cli_options->icu_data_dir.empty()) { | | 840 | + // Check whether the NODE_ICU_DEFAULT_DATA_DIR contains the right data | | 841 | + // file and can be read. | | 842 | + static const char full_path[] = | | 843 | + NODE_ICU_DEFAULT_DATA_DIR "/" U_ICUDATA_NAME ".dat"; | | 844 | + | | 845 | + FILE* f = fopen(full_path, "rb"); | | 846 | + | | 847 | + if (f != nullptr) { | | 848 | + fclose(f); | | 849 | + per_process::cli_options->icu_data_dir = NODE_ICU_DEFAULT_DATA_DIR; | | 850 | + } | | 851 | + } | | 852 | +#endif // NODE_ICU_DEFAULT_DATA_DIR | | 853 | + | 834 | 854 | // Initialize ICU. | 835 | 855 | // If icu_data_dir is empty here, it will load the 'minimal' data. | 836 | 856 | if (!i18n::InitializeICUDirectory(per_process::cli_options->icu_data_dir)) { | |
|