Neil Fuller | c1a723a | 2020-08-10 16:55:37 +0100 | [diff] [blame^] | 1 | #!/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. |
| 18 | set -e |
| 19 | |
| 20 | CITY_SIZES=(500 1000 15000) |
| 21 | EXTERNAL_GEONAMES_DIR=${ANDROID_BUILD_TOP}/external/geonames |
| 22 | SYSTEM_TIMEZONE_DIR=${ANDROID_BUILD_TOP}/system/timezone |
| 23 | KNOWN_DIFFS_DIR=${SYSTEM_TIMEZONE_DIR}/geolocation/validation/geonames/known_diffs |
| 24 | TMP_DIR=$(mktemp -d -t geonames-XXXXXXXXXX) |
| 25 | COMPARISON_CMD=geotz_geonames_comparison |
| 26 | |
| 27 | if (( $# < 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 |
| 33 | fi |
| 34 | |
| 35 | CITY_SIZE=$1 |
| 36 | GEONAMES_CITIES_ZIP_FILE=${EXTERNAL_GEONAMES_DIR}/export/dump/cities${CITY_SIZE}.zip |
| 37 | |
| 38 | # Find the Java tool before we begin. |
| 39 | if [[ -z $(which ${COMPARISON_CMD}) ]]; then |
| 40 | echo "${COMPARISON_CMD} not found. Not built?" |
| 41 | exit 1 |
| 42 | fi |
| 43 | |
| 44 | INPUT_DIR=${TMP_DIR}/input |
| 45 | mkdir ${INPUT_DIR} |
| 46 | |
| 47 | OUTPUT_DIR=${TMP_DIR}/output |
| 48 | mkdir ${OUTPUT_DIR} |
| 49 | |
| 50 | unzip ${GEONAMES_CITIES_ZIP_FILE} -d ${INPUT_DIR} |
| 51 | GEONAMES_CITIES_TXT_FILE=${INPUT_DIR}/cities${CITY_SIZE}.txt |
| 52 | |
| 53 | KNOWN_DIFF_FILES=() |
| 54 | for 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 |
| 61 | done |
| 62 | KNOWN_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 | |
| 72 | GEONAMES_SHA=$(git --git-dir=${EXTERNAL_GEONAMES_DIR}/.git rev-parse --short HEAD) |
| 73 | echo ${EXTERNAL_GEONAMES_DIR} git SHA is: ${GEONAMES_SHA} |