lin
2025-08-14 dae8bad597b6607a449b32bf76c523423f7720ed
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
#!/usr/bin/python -B
 
"""Regenerates (just) ICU data source files used to build ICU data files."""
 
from __future__ import print_function
 
import os
import pipes
import shutil
import subprocess
import sys
 
import i18nutil
import icuutil
 
 
# Run with no arguments from any directory, with no special setup required.
# See icu4c/source/data/cldr-icu-readme.txt for the upstream ICU instructions.
def main():
  cldr_dir = icuutil.cldrDir()
  print('Found cldr in %s ...' % cldr_dir)
  icu_dir = icuutil.icuDir()
  print('Found icu in %s ...' % icu_dir)
 
  # Ant doesn't have any mechanism for using a build directory separate from the
  # source directory so this build script creates a temporary directory and then
  # copies all necessary ICU4J and CLDR source code to here before building it:
  i18nutil.SwitchToNewTemporaryDirectory()
 
  print('Copying ICU4J source code ...')
  shutil.copytree(os.path.join(icu_dir, 'icu4j'), 'icu4j', True)
  print('Building ICU4J ...')
  subprocess.check_call([
      'ant',
      '-f', 'icu4j/build.xml',
      'jar',
      'cldrUtil',
  ])
 
  # Append the newly built JAR files to the Java CLASSPATH to use these instead
  # of the pre-built JAR files in the CLDR source tree, to ensure that the same
  # version of ICU is being used to build the data as will use the data:
  cp = []
  try:
    cp.append(os.environ['CLASSPATH'])
  except KeyError:
    pass
  cp.append('icu4j/icu4j.jar')
  cp.append('icu4j/out/cldr_util/lib/utilities.jar')
  os.environ['CLASSPATH'] = ':'.join(cp)
 
  # This is the location of the original CLDR source tree (not the temporary
  # copy of the tools source code) from where the data files are to be read:
  os.environ['CLDR_DIR'] = cldr_dir
 
  print('Copying CLDR source code ...')
  shutil.copytree(os.path.join(cldr_dir, 'tools/java'), 'cldr-tools-java', True)
  print('Building CLDR tools ...')
  subprocess.check_call([
      'ant',
      '-f', 'cldr-tools-java/build.xml',
      'tool',
      'AddPseudolocales',
  ])
 
  # This is the temporary directory in which the CLDR tools have been built:
  os.environ['CLDR_CLASSES'] = os.path.join(
      os.getcwd(), 'cldr-tools-java/classes')
 
  # It's essential to set CLDR_DTD_CACHE for otherwise the repeated requests for
  # the same file will cause the unicode.org web server to block this machine:
  os.makedirs('cldr-dtd-cache')
  os.environ['ANT_OPTS'] = '-DCLDR_DTD_CACHE=%s' % pipes.quote(os.path.join(
      os.getcwd(), 'cldr-dtd-cache'))
 
  print('Building ICU data source files ...')
  subprocess.check_call([
      'ant',
      '-f', os.path.join(icu_dir, 'icu4c/source/data/build.xml'),
      'clean',
      'all',
  ])
 
  print('Look in %s/icu4c/source/data for new data source files' % icu_dir)
  sys.exit(0)
 
if __name__ == '__main__':
  main()