1 #!/usr/bin/python -B 2 3 # Copyright 2017 The Android Open Source Project 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 """Generates a time zone distro file""" 18 19 import argparse 20 import os 21 import shutil 22 import subprocess 23 import sys 24 25 sys.path.append('%s/external/icu/tools' % os.environ.get('ANDROID_BUILD_TOP')) 26 import i18nutil 27 28 29 android_build_top = i18nutil.GetAndroidRootOrDie() 30 android_host_out_dir = i18nutil.GetAndroidHostOutOrDie() 31 timezone_dir = os.path.realpath('%s/system/timezone' % android_build_top) 32 i18nutil.CheckDirExists(timezone_dir, 'system/timezone') 33 34 def RunCreateTimeZoneDistro(properties_file, distro_output_dir): 35 # Build the libraries needed. 36 subprocess.check_call(['make', '-C', android_build_top, 'time_zone_distro_tools-host']) 37 38 libs = [ 'time_zone_distro_tools-host', 'time_zone_distro-host' ] 39 host_java_libs_dir = '%s/../common/obj/JAVA_LIBRARIES' % android_host_out_dir 40 classpath_components = [] 41 for lib in libs: 42 classpath_components.append('%s/%s_intermediates/javalib.jar' % (host_java_libs_dir, lib)) 43 44 classpath = ':'.join(classpath_components) 45 46 # Run the CreateTimeZoneDistro tool 47 subprocess.check_call(['java', '-cp', classpath, 48 'com.android.timezone.distro.tools.CreateTimeZoneDistro', properties_file, 49 distro_output_dir]) 50 51 52 def CreateTimeZoneDistro(iana_version, revision, tzdata_file, icu_file, tzlookup_file, output_dir): 53 original_cwd = os.getcwd() 54 55 i18nutil.SwitchToNewTemporaryDirectory() 56 working_dir = os.getcwd() 57 58 # Generate the properties file. 59 properties_file = '%s/distro.properties' % working_dir 60 with open(properties_file, "w") as properties: 61 properties.write('rules.version=%s\n' % iana_version) 62 properties.write('revision=%s\n' % revision) 63 properties.write('tzdata.file=%s\n' % tzdata_file) 64 properties.write('icu.file=%s\n' % icu_file) 65 properties.write('tzlookup.file=%s\n' % tzlookup_file) 66 67 RunCreateTimeZoneDistro(properties_file, output_dir) 68 69 os.chdir(original_cwd) 70 71 72 def main(): 73 parser = argparse.ArgumentParser() 74 parser.add_argument('-iana_version', required=True, 75 help='The IANA time zone rules release version, e.g. 2017b') 76 parser.add_argument('-revision', type=int, default=1, 77 help='The distro revision for the IANA version, default = 1') 78 parser.add_argument('-tzdata', required=True, help='The location of the tzdata file to include') 79 parser.add_argument('-icu', required=True, 80 help='The location of the ICU overlay .dat file to include') 81 parser.add_argument('-tzlookup', required=True, 82 help='The location of the tzlookup.xml file to include') 83 parser.add_argument('-output', required=True, help='The output directory') 84 args = parser.parse_args() 85 86 iana_version = args.iana_version 87 revision = args.revision 88 tzdata_file = os.path.abspath(args.tzdata) 89 icu_file = os.path.abspath(args.icu) 90 tzlookup_file = os.path.abspath(args.tzlookup) 91 output_dir = os.path.abspath(args.output) 92 93 CreateTimeZoneDistro( 94 iana_version=iana_version, 95 revision=revision, 96 tzdata_file=tzdata_file, 97 icu_file=icu_file, 98 tzlookup_file=tzlookup_file, 99 output_dir=output_dir) 100 101 print 'Distro files created in %s' % output_dir 102 sys.exit(0) 103 104 105 if __name__ == '__main__': 106 main() 107