diff --git a/tools/cldr/lib/README.txt b/tools/cldr/lib/README.txt index 66df9c6232c..abd9b2b0ffd 100644 --- a/tools/cldr/lib/README.txt +++ b/tools/cldr/lib/README.txt @@ -41,7 +41,7 @@ doesn't work on your system. To regenerate the CLDR API jar you need to build the "jar" target manually using the Ant build.xml file in the "tools/java" directory of the CLDR project: -$ cd /tools/java +$ cd "$CLDR_ROOT/tools/java" $ ant clean jar This should result in the cldr.jar file being built into that directory, which @@ -62,7 +62,7 @@ $ mvn install:install-file \ -Dpackaging=jar \ -DgeneratePom=true \ -DlocalRepositoryPath=. \ - -Dfile=/tools/java/cldr.jar + -Dfile="$CLDR_ROOT/tools/java/cldr.jar" And if you have updated one of these libraries then from this directory run: diff --git a/tools/cldr/lib/install-cldr-jars.sh b/tools/cldr/lib/install-cldr-jars.sh index 7b630643990..ab9501e4848 100755 --- a/tools/cldr/lib/install-cldr-jars.sh +++ b/tools/cldr/lib/install-cldr-jars.sh @@ -15,6 +15,12 @@ # Usage (from the directory of this script): # # ./install-cldr-jars.sh +# +# Note to maintainers: This script cannot be assumed to run on a Unix/Linux +# based system, and while a Posix compliant bash shell is required, any +# assumptions about auxiliary Unix tools should be minimized (e.g. things +# like "dirname" or "tempfile" may not exist). Where bash-only alternatives +# have to be used, they should be clearly documented. # Exit with a message for fatal errors. function die() { @@ -28,35 +34,28 @@ function die() { function run_with_logging() { echo >> "${LOG_FILE}" echo "Running: ${@}" >> "${LOG_FILE}" - echo "----------------------------------------------------------------" >> "${LOG_FILE}" + echo -- "----------------------------------------------------------------" >> "${LOG_FILE}" "${@}" >> "${LOG_FILE}" 2>&1 if (( $? != 0 )) ; then - echo "---- Previous command failed ----" >> "${LOG_FILE}" + echo -- "---- Previous command failed ----" >> "${LOG_FILE}" echo "Error running: ${@}" read -p "Show log file? " -n 1 -r echo if [[ "${REPLY}" =~ ^[Yy]$ ]] ; then less -X "${LOG_FILE}" fi - mv -f "${LOG_FILE}" "${ROOT_DIR}/last_log.txt" - echo "Log file: ${ROOT_DIR}/last_log.txt" + echo "Log file: ${LOG_FILE}" exit 1 fi - echo "---- Previous command succeeded ----" >> "${LOG_FILE}" + echo -- "---- Previous command succeeded ----" >> "${LOG_FILE}" } # First require that we are run from the same directory as the script. -ROOT_DIR="$(realpath $(dirname $0))" -if [[ "${ROOT_DIR}" != "$(realpath ${PWD})" ]] ; then - echo "WARNING: Shell script should be run from the Maven lib/ directory" - echo "Current directory:" - echo " ${PWD}" - echo "Maven lib/ direcory (where this script is):" - echo " ${ROOT_DIR}" - read -p "Change to lib/ directory and continue? " -n 1 -r - echo - [[ "${REPLY}" =~ ^[Yy]$ ]] || die "Script must be run from the Maven lib/ directory" - cd "$ROOT_DIR" +# Can't assume users have "dirname" available so hack it a bit with shell +# substitution (if no directory path was prepended, SCRIPT_DIR==$0). +SCRIPT_DIR=${0%/*} +if [[ "$SCRIPT_DIR" != "$0" ]] ; then + cd $SCRIPT_DIR fi # Check for some expected environmental things early. @@ -67,9 +66,10 @@ which mvn > /dev/null || die "Cannot find Maven executable 'mvn' in the current (( $# == 1 )) && [[ -d "$1" ]] || die "Usage: ./install-cldr-jars.sh " # Set up a log file (and be nice about tidying it up). -LOG_FILE="$(tempfile)" || die "Cannot create temporary file!" -trap "rm -f -- '${LOG_FILE}'" EXIT -echo "---- LOG FILE ---- $(date '+%F %T') ----" >> "${LOG_FILE}" +# Cannot assume "tempfile" exists so use a timestamp (we expect "date" to exist though). +LOG_FILE="${TMPDIR:-/tmp}/cldr2icu_log_$(date '+%m%d_%H%M%S').txt" +touch $LOG_FILE || die "Cannot create temporary file: ${LOG_FILE}" +echo -- "---- LOG FILE ---- $(date '+%F %T') ----" >> "${LOG_FILE}" # Build the cldr.jar in the CLDR tools directory. CLDR_TOOLS_DIR="$1/tools/java" @@ -98,6 +98,5 @@ run_with_logging mvn -B dependency:purge-local-repository \ -Dproject.parent.relativePath="" \ -DmanualIncludes=org.unicode.cldr:cldr-api:jar -mv -f "${LOG_FILE}" "last_log.txt" -echo "All done! (log file: last_log.txt)" -trap - EXIT +echo "All done!" +echo "Log file: ${LOG_FILE}"