blob: 551f3d7f8832deb2ddde5b64313136c36493d3f7 [file] [log] [blame]
Neil Fullerc1a723a2020-08-10 16:55:37 +01001#!/usr/bin/env bash
2
3# Copyright 2020 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# Fail fast on any error.
18set -e
19
20CITY_SIZES=(500 1000 15000)
21EXTERNAL_GEONAMES_DIR=${ANDROID_BUILD_TOP}/external/geonames
22SYSTEM_TIMEZONE_DIR=${ANDROID_BUILD_TOP}/system/timezone
23KNOWN_DIFFS_DIR=${SYSTEM_TIMEZONE_DIR}/geolocation/validation/geonames/known_diffs
24TMP_DIR=$(mktemp -d -t geonames-XXXXXXXXXX)
25COMPARISON_CMD=geotz_geonames_comparison
26
27if (( $# < 1 )); then
28 echo "Usage: ${0} [500|1000|15000]"
29 echo
30 echo " The number determines the geonames file to use (500 means <= 500 population)"
31 echo " 500 is generally fine: This includes 1,000 and 15,000 population too."
32 exit 1
33fi
34
35CITY_SIZE=$1
36GEONAMES_CITIES_ZIP_FILE=${EXTERNAL_GEONAMES_DIR}/export/dump/cities${CITY_SIZE}.zip
37
38# Find the Java tool before we begin.
39if [[ -z $(which ${COMPARISON_CMD}) ]]; then
40 echo "${COMPARISON_CMD} not found. Not built?"
41 exit 1
42fi
43
44INPUT_DIR=${TMP_DIR}/input
45mkdir ${INPUT_DIR}
46
47OUTPUT_DIR=${TMP_DIR}/output
48mkdir ${OUTPUT_DIR}
49
50unzip ${GEONAMES_CITIES_ZIP_FILE} -d ${INPUT_DIR}
51GEONAMES_CITIES_TXT_FILE=${INPUT_DIR}/cities${CITY_SIZE}.txt
52
53KNOWN_DIFF_FILES=()
54for SIZE in ${CITY_SIZES[@]}; do
55 if (( "${SIZE}" >= ${CITY_SIZE} )); then
56 KNOWN_DIFF_FILE=${KNOWN_DIFFS_DIR}/known_diffs${SIZE}.prototxt
57 if [ -f ${KNOWN_DIFF_FILE} ]; then
58 KNOWN_DIFF_FILES+=(${KNOWN_DIFF_FILE})
59 fi
60 fi
61done
62KNOWN_DIFFS_ARG=$(IFS=,; echo "${KNOWN_DIFF_FILES[*]}")
63
64${COMPARISON_CMD} \
65 ${SYSTEM_TIMEZONE_DIR}/geolocation/output_data/odbl/tzs2.dat \
66 ${SYSTEM_TIMEZONE_DIR}/output_data/android/tzids.prototxt \
67 2020-01-01T00:00:00Z \
68 ${GEONAMES_CITIES_TXT_FILE} \
69 ${OUTPUT_DIR} \
70 "${KNOWN_DIFFS_ARG}"
71
72GEONAMES_SHA=$(git --git-dir=${EXTERNAL_GEONAMES_DIR}/.git rev-parse --short HEAD)
73echo ${EXTERNAL_GEONAMES_DIR} git SHA is: ${GEONAMES_SHA}