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 19from __future__ import print_function 20 21import argparse 22import os 23import shutil 24import subprocess 25import sys 26 27sys.path.append('%s/external/icu/tools' % os.environ.get('ANDROID_BUILD_TOP')) 28import i18nutil 29 30 31android_build_top = i18nutil.GetAndroidRootOrDie() 32android_host_out_dir = i18nutil.GetAndroidHostOutOrDie() 33timezone_dir = os.path.realpath('%s/system/timezone' % android_build_top) 34i18nutil.CheckDirExists(timezone_dir, 'system/timezone') 35 36def RunCreateTimeZoneDistro(properties_file): 37 # Build the libraries needed. 38 subprocess.check_call(['make', '-C', android_build_top, 'create_time_zone_distro', 39 'time_zone_distro']) 40 41 libs = [ 'create_time_zone_distro', 'time_zone_distro' ] 42 host_java_libs_dir = '%s/../common/obj/JAVA_LIBRARIES' % android_host_out_dir 43 classpath_components = [] 44 for lib in libs: 45 classpath_components.append('%s/%s_intermediates/javalib.jar' % (host_java_libs_dir, lib)) 46 47 classpath = ':'.join(classpath_components) 48 49 # Run the CreateTimeZoneDistro tool 50 subprocess.check_call(['java', '-cp', classpath, 51 'com.android.timezone.distro.tools.CreateTimeZoneDistro', properties_file]) 52 53 54def CreateTimeZoneDistro( 55 iana_version, revision, tzdata_file, icu_file, tzlookup_file, output_distro_dir, 56 output_version_file): 57 original_cwd = os.getcwd() 58 59 i18nutil.SwitchToNewTemporaryDirectory() 60 working_dir = os.getcwd() 61 62 # Generate the properties file. 63 properties_file = '%s/distro.properties' % working_dir 64 with open(properties_file, "w") as properties: 65 properties.write('rules.version=%s\n' % iana_version) 66 properties.write('revision=%s\n' % revision) 67 properties.write('tzdata.file=%s\n' % tzdata_file) 68 properties.write('icu.file=%s\n' % icu_file) 69 properties.write('tzlookup.file=%s\n' % tzlookup_file) 70 properties.write('output.distro.dir=%s\n' % output_distro_dir) 71 properties.write('output.version.file=%s\n' % output_version_file) 72 73 RunCreateTimeZoneDistro(properties_file) 74 75 os.chdir(original_cwd) 76 77 78def main(): 79 parser = argparse.ArgumentParser() 80 parser.add_argument('-iana_version', required=True, 81 help='The IANA time zone rules release version, e.g. 2017b') 82 parser.add_argument('-revision', type=int, default=1, 83 help='The distro revision for the IANA version, default = 1') 84 parser.add_argument('-tzdata', required=True, help='The location of the tzdata file to include') 85 parser.add_argument('-icu', required=True, 86 help='The location of the ICU overlay .dat file to include') 87 parser.add_argument('-tzlookup', required=True, 88 help='The location of the tzlookup.xml file to include') 89 parser.add_argument('-output_distro_dir', required=True, 90 help='The output directory for the distro.zip') 91 parser.add_argument('-output_version_file', required=True, 92 help='The output path for the version file') 93 args = parser.parse_args() 94 95 iana_version = args.iana_version 96 revision = args.revision 97 tzdata_file = os.path.abspath(args.tzdata) 98 icu_file = os.path.abspath(args.icu) 99 tzlookup_file = os.path.abspath(args.tzlookup) 100 output_distro_dir = os.path.abspath(args.output_distro_dir) 101 output_version_file = os.path.abspath(args.output_version_file) 102 103 CreateTimeZoneDistro( 104 iana_version=iana_version, 105 revision=revision, 106 tzdata_file=tzdata_file, 107 icu_file=icu_file, 108 tzlookup_file=tzlookup_file, 109 output_distro_dir=output_distro_dir, 110 output_version_file=output_version_file) 111 112 print('Distro file created in %s' % output_distro_dir) 113 print('Version file created as %s' % output_version_file) 114 sys.exit(0) 115 116 117if __name__ == '__main__': 118 main() 119