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