build: remove dependency on icu io library
The library is only used in a single build-time tool where it can be easily substituted by regular libc I/O functions. PR-URL: https://github.com/nodejs/node/pull/13656 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
This commit is contained in:
parent
87d682b69a
commit
2ea60e926e
1
configure
vendored
1
configure
vendored
@ -1284,7 +1284,6 @@ def configure_intl(o):
|
||||
'stubdata': 'stubdata',
|
||||
'common': 'common',
|
||||
'i18n': 'i18n',
|
||||
'io': 'io',
|
||||
'tools': 'tools/toolutil',
|
||||
'genccode': 'tools/genccode',
|
||||
'genrb': 'tools/genrb',
|
||||
|
@ -480,7 +480,6 @@
|
||||
'<@(icu_src_tools)',
|
||||
'<@(icu_src_common)',
|
||||
'<@(icu_src_i18n)',
|
||||
'<@(icu_src_io)',
|
||||
'<@(icu_src_stubdata)',
|
||||
],
|
||||
'sources!': [
|
||||
@ -492,7 +491,6 @@
|
||||
'include_dirs': [
|
||||
'<(icu_path)/source/common',
|
||||
'<(icu_path)/source/i18n',
|
||||
'<(icu_path)/source/io',
|
||||
'<(icu_path)/source/tools/toolutil',
|
||||
],
|
||||
'defines': [
|
||||
@ -512,7 +510,6 @@
|
||||
'include_dirs': [
|
||||
'<(icu_path)/source/common',
|
||||
'<(icu_path)/source/i18n',
|
||||
'<(icu_path)/source/io',
|
||||
'<(icu_path)/source/tools/toolutil',
|
||||
],
|
||||
'conditions': [
|
||||
|
@ -52,7 +52,6 @@ Japanese, it doesn't *claim* to have Japanese.
|
||||
|
||||
#include "string.h"
|
||||
#include "charstr.h" // ICU internal header
|
||||
#include <unicode/ustdio.h>
|
||||
#include <unicode/ures.h>
|
||||
#include <unicode/udata.h>
|
||||
#include <unicode/putil.h>
|
||||
@ -69,36 +68,36 @@ CharString packageName;
|
||||
const char* locale = RES_INDEX; // locale referring to our index
|
||||
|
||||
void usage() {
|
||||
u_printf("Usage: %s [options]\n", PROG);
|
||||
u_printf(
|
||||
printf("Usage: %s [options]\n", PROG);
|
||||
printf(
|
||||
"This program lists and optionally regenerates the locale "
|
||||
"manifests\n"
|
||||
" in ICU 'res_index.res' files.\n");
|
||||
u_printf(
|
||||
printf(
|
||||
" -i ICUDATA Set ICUDATA dir to ICUDATA.\n"
|
||||
" NOTE: this must be the first option given.\n");
|
||||
u_printf(" -h This Help\n");
|
||||
u_printf(" -v Verbose Mode on\n");
|
||||
u_printf(" -l List locales to stdout\n");
|
||||
u_printf(
|
||||
printf(" -h This Help\n");
|
||||
printf(" -v Verbose Mode on\n");
|
||||
printf(" -l List locales to stdout\n");
|
||||
printf(
|
||||
" if Verbose mode, then missing (unopenable)"
|
||||
"locales\n"
|
||||
" will be listed preceded by a '#'.\n");
|
||||
u_printf(
|
||||
printf(
|
||||
" -b res_index.txt Write 'corrected' bundle "
|
||||
"to res_index.txt\n"
|
||||
" missing bundles will be "
|
||||
"OMITTED\n");
|
||||
u_printf(
|
||||
printf(
|
||||
" -T TREE Choose tree TREE\n"
|
||||
" (TREE should be one of: \n"
|
||||
" ROOT, brkitr, coll, curr, lang, rbnf, region, zone)\n");
|
||||
// see ureslocs.h and elsewhere
|
||||
u_printf(
|
||||
printf(
|
||||
" -N NAME Choose name NAME\n"
|
||||
" (default: '%s')\n",
|
||||
U_ICUDATA_NAME);
|
||||
u_printf(
|
||||
printf(
|
||||
"\nNOTE: for best results, this tool ought to be "
|
||||
"linked against\n"
|
||||
"stubdata. i.e. '%s -l' SHOULD return an error with "
|
||||
@ -108,7 +107,7 @@ void usage() {
|
||||
|
||||
#define ASSERT_SUCCESS(status, what) \
|
||||
if (U_FAILURE(*status)) { \
|
||||
u_printf("%s:%d: %s: ERROR: %s %s\n", \
|
||||
printf("%s:%d: %s: ERROR: %s %s\n", \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
PROG, \
|
||||
@ -130,7 +129,7 @@ void calculatePackageName(UErrorCode* status) {
|
||||
}
|
||||
}
|
||||
if (VERBOSE) {
|
||||
u_printf("packageName: %s\n", packageName.data());
|
||||
printf("packageName: %s\n", packageName.data());
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,7 +145,7 @@ void calculatePackageName(UErrorCode* status) {
|
||||
int localeExists(const char* loc, UBool* exists) {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
if (VERBOSE > 1) {
|
||||
u_printf("Trying to open %s:%s\n", packageName.data(), loc);
|
||||
printf("Trying to open %s:%s\n", packageName.data(), loc);
|
||||
}
|
||||
LocalUResourceBundlePointer aResource(
|
||||
ures_openDirect(packageName.data(), loc, &status));
|
||||
@ -154,13 +153,13 @@ int localeExists(const char* loc, UBool* exists) {
|
||||
if (U_SUCCESS(status)) {
|
||||
*exists = true;
|
||||
if (VERBOSE > 1) {
|
||||
u_printf("%s:%s existed!\n", packageName.data(), loc);
|
||||
printf("%s:%s existed!\n", packageName.data(), loc);
|
||||
}
|
||||
return 0;
|
||||
} else if (status == U_MISSING_RESOURCE_ERROR) {
|
||||
*exists = false;
|
||||
if (VERBOSE > 1) {
|
||||
u_printf("%s:%s did NOT exist (%s)!\n",
|
||||
printf("%s:%s did NOT exist (%s)!\n",
|
||||
packageName.data(),
|
||||
loc,
|
||||
u_errorName(status));
|
||||
@ -168,7 +167,7 @@ int localeExists(const char* loc, UBool* exists) {
|
||||
return 0; // "good" failure
|
||||
} else {
|
||||
// some other failure..
|
||||
u_printf("%s:%d: %s: ERROR %s opening %s:%s for test.\n",
|
||||
printf("%s:%d: %s: ERROR %s opening %s for test.\n",
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
u_errorName(status),
|
||||
@ -178,9 +177,9 @@ int localeExists(const char* loc, UBool* exists) {
|
||||
}
|
||||
}
|
||||
|
||||
void printIndent(const LocalUFILEPointer* bf, int indent) {
|
||||
void printIndent(FILE* bf, int indent) {
|
||||
for (int i = 0; i < indent + 1; i++) {
|
||||
u_fprintf(bf->getAlias(), " ");
|
||||
fprintf(bf, " ");
|
||||
}
|
||||
}
|
||||
|
||||
@ -191,7 +190,7 @@ void printIndent(const LocalUFILEPointer* bf, int indent) {
|
||||
*/
|
||||
int dumpAllButInstalledLocales(int lev,
|
||||
LocalUResourceBundlePointer* bund,
|
||||
LocalUFILEPointer* bf,
|
||||
FILE* bf,
|
||||
UErrorCode* status) {
|
||||
ures_resetIterator(bund->getAlias());
|
||||
LocalUResourceBundlePointer t;
|
||||
@ -200,30 +199,30 @@ int dumpAllButInstalledLocales(int lev,
|
||||
ASSERT_SUCCESS(status, "while processing table");
|
||||
const char* key = ures_getKey(t.getAlias());
|
||||
if (VERBOSE > 1) {
|
||||
u_printf("dump@%d: got key %s\n", lev, key);
|
||||
printf("dump@%d: got key %s\n", lev, key);
|
||||
}
|
||||
if (lev == 0 && !strcmp(key, INSTALLEDLOCALES)) {
|
||||
if (VERBOSE > 1) {
|
||||
u_printf("dump: skipping '%s' as it must be evaluated.\n", key);
|
||||
printf("dump: skipping '%s' as it must be evaluated.\n", key);
|
||||
}
|
||||
} else {
|
||||
printIndent(bf, lev);
|
||||
u_fprintf(bf->getAlias(), "%s", key);
|
||||
fprintf(bf, "%s", key);
|
||||
switch (ures_getType(t.getAlias())) {
|
||||
case URES_STRING: {
|
||||
int32_t len = 0;
|
||||
const UChar* s = ures_getString(t.getAlias(), &len, status);
|
||||
ASSERT_SUCCESS(status, "getting string");
|
||||
u_fprintf(bf->getAlias(), ":string {\"");
|
||||
u_file_write(s, len, bf->getAlias());
|
||||
u_fprintf(bf->getAlias(), "\"}");
|
||||
fprintf(bf, ":string {\"");
|
||||
fwrite(s, len, 1, bf);
|
||||
fprintf(bf, "\"}");
|
||||
} break;
|
||||
default: {
|
||||
u_printf("ERROR: unhandled type in dumpAllButInstalledLocales().\n");
|
||||
printf("ERROR: unhandled type in dumpAllButInstalledLocales().\n");
|
||||
return 1;
|
||||
} break;
|
||||
}
|
||||
u_fprintf(bf->getAlias(), "\n");
|
||||
fprintf(bf, "\n");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@ -232,20 +231,19 @@ int dumpAllButInstalledLocales(int lev,
|
||||
int list(const char* toBundle) {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
|
||||
LocalUFILEPointer bf;
|
||||
FILE* bf = NULL;
|
||||
|
||||
if (toBundle != NULL) {
|
||||
if (VERBOSE) {
|
||||
u_printf("writing to bundle %s\n", toBundle);
|
||||
printf("writing to bundle %s\n", toBundle);
|
||||
}
|
||||
// we write UTF-8 with BOM only. No exceptions.
|
||||
bf.adoptInstead(u_fopen(toBundle, "w", "en_US_POSIX", "UTF-8"));
|
||||
if (bf.isNull()) {
|
||||
u_printf("ERROR: Could not open '%s' for writing.\n", toBundle);
|
||||
bf = fopen(toBundle, "wb");
|
||||
if (bf == NULL) {
|
||||
printf("ERROR: Could not open '%s' for writing.\n", toBundle);
|
||||
return 1;
|
||||
}
|
||||
u_fputc(0xFEFF, bf.getAlias()); // write BOM
|
||||
u_fprintf(bf.getAlias(), "// -*- Coding: utf-8; -*-\n//\n");
|
||||
fprintf(bf, "\xEF\xBB\xBF"); // write UTF-8 BOM
|
||||
fprintf(bf, "// -*- Coding: utf-8; -*-\n//\n");
|
||||
}
|
||||
|
||||
// first, calculate the bundle name.
|
||||
@ -253,7 +251,7 @@ int list(const char* toBundle) {
|
||||
ASSERT_SUCCESS(&status, "calculating package name");
|
||||
|
||||
if (VERBOSE) {
|
||||
u_printf("\"locale\": %s\n", locale);
|
||||
printf("\"locale\": %s\n", locale);
|
||||
}
|
||||
|
||||
LocalUResourceBundlePointer bund(
|
||||
@ -265,29 +263,30 @@ int list(const char* toBundle) {
|
||||
|
||||
int32_t count = ures_getSize(installedLocales.getAlias());
|
||||
if (VERBOSE) {
|
||||
u_printf("Locales: %d\n", count);
|
||||
printf("Locales: %d\n", count);
|
||||
}
|
||||
|
||||
if (bf.isValid()) {
|
||||
if (bf != NULL) {
|
||||
// write the HEADER
|
||||
u_fprintf(bf.getAlias(),
|
||||
fprintf(bf,
|
||||
"// Warning this file is automatically generated\n"
|
||||
"// Updated by %s based on %s:%s.txt\n",
|
||||
PROG,
|
||||
packageName.data(),
|
||||
locale);
|
||||
u_fprintf(bf.getAlias(),
|
||||
fprintf(bf,
|
||||
"%s:table(nofallback) {\n"
|
||||
" // First, everything besides InstalledLocales:\n",
|
||||
locale);
|
||||
if (dumpAllButInstalledLocales(0, &bund, &bf, &status)) {
|
||||
u_printf("Error dumping prolog for %s\n", toBundle);
|
||||
if (dumpAllButInstalledLocales(0, &bund, bf, &status)) {
|
||||
printf("Error dumping prolog for %s\n", toBundle);
|
||||
fclose(bf);
|
||||
return 1;
|
||||
}
|
||||
// in case an error was missed
|
||||
ASSERT_SUCCESS(&status, "while writing prolog");
|
||||
|
||||
u_fprintf(bf.getAlias(),
|
||||
fprintf(bf,
|
||||
" %s:table { // %d locales in input %s.res\n",
|
||||
INSTALLEDLOCALES,
|
||||
count,
|
||||
@ -305,35 +304,38 @@ int list(const char* toBundle) {
|
||||
|
||||
const char* key = ures_getKey(subkey.getAlias());
|
||||
if (VERBOSE > 1) {
|
||||
u_printf("@%d: %s\n", i, key);
|
||||
printf("@%d: %s\n", i, key);
|
||||
}
|
||||
// now, see if the locale is installed..
|
||||
|
||||
UBool exists;
|
||||
if (localeExists(key, &exists)) {
|
||||
if (bf != NULL) fclose(bf);
|
||||
return 1; // get out.
|
||||
}
|
||||
if (exists) {
|
||||
validCount++;
|
||||
u_printf("%s\n", key);
|
||||
if (bf.isValid()) {
|
||||
u_fprintf(bf.getAlias(), " %s {\"\"}\n", key);
|
||||
printf("%s\n", key);
|
||||
if (bf != NULL) {
|
||||
fprintf(bf, " %s {\"\"}\n", key);
|
||||
}
|
||||
} else {
|
||||
if (bf.isValid()) {
|
||||
u_fprintf(bf.getAlias(), "// %s {\"\"}\n", key);
|
||||
if (bf != NULL) {
|
||||
fprintf(bf, "// %s {\"\"}\n", key);
|
||||
}
|
||||
if (VERBOSE) {
|
||||
u_printf("#%s\n", key); // verbosity one - '' vs '#'
|
||||
printf("#%s\n", key); // verbosity one - '' vs '#'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bf.isValid()) {
|
||||
u_fprintf(bf.getAlias(), " } // %d/%d valid\n", validCount, count);
|
||||
if (bf != NULL) {
|
||||
fprintf(bf, " } // %d/%d valid\n", validCount, count);
|
||||
// write the HEADER
|
||||
u_fprintf(bf.getAlias(), "}\n");
|
||||
fprintf(bf, "}\n");
|
||||
fclose(bf);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -346,24 +348,24 @@ int main(int argc, const char* argv[]) {
|
||||
VERBOSE++;
|
||||
} else if (!strcmp(arg, "-i") && (argsLeft >= 1)) {
|
||||
if (i != 1) {
|
||||
u_printf("ERROR: -i must be the first argument given.\n");
|
||||
printf("ERROR: -i must be the first argument given.\n");
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
const char* dir = argv[++i];
|
||||
u_setDataDirectory(dir);
|
||||
if (VERBOSE) {
|
||||
u_printf("ICUDATA is now %s\n", dir);
|
||||
printf("ICUDATA is now %s\n", dir);
|
||||
}
|
||||
} else if (!strcmp(arg, "-T") && (argsLeft >= 1)) {
|
||||
TREE = argv[++i];
|
||||
if (VERBOSE) {
|
||||
u_printf("TREE is now %s\n", TREE);
|
||||
printf("TREE is now %s\n", TREE);
|
||||
}
|
||||
} else if (!strcmp(arg, "-N") && (argsLeft >= 1)) {
|
||||
NAME = argv[++i];
|
||||
if (VERBOSE) {
|
||||
u_printf("NAME is now %s\n", NAME);
|
||||
printf("NAME is now %s\n", NAME);
|
||||
}
|
||||
} else if (!strcmp(arg, "-?") || !strcmp(arg, "-h")) {
|
||||
usage();
|
||||
@ -377,7 +379,7 @@ int main(int argc, const char* argv[]) {
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
u_printf("Unknown or malformed option: %s\n", arg);
|
||||
printf("Unknown or malformed option: %s\n", arg);
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
|
@ -56,6 +56,7 @@ def icu_ignore(dir, files):
|
||||
elif subdir == 'source':
|
||||
ign = ign + ['layout','samples','test','extra','config','layoutex','allinone','data']
|
||||
ign = ign + ['runConfigureICU','install-sh','mkinstalldirs','configure']
|
||||
ign = ign + ['io']
|
||||
elif subdir == 'source/tools':
|
||||
ign = ign + ['tzcode','ctestfw','gensprep','gennorm2','gendict','icuswap',
|
||||
'genbrk','gencfu','gencolusb','genren','memcheck','makeconv','gencnval','icuinfo','gentest']
|
||||
|
Loading…
x
Reference in New Issue
Block a user