]> granicus.if.org Git - icu/commitdiff
ICU-21545 Add plumbing for running icuexportdata in BRS
authorShane F. Carr <shane@unicode.org>
Tue, 21 Sep 2021 05:15:02 +0000 (05:15 +0000)
committerShane F. Carr <shane@unicode.org>
Tue, 21 Sep 2021 22:40:27 +0000 (17:40 -0500)
See #1857

- Renames tool from icuwriteuprops
- Adds more command-line flags

13 files changed:
.ci-builds/.azure-pipelines.yml
docs/processes/release/tasks/publish/index.md
icu4c/source/allinone/allinone.sln
icu4c/source/configure
icu4c/source/configure.ac
icu4c/source/tools/Makefile.in
icu4c/source/tools/icuexportdata/Makefile.in [moved from icu4c/source/tools/icuwriteuprops/Makefile.in with 95% similarity]
icu4c/source/tools/icuexportdata/icuexportdata.1.in [moved from icu4c/source/tools/icuwriteuprops/icuwriteuprops.1.in with 81% similarity]
icu4c/source/tools/icuexportdata/icuexportdata.cpp [moved from icu4c/source/tools/icuwriteuprops/icuwriteuprops.cpp with 57% similarity]
icu4c/source/tools/icuexportdata/icuexportdata.vcxproj [moved from icu4c/source/tools/icuwriteuprops/icuwriteuprops.vcxproj with 90% similarity]
icu4c/source/tools/icuexportdata/icuexportdata.vcxproj.filters [moved from icu4c/source/tools/icuwriteuprops/icuwriteuprops.vcxproj.filters with 93% similarity]
icu4c/source/tools/icuexportdata/sources.txt [new file with mode: 0644]
icu4c/source/tools/icuwriteuprops/sources.txt [deleted file]

index 4a424ec3849699dde81f2b46d91c8edb05922842..7092593fa8e514c007d89f72028708aee7091c6b 100644 (file)
@@ -582,3 +582,48 @@ jobs:
       env:
         CC: gcc
         CXX: g++
+#-------------------------------------------------------------------------
+- job: ICU4C_icuexportdata_Ubuntu_1804
+  displayName: 'C: Create Artifacts from icuexportdata'
+  timeoutInMinutes: 30
+  pool:
+    vmImage: 'ubuntu-18.04'
+  steps:
+    - checkout: self
+      lfs: true
+      fetchDepth: 10
+    - script: |
+        cd icu4c/source && ./runConfigureICU Linux && make -j2
+      displayName: 'Build'
+      env:
+        CC: clang
+        CXX: clang++
+    - script: |
+        mkdir -p icu4c/source/icuexportdata_uprops_full/fast
+        mkdir -p icu4c/source/icuexportdata_uprops_full/small
+        cd icu4c/source
+        LD_LIBRARY_PATH=lib ./bin/icuexportdata --mode uprops --index --copyright --destdir icuexportdata_uprops_full/fast --trie-type fast --all
+        LD_LIBRARY_PATH=lib ./bin/icuexportdata --mode uprops --index --copyright --destdir icuexportdata_uprops_full/small --trie-type small --all
+      displayName: 'Build Unicode property data export file (Full)'
+    # In the sample file, include:
+    # - Basic binary properties: AHex WSpace
+    # - Property of strings: Basic_Emoji
+    # - POSIX binary property: blank
+    # - Enumerated properties: gc nt sc
+    - script: |
+        mkdir -p icu4c/source/icuexportdata_uprops_sample/fast
+        mkdir -p icu4c/source/icuexportdata_uprops_sample/small
+        cd icu4c/source
+        LD_LIBRARY_PATH=lib ./bin/icuexportdata --mode uprops --index --copyright --destdir icuexportdata_uprops_sample/fast --trie-type fast AHex gc nt Basic_Emoji sc WSpace blank
+        LD_LIBRARY_PATH=lib ./bin/icuexportdata --mode uprops --index --copyright --destdir icuexportdata_uprops_sample/small --trie-type small AHex gc nt Basic_Emoji sc WSpace blank
+      displayName: 'Build Unicode property data export file (Sample)'
+    - task: PublishBuildArtifacts@1
+      displayName: 'Publish Artifact: icuexportdata_uprops_full'
+      inputs:
+        PathtoPublish: 'icu4c/source/icuexportdata_uprops_full'
+        ArtifactName: 'icuexportdata_uprops_full'
+    - task: PublishBuildArtifacts@1
+      displayName: 'Publish Artifact: icuexportdata_uprops_sample'
+      inputs:
+        PathtoPublish: 'icu4c/source/icuexportdata_uprops_sample'
+        ArtifactName: 'icuexportdata_uprops_sample'
index c983aea9d56b711388e473fa9ac9009dd95cbe4c..82395bd7979fe8d1bc08ea0ec51d801c49e98aee 100644 (file)
@@ -351,6 +351,14 @@ run \`make dist\`.
         archive](https://sourceforge.net/p/icu/mailman/message/36275940/) for
         advice.~~
 
+#### Output of icuexportdata:
+
+This step publishes pre-processed Unicode property data, which may be ingested by downstream clients such as ICU4X.
+
+*   Using the output from the build bots:
+    *   Navigate to the Azure Pipelines artifacts as described in the previous section
+    *   Download the files named *icuexportdata_uprops_full.zip* and *icuexportdata_uprops_sample.zip*
+
 ### Signing archives and creating checksums:
 
 #### Step 1. PGP files:
index 858ad6ba9b4b4bfb0e0dbe265df55865fdb53409..48de0977128a34b94723ff59050cb5f63fe840b5 100644 (file)
@@ -106,7 +106,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pkgdata", "..\tools\pkgdata
                {73C0A65B-D1F2-4DE1-B3A6-15DAD2C23F3D} = {73C0A65B-D1F2-4DE1-B3A6-15DAD2C23F3D}
        EndProjectSection
 EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "icuwriteuprops", "..\tools\icuwriteuprops\icuwriteuprops.vcxproj", "{C5185F6D-BC0A-4DF7-A63C-B107D1C9C82F}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "icuexportdata", "..\tools\icuexportdata\icuexportdata.vcxproj", "{C5185F6D-BC0A-4DF7-A63C-B107D1C9C82F}"
        ProjectSection(ProjectDependencies) = postProject
                {6B231032-3CB5-4EED-9210-810D666A23A0} = {6B231032-3CB5-4EED-9210-810D666A23A0}
                {73C0A65B-D1F2-4DE1-B3A6-15DAD2C23F3D} = {73C0A65B-D1F2-4DE1-B3A6-15DAD2C23F3D}
index 9f8d19ec5b45a145df9147438264b6d0c46f5229..220591aae3356e0dfee5d471c00c1bf78ec6f904 100755 (executable)
@@ -8061,7 +8061,7 @@ echo "CXXFLAGS=$CXXFLAGS"
 
 
 # output the Makefiles
-ac_config_files="$ac_config_files icudefs.mk Makefile data/pkgdataMakefile config/Makefile.inc config/icu.pc config/pkgdataMakefile data/Makefile stubdata/Makefile common/Makefile i18n/Makefile layoutex/Makefile io/Makefile extra/Makefile extra/uconv/Makefile extra/uconv/pkgdataMakefile extra/scrptrun/Makefile tools/Makefile tools/ctestfw/Makefile tools/toolutil/Makefile tools/makeconv/Makefile tools/genrb/Makefile tools/genccode/Makefile tools/gencmn/Makefile tools/gencnval/Makefile tools/gendict/Makefile tools/gentest/Makefile tools/gennorm2/Makefile tools/genbrk/Makefile tools/gensprep/Makefile tools/icuinfo/Makefile tools/icupkg/Makefile tools/icuswap/Makefile tools/pkgdata/Makefile tools/icuwriteuprops/Makefile tools/tzcode/Makefile tools/gencfu/Makefile tools/escapesrc/Makefile test/Makefile test/compat/Makefile test/testdata/Makefile test/testdata/pkgdataMakefile test/hdrtst/Makefile test/intltest/Makefile test/cintltst/Makefile test/iotest/Makefile test/letest/Makefile test/perf/Makefile test/perf/collationperf/Makefile test/perf/collperf/Makefile test/perf/collperf2/Makefile test/perf/dicttrieperf/Makefile test/perf/ubrkperf/Makefile test/perf/charperf/Makefile test/perf/convperf/Makefile test/perf/localecanperf/Makefile test/perf/normperf/Makefile test/perf/DateFmtPerf/Makefile test/perf/howExpensiveIs/Makefile test/perf/strsrchperf/Makefile test/perf/unisetperf/Makefile test/perf/usetperf/Makefile test/perf/ustrperf/Makefile test/perf/utfperf/Makefile test/perf/utrie2perf/Makefile test/perf/leperf/Makefile test/fuzzer/Makefile samples/Makefile samples/date/Makefile samples/cal/Makefile samples/layout/Makefile"
+ac_config_files="$ac_config_files icudefs.mk Makefile data/pkgdataMakefile config/Makefile.inc config/icu.pc config/pkgdataMakefile data/Makefile stubdata/Makefile common/Makefile i18n/Makefile layoutex/Makefile io/Makefile extra/Makefile extra/uconv/Makefile extra/uconv/pkgdataMakefile extra/scrptrun/Makefile tools/Makefile tools/ctestfw/Makefile tools/toolutil/Makefile tools/makeconv/Makefile tools/genrb/Makefile tools/genccode/Makefile tools/gencmn/Makefile tools/gencnval/Makefile tools/gendict/Makefile tools/gentest/Makefile tools/gennorm2/Makefile tools/genbrk/Makefile tools/gensprep/Makefile tools/icuinfo/Makefile tools/icupkg/Makefile tools/icuswap/Makefile tools/pkgdata/Makefile tools/icuexportdata/Makefile tools/tzcode/Makefile tools/gencfu/Makefile tools/escapesrc/Makefile test/Makefile test/compat/Makefile test/testdata/Makefile test/testdata/pkgdataMakefile test/hdrtst/Makefile test/intltest/Makefile test/cintltst/Makefile test/iotest/Makefile test/letest/Makefile test/perf/Makefile test/perf/collationperf/Makefile test/perf/collperf/Makefile test/perf/collperf2/Makefile test/perf/dicttrieperf/Makefile test/perf/ubrkperf/Makefile test/perf/charperf/Makefile test/perf/convperf/Makefile test/perf/localecanperf/Makefile test/perf/normperf/Makefile test/perf/DateFmtPerf/Makefile test/perf/howExpensiveIs/Makefile test/perf/strsrchperf/Makefile test/perf/unisetperf/Makefile test/perf/usetperf/Makefile test/perf/ustrperf/Makefile test/perf/utfperf/Makefile test/perf/utrie2perf/Makefile test/perf/leperf/Makefile test/fuzzer/Makefile samples/Makefile samples/date/Makefile samples/cal/Makefile samples/layout/Makefile"
 
 cat >confcache <<\_ACEOF
 # This file is a shell script that caches the results of configure
@@ -8804,7 +8804,7 @@ do
     "tools/icupkg/Makefile") CONFIG_FILES="$CONFIG_FILES tools/icupkg/Makefile" ;;
     "tools/icuswap/Makefile") CONFIG_FILES="$CONFIG_FILES tools/icuswap/Makefile" ;;
     "tools/pkgdata/Makefile") CONFIG_FILES="$CONFIG_FILES tools/pkgdata/Makefile" ;;
-    "tools/icuwriteuprops/Makefile") CONFIG_FILES="$CONFIG_FILES tools/icuwriteuprops/Makefile" ;;
+    "tools/icuexportdata/Makefile") CONFIG_FILES="$CONFIG_FILES tools/icuexportdata/Makefile" ;;
     "tools/tzcode/Makefile") CONFIG_FILES="$CONFIG_FILES tools/tzcode/Makefile" ;;
     "tools/gencfu/Makefile") CONFIG_FILES="$CONFIG_FILES tools/gencfu/Makefile" ;;
     "tools/escapesrc/Makefile") CONFIG_FILES="$CONFIG_FILES tools/escapesrc/Makefile" ;;
index decc0684ca2726279bcfceea8d0ec4bf0dc372da..22c11af06a326c44dc205bc85cf3d215df207923 100644 (file)
@@ -1389,7 +1389,7 @@ AC_CONFIG_FILES([icudefs.mk \
                tools/icupkg/Makefile \
                tools/icuswap/Makefile \
                tools/pkgdata/Makefile \
-               tools/icuwriteuprops/Makefile \
+               tools/icuexportdata/Makefile \
                tools/tzcode/Makefile \
                tools/gencfu/Makefile \
                tools/escapesrc/Makefile \
index 74f60d4acef5afa9335a5f13986d2676c0691f82..e0896f120615e44200e0a000e854da640ca88219 100644 (file)
@@ -17,7 +17,7 @@ subdir = tools
 
 SUBDIRS = toolutil ctestfw makeconv genrb genbrk \
 gencnval gensprep icuinfo genccode gencmn icupkg pkgdata \
-gentest gennorm2 gencfu gendict icuwriteuprops
+gentest gennorm2 gencfu gendict icuexportdata
 
 ifneq (@platform_make_fragment_name@,mh-cygwin-msvc)
 SUBDIRS += escapesrc
similarity index 95%
rename from icu4c/source/tools/icuwriteuprops/Makefile.in
rename to icu4c/source/tools/icuexportdata/Makefile.in
index d4f5fa270de101f04ae3037a18cb4c3f5e89e3ae..6899d74d1b06abe33afce23f07ba6eecb379b328 100644 (file)
@@ -1,4 +1,4 @@
-## Makefile.in for ICU - tools/icuwriteuprops
+## Makefile.in for ICU - tools/icuexportdata
 ## Copyright (C) 2021 and later: Unicode, Inc. and others.
 ## License & terms of use: http://www.unicode.org/copyright.html
 
@@ -11,9 +11,9 @@ top_builddir = ../..
 include $(top_builddir)/icudefs.mk
 
 ## Build directory information
-subdir = tools/icuwriteuprops
+subdir = tools/icuexportdata
 
-TARGET_STUB_NAME = icuwriteuprops
+TARGET_STUB_NAME = icuexportdata
 
 SECTION = 1
 
similarity index 81%
rename from icu4c/source/tools/icuwriteuprops/icuwriteuprops.1.in
rename to icu4c/source/tools/icuexportdata/icuexportdata.1.in
index 5f0e405ee88257b88b5618445232ae996494553e..71243ef053537fa58f5e01cd050aac757879794a 100644 (file)
@@ -1,6 +1,6 @@
 .\" Hey, Emacs! This is -*-nroff-*- you know...
 .\"
-.\" icuwriteuprops.1: manual page for the icuwriteuprops utility
+.\" icuexportdata.1: manual page for the icuexportdata utility
 .\"
 .\" Copyright (C) 2016 and later: Unicode, Inc. and others.
 .\" License & terms of use: http://www.unicode.org/copyright.html
@@ -9,5 +9,5 @@
 .\"
 .TH MAKECONV 1 "12 June 2021" "ICU MANPAGE" "ICU @VERSION@ Manual"
 .SH NAME
-.B icuwriteuprops
+.B icuexportdata
 \- Writes text files with Unicode properties data from ICU.
similarity index 57%
rename from icu4c/source/tools/icuwriteuprops/icuwriteuprops.cpp
rename to icu4c/source/tools/icuexportdata/icuexportdata.cpp
index 9a74efaf0f5ff33295503fd6a3670bb1c39d9208..737f891c515ac6e3fe7ca125d533a6c08d2bf5bc 100644 (file)
@@ -2,6 +2,7 @@
 // License & terms of use: http://www.unicode.org/copyright.html
 
 #include <iostream>
+#include <vector>
 #include "toolutil.h"
 #include "uoptions.h"
 #include "cmemory.h"
@@ -24,6 +25,7 @@ UBool QUIET = FALSE;
 
 UBool haveCopyright = TRUE;
 UCPTrieType trieType = UCPTRIE_TYPE_SMALL;
+const char* destdir = "";
 
 void handleError(ErrorCode& status, const char* context) {
     if (status.isFailure()) {
@@ -33,7 +35,7 @@ void handleError(ErrorCode& status, const char* context) {
 }
 
 void dumpBinaryProperty(UProperty uproperty, FILE* f) {
-    IcuToolErrorCode status("icuwriteuprops: dumpBinaryProperty");
+    IcuToolErrorCode status("icuexportdata: dumpBinaryProperty");
     const char* fullPropName = u_getPropertyName(uproperty, U_LONG_PROPERTY_NAME);
     const char* shortPropName = u_getPropertyName(uproperty, U_SHORT_PROPERTY_NAME);
     const USet* uset = u_getBinaryPropertySet(uproperty, status);
@@ -41,12 +43,12 @@ void dumpBinaryProperty(UProperty uproperty, FILE* f) {
 
     fputs("[[binary_property]]\n", f);
     fprintf(f, "long_name = \"%s\"\n", fullPropName);
-    fprintf(f, "short_name = \"%s\"\n", shortPropName);
+    if (shortPropName) fprintf(f, "short_name = \"%s\"\n", shortPropName);
     usrc_writeUnicodeSet(f, uset, UPRV_TARGET_SYNTAX_TOML);
 }
 
 void dumpEnumeratedProperty(UProperty uproperty, FILE* f) {
-    IcuToolErrorCode status("icuwriteuprops: dumpEnumeratedProperty");
+    IcuToolErrorCode status("icuexportdata: dumpEnumeratedProperty");
     const char* fullPropName = u_getPropertyName(uproperty, U_LONG_PROPERTY_NAME);
     const char* shortPropName = u_getPropertyName(uproperty, U_SHORT_PROPERTY_NAME);
     const UCPMap* umap = u_getIntPropertyMap(uproperty, status);
@@ -54,7 +56,7 @@ void dumpEnumeratedProperty(UProperty uproperty, FILE* f) {
 
     fputs("[[enum_property]]\n", f);
     fprintf(f, "long_name = \"%s\"\n", fullPropName);
-    fprintf(f, "short_name = \"%s\"\n", shortPropName);
+    if (shortPropName) fprintf(f, "short_name = \"%s\"\n", shortPropName);
     usrc_writeUCPMap(f, umap, uproperty, UPRV_TARGET_SYNTAX_TOML);
     fputs("\n", f);
 
@@ -79,34 +81,69 @@ void dumpEnumeratedProperty(UProperty uproperty, FILE* f) {
     usrc_writeUCPTrie(f, shortPropName, utrie.getAlias(), UPRV_TARGET_SYNTAX_TOML);
 }
 
+FILE* prepareOutputFile(const char* basename) {
+    IcuToolErrorCode status("icuexportdata");
+    CharString outFileName;
+    if (destdir != nullptr && *destdir != 0) {
+        outFileName.append(destdir, status).ensureEndsWithFileSeparator(status);
+    }
+    outFileName.append(basename, status);
+    outFileName.append(".toml", status);
+    handleError(status, basename);
+
+    FILE* f = fopen(outFileName.data(), "w");
+    if (f == nullptr) {
+        std::cerr << "Unable to open file: " << outFileName.data() << std::endl;
+        exit(U_FILE_ACCESS_ERROR);
+    }
+    if (!QUIET) {
+        std::cout << "Writing to: " << outFileName.data() << std::endl;
+    }
+
+    if (haveCopyright) {
+        usrc_writeCopyrightHeader(f, "#", 2021);
+    }
+    usrc_writeFileNameGeneratedBy(f, "#", basename, "icuexportdata.cpp");
+
+    return f;
+}
+
 enum {
     OPT_HELP_H,
     OPT_HELP_QUESTION_MARK,
-    OPT_COPYRIGHT,
+    OPT_MODE,
     OPT_TRIE_TYPE,
     OPT_VERSION,
     OPT_DESTDIR,
+    OPT_ALL,
+    OPT_INDEX,
+    OPT_COPYRIGHT,
     OPT_VERBOSE,
     OPT_QUIET,
 
     OPT_COUNT
 };
 
-#define UOPTION_TRIE_TYPE UOPTION_DEF("trie-type", 't', UOPT_REQUIRES_ARG)
+#define UOPTION_MODE UOPTION_DEF("mode", 'm', UOPT_REQUIRES_ARG)
+#define UOPTION_TRIE_TYPE UOPTION_DEF("trie-type", '\1', UOPT_REQUIRES_ARG)
+#define UOPTION_ALL UOPTION_DEF("all", '\1', UOPT_NO_ARG)
+#define UOPTION_INDEX UOPTION_DEF("index", '\1', UOPT_NO_ARG)
 
 static UOption options[]={
     UOPTION_HELP_H,
     UOPTION_HELP_QUESTION_MARK,
-    UOPTION_COPYRIGHT,
+    UOPTION_MODE,
     UOPTION_TRIE_TYPE,
     UOPTION_VERSION,
     UOPTION_DESTDIR,
+    UOPTION_ALL,
+    UOPTION_INDEX,
+    UOPTION_COPYRIGHT,
     UOPTION_VERBOSE,
     UOPTION_QUIET,
 };
 
 int main(int argc, char* argv[]) {
-
     U_MAIN_INIT_ARGS(argc, argv);
 
     /* preset then read command line options */
@@ -114,7 +151,7 @@ int main(int argc, char* argv[]) {
     argc=u_parseArgs(argc, argv, UPRV_LENGTHOF(options), options);
 
     if(options[OPT_VERSION].doesOccur) {
-        printf("icuwriteuprops version %s, ICU tool to write Unicode property .toml files\n",
+        printf("icuexportdata version %s, ICU tool to dump data files for external consumers\n",
                U_ICU_DATA_VERSION);
         printf("%s\n", U_COPYRIGHT_STRING);
         exit(0);
@@ -129,28 +166,64 @@ int main(int argc, char* argv[]) {
         argc=-1;
     }
 
-    if(argc<0 || options[OPT_HELP_H].doesOccur || options[OPT_HELP_QUESTION_MARK].doesOccur) {
+    /* get the options values */
+    haveCopyright = options[OPT_COPYRIGHT].doesOccur;
+    destdir = options[OPT_DESTDIR].value;
+    VERBOSE = options[OPT_VERBOSE].doesOccur;
+    QUIET = options[OPT_QUIET].doesOccur;
+
+    // Load list of Unicode properties
+    std::vector<const char*> propNames;
+    for (int i=1; i<argc; i++) {
+        propNames.push_back(argv[i]);
+    }
+    if (options[OPT_ALL].doesOccur) {
+        for (int i=UCHAR_BINARY_START; i<UCHAR_INT_LIMIT; i++) {
+            if (i == UCHAR_BINARY_LIMIT) {
+                i = UCHAR_INT_START;
+            }
+            UProperty uprop = static_cast<UProperty>(i);
+            const char* propName = u_getPropertyName(uprop, U_SHORT_PROPERTY_NAME);
+            if (propName == NULL) {
+                propName = u_getPropertyName(uprop, U_LONG_PROPERTY_NAME);
+                if (propName != NULL && VERBOSE) {
+                    std::cerr << "Note: falling back to long name for: " << propName << std::endl;
+                }
+            }
+            if (propName != NULL) {
+                propNames.push_back(propName);
+            }
+        }
+    }
+
+    if (propNames.empty()
+            || options[OPT_HELP_H].doesOccur
+            || options[OPT_HELP_QUESTION_MARK].doesOccur
+            || !options[OPT_MODE].doesOccur) {
         FILE *stdfile=argc<0 ? stderr : stdout;
         fprintf(stdfile,
-            "usage: %s [-options] properties...\n"
+            "usage: %s -m uprops [-options] [--all | properties...]\n"
             "\tdump Unicode property data to .toml files\n"
             "options:\n"
             "\t-h or -? or --help  this usage text\n"
             "\t-V or --version     show a version message\n"
-            "\t-c or --copyright   include a copyright notice\n"
-            "\t-t or --trie-type   set the trie type (small or fast, default small)\n"
+            "\t-m or --mode        mode: currently only 'uprops', but more may be added\n"
+            "\t      --trie-type   set the trie type (small or fast, default small)\n"
             "\t-d or --destdir     destination directory, followed by the path\n"
+            "\t      --all         write out all properties known to icuexportdata\n"
+            "\t      --index       write an _index.toml summarizing all data exported\n"
+            "\t-c or --copyright   include a copyright notice\n"
             "\t-v or --verbose     Turn on verbose output\n"
             "\t-q or --quiet       do not display warnings and progress\n",
             argv[0]);
         return argc<0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR;
     }
 
-    /* get the options values */
-    haveCopyright = options[OPT_COPYRIGHT].doesOccur;
-    const char *destdir = options[OPT_DESTDIR].value;
-    VERBOSE = options[OPT_VERBOSE].doesOccur;
-    QUIET = options[OPT_QUIET].doesOccur;
+    const char* mode = options[OPT_MODE].value;
+    if (uprv_strcmp(mode, "uprops") != 0) {
+        fprintf(stderr, "Invalid option for --mode (must be uprops)\n");
+        return U_ILLEGAL_ARGUMENT_ERROR;
+    }
 
     if (options[OPT_TRIE_TYPE].doesOccur) {
         if (uprv_strcmp(options[OPT_TRIE_TYPE].value, "fast") == 0) {
@@ -163,36 +236,22 @@ int main(int argc, char* argv[]) {
         }
     }
 
-    for (int i=1; i<argc; i++) {
-        auto propName = argv[i];
+    for (const char* propName : propNames) {
         UProperty propEnum = u_getPropertyEnum(propName);
         if (propEnum == UCHAR_INVALID_CODE) {
             std::cerr << "Error: Invalid property alias: " << propName << std::endl;
             return U_ILLEGAL_ARGUMENT_ERROR;
         }
 
-        IcuToolErrorCode status("icuwriteuprops");
-        CharString outFileName;
-        if (destdir != nullptr && *destdir != 0) {
-            outFileName.append(destdir, status).ensureEndsWithFileSeparator(status);
-        }
-        outFileName.append(propName, status);
-        outFileName.append(".toml", status);
-        handleError(status, propName);
-
-        FILE* f = fopen(outFileName.data(), "w");
-        if (f == nullptr) {
-            std::cerr << "Unable to open file: " << outFileName.data() << std::endl;
-            return U_FILE_ACCESS_ERROR;
-        }
-        if (!QUIET) {
-            std::cout << "Writing to: " << outFileName.data() << std::endl;
-        }
+        FILE* f = prepareOutputFile(propName);
 
-        if (haveCopyright) {
-            usrc_writeCopyrightHeader(f, "#", 2021);
-        }
-        usrc_writeFileNameGeneratedBy(f, "#", propName, "icuwriteuprops.cpp");
+        UVersionInfo versionInfo;
+        u_getUnicodeVersion(versionInfo);
+        char uvbuf[U_MAX_VERSION_STRING_LENGTH];
+        u_versionToString(versionInfo, uvbuf);
+        fprintf(f, "icu_version = \"%s\"\nunicode_version = \"%s\"\n\n",
+            U_ICU_VERSION,
+            uvbuf);
 
         if (propEnum < UCHAR_BINARY_LIMIT) {
             dumpBinaryProperty(propEnum, f);
@@ -205,4 +264,17 @@ int main(int argc, char* argv[]) {
 
         fclose(f);
     }
+
+    if (options[OPT_INDEX].doesOccur) {
+        FILE* f = prepareOutputFile("_index");
+        fprintf(f, "index = [\n");
+        for (const char* propName : propNames) {
+            // At this point, propName is a valid property name, so it should be alphanum ASCII
+            fprintf(f, "  { filename=\"%s.toml\" },\n", propName);
+        }
+        fprintf(f, "]\n");
+        fclose(f);
+    }
+
+    return 0;
 }
similarity index 90%
rename from icu4c/source/tools/icuwriteuprops/icuwriteuprops.vcxproj
rename to icu4c/source/tools/icuexportdata/icuexportdata.vcxproj
index 046652eefa58a0792ad1a08e5bddc12cf899b1ed..48b4c23cf8bd20afd37203909bedc020fc00bf83 100644 (file)
   <!-- Options that are common to *all* configurations -->
   <ItemDefinitionGroup>
     <Midl>
-      <TypeLibraryName>$(OutDir)/icuwriteuprops.tlb</TypeLibraryName>
+      <TypeLibraryName>$(OutDir)/icuexportdata.tlb</TypeLibraryName>
     </Midl>
     <ClCompile>
       <WarningLevel>Level3</WarningLevel>
       <CompileAs>Default</CompileAs>
       <DisableLanguageExtensions>false</DisableLanguageExtensions>
       <AdditionalIncludeDirectories>..\..\..\include;..\..\common;..\toolutil;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <PrecompiledHeaderOutputFile>$(OutDir)/icuwriteuprops.pch</PrecompiledHeaderOutputFile>
+      <PrecompiledHeaderOutputFile>$(OutDir)/icuexportdata.pch</PrecompiledHeaderOutputFile>
       <AssemblerListingLocation>$(OutDir)/</AssemblerListingLocation>
       <ObjectFileName>$(OutDir)/</ObjectFileName>
-      <ProgramDataBaseFileName>$(OutDir)/icuwriteuprops.pdb</ProgramDataBaseFileName>
+      <ProgramDataBaseFileName>$(OutDir)/icuexportdata.pdb</ProgramDataBaseFileName>
     </ClCompile>
     <Link>
       <SubSystem>Console</SubSystem>
-      <OutputFile>$(OutDir)/icuwriteuprops.exe</OutputFile>
+      <OutputFile>$(OutDir)/icuexportdata.exe</OutputFile>
       <AdditionalLibraryDirectories>..\..\..\$(IcuLibOutputDir);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
     </Link>
     <CustomBuildStep>
@@ -72,7 +72,7 @@
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup>
-    <ClCompile Include="icuwriteuprops.cpp" />
+    <ClCompile Include="icuexportdata.cpp" />
   </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
similarity index 93%
rename from icu4c/source/tools/icuwriteuprops/icuwriteuprops.vcxproj.filters
rename to icu4c/source/tools/icuexportdata/icuexportdata.vcxproj.filters
index 966815c2540f6f0193b65c70e8cd65de6f3145f7..02b3257ba3273ef516f10e38344523790ea310d9 100644 (file)
@@ -15,7 +15,7 @@
     </Filter>
   </ItemGroup>
   <ItemGroup>
-    <ClCompile Include="icuwriteuprops.cpp">
+    <ClCompile Include="icuexportdata.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
   </ItemGroup>
diff --git a/icu4c/source/tools/icuexportdata/sources.txt b/icu4c/source/tools/icuexportdata/sources.txt
new file mode 100644 (file)
index 0000000..13520ec
--- /dev/null
@@ -0,0 +1 @@
+icuexportdata.cpp
diff --git a/icu4c/source/tools/icuwriteuprops/sources.txt b/icu4c/source/tools/icuwriteuprops/sources.txt
deleted file mode 100644 (file)
index bce8117..0000000
+++ /dev/null
@@ -1 +0,0 @@
-icuwriteuprops.cpp