Index: build_tools/write_icudata_lst.py |
diff --git a/build_tools/write_icudata_lst.py b/build_tools/write_icudata_lst.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..40e9ff34cffb4338fec71511928c339c5a2551d7 |
--- /dev/null |
+++ b/build_tools/write_icudata_lst.py |
@@ -0,0 +1,77 @@ |
+"""Writes the icudata.lst file icupkg needs based on the information the gyp/gn |
+generators can give it.""" |
+ |
+from __future__ import print_function |
+ |
+import argparse |
+import os |
+import sys |
+ |
+def change_ext(path, new_ext): |
+ return os.path.splitext(path)[0] + new_ext |
+ |
+def main(): |
+ parser = argparse.ArgumentParser( |
+ description=('Generates an icudata.lst file to be compiled by icu.')) |
+ |
+ parser.add_argument('--inroot', |
+ required=True, |
+ help='The root of the indata files.') |
+ |
+ parser.add_argument('--infile', |
+ help='File that should contain a raw list.') |
+ |
+ parser.add_argument('--outfile', |
+ required=True, |
+ help='File that will contain an ICU formatted list.') |
+ |
+ parser.add_argument('--PRODUCT_DIR', |
+ help=('The value of the PRODUCT_DIR env var. ' + |
+ 'Either this or --gn-root needs to be set.')) |
+ |
+ parser.add_argument('--gn-root', |
+ help=('The root of the gn build dir. Either this ' |
+ ' or PRODUCT_DIR (for gyp) must be set')) |
+ |
+ parser.add_argument('files', |
+ nargs='*', |
+ help=('Files that were processed. Will magically ' |
+ 'be mapped to result files by this script.')) |
+ |
+ args = parser.parse_args() |
+ |
+ if args.gn_root is None and args.PRODUCT_DIR is None: |
+ print('One of --gn-root and --PRODUCT_DIR must be set.') |
+ sys.exit(1) |
+ |
+ def map_to_result(filepath): |
+ filepath = filepath.strip() |
+ if args.PRODUCT_DIR is not None: |
+ # gyp for Ninja. |
+ filepath = filepath.replace('$!PRODUCT_DIR', args.PRODUCT_DIR) |
+ # gyp for Make. |
+ filepath = filepath.replace('$(obj)', args.PRODUCT_DIR + '/obj') |
+ if args.gn_root is not None: |
+ filepath = filepath.replace('//', args.gn_root + '/') |
+ if len(filepath) > 1 and filepath[0] == filepath[-1] == '"': |
+ # Strip quote. |
+ filepath = filepath[1:-1] |
+ short_path = os.path.relpath(filepath, args.inroot) |
+ if short_path.startswith('..'): |
+ short_path = filepath |
+ return short_path |
+ |
+ tmp_file = args.outfile + '.tmp' |
+ with open(tmp_file, 'w') as icudata_lst: |
+ if args.infile: |
+ with open(args.infile, 'r') as infile: |
+ for filename in infile: |
+ icudata_lst.write('%s\n' % map_to_result(filename)) |
+ for filename in args.files: |
+ icudata_lst.write('%s\n' % map_to_result(filename)) |
+ if os.path.isfile(args.outfile): |
+ os.unlink(args.outfile) |
+ os.rename(tmp_file, args.outfile) |
+ |
+if __name__ == '__main__': |
+ main() |