blob: 40a375c7c9d9c1ea35794c6d1d439d94dc69d4d4 [file] [log] [blame]
Neil Fuller04b22852015-10-26 16:21:44 +00001#!/bin/bash
2
Neil Fuller3a353ce2015-10-09 13:30:08 +01003# 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 Change9935982018-09-21 14:55:40 +010019# Flag for applying java doc patches or not
20APPLY_DOC_PATCH=1
21
22# Build Options used by Android.bp
23while 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
31done
32
33if [ -n "$SRCGEN_TOOL" ]; then
34 source $(dirname $BASH_SOURCE)/common.sh --do-not-make
35 SRCGEN_TOOL_BINARY=${SRCGEN_TOOL}
36else
37 source $(dirname $BASH_SOURCE)/common.sh
38 SRCGEN_TOOL_BINARY=${ANDROID_HOST_OUT}/bin/android_icu4j_srcgen_binary
39fi
40
41if [ -n "$GEN_DIR" ]; then
42 ANDROID_ICU4J_DIR=${GEN_DIR}/android_icu4j
43 mkdir -p ${ANDROID_ICU4J_DIR}
44fi
45
Victor Chang90ec62d2020-07-27 18:45:39 +010046ALLOWLIST_API_FILE=${ICU_SRCGEN_DIR}/allowlisted-public-api.txt
Neil Fuller9189af52018-10-01 17:25:00 +010047CORE_PLATFORM_API_FILE=${ICU_SRCGEN_DIR}/core-platform-api.txt
Victor Changc37b03c2019-08-08 18:01:42 +010048INTRA_CORE_API_FILE=${ICU_SRCGEN_DIR}/intra-core-api.txt
Paul Duffinda28d522018-11-07 14:55:37 +000049UNSUPPORTED_APP_USAGE_FILE=${ICU_SRCGEN_DIR}/unsupported-app-usage.json
Neil Fuller9189af52018-10-01 17:25:00 +010050
Neil Fuller3a353ce2015-10-09 13:30:08 +010051# Clean out previous generated code / resources.
52DEST_SRC_DIR=${ANDROID_ICU4J_DIR}/src/main/java
Victor Changc9ae0db2019-10-28 18:56:09 +000053rm -rf ${DEST_SRC_DIR}
54mkdir -p ${DEST_SRC_DIR}
Neil Fuller3a353ce2015-10-09 13:30:08 +010055
56DEST_RESOURCE_DIR=${ANDROID_ICU4J_DIR}/resources
57rm -rf ${DEST_RESOURCE_DIR}
58mkdir -p ${DEST_RESOURCE_DIR}
59
60# Generate the source code needed by Android.
Victor Chang90ec62d2020-07-27 18:45:39 +010061# Branches used for testing new versions of ICU will have have the ${ALLOWLIST_API_FILE} file
Victor Chang49ae1bd2018-10-02 19:32:00 +010062# 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.
64ICU4J_BASE_COMMAND="${SRCGEN_TOOL_BINARY} Icu4jTransform"
Victor Chang90ec62d2020-07-27 18:45:39 +010065if [ -e "${ALLOWLIST_API_FILE}" ]; then
66 ICU4J_BASE_COMMAND+=" --hide-non-allowlisted-api ${ALLOWLIST_API_FILE}"
Victor Chang49ae1bd2018-10-02 19:32:00 +010067fi
Victor Changc37b03c2019-08-08 18:01:42 +010068${ICU4J_BASE_COMMAND} ${INPUT_DIRS} ${DEST_SRC_DIR} ${CORE_PLATFORM_API_FILE} ${INTRA_CORE_API_FILE} ${UNSUPPORTED_APP_USAGE_FILE}
Neil Fuller3a353ce2015-10-09 13:30:08 +010069
Neil Fullercc49f812015-11-02 18:18:32 +000070# Copy / transform the resources needed by the android_icu4j code.
Neil Fuller3a353ce2015-10-09 13:30:08 +010071for INPUT_DIR in ${INPUT_DIRS}; do
Neil Fuller04b22852015-10-26 16:21:44 +000072 RESOURCES=$(find ${INPUT_DIR} -type f | egrep -v '(\.java|\/package\.html|\/ICUConfig\.properties)' || true )
Neil Fuller3a353ce2015-10-09 13:30:08 +010073 for RESOURCE in ${RESOURCES}; do
74 SOURCE_DIR=$(dirname ${RESOURCE})
75 RELATIVE_SOURCE_DIR=$(echo ${SOURCE_DIR} | sed "s,${INPUT_DIR}/,,")
Neil Fuller04b22852015-10-26 16:21:44 +000076 RELATIVE_DEST_DIR=$(echo ${RELATIVE_SOURCE_DIR} | sed 's,com/ibm/icu,android/icu,')
Neil Fuller3a353ce2015-10-09 13:30:08 +010077 DEST_DIR=${DEST_RESOURCE_DIR}/${RELATIVE_DEST_DIR}
78 mkdir -p ${DEST_DIR}
79 cp $RESOURCE ${DEST_DIR}
80 done
81done
82
83# Create the ICUConfig.properties for Android.
84mkdir -p ${ANDROID_ICU4J_DIR}/resources/android/icu
85sed '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 Fullercc49f812015-11-02 18:18:32 +000086
87# Clean out previous generated sample code.
88SAMPLE_DEST_DIR=${ANDROID_ICU4J_DIR}/src/samples/java
89rm -rf ${SAMPLE_DEST_DIR}
90mkdir -p ${SAMPLE_DEST_DIR}
91
92echo Processing sample code
93# Create the android_icu4j sample code
Victor Change9935982018-09-21 14:55:40 +010094${SRCGEN_TOOL_BINARY} Icu4jBasicTransform ${SAMPLE_INPUT_FILES} ${SAMPLE_DEST_DIR}
Paul Duffin69ef1ba2016-02-26 16:21:51 +000095
96# Clean out previous generated test code.
97TEST_DEST_DIR=${ANDROID_ICU4J_DIR}/src/main/tests
98rm -rf ${TEST_DEST_DIR}
99mkdir -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.
104echo Unpacking testdata.jar
105TESTDATA_DIR=$(mktemp -d)/src
106mkdir -p ${TESTDATA_DIR}
107unzip ${ICU4J_DIR}/main/shared/data/testdata.jar com/ibm/icu/* -d ${TESTDATA_DIR}
108
109echo Processing test code
110# Create the android_icu4j test code
111ALL_TEST_INPUT_DIRS="${TEST_INPUT_DIRS} ${TESTDATA_DIR}"
Victor Change9935982018-09-21 14:55:40 +0100112${SRCGEN_TOOL_BINARY} Icu4jTestsTransform ${ALL_TEST_INPUT_DIRS} ${TEST_DEST_DIR}
Victor Chang5d40af92017-07-24 17:46:55 +0100113# Apply line-based javadoc patches
Victor Change9935982018-09-21 14:55:40 +0100114if [ "$APPLY_DOC_PATCH" -eq "1" ]; then
115 ${ANDROID_BUILD_TOP}/external/icu/tools/srcgen/javadoc_patches/apply_patches.sh
116fi
Victor Chang5d40af92017-07-24 17:46:55 +0100117
Paul Duffin69ef1ba2016-02-26 16:21:51 +0000118# Copy the data files.
119echo Copying test data
120for INPUT_DIR in ${ALL_TEST_INPUT_DIRS}; do
Paul Duffin79864822016-03-14 12:08:13 +0000121 RESOURCES=$(find ${INPUT_DIR} -type f | egrep -v '(\.java|com\.ibm\.icu.*\.dat|/package\.html)' || true )
Paul Duffin69ef1ba2016-02-26 16:21:51 +0000122 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
130done
Paul Duffin79864822016-03-14 12:08:13 +0000131
132echo Repackaging serialized test data
133# Excludes JavaTimeZone.dat files as they depend on sun.util.calendar.ZoneInfo
134for 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
148done