1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
|
# Copyright (C) 2018 and later: Unicode, Inc. and others.
# License & terms of use: http://www.unicode.org/copyright.html
# Python 2/3 Compatibility (ICU-20299)
# TODO(ICU-20301): Remove this.
from __future__ import print_function
from icutools.databuilder import *
from icutools.databuilder import utils
from icutools.databuilder.request_types import *
import os
import sys
def generate(config, io, common_vars):
requests = []
if len(io.glob("misc/*")) == 0:
print("Error: Cannot find data directory; please specify --src_dir", file=sys.stderr)
exit(1)
requests += generate_cnvalias(config, io, common_vars)
requests += generate_ulayout(config, io, common_vars)
requests += generate_uemoji(config, io, common_vars)
requests += generate_confusables(config, io, common_vars)
requests += generate_conversion_mappings(config, io, common_vars)
requests += generate_brkitr_brk(config, io, common_vars)
requests += generate_brkitr_lstm(config, io, common_vars)
requests += generate_brkitr_adaboost(config, io, common_vars)
requests += generate_stringprep(config, io, common_vars)
requests += generate_brkitr_dictionaries(config, io, common_vars)
requests += generate_normalization(config, io, common_vars)
requests += generate_coll_ucadata(config, io, common_vars)
requests += generate_full_unicore_data(config, io, common_vars)
requests += generate_unames(config, io, common_vars)
requests += generate_misc(config, io, common_vars)
requests += generate_curr_supplemental(config, io, common_vars)
requests += generate_zone_supplemental(config, io, common_vars)
requests += generate_translit(config, io, common_vars)
# Res Tree Files
# (input dirname, output dirname, resfiles.mk path, mk version var, mk source var, use pool file, dep files)
requests += generate_tree(config, io, common_vars,
"locales",
None,
config.use_pool_bundle,
[])
requests += generate_tree(config, io, common_vars,
"curr",
"curr",
config.use_pool_bundle,
[])
requests += generate_tree(config, io, common_vars,
"lang",
"lang",
config.use_pool_bundle,
[])
requests += generate_tree(config, io, common_vars,
"region",
"region",
config.use_pool_bundle,
[])
requests += generate_tree(config, io, common_vars,
"zone",
"zone",
config.use_pool_bundle,
[])
requests += generate_tree(config, io, common_vars,
"unit",
"unit",
config.use_pool_bundle,
[])
requests += generate_tree(config, io, common_vars,
"coll",
"coll",
# Never use pool bundle for coll, brkitr, or rbnf
False,
# Depends on timezoneTypes.res and keyTypeData.res.
# TODO: We should not need this dependency to build collation.
# TODO: Bake keyTypeData.res into the common library?
[DepTarget("coll_ucadata"), DepTarget("misc_res"), InFile("unidata/UCARules.txt")])
requests += generate_tree(config, io, common_vars,
"brkitr",
"brkitr",
# Never use pool bundle for coll, brkitr, or rbnf
False,
[DepTarget("brkitr_brk"), DepTarget("dictionaries")])
requests += generate_tree(config, io, common_vars,
"rbnf",
"rbnf",
# Never use pool bundle for coll, brkitr, or rbnf
False,
[])
requests += [
ListRequest(
name = "icudata_list",
variable_name = "icudata_all_output_files",
output_file = TmpFile("icudata.lst"),
include_tmp = False
)
]
return requests
def generate_cnvalias(config, io, common_vars):
# UConv Name Aliases
input_file = InFile("mappings/convrtrs.txt")
output_file = OutFile("cnvalias.icu")
return [
SingleExecutionRequest(
name = "cnvalias",
category = "cnvalias",
dep_targets = [],
input_files = [input_file],
output_files = [output_file],
tool = IcuTool("gencnval"),
args = "-s {IN_DIR} -d {OUT_DIR} "
"{INPUT_FILES[0]}",
format_with = {}
)
]
def generate_confusables(config, io, common_vars):
# CONFUSABLES
txt1 = InFile("unidata/confusables.txt")
txt2 = InFile("unidata/confusablesWholeScript.txt")
cfu = OutFile("confusables.cfu")
return [
SingleExecutionRequest(
name = "confusables",
category = "confusables",
dep_targets = [DepTarget("cnvalias")],
input_files = [txt1, txt2],
output_files = [cfu],
tool = IcuTool("gencfu"),
args = "-d {OUT_DIR} -i {OUT_DIR} "
"-c -r {IN_DIR}/{INPUT_FILES[0]} -w {IN_DIR}/{INPUT_FILES[1]} "
"-o {OUTPUT_FILES[0]}",
format_with = {}
)
]
def generate_conversion_mappings(config, io, common_vars):
# UConv Conversion Table Files
input_files = [InFile(filename) for filename in io.glob("mappings/*.ucm")]
output_files = [OutFile("%s.cnv" % v.filename[9:-4]) for v in input_files]
# TODO: handle BUILD_SPECIAL_CNV_FILES? Means to add --ignore-siso-check flag to makeconv
return [
RepeatedOrSingleExecutionRequest(
name = "conversion_mappings",
category = "conversion_mappings",
dep_targets = [],
input_files = input_files,
output_files = output_files,
tool = IcuTool("makeconv"),
args = "-s {IN_DIR} -d {OUT_DIR} -c {INPUT_FILE_PLACEHOLDER}",
format_with = {},
repeat_with = {
"INPUT_FILE_PLACEHOLDER": utils.SpaceSeparatedList(file.filename for file in input_files)
}
)
]
def generate_brkitr_brk(config, io, common_vars):
# BRK Files
input_files = [InFile(filename) for filename in io.glob("brkitr/rules/*.txt")]
output_files = [OutFile("brkitr/%s.brk" % v.filename[13:-4]) for v in input_files]
return [
RepeatedExecutionRequest(
name = "brkitr_brk",
category = "brkitr_rules",
dep_targets =
[DepTarget("cnvalias"),
DepTarget("ulayout"), DepTarget("uemoji"), DepTarget("lstm_res"), DepTarget("adaboost_res")],
input_files = input_files,
output_files = output_files,
tool = IcuTool("genbrk"),
args = "-d {OUT_DIR} -i {OUT_DIR} "
"-c -r {IN_DIR}/{INPUT_FILE} "
"-o {OUTPUT_FILE}",
format_with = {},
repeat_with = {}
)
]
def generate_stringprep(config, io, common_vars):
# SPP FILES
input_files = [InFile(filename) for filename in io.glob("sprep/*.txt")]
output_files = [OutFile("%s.spp" % v.filename[6:-4]) for v in input_files]
bundle_names = [v.filename[6:-4] for v in input_files]
return [
RepeatedExecutionRequest(
name = "stringprep",
category = "stringprep",
dep_targets = [InFile("unidata/NormalizationCorrections.txt")],
input_files = input_files,
output_files = output_files,
tool = IcuTool("gensprep"),
args = "-s {IN_DIR}/sprep -d {OUT_DIR} -i {OUT_DIR} "
"-b {BUNDLE_NAME} -m {IN_DIR}/unidata -u 3.2.0 {BUNDLE_NAME}.txt",
format_with = {},
repeat_with = {
"BUNDLE_NAME": bundle_names
}
)
]
def generate_brkitr_dictionaries(config, io, common_vars):
# Dict Files
input_files = [InFile(filename) for filename in io.glob("brkitr/dictionaries/*.txt")]
output_files = [OutFile("brkitr/%s.dict" % v.filename[20:-4]) for v in input_files]
extra_options_map = {
"brkitr/dictionaries/burmesedict.txt": "--bytes --transform offset-0x1000",
"brkitr/dictionaries/cjdict.txt": "--uchars",
"brkitr/dictionaries/khmerdict.txt": "--bytes --transform offset-0x1780",
"brkitr/dictionaries/laodict.txt": "--bytes --transform offset-0x0e80",
"brkitr/dictionaries/thaidict.txt": "--bytes --transform offset-0x0e00"
}
extra_optionses = [extra_options_map[v.filename] for v in input_files]
return [
RepeatedExecutionRequest(
name = "dictionaries",
category = "brkitr_dictionaries",
dep_targets = [],
input_files = input_files,
output_files = output_files,
tool = IcuTool("gendict"),
args = "-i {OUT_DIR} "
"-c {EXTRA_OPTIONS} "
"{IN_DIR}/{INPUT_FILE} {OUT_DIR}/{OUTPUT_FILE}",
format_with = {},
repeat_with = {
"EXTRA_OPTIONS": extra_optionses
}
)
]
def generate_normalization(config, io, common_vars):
# NRM Files
input_files = [InFile(filename) for filename in io.glob("in/*.nrm")]
# nfc.nrm is pre-compiled into C++; see generate_full_unicore_data
input_files.remove(InFile("in/nfc.nrm"))
output_files = [OutFile(v.filename[3:]) for v in input_files]
return [
RepeatedExecutionRequest(
name = "normalization",
category = "normalization",
dep_targets = [],
input_files = input_files,
output_files = output_files,
tool = IcuTool("icupkg"),
args = "-t{ICUDATA_CHAR} {IN_DIR}/{INPUT_FILE} {OUT_DIR}/{OUTPUT_FILE}",
format_with = {},
repeat_with = {}
)
]
def generate_coll_ucadata(config, io, common_vars):
# Collation Dependency File (ucadata.icu)
input_file = InFile("in/coll/ucadata-%s.icu" % config.coll_han_type)
output_file = OutFile("coll/ucadata.icu")
return [
SingleExecutionRequest(
name = "coll_ucadata",
category = "coll_ucadata",
dep_targets = [],
input_files = [input_file],
output_files = [output_file],
tool = IcuTool("icupkg"),
args = "-t{ICUDATA_CHAR} {IN_DIR}/{INPUT_FILES[0]} {OUT_DIR}/{OUTPUT_FILES[0]}",
format_with = {}
)
]
def generate_full_unicore_data(config, io, common_vars):
# The core Unicode properties files (pnames.icu, uprops.icu, ucase.icu, ubidi.icu)
# are hardcoded in the common DLL and therefore not included in the data package any more.
# They are not built by default but need to be built for ICU4J data,
# both in the .jar and in the .dat file (if ICU4J uses the .dat file).
# See ICU-4497.
if not config.include_uni_core_data:
return []
basenames = [
"pnames.icu",
"uprops.icu",
"ucase.icu",
"ubidi.icu",
"nfc.nrm"
]
input_files = [InFile("in/%s" % bn) for bn in basenames]
output_files = [OutFile(bn) for bn in basenames]
return [
RepeatedExecutionRequest(
name = "unicore",
category = "unicore",
input_files = input_files,
output_files = output_files,
tool = IcuTool("icupkg"),
args = "-t{ICUDATA_CHAR} {IN_DIR}/{INPUT_FILE} {OUT_DIR}/{OUTPUT_FILE}"
)
]
def generate_unames(config, io, common_vars):
# Unicode Character Names
input_file = InFile("in/unames.icu")
output_file = OutFile("unames.icu")
return [
SingleExecutionRequest(
name = "unames",
category = "unames",
dep_targets = [],
input_files = [input_file],
output_files = [output_file],
tool = IcuTool("icupkg"),
args = "-t{ICUDATA_CHAR} {IN_DIR}/{INPUT_FILES[0]} {OUT_DIR}/{OUTPUT_FILES[0]}",
format_with = {}
)
]
def generate_ulayout(config, io, common_vars):
# Unicode text layout properties
basename = "ulayout"
input_file = InFile("in/%s.icu" % basename)
output_file = OutFile("%s.icu" % basename)
return [
SingleExecutionRequest(
name = basename,
category = basename,
dep_targets = [],
input_files = [input_file],
output_files = [output_file],
tool = IcuTool("icupkg"),
args = "-t{ICUDATA_CHAR} {IN_DIR}/{INPUT_FILES[0]} {OUT_DIR}/{OUTPUT_FILES[0]}",
format_with = {}
)
]
def generate_uemoji(config, io, common_vars):
# Unicode emoji properties
basename = "uemoji"
input_file = InFile("in/%s.icu" % basename)
output_file = OutFile("%s.icu" % basename)
return [
SingleExecutionRequest(
name = basename,
category = basename,
dep_targets = [],
input_files = [input_file],
output_files = [output_file],
tool = IcuTool("icupkg"),
args = "-t{ICUDATA_CHAR} {IN_DIR}/{INPUT_FILES[0]} {OUT_DIR}/{OUTPUT_FILES[0]}",
format_with = {}
)
]
def generate_misc(config, io, common_vars):
# Misc Data Res Files
input_files = [InFile(filename) for filename in io.glob("misc/*.txt")]
input_basenames = [v.filename[5:] for v in input_files]
output_files = [OutFile("%s.res" % v[:-4]) for v in input_basenames]
return [
RepeatedExecutionRequest(
name = "misc_res",
category = "misc",
dep_targets = [DepTarget("cnvalias")], # ICU-21175
input_files = input_files,
output_files = output_files,
tool = IcuTool("genrb"),
args = "-s {IN_DIR}/misc -d {OUT_DIR} -i {OUT_DIR} "
"-k -q "
"{INPUT_BASENAME}",
format_with = {},
repeat_with = {
"INPUT_BASENAME": input_basenames
}
)
]
def generate_curr_supplemental(config, io, common_vars):
# Currency Supplemental Res File
input_file = InFile("curr/supplementalData.txt")
input_basename = "supplementalData.txt"
output_file = OutFile("curr/supplementalData.res")
return [
SingleExecutionRequest(
name = "curr_supplemental_res",
category = "curr_supplemental",
dep_targets = [],
input_files = [input_file],
output_files = [output_file],
tool = IcuTool("genrb"),
args = "-s {IN_DIR}/curr -d {OUT_DIR}/curr -i {OUT_DIR} "
"-k "
"{INPUT_BASENAME}",
format_with = {
"INPUT_BASENAME": input_basename
}
)
]
def generate_zone_supplemental(config, io, common_vars):
# tzdbNames Res File
input_file = InFile("zone/tzdbNames.txt")
input_basename = "tzdbNames.txt"
output_file = OutFile("zone/tzdbNames.res")
return [
SingleExecutionRequest(
name = "zone_supplemental_res",
category = "zone_supplemental",
dep_targets = [],
input_files = [input_file],
output_files = [output_file],
tool = IcuTool("genrb"),
args = "-s {IN_DIR}/zone -d {OUT_DIR}/zone -i {OUT_DIR} "
"-k "
"{INPUT_BASENAME}",
format_with = {
"INPUT_BASENAME": input_basename
}
)
]
def generate_translit(config, io, common_vars):
input_files = [
InFile("translit/root.txt"),
InFile("translit/en.txt"),
InFile("translit/el.txt")
]
dep_files = set(InFile(filename) for filename in io.glob("translit/*.txt"))
dep_files -= set(input_files)
dep_files = list(sorted(dep_files))
input_basenames = [v.filename[9:] for v in input_files]
output_files = [
OutFile("translit/%s.res" % v[:-4])
for v in input_basenames
]
return [
RepeatedOrSingleExecutionRequest(
name = "translit_res",
category = "translit",
dep_targets = dep_files,
input_files = input_files,
output_files = output_files,
tool = IcuTool("genrb"),
args = "-s {IN_DIR}/translit -d {OUT_DIR}/translit -i {OUT_DIR} "
"-k "
"{INPUT_BASENAME}",
format_with = {
},
repeat_with = {
"INPUT_BASENAME": utils.SpaceSeparatedList(input_basenames)
}
)
]
def generate_brkitr_lstm(config, io, common_vars):
input_files = [InFile(filename) for filename in io.glob("brkitr/lstm/*.txt")]
input_basenames = [v.filename[12:] for v in input_files]
output_files = [
OutFile("brkitr/%s.res" % v[:-4])
for v in input_basenames
]
return [
RepeatedOrSingleExecutionRequest(
name = "lstm_res",
category = "brkitr_lstm",
dep_targets = [],
input_files = input_files,
output_files = output_files,
tool = IcuTool("genrb"),
args = "-s {IN_DIR}/brkitr/lstm -d {OUT_DIR}/brkitr -i {OUT_DIR} "
"-k "
"{INPUT_BASENAME}",
format_with = {
},
repeat_with = {
"INPUT_BASENAME": utils.SpaceSeparatedList(input_basenames)
}
)
]
def generate_brkitr_adaboost(config, io, common_vars):
input_files = [InFile(filename) for filename in io.glob("brkitr/adaboost/*.txt")]
input_basenames = [v.filename[16:] for v in input_files]
output_files = [
OutFile("brkitr/%s.res" % v[:-4])
for v in input_basenames
]
return [
RepeatedOrSingleExecutionRequest(
name = "adaboost_res",
category = "brkitr_adaboost",
dep_targets = [],
input_files = input_files,
output_files = output_files,
tool = IcuTool("genrb"),
args = "-s {IN_DIR}/brkitr/adaboost -d {OUT_DIR}/brkitr -i {OUT_DIR} "
"-k "
"{INPUT_BASENAME}",
format_with = {
},
repeat_with = {
"INPUT_BASENAME": utils.SpaceSeparatedList(input_basenames)
}
)
]
def generate_tree(
config,
io,
common_vars,
sub_dir,
out_sub_dir,
use_pool_bundle,
dep_targets):
requests = []
category = "%s_tree" % sub_dir
out_prefix = "%s/" % out_sub_dir if out_sub_dir else ""
input_files = [InFile(filename) for filename in io.glob("%s/*.txt" % sub_dir)]
if sub_dir == "curr":
input_files.remove(InFile("curr/supplementalData.txt"))
if sub_dir == "zone":
input_files.remove(InFile("zone/tzdbNames.txt"))
input_basenames = [v.filename[len(sub_dir)+1:] for v in input_files]
output_files = [
OutFile("%s%s.res" % (out_prefix, v[:-4]))
for v in input_basenames
]
# Generate Pool Bundle
if use_pool_bundle:
input_pool_files = [OutFile("%spool.res" % out_prefix)]
pool_target_name = "%s_pool_write" % sub_dir
use_pool_bundle_option = "--usePoolBundle {OUT_DIR}/{OUT_PREFIX}".format(
OUT_PREFIX = out_prefix,
**common_vars
)
requests += [
SingleExecutionRequest(
name = pool_target_name,
category = category,
dep_targets = dep_targets,
input_files = input_files,
output_files = input_pool_files,
tool = IcuTool("genrb"),
args = "-s {IN_DIR}/{IN_SUB_DIR} -d {OUT_DIR}/{OUT_PREFIX} -i {OUT_DIR} "
"--writePoolBundle -k "
"{INPUT_BASENAMES_SPACED}",
format_with = {
"IN_SUB_DIR": sub_dir,
"OUT_PREFIX": out_prefix,
"INPUT_BASENAMES_SPACED": utils.SpaceSeparatedList(input_basenames)
}
),
]
dep_targets = dep_targets + [DepTarget(pool_target_name)]
else:
use_pool_bundle_option = ""
# Generate Res File Tree
requests += [
RepeatedOrSingleExecutionRequest(
name = "%s_res" % sub_dir,
category = category,
dep_targets = dep_targets,
input_files = input_files,
output_files = output_files,
tool = IcuTool("genrb"),
args = "-s {IN_DIR}/{IN_SUB_DIR} -d {OUT_DIR}/{OUT_PREFIX} -i {OUT_DIR} "
"{EXTRA_OPTION} -k "
"{INPUT_BASENAME}",
format_with = {
"IN_SUB_DIR": sub_dir,
"OUT_PREFIX": out_prefix,
"EXTRA_OPTION": use_pool_bundle_option
},
repeat_with = {
"INPUT_BASENAME": utils.SpaceSeparatedList(input_basenames)
}
)
]
# Generate res_index file
# Exclude the deprecated locale variants and root; see ICU-20628. This
# could be data-driven, but we do not want to perform I/O in this script
# (for example, we do not want to read from an XML file).
excluded_locales = set([
"ja_JP_TRADITIONAL",
"th_TH_TRADITIONAL",
"de_",
"de__PHONEBOOK",
"es_",
"es__TRADITIONAL",
"root",
])
# Put alias locales in a separate structure; see ICU-20627
dependency_data = io.read_locale_deps(sub_dir)
if "aliases" in dependency_data:
alias_locales = set(dependency_data["aliases"].keys())
else:
alias_locales = set()
alias_files = []
installed_files = []
for f in input_files:
file_stem = IndexRequest.locale_file_stem(f)
if file_stem in excluded_locales:
continue
destination = alias_files if file_stem in alias_locales else installed_files
destination.append(f)
cldr_version = dependency_data["cldrVersion"] if sub_dir == "locales" else None
index_file_txt = TmpFile("{IN_SUB_DIR}/{INDEX_NAME}.txt".format(
IN_SUB_DIR = sub_dir,
**common_vars
))
index_res_file = OutFile("{OUT_PREFIX}{INDEX_NAME}.res".format(
OUT_PREFIX = out_prefix,
**common_vars
))
index_file_target_name = "%s_index_txt" % sub_dir
requests += [
IndexRequest(
name = index_file_target_name,
category = category,
installed_files = installed_files,
alias_files = alias_files,
txt_file = index_file_txt,
output_file = index_res_file,
cldr_version = cldr_version,
args = "-s {TMP_DIR}/{IN_SUB_DIR} -d {OUT_DIR}/{OUT_PREFIX} -i {OUT_DIR} "
"-k "
"{INDEX_NAME}.txt",
format_with = {
"IN_SUB_DIR": sub_dir,
"OUT_PREFIX": out_prefix
}
)
]
return requests
|