Neil Fuller | 86e72c5 | 2017-06-12 15:36:06 +0100 | [diff] [blame] | 1 | #!/usr/bin/python -B |
| 2 | |
Neil Fuller | 56166d3 | 2017-06-12 12:57:10 +0100 | [diff] [blame] | 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 the timezone data files used by Android.""" |
Neil Fuller | 86e72c5 | 2017-06-12 15:36:06 +0100 | [diff] [blame] | 18 | |
Luca Stefani | 136579e | 2019-01-04 17:09:55 +0100 | [diff] [blame] | 19 | from __future__ import print_function |
| 20 | |
Neil Fuller | 86e72c5 | 2017-06-12 15:36:06 +0100 | [diff] [blame] | 21 | import glob |
Neil Fuller | 86e72c5 | 2017-06-12 15:36:06 +0100 | [diff] [blame] | 22 | import os |
Neil Fuller | cdf5695 | 2018-02-20 17:12:37 +0000 | [diff] [blame] | 23 | import re |
Neil Fuller | 86e72c5 | 2017-06-12 15:36:06 +0100 | [diff] [blame] | 24 | import subprocess |
| 25 | import sys |
| 26 | import tarfile |
| 27 | import tempfile |
| 28 | |
Neil Fuller | ad7e81c | 2017-06-15 16:45:56 +0100 | [diff] [blame] | 29 | sys.path.append('%s/external/icu/tools' % os.environ.get('ANDROID_BUILD_TOP')) |
Neil Fuller | 86e72c5 | 2017-06-12 15:36:06 +0100 | [diff] [blame] | 30 | import i18nutil |
Neil Fuller | fa89b03 | 2017-06-14 15:58:26 +0100 | [diff] [blame] | 31 | import icuutil |
Neil Fuller | 56166d3 | 2017-06-12 12:57:10 +0100 | [diff] [blame] | 32 | import tzdatautil |
Neil Fuller | 86e72c5 | 2017-06-12 15:36:06 +0100 | [diff] [blame] | 33 | |
Neil Fuller | 86e72c5 | 2017-06-12 15:36:06 +0100 | [diff] [blame] | 34 | |
| 35 | # Calculate the paths that are referred to by multiple functions. |
| 36 | android_build_top = i18nutil.GetAndroidRootOrDie() |
Neil Fuller | 56166d3 | 2017-06-12 12:57:10 +0100 | [diff] [blame] | 37 | timezone_dir = os.path.realpath('%s/system/timezone' % android_build_top) |
| 38 | i18nutil.CheckDirExists(timezone_dir, 'system/timezone') |
| 39 | |
Neil Fuller | 8cec561 | 2017-10-11 10:38:17 +0100 | [diff] [blame] | 40 | android_host_out = i18nutil.GetAndroidHostOutOrDie() |
| 41 | |
Neil Fuller | 0480f46 | 2019-04-09 19:23:35 +0100 | [diff] [blame] | 42 | zone_compactor_dir = os.path.realpath('%s/system/timezone/input_tools/android' % android_build_top) |
| 43 | i18nutil.CheckDirExists(zone_compactor_dir, 'system/timezone/input_tools/android') |
Neil Fuller | 56166d3 | 2017-06-12 12:57:10 +0100 | [diff] [blame] | 44 | |
Neil Fuller | cdf5695 | 2018-02-20 17:12:37 +0000 | [diff] [blame] | 45 | timezone_input_tools_dir = os.path.realpath('%s/input_tools' % timezone_dir) |
Neil Fuller | 56166d3 | 2017-06-12 12:57:10 +0100 | [diff] [blame] | 46 | timezone_input_data_dir = os.path.realpath('%s/input_data' % timezone_dir) |
| 47 | |
Neil Fuller | 35467e1 | 2017-06-12 16:55:44 +0100 | [diff] [blame] | 48 | timezone_output_data_dir = '%s/output_data' % timezone_dir |
| 49 | i18nutil.CheckDirExists(timezone_output_data_dir, 'output_data') |
Neil Fuller | 86e72c5 | 2017-06-12 15:36:06 +0100 | [diff] [blame] | 50 | |
| 51 | tmp_dir = tempfile.mkdtemp('-tzdata') |
| 52 | |
Neil Fuller | a591fb0 | 2018-05-08 17:29:11 +0100 | [diff] [blame] | 53 | def GenerateZicInputFile(extracted_iana_data_dir): |
| 54 | # Android APIs assume DST means "summer time" so we follow the rearguard format |
| 55 | # introduced in 2018e. |
| 56 | zic_input_file_name = 'rearguard.zi' |
Neil Fuller | 86e72c5 | 2017-06-12 15:36:06 +0100 | [diff] [blame] | 57 | |
Neil Fuller | a591fb0 | 2018-05-08 17:29:11 +0100 | [diff] [blame] | 58 | # 'NDATA=' is used to remove unnecessary rules files. |
| 59 | subprocess.check_call(['make', '-C', extracted_iana_data_dir, 'NDATA=', zic_input_file_name]) |
| 60 | |
| 61 | zic_input_file = '%s/%s' % (extracted_iana_data_dir, zic_input_file_name) |
| 62 | if not os.path.exists(zic_input_file): |
Luca Stefani | 136579e | 2019-01-04 17:09:55 +0100 | [diff] [blame] | 63 | print('Could not find %s' % zic_input_file) |
Neil Fuller | a591fb0 | 2018-05-08 17:29:11 +0100 | [diff] [blame] | 64 | sys.exit(1) |
| 65 | return zic_input_file |
| 66 | |
| 67 | |
| 68 | def WriteSetupFile(zic_input_file): |
Neil Fuller | 86e72c5 | 2017-06-12 15:36:06 +0100 | [diff] [blame] | 69 | """Writes the list of zones that ZoneCompactor should process.""" |
| 70 | links = [] |
| 71 | zones = [] |
Neil Fuller | a591fb0 | 2018-05-08 17:29:11 +0100 | [diff] [blame] | 72 | for line in open(zic_input_file): |
| 73 | fields = line.split() |
| 74 | if fields: |
Neil Fuller | 4da0af1 | 2020-05-19 14:56:15 +0100 | [diff] [blame] | 75 | line_type = fields[0] |
| 76 | if line_type == 'Link': |
| 77 | # Each "Link" line requires the creation of a link from an old tz ID to |
| 78 | # a new tz ID, and implies the existence of a zone with the old tz ID. |
| 79 | # |
| 80 | # IANA terminology: |
| 81 | # TARGET = the new tz ID, LINK-NAME = the old tz ID |
| 82 | target = fields[1] |
| 83 | link_name = fields[2] |
| 84 | links.append('Link %s %s' % (target, link_name)) |
| 85 | zones.append('Zone %s' % link_name) |
| 86 | elif line_type == 'Zone': |
| 87 | # Each "Zone" line indicates the existence of a tz ID. |
| 88 | # |
| 89 | # IANA terminology: |
| 90 | # NAME is the tz ID, other fields like STDOFF, RULES, FORMAT,[UNTIL] are |
| 91 | # ignored. |
| 92 | name = fields[1] |
| 93 | zones.append('Zone %s' % name) |
Neil Fuller | 86e72c5 | 2017-06-12 15:36:06 +0100 | [diff] [blame] | 94 | |
| 95 | zone_compactor_setup_file = '%s/setup' % tmp_dir |
| 96 | setup = open(zone_compactor_setup_file, 'w') |
Neil Fuller | 4da0af1 | 2020-05-19 14:56:15 +0100 | [diff] [blame] | 97 | |
| 98 | # Ordering requirement from ZoneCompactor: Links must come first. |
Neil Fuller | 86e72c5 | 2017-06-12 15:36:06 +0100 | [diff] [blame] | 99 | for link in sorted(set(links)): |
| 100 | setup.write('%s\n' % link) |
| 101 | for zone in sorted(set(zones)): |
| 102 | setup.write('%s\n' % zone) |
| 103 | setup.close() |
| 104 | return zone_compactor_setup_file |
| 105 | |
| 106 | |
Neil Fuller | cdf5695 | 2018-02-20 17:12:37 +0000 | [diff] [blame] | 107 | def BuildIcuData(iana_data_tar_file): |
Neil Fuller | 86e72c5 | 2017-06-12 15:36:06 +0100 | [diff] [blame] | 108 | icu_build_dir = '%s/icu' % tmp_dir |
| 109 | |
Neil Fuller | fa89b03 | 2017-06-14 15:58:26 +0100 | [diff] [blame] | 110 | icuutil.PrepareIcuBuild(icu_build_dir) |
Neil Fuller | cdf5695 | 2018-02-20 17:12:37 +0000 | [diff] [blame] | 111 | icuutil.MakeTzDataFiles(icu_build_dir, iana_data_tar_file) |
Neil Fuller | fa89b03 | 2017-06-14 15:58:26 +0100 | [diff] [blame] | 112 | |
| 113 | # Create ICU system image files. |
| 114 | icuutil.MakeAndCopyIcuDataFiles(icu_build_dir) |
| 115 | |
Neil Fuller | 64bd411 | 2018-11-01 18:14:07 +0000 | [diff] [blame] | 116 | icu_overlay_dir = '%s/icu_overlay' % timezone_output_data_dir |
| 117 | |
Neil Fuller | fa89b03 | 2017-06-14 15:58:26 +0100 | [diff] [blame] | 118 | # Create the ICU overlay time zone file. |
Neil Fuller | 64bd411 | 2018-11-01 18:14:07 +0000 | [diff] [blame] | 119 | icu_overlay_dat_file = '%s/icu_tzdata.dat' % icu_overlay_dir |
Neil Fuller | fa89b03 | 2017-06-14 15:58:26 +0100 | [diff] [blame] | 120 | icuutil.MakeAndCopyOverlayTzIcuData(icu_build_dir, icu_overlay_dat_file) |
Neil Fuller | 86e72c5 | 2017-06-12 15:36:06 +0100 | [diff] [blame] | 121 | |
Neil Fuller | 64bd411 | 2018-11-01 18:14:07 +0000 | [diff] [blame] | 122 | # Copy ICU license file(s) |
| 123 | icuutil.CopyLicenseFiles(icu_overlay_dir) |
| 124 | |
Neil Fuller | 86e72c5 | 2017-06-12 15:36:06 +0100 | [diff] [blame] | 125 | |
Neil Fuller | cdf5695 | 2018-02-20 17:12:37 +0000 | [diff] [blame] | 126 | def GetIanaVersion(iana_tar_file): |
| 127 | iana_tar_filename = os.path.basename(iana_tar_file) |
| 128 | iana_version = re.search('tz(?:data|code)(.+)\\.tar\\.gz', iana_tar_filename).group(1) |
Neil Fuller | ad7e81c | 2017-06-15 16:45:56 +0100 | [diff] [blame] | 129 | return iana_version |
| 130 | |
Neil Fuller | 8cec561 | 2017-10-11 10:38:17 +0100 | [diff] [blame] | 131 | |
Neil Fuller | cdf5695 | 2018-02-20 17:12:37 +0000 | [diff] [blame] | 132 | def ExtractTarFile(tar_file, dir): |
Luca Stefani | 136579e | 2019-01-04 17:09:55 +0100 | [diff] [blame] | 133 | print('Extracting %s...' % tar_file) |
Neil Fuller | cdf5695 | 2018-02-20 17:12:37 +0000 | [diff] [blame] | 134 | if not os.path.exists(dir): |
| 135 | os.mkdir(dir) |
| 136 | tar = tarfile.open(tar_file, 'r') |
| 137 | tar.extractall(dir) |
Neil Fuller | 86e72c5 | 2017-06-12 15:36:06 +0100 | [diff] [blame] | 138 | |
Neil Fuller | cdf5695 | 2018-02-20 17:12:37 +0000 | [diff] [blame] | 139 | |
| 140 | def BuildZic(iana_tools_dir): |
Neil Fuller | 2aba99c | 2019-02-26 13:15:34 +0000 | [diff] [blame] | 141 | iana_zic_code_tar_file = tzdatautil.GetIanaTarFile(iana_tools_dir, 'tzcode') |
Neil Fuller | cdf5695 | 2018-02-20 17:12:37 +0000 | [diff] [blame] | 142 | iana_zic_code_version = GetIanaVersion(iana_zic_code_tar_file) |
Neil Fuller | 2aba99c | 2019-02-26 13:15:34 +0000 | [diff] [blame] | 143 | iana_zic_data_tar_file = tzdatautil.GetIanaTarFile(iana_tools_dir, 'tzdata') |
Neil Fuller | cdf5695 | 2018-02-20 17:12:37 +0000 | [diff] [blame] | 144 | iana_zic_data_version = GetIanaVersion(iana_zic_data_tar_file) |
| 145 | |
Luca Stefani | 136579e | 2019-01-04 17:09:55 +0100 | [diff] [blame] | 146 | print('Found IANA zic release %s/%s in %s/%s ...' \ |
Neil Fuller | ed0c59b | 2020-05-03 21:18:13 +0100 | [diff] [blame] | 147 | % (iana_zic_code_version, iana_zic_data_version, iana_zic_code_tar_file, |
| 148 | iana_zic_data_tar_file)) |
Neil Fuller | cdf5695 | 2018-02-20 17:12:37 +0000 | [diff] [blame] | 149 | |
| 150 | zic_build_dir = '%s/zic' % tmp_dir |
| 151 | ExtractTarFile(iana_zic_code_tar_file, zic_build_dir) |
| 152 | ExtractTarFile(iana_zic_data_tar_file, zic_build_dir) |
| 153 | |
| 154 | # zic |
Luca Stefani | 136579e | 2019-01-04 17:09:55 +0100 | [diff] [blame] | 155 | print('Building zic...') |
Neil Fuller | cdf5695 | 2018-02-20 17:12:37 +0000 | [diff] [blame] | 156 | # VERSION_DEPS= is to stop the build process looking for files that might not |
| 157 | # be present across different versions. |
| 158 | subprocess.check_call(['make', '-C', zic_build_dir, 'zic']) |
| 159 | |
| 160 | zic_binary_file = '%s/zic' % zic_build_dir |
| 161 | if not os.path.exists(zic_binary_file): |
Luca Stefani | 136579e | 2019-01-04 17:09:55 +0100 | [diff] [blame] | 162 | print('Could not find %s' % zic_binary_file) |
Neil Fuller | a591fb0 | 2018-05-08 17:29:11 +0100 | [diff] [blame] | 163 | sys.exit(1) |
Neil Fuller | cdf5695 | 2018-02-20 17:12:37 +0000 | [diff] [blame] | 164 | return zic_binary_file |
| 165 | |
| 166 | |
| 167 | def BuildTzdata(zic_binary_file, extracted_iana_data_dir, iana_data_version): |
Luca Stefani | 136579e | 2019-01-04 17:09:55 +0100 | [diff] [blame] | 168 | print('Generating zic input file...') |
Neil Fuller | a591fb0 | 2018-05-08 17:29:11 +0100 | [diff] [blame] | 169 | zic_input_file = GenerateZicInputFile(extracted_iana_data_dir) |
| 170 | |
Luca Stefani | 136579e | 2019-01-04 17:09:55 +0100 | [diff] [blame] | 171 | print('Calling zic...') |
Neil Fuller | 86e72c5 | 2017-06-12 15:36:06 +0100 | [diff] [blame] | 172 | zic_output_dir = '%s/data' % tmp_dir |
| 173 | os.mkdir(zic_output_dir) |
Neil Fuller | a591fb0 | 2018-05-08 17:29:11 +0100 | [diff] [blame] | 174 | zic_cmd = [zic_binary_file, '-d', zic_output_dir, zic_input_file] |
Neil Fuller | 86e72c5 | 2017-06-12 15:36:06 +0100 | [diff] [blame] | 175 | subprocess.check_call(zic_cmd) |
| 176 | |
Neil Fuller | cdf5695 | 2018-02-20 17:12:37 +0000 | [diff] [blame] | 177 | # ZoneCompactor |
Neil Fuller | a591fb0 | 2018-05-08 17:29:11 +0100 | [diff] [blame] | 178 | zone_compactor_setup_file = WriteSetupFile(zic_input_file) |
Neil Fuller | 86e72c5 | 2017-06-12 15:36:06 +0100 | [diff] [blame] | 179 | |
Luca Stefani | 136579e | 2019-01-04 17:09:55 +0100 | [diff] [blame] | 180 | print('Calling ZoneCompactor to update tzdata to %s...' % iana_data_version) |
Neil Fuller | d322be6 | 2019-09-16 16:25:03 +0100 | [diff] [blame] | 181 | |
| 182 | tzdatautil.InvokeSoong(android_build_top, ['zone_compactor']) |
Neil Fuller | 86e72c5 | 2017-06-12 15:36:06 +0100 | [diff] [blame] | 183 | |
Neil Fuller | cdf5695 | 2018-02-20 17:12:37 +0000 | [diff] [blame] | 184 | # Create args for ZoneCompactor |
Neil Fuller | cdf5695 | 2018-02-20 17:12:37 +0000 | [diff] [blame] | 185 | header_string = 'tzdata%s' % iana_data_version |
Neil Fuller | 35467e1 | 2017-06-12 16:55:44 +0100 | [diff] [blame] | 186 | |
Luca Stefani | 136579e | 2019-01-04 17:09:55 +0100 | [diff] [blame] | 187 | print('Executing ZoneCompactor...') |
Neil Fuller | d322be6 | 2019-09-16 16:25:03 +0100 | [diff] [blame] | 188 | command = '%s/bin/zone_compactor' % android_host_out |
Neil Fuller | 35467e1 | 2017-06-12 16:55:44 +0100 | [diff] [blame] | 189 | iana_output_data_dir = '%s/iana' % timezone_output_data_dir |
Neil Fuller | 61b7d56 | 2020-05-21 14:43:47 +0100 | [diff] [blame] | 190 | subprocess.check_call([command, zone_compactor_setup_file, zic_output_dir, iana_output_data_dir, |
| 191 | header_string]) |
Neil Fuller | 56166d3 | 2017-06-12 12:57:10 +0100 | [diff] [blame] | 192 | |
| 193 | |
Neil Fuller | 7803149 | 2020-08-07 21:17:58 +0100 | [diff] [blame] | 194 | def BuildTzlookupAndTzIds(iana_data_dir): |
Neil Fuller | 8cec561 | 2017-10-11 10:38:17 +0100 | [diff] [blame] | 195 | countryzones_source_file = '%s/android/countryzones.txt' % timezone_input_data_dir |
Neil Fuller | 35467e1 | 2017-06-12 16:55:44 +0100 | [diff] [blame] | 196 | tzlookup_dest_file = '%s/android/tzlookup.xml' % timezone_output_data_dir |
Neil Fuller | 7803149 | 2020-08-07 21:17:58 +0100 | [diff] [blame] | 197 | tzids_dest_file = '%s/android/tzids.prototxt' % timezone_output_data_dir |
Neil Fuller | 8cec561 | 2017-10-11 10:38:17 +0100 | [diff] [blame] | 198 | |
Neil Fuller | 7803149 | 2020-08-07 21:17:58 +0100 | [diff] [blame] | 199 | print('Calling TzLookupGenerator to create tzlookup.xml / tzids.prototxt...') |
Neil Fuller | d322be6 | 2019-09-16 16:25:03 +0100 | [diff] [blame] | 200 | tzdatautil.InvokeSoong(android_build_top, ['tzlookup_generator']) |
Neil Fuller | 8cec561 | 2017-10-11 10:38:17 +0100 | [diff] [blame] | 201 | |
Neil Fuller | 8cec561 | 2017-10-11 10:38:17 +0100 | [diff] [blame] | 202 | zone_tab_file = '%s/zone.tab' % iana_data_dir |
Neil Fuller | 008dfcd | 2020-05-06 16:43:30 +0100 | [diff] [blame] | 203 | backward_file = '%s/backward' % iana_data_dir |
Neil Fuller | d322be6 | 2019-09-16 16:25:03 +0100 | [diff] [blame] | 204 | command = '%s/bin/tzlookup_generator' % android_host_out |
Neil Fuller | 008dfcd | 2020-05-06 16:43:30 +0100 | [diff] [blame] | 205 | subprocess.check_call([command, countryzones_source_file, zone_tab_file, backward_file, |
Neil Fuller | 7803149 | 2020-08-07 21:17:58 +0100 | [diff] [blame] | 206 | tzlookup_dest_file, tzids_dest_file]) |
Neil Fuller | 56166d3 | 2017-06-12 12:57:10 +0100 | [diff] [blame] | 207 | |
Neil Fuller | 86e72c5 | 2017-06-12 15:36:06 +0100 | [diff] [blame] | 208 | |
Neil Fuller | f85e814 | 2019-10-28 17:21:55 +0000 | [diff] [blame] | 209 | def BuildTelephonylookup(): |
| 210 | telephonylookup_source_file = '%s/android/telephonylookup.txt' % timezone_input_data_dir |
| 211 | telephonylookup_dest_file = '%s/android/telephonylookup.xml' % timezone_output_data_dir |
| 212 | |
| 213 | print('Calling TelephonyLookupGenerator to create telephonylookup.xml...') |
| 214 | tzdatautil.InvokeSoong(android_build_top, ['telephonylookup_generator']) |
| 215 | |
| 216 | command = '%s/bin/telephonylookup_generator' % android_host_out |
| 217 | subprocess.check_call([command, telephonylookup_source_file, telephonylookup_dest_file]) |
| 218 | |
| 219 | |
Neil Fuller | e2d551b | 2018-10-29 15:32:06 +0000 | [diff] [blame] | 220 | def CreateDistroFiles(iana_data_version, output_distro_dir, output_version_file): |
Neil Fuller | ad7e81c | 2017-06-15 16:45:56 +0100 | [diff] [blame] | 221 | create_distro_script = '%s/distro/tools/create-distro.py' % timezone_dir |
| 222 | |
| 223 | tzdata_file = '%s/iana/tzdata' % timezone_output_data_dir |
| 224 | icu_file = '%s/icu_overlay/icu_tzdata.dat' % timezone_output_data_dir |
| 225 | tzlookup_file = '%s/android/tzlookup.xml' % timezone_output_data_dir |
Neil Fuller | f85e814 | 2019-10-28 17:21:55 +0000 | [diff] [blame] | 226 | telephonylookup_file = '%s/android/telephonylookup.xml' % timezone_output_data_dir |
Neil Fuller | ad7e81c | 2017-06-15 16:45:56 +0100 | [diff] [blame] | 227 | |
Neil Fuller | e2d551b | 2018-10-29 15:32:06 +0000 | [diff] [blame] | 228 | distro_file_pattern = '%s/*.zip' % output_distro_dir |
| 229 | existing_files = glob.glob(distro_file_pattern) |
Neil Fuller | ad7e81c | 2017-06-15 16:45:56 +0100 | [diff] [blame] | 230 | |
Luca Stefani | 136579e | 2019-01-04 17:09:55 +0100 | [diff] [blame] | 231 | print('Removing %s' % existing_files) |
Neil Fuller | ad7e81c | 2017-06-15 16:45:56 +0100 | [diff] [blame] | 232 | for existing_file in existing_files: |
| 233 | os.remove(existing_file) |
| 234 | |
| 235 | subprocess.check_call([create_distro_script, |
Neil Fuller | cdf5695 | 2018-02-20 17:12:37 +0000 | [diff] [blame] | 236 | '-iana_version', iana_data_version, |
Neil Fuller | ad7e81c | 2017-06-15 16:45:56 +0100 | [diff] [blame] | 237 | '-tzdata', tzdata_file, |
| 238 | '-icu', icu_file, |
| 239 | '-tzlookup', tzlookup_file, |
Neil Fuller | f85e814 | 2019-10-28 17:21:55 +0000 | [diff] [blame] | 240 | '-telephonylookup', telephonylookup_file, |
Neil Fuller | e2d551b | 2018-10-29 15:32:06 +0000 | [diff] [blame] | 241 | '-output_distro_dir', output_distro_dir, |
| 242 | '-output_version_file', output_version_file]) |
Neil Fuller | ad7e81c | 2017-06-15 16:45:56 +0100 | [diff] [blame] | 243 | |
Neil Fuller | ad3c876 | 2017-10-20 15:58:57 +0100 | [diff] [blame] | 244 | def UpdateTestFiles(): |
| 245 | testing_data_dir = '%s/testing/data' % timezone_dir |
| 246 | update_test_files_script = '%s/create-test-data.sh' % testing_data_dir |
| 247 | subprocess.check_call([update_test_files_script], cwd=testing_data_dir) |
| 248 | |
Neil Fuller | 86e72c5 | 2017-06-12 15:36:06 +0100 | [diff] [blame] | 249 | |
| 250 | # Run with no arguments from any directory, with no special setup required. |
| 251 | # See http://www.iana.org/time-zones/ for more about the source of this data. |
| 252 | def main(): |
Luca Stefani | 136579e | 2019-01-04 17:09:55 +0100 | [diff] [blame] | 253 | print('Source data file structure: %s' % timezone_input_data_dir) |
| 254 | print('Source tools file structure: %s' % timezone_input_tools_dir) |
Neil Fuller | ed0c59b | 2020-05-03 21:18:13 +0100 | [diff] [blame] | 255 | print('Intermediate / working dir: %s' % tmp_dir) |
Luca Stefani | 136579e | 2019-01-04 17:09:55 +0100 | [diff] [blame] | 256 | print('Output data file structure: %s' % timezone_output_data_dir) |
Neil Fuller | 56166d3 | 2017-06-12 12:57:10 +0100 | [diff] [blame] | 257 | |
Neil Fuller | 8cec561 | 2017-10-11 10:38:17 +0100 | [diff] [blame] | 258 | iana_input_data_dir = '%s/iana' % timezone_input_data_dir |
Neil Fuller | 2aba99c | 2019-02-26 13:15:34 +0000 | [diff] [blame] | 259 | iana_data_tar_file = tzdatautil.GetIanaTarFile(iana_input_data_dir, 'tzdata') |
Neil Fuller | cdf5695 | 2018-02-20 17:12:37 +0000 | [diff] [blame] | 260 | iana_data_version = GetIanaVersion(iana_data_tar_file) |
Luca Stefani | 136579e | 2019-01-04 17:09:55 +0100 | [diff] [blame] | 261 | print('IANA time zone data release %s in %s ...' % (iana_data_version, iana_data_tar_file)) |
Neil Fuller | fa89b03 | 2017-06-14 15:58:26 +0100 | [diff] [blame] | 262 | |
| 263 | icu_dir = icuutil.icuDir() |
Luca Stefani | 136579e | 2019-01-04 17:09:55 +0100 | [diff] [blame] | 264 | print('Found icu in %s ...' % icu_dir) |
Neil Fuller | 86e72c5 | 2017-06-12 15:36:06 +0100 | [diff] [blame] | 265 | |
Neil Fuller | cdf5695 | 2018-02-20 17:12:37 +0000 | [diff] [blame] | 266 | BuildIcuData(iana_data_tar_file) |
| 267 | |
| 268 | iana_tools_dir = '%s/iana' % timezone_input_tools_dir |
| 269 | zic_binary_file = BuildZic(iana_tools_dir) |
| 270 | |
| 271 | iana_data_dir = '%s/iana_data' % tmp_dir |
| 272 | ExtractTarFile(iana_data_tar_file, iana_data_dir) |
| 273 | BuildTzdata(zic_binary_file, iana_data_dir, iana_data_version) |
Neil Fuller | ed0c59b | 2020-05-03 21:18:13 +0100 | [diff] [blame] | 274 | |
Neil Fuller | 7803149 | 2020-08-07 21:17:58 +0100 | [diff] [blame] | 275 | BuildTzlookupAndTzIds(iana_data_dir) |
Neil Fuller | ed0c59b | 2020-05-03 21:18:13 +0100 | [diff] [blame] | 276 | |
Neil Fuller | f85e814 | 2019-10-28 17:21:55 +0000 | [diff] [blame] | 277 | BuildTelephonylookup() |
Neil Fuller | ad7e81c | 2017-06-15 16:45:56 +0100 | [diff] [blame] | 278 | |
Neil Fuller | e2d551b | 2018-10-29 15:32:06 +0000 | [diff] [blame] | 279 | # Create a distro file and version file from the output from prior stages. |
| 280 | output_distro_dir = '%s/distro' % timezone_output_data_dir |
| 281 | output_version_file = '%s/version/tz_version' % timezone_output_data_dir |
| 282 | CreateDistroFiles(iana_data_version, output_distro_dir, output_version_file) |
Neil Fuller | ad7e81c | 2017-06-15 16:45:56 +0100 | [diff] [blame] | 283 | |
Neil Fuller | ad3c876 | 2017-10-20 15:58:57 +0100 | [diff] [blame] | 284 | # Update test versions of distro files too. |
| 285 | UpdateTestFiles() |
| 286 | |
Luca Stefani | 136579e | 2019-01-04 17:09:55 +0100 | [diff] [blame] | 287 | print('Look in %s and %s for new files' % (timezone_output_data_dir, icu_dir)) |
Neil Fuller | 86e72c5 | 2017-06-12 15:36:06 +0100 | [diff] [blame] | 288 | sys.exit(0) |
| 289 | |
| 290 | |
| 291 | if __name__ == '__main__': |
| 292 | main() |