diff options
author | Neil Fuller <nfuller@google.com> | 2015-08-24 18:14:50 +0100 |
---|---|---|
committer | Neil Fuller <nfuller@google.com> | 2015-08-25 10:11:01 +0100 |
commit | 6a1d94f8bd51a1f45fdb8f0b3efc5337c0d408df (patch) | |
tree | ac1d50145c6a2106dbaed136eeb26a1f9b53c0d4 /tools/updateicudata.py | |
parent | d23839d4d460aa5f81eeb4986c05c8745e0633b7 (diff) | |
download | icu-6a1d94f8bd51a1f45fdb8f0b3efc5337c0d408df.tar.gz |
Extract ICU .dat / .jar file generation code
Create an independent script for regenerating ICU
data files independently of timezone updates.
Bug: 23419215
Change-Id: Iad0e6399a78d34073506543461d9d0e9ee751078
Diffstat (limited to 'tools/updateicudata.py')
-rwxr-xr-x | tools/updateicudata.py | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/tools/updateicudata.py b/tools/updateicudata.py new file mode 100755 index 000000000..67a280ca8 --- /dev/null +++ b/tools/updateicudata.py @@ -0,0 +1,117 @@ +#!/usr/bin/python + +"""Regenerates ICU data files.""" + +import glob +import os +import shutil +import subprocess +import sys + +import i18nutil + +# Find the icu directory. +android_build_top = i18nutil.GetAndroidRootOrDie() +icu_dir = os.path.realpath('%s/external/icu' % android_build_top) +icu4c_dir = os.path.realpath('%s/icu4c/source' % icu_dir) +icu4j_dir = os.path.realpath('%s/icu4j' % icu_dir) +i18nutil.CheckDirExists(icu4c_dir, 'external/icu/icu4c/source') +i18nutil.CheckDirExists(icu4j_dir, 'external/icu/icu4j') + +def PrepareIcuBuild(icu_build_dir): + # Keep track of the original cwd so we can go back to it at the end. + original_working_dir = os.getcwd() + + # Create a directory to run 'make' from. + os.mkdir(icu_build_dir) + os.chdir(icu_build_dir) + + # Build the ICU tools. + print 'Configuring ICU tools...' + subprocess.check_call(['%s/runConfigureICU' % icu4c_dir, 'Linux']) + + os.chdir(original_working_dir) + +def icuDir(): + return icu_dir + +def MakeTzDataFiles(icu_build_dir, data_filename): + # Keep track of the original cwd so we can go back to it at the end. + original_working_dir = os.getcwd() + + # Fix missing files. + os.chdir('%s/tools/tzcode' % icu_build_dir) + + # The tz2icu tool only picks up icuregions and icuzones in they are in the CWD + for icu_data_file in [ 'icuregions', 'icuzones']: + icu_data_file_source = '%s/tools/tzcode/%s' % (icu4c_dir, icu_data_file) + icu_data_file_symlink = './%s' % icu_data_file + os.symlink(icu_data_file_source, icu_data_file_symlink) + + shutil.copyfile('%s/%s' % (original_working_dir, data_filename), + data_filename) + + print 'Making ICU tz data files...' + # The Makefile assumes the existence of the bin directory. + os.mkdir('%s/bin' % icu_build_dir) + subprocess.check_call(['make']) + + # Copy the source file to its ultimate destination. + icu_txt_data_dir = '%s/data/misc' % icu4c_dir + print 'Copying zoneinfo64.txt to %s ...' % icu_txt_data_dir + shutil.copy('zoneinfo64.txt', icu_txt_data_dir) + + os.chdir(original_working_dir) + + +def MakeAndCopyIcuDataFiles(icu_build_dir): + # Keep track of the original cwd so we can go back to it at the end. + original_working_dir = os.getcwd() + + # Regenerate the .dat file. + os.chdir(icu_build_dir) + subprocess.check_call(['make', 'INCLUDE_UNI_CORE_DATA=1', '-j32']) + + # Copy the .dat file to its ultimate destination. + icu_dat_data_dir = '%s/stubdata' % icu4c_dir + datfiles = glob.glob('data/out/tmp/icudt??l.dat') + if len(datfiles) != 1: + print 'ERROR: Unexpectedly found %d .dat files (%s). Halting.' % (len(datfiles), datfiles) + sys.exit(1) + datfile = datfiles[0] + print 'Copying %s to %s ...' % (datfile, icu_dat_data_dir) + shutil.copy(datfile, icu_dat_data_dir) + + # Generate the ICU4J .jar files + os.chdir('%s/data' % icu_build_dir) + subprocess.check_call(['make', 'icu4j-data']) + + # Copy the ICU4J .jar files to their ultimate destination. + icu_jar_data_dir = '%s/main/shared/data' % icu4j_dir + jarfiles = glob.glob('out/icu4j/*.jar') + if len(jarfiles) != 2: + print 'ERROR: Unexpectedly found %d .jar files (%s). Halting.' % (len(jarfiles), jarfiles) + sys.exit(1) + for jarfile in jarfiles: + print 'Copying %s to %s ...' % (jarfile, icu_jar_data_dir) + shutil.copy(jarfile, icu_jar_data_dir) + + # Switch back to the original working cwd. + os.chdir(original_working_dir) + +# Run with no arguments from any directory, with no special setup required. +def main(): + i18nutil.SwitchToNewTemporaryDirectory() + icu_build_dir = '%s/icu' % os.getcwd() + + print 'Found icu in %s ...' % icu_dir + + PrepareIcuBuild(icu_build_dir) + + MakeAndCopyIcuDataFiles(icu_build_dir) + + print 'Look in %s for new data files' % icu_dir + sys.exit(0) + +if __name__ == '__main__': + main() |