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. 18set -e 19 20# Ordered in reverse so duplicate known issues are reported against the smaller 21# city file. 22CITY_SIZES=(15000 5000 1000 500) 23EXTERNAL_GEONAMES_DIR=${ANDROID_BUILD_TOP}/external/geonames 24SYSTEM_TIMEZONE_DIR=${ANDROID_BUILD_TOP}/system/timezone 25GEOTZ_DIR=${ANDROID_BUILD_TOP}/packages/modules/GeoTZ 26KNOWN_DIFFS_DIR=${GEOTZ_DIR}/validation/geonames/known_diffs 27TMP_DIR=$(mktemp -d -t geonames-XXXXXXXXXX) 28COMPARISON_CMD=geotz_geonames_comparison 29 30if (( $# < 1 )); then 31 echo "Usage: ${0} [500|1000|5000|15000]" 32 echo 33 echo " The number determines the geonames file to use (500 means <= 500 population)" 34 echo " 500 is generally fine to start: This includes 1,000, 5,000 and 15,000 population too." 35 echo " If you find differences, run with 15,000 and fix issues, then 5,000, then 1,000, etc." 36 exit 1 37fi 38 39CITY_SIZE=$1 40GEONAMES_CITIES_ZIP_FILE=${EXTERNAL_GEONAMES_DIR}/export/dump/cities${CITY_SIZE}.zip 41 42# Find the Java tool before we begin. 43if [[ -z $(which ${COMPARISON_CMD}) ]]; then 44 echo "${COMPARISON_CMD} not found. Not built?" 45 exit 1 46fi 47 48INPUT_DIR=${TMP_DIR}/input 49mkdir ${INPUT_DIR} 50 51OUTPUT_DIR=${TMP_DIR}/output 52mkdir ${OUTPUT_DIR} 53 54unzip ${GEONAMES_CITIES_ZIP_FILE} -d ${INPUT_DIR} 55GEONAMES_CITIES_TXT_FILE=${INPUT_DIR}/cities${CITY_SIZE}.txt 56 57KNOWN_DIFF_FILES=() 58for SIZE in ${CITY_SIZES[@]}; do 59 if (( "${SIZE}" >= ${CITY_SIZE} )); then 60 KNOWN_DIFF_FILE=${KNOWN_DIFFS_DIR}/known_diffs${SIZE}.prototxt 61 if [ -f ${KNOWN_DIFF_FILE} ]; then 62 KNOWN_DIFF_FILES+=(${KNOWN_DIFF_FILE}) 63 fi 64 fi 65done 66KNOWN_DIFFS_ARG=$(IFS=,; echo "${KNOWN_DIFF_FILES[*]}") 67 68${COMPARISON_CMD} \ 69 ${GEOTZ_DIR}/output_data/odbl/tzs2.dat \ 70 ${SYSTEM_TIMEZONE_DIR}/output_data/android/tzids.prototxt \ 71 2020-01-01T00:00:00Z \ 72 ${GEONAMES_CITIES_TXT_FILE} \ 73 ${OUTPUT_DIR} \ 74 "${KNOWN_DIFFS_ARG}" 75 76GEONAMES_SHA=$(git --git-dir=${EXTERNAL_GEONAMES_DIR}/.git rev-parse --short HEAD) 77echo ${EXTERNAL_GEONAMES_DIR} git SHA is: ${GEONAMES_SHA} 78