| Neil Fuller | 04b2285 | 2015-10-26 16:21:44 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| Neil Fuller | 3a353ce | 2015-10-09 13:30:08 +0100 | [diff] [blame] | 3 | # Copyright (C) 2015 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 | # A script for generating the source code of the subset of ICU used by Android in libcore. |
| 18 | |
| Victor Chang | e993598 | 2018-09-21 14:55:40 +0100 | [diff] [blame] | 19 | # Flag for applying java doc patches or not |
| 20 | APPLY_DOC_PATCH=1 |
| 21 | |
| 22 | # Build Options used by Android.bp |
| 23 | while true; do |
| 24 | case "$1" in |
| 25 | --no-doc-patch ) APPLY_DOC_PATCH=0; shift ;; |
| 26 | --srcgen-tool ) SRCGEN_TOOL="$2"; shift 2;; |
| 27 | --gen ) GEN_DIR="$2"; shift 2 ;; |
| 28 | -- ) shift; break ;; |
| 29 | * ) break ;; |
| 30 | esac |
| 31 | done |
| 32 | |
| 33 | if [ -n "$SRCGEN_TOOL" ]; then |
| 34 | source $(dirname $BASH_SOURCE)/common.sh --do-not-make |
| 35 | SRCGEN_TOOL_BINARY=${SRCGEN_TOOL} |
| 36 | else |
| 37 | source $(dirname $BASH_SOURCE)/common.sh |
| 38 | SRCGEN_TOOL_BINARY=${ANDROID_HOST_OUT}/bin/android_icu4j_srcgen_binary |
| 39 | fi |
| 40 | |
| 41 | if [ -n "$GEN_DIR" ]; then |
| 42 | ANDROID_ICU4J_DIR=${GEN_DIR}/android_icu4j |
| 43 | mkdir -p ${ANDROID_ICU4J_DIR} |
| 44 | fi |
| 45 | |
| Victor Chang | 90ec62d | 2020-07-27 18:45:39 +0100 | [diff] [blame] | 46 | ALLOWLIST_API_FILE=${ICU_SRCGEN_DIR}/allowlisted-public-api.txt |
| Neil Fuller | 9189af5 | 2018-10-01 17:25:00 +0100 | [diff] [blame] | 47 | CORE_PLATFORM_API_FILE=${ICU_SRCGEN_DIR}/core-platform-api.txt |
| Victor Chang | c37b03c | 2019-08-08 18:01:42 +0100 | [diff] [blame] | 48 | INTRA_CORE_API_FILE=${ICU_SRCGEN_DIR}/intra-core-api.txt |
| Paul Duffin | da28d52 | 2018-11-07 14:55:37 +0000 | [diff] [blame] | 49 | UNSUPPORTED_APP_USAGE_FILE=${ICU_SRCGEN_DIR}/unsupported-app-usage.json |
| Neil Fuller | 9189af5 | 2018-10-01 17:25:00 +0100 | [diff] [blame] | 50 | |
| Neil Fuller | 3a353ce | 2015-10-09 13:30:08 +0100 | [diff] [blame] | 51 | # Clean out previous generated code / resources. |
| 52 | DEST_SRC_DIR=${ANDROID_ICU4J_DIR}/src/main/java |
| Victor Chang | c9ae0db | 2019-10-28 18:56:09 +0000 | [diff] [blame] | 53 | rm -rf ${DEST_SRC_DIR} |
| 54 | mkdir -p ${DEST_SRC_DIR} |
| Neil Fuller | 3a353ce | 2015-10-09 13:30:08 +0100 | [diff] [blame] | 55 | |
| 56 | DEST_RESOURCE_DIR=${ANDROID_ICU4J_DIR}/resources |
| 57 | rm -rf ${DEST_RESOURCE_DIR} |
| 58 | mkdir -p ${DEST_RESOURCE_DIR} |
| 59 | |
| 60 | # Generate the source code needed by Android. |
| Victor Chang | 90ec62d | 2020-07-27 18:45:39 +0100 | [diff] [blame] | 61 | # Branches used for testing new versions of ICU will have have the ${ALLOWLIST_API_FILE} file |
| Victor Chang | 49ae1bd | 2018-10-02 19:32:00 +0100 | [diff] [blame] | 62 | # that prevents new (stable) APIs being added to the Android public SDK API. The file should |
| 63 | # not exist on "normal" release branches and master. |
| 64 | ICU4J_BASE_COMMAND="${SRCGEN_TOOL_BINARY} Icu4jTransform" |
| Victor Chang | 90ec62d | 2020-07-27 18:45:39 +0100 | [diff] [blame] | 65 | if [ -e "${ALLOWLIST_API_FILE}" ]; then |
| 66 | ICU4J_BASE_COMMAND+=" --hide-non-allowlisted-api ${ALLOWLIST_API_FILE}" |
| Victor Chang | 49ae1bd | 2018-10-02 19:32:00 +0100 | [diff] [blame] | 67 | fi |
| Victor Chang | c37b03c | 2019-08-08 18:01:42 +0100 | [diff] [blame] | 68 | ${ICU4J_BASE_COMMAND} ${INPUT_DIRS} ${DEST_SRC_DIR} ${CORE_PLATFORM_API_FILE} ${INTRA_CORE_API_FILE} ${UNSUPPORTED_APP_USAGE_FILE} |
| Neil Fuller | 3a353ce | 2015-10-09 13:30:08 +0100 | [diff] [blame] | 69 | |
| Neil Fuller | cc49f81 | 2015-11-02 18:18:32 +0000 | [diff] [blame] | 70 | # Copy / transform the resources needed by the android_icu4j code. |
| Neil Fuller | 3a353ce | 2015-10-09 13:30:08 +0100 | [diff] [blame] | 71 | for INPUT_DIR in ${INPUT_DIRS}; do |
| Neil Fuller | 04b2285 | 2015-10-26 16:21:44 +0000 | [diff] [blame] | 72 | RESOURCES=$(find ${INPUT_DIR} -type f | egrep -v '(\.java|\/package\.html|\/ICUConfig\.properties)' || true ) |
| Neil Fuller | 3a353ce | 2015-10-09 13:30:08 +0100 | [diff] [blame] | 73 | for RESOURCE in ${RESOURCES}; do |
| 74 | SOURCE_DIR=$(dirname ${RESOURCE}) |
| 75 | RELATIVE_SOURCE_DIR=$(echo ${SOURCE_DIR} | sed "s,${INPUT_DIR}/,,") |
| Neil Fuller | 04b2285 | 2015-10-26 16:21:44 +0000 | [diff] [blame] | 76 | RELATIVE_DEST_DIR=$(echo ${RELATIVE_SOURCE_DIR} | sed 's,com/ibm/icu,android/icu,') |
| Neil Fuller | 3a353ce | 2015-10-09 13:30:08 +0100 | [diff] [blame] | 77 | DEST_DIR=${DEST_RESOURCE_DIR}/${RELATIVE_DEST_DIR} |
| 78 | mkdir -p ${DEST_DIR} |
| 79 | cp $RESOURCE ${DEST_DIR} |
| 80 | done |
| 81 | done |
| 82 | |
| 83 | # Create the ICUConfig.properties for Android. |
| 84 | mkdir -p ${ANDROID_ICU4J_DIR}/resources/android/icu |
| 85 | sed 's,com.ibm.icu,android.icu,' ${ANDROID_BUILD_TOP}/external/icu/icu4j/main/classes/core/src/com/ibm/icu/ICUConfig.properties > ${ANDROID_ICU4J_DIR}/resources/android/icu/ICUConfig.properties |
| Neil Fuller | cc49f81 | 2015-11-02 18:18:32 +0000 | [diff] [blame] | 86 | |
| 87 | # Clean out previous generated sample code. |
| 88 | SAMPLE_DEST_DIR=${ANDROID_ICU4J_DIR}/src/samples/java |
| 89 | rm -rf ${SAMPLE_DEST_DIR} |
| 90 | mkdir -p ${SAMPLE_DEST_DIR} |
| 91 | |
| 92 | echo Processing sample code |
| 93 | # Create the android_icu4j sample code |
| Victor Chang | e993598 | 2018-09-21 14:55:40 +0100 | [diff] [blame] | 94 | ${SRCGEN_TOOL_BINARY} Icu4jBasicTransform ${SAMPLE_INPUT_FILES} ${SAMPLE_DEST_DIR} |
| Paul Duffin | 69ef1ba | 2016-02-26 16:21:51 +0000 | [diff] [blame] | 95 | |
| 96 | # Clean out previous generated test code. |
| 97 | TEST_DEST_DIR=${ANDROID_ICU4J_DIR}/src/main/tests |
| 98 | rm -rf ${TEST_DEST_DIR} |
| 99 | mkdir -p ${TEST_DEST_DIR} |
| 100 | |
| 101 | # Create a temporary directory into which the testdata.jar can be unzipped. It must be called src |
| 102 | # as that is what is used to determine the root of the directory containing all the files to |
| 103 | # copy and that is used to calculate the relative path to the file that is used for its output path. |
| 104 | echo Unpacking testdata.jar |
| 105 | TESTDATA_DIR=$(mktemp -d)/src |
| 106 | mkdir -p ${TESTDATA_DIR} |
| 107 | unzip ${ICU4J_DIR}/main/shared/data/testdata.jar com/ibm/icu/* -d ${TESTDATA_DIR} |
| 108 | |
| 109 | echo Processing test code |
| 110 | # Create the android_icu4j test code |
| 111 | ALL_TEST_INPUT_DIRS="${TEST_INPUT_DIRS} ${TESTDATA_DIR}" |
| Victor Chang | e993598 | 2018-09-21 14:55:40 +0100 | [diff] [blame] | 112 | ${SRCGEN_TOOL_BINARY} Icu4jTestsTransform ${ALL_TEST_INPUT_DIRS} ${TEST_DEST_DIR} |
| Victor Chang | 5d40af9 | 2017-07-24 17:46:55 +0100 | [diff] [blame] | 113 | # Apply line-based javadoc patches |
| Victor Chang | e993598 | 2018-09-21 14:55:40 +0100 | [diff] [blame] | 114 | if [ "$APPLY_DOC_PATCH" -eq "1" ]; then |
| 115 | ${ANDROID_BUILD_TOP}/external/icu/tools/srcgen/javadoc_patches/apply_patches.sh |
| 116 | fi |
| Victor Chang | 5d40af9 | 2017-07-24 17:46:55 +0100 | [diff] [blame] | 117 | |
| Paul Duffin | 69ef1ba | 2016-02-26 16:21:51 +0000 | [diff] [blame] | 118 | # Copy the data files. |
| 119 | echo Copying test data |
| 120 | for INPUT_DIR in ${ALL_TEST_INPUT_DIRS}; do |
| Paul Duffin | 7986482 | 2016-03-14 12:08:13 +0000 | [diff] [blame] | 121 | RESOURCES=$(find ${INPUT_DIR} -type f | egrep -v '(\.java|com\.ibm\.icu.*\.dat|/package\.html)' || true ) |
| Paul Duffin | 69ef1ba | 2016-02-26 16:21:51 +0000 | [diff] [blame] | 122 | for RESOURCE in ${RESOURCES}; do |
| 123 | SOURCE_DIR=$(dirname ${RESOURCE}) |
| 124 | RELATIVE_SOURCE_DIR=$(echo ${SOURCE_DIR} | sed "s,${INPUT_DIR}/,,") |
| 125 | RELATIVE_DEST_DIR=$(echo ${RELATIVE_SOURCE_DIR} | sed 's,com/ibm/icu,android/icu,') |
| 126 | DEST_DIR=${TEST_DEST_DIR}/${RELATIVE_DEST_DIR} |
| 127 | mkdir -p ${DEST_DIR} |
| 128 | cp $RESOURCE ${DEST_DIR} |
| 129 | done |
| 130 | done |
| Paul Duffin | 7986482 | 2016-03-14 12:08:13 +0000 | [diff] [blame] | 131 | |
| 132 | echo Repackaging serialized test data |
| 133 | # Excludes JavaTimeZone.dat files as they depend on sun.util.calendar.ZoneInfo |
| 134 | for INPUT_DIR in ${ALL_TEST_INPUT_DIRS}; do |
| 135 | RESOURCES=$(find ${INPUT_DIR} -type f | egrep '(/com\.ibm\.icu.*\.dat)' | egrep -v "JavaTimeZone.dat" || true ) |
| 136 | for RESOURCE in ${RESOURCES}; do |
| 137 | SOURCE_DIR=$(dirname ${RESOURCE}) |
| 138 | RELATIVE_SOURCE_DIR=$(echo ${SOURCE_DIR} | sed "s,${INPUT_DIR}/,,") |
| 139 | RELATIVE_DEST_DIR=$(echo ${RELATIVE_SOURCE_DIR} | sed 's,com/ibm/icu,android/icu,') |
| 140 | SOURCE_NAME=$(basename ${RESOURCE}) |
| 141 | DEST_NAME=${SOURCE_NAME/com.ibm/android} |
| 142 | DEST_DIR=${TEST_DEST_DIR}/${RELATIVE_DEST_DIR} |
| 143 | mkdir -p ${DEST_DIR} |
| 144 | # A simple textual substitution works even though the file is binary as 'com.ibm' and 'android' |
| 145 | # are the same length. |
| 146 | sed 's|com[./]ibm|android|g' $RESOURCE > ${DEST_DIR}/${DEST_NAME} |
| 147 | done |
| 148 | done |