blob: d07012fe048966e000c86fc6c0857a8e6bace145 [file] [log] [blame]
Kevin Rocard82d3a0b2019-06-18 15:39:17 -07001#/usr/bin/env bash
2
3set -euo pipefail
4
5if (echo "$@" |grep -qe -h); then
6 echo "This script will generate a new HAL version identical to an other one."
7 echo "This helps creating the boilerplate for a new version."
8 echo
9 echo "USAGE: $0 [BASE_VERSION] [NEW_VERSION]"
10 echo " BASE_VERSION default value is the highest version currently existing"
11 echo " NEW_VERSION default value is BASE_VERSION + 1"
12 echo
13 echo "Example: to generate a V6.0 by copying V5, do: $0 5.0 6.0"
14 exit
15fi
16readonly HAL_DIRECTORY=hardware/interfaces/audio
17readonly HAL_VTS_DIRECTORY=core/all-versions/vts/functional
18readonly HAL_VTS_FILE=AudioPrimaryHidlHalTest.cpp
19readonly HAL_SERVICE_DIRECTORY=common/all-versions/default/service/
20readonly HAL_SERVICE_CPP=service.cpp
21
22readonly FWK_DIRECTORY=frameworks/av/media/libaudiohal
23readonly IMPL_DIRECTORY=impl
24readonly IMPL_FACTORYHAL=$IMPL_DIRECTORY/include/libaudiohal/FactoryHalHidl.h
25
26readonly VTS_DIRECTORY=test/vts-testcase/hal/audio
27readonly VTS_LIST=test/vts/tools/build/tasks/list/vts_test_lib_hidl_package_list.mk
28readonly WATCHDOG=frameworks/base/services/core/java/com/android/server/Watchdog.cpp
29readonly GSI_CURRENT=build/make/target/product/gsi/current.txt
30
31readonly BASE_VERSION=${1:-$(ls $ANDROID_BUILD_TOP/$HAL_DIRECTORY | grep -E '[0-9]+\.[0-9]+' |
32 sort -n |tail -n1)}
33readonly BASE_MAJOR_VERSION=${BASE_VERSION%.*}
34readonly BASE_MINOR_VERSION=${BASE_VERSION##*.}
35
36readonly NEW_VERSION="${2:-$((${BASE_MAJOR_VERSION} + 1)).0}"
37readonly NEW_MAJOR_VERSION=${NEW_VERSION%.*}
38readonly NEW_MINOR_VERSION=${NEW_VERSION##*.}
39
40
41readonly BASE_VERSION_REGEX="${BASE_MAJOR_VERSION}[._]${BASE_MINOR_VERSION}"
42readonly NEW_VERSION_REGEX="${NEW_MAJOR_VERSION}[._]${NEW_MINOR_VERSION}"
43
44readonly BASE_VERSION_ESCAPE="${BASE_MAJOR_VERSION}\.${BASE_MINOR_VERSION}"
45readonly BASE_VERSION_UNDERSCORE="${BASE_MAJOR_VERSION}_${BASE_MINOR_VERSION}"
46readonly NEW_VERSION_UNDERSCORE="${NEW_MAJOR_VERSION}_${NEW_MINOR_VERSION}"
47updateVersion() {
48 if [ $1 == "-e" ]; then
49 local -r REGEX="$2"; shift 2
50 else
51 local -r REGEX="$BASE_VERSION_REGEX"
52 fi
53 awk -i inplace -e "{if (!/$REGEX/) print; else {
54 if (original_before) print
55 if (original_after) original_line=\$0;
56
57 gsub(/$BASE_VERSION_ESCAPE/,\"$NEW_VERSION\");
58 gsub(/$BASE_VERSION_UNDERSCORE/,\"$NEW_VERSION_UNDERSCORE\");
59 gsub(/MAJOR_VERSION=$BASE_MAJOR_VERSION/,
60 \"MAJOR_VERSION=$NEW_MAJOR_VERSION\");
61 gsub(/MINOR_VERSION=$BASE_MINOR_VERSION/,
62 \"MINOR_VERSION=$NEW_MINOR_VERSION\");
63
64 print
65 if (original_after) print original_line
66 }}" "$@"
67}
68
69updateAudioVersion() {
70 updateVersion -e "audio.*$BASE_VERSION_REGEX" "$@"
71}
72
73updateLicenceDates() {
74 # Update date on the 2 first lines
75 sed -i "1,2 s/20[0-9][0-9]/$(date +"%Y")/g" "$@"
76}
77
78echo "Creating new audio HAL V$NEW_VERSION based on V$BASE_VERSION"
79echo "Press Ctrl-C to cancel, Enter to continue"
80read
81
82MODIFIED=
83runIfNeeded() {
84 local -r TARGET=$1; shift
85 cd $ANDROID_BUILD_TOP/$TARGET
86 if grep -q -r "audio.*$NEW_VERSION_REGEX"; then
87 echo " Skipping $TARGET as already up to date"
88 else
89 echo " Updating $PWD"
90 MODIFIED+=$'\n - '$TARGET
91 "$@"
92 fi
93}
94
95createHALVersion() {
96 local -r DIRS=". common effect"
97 local COPY=
98 echo "Copy $BASE_VERSION to $NEW_VERSION in $DIRS"
99 for DIR in $DIRS; do
100 cp -Tar $DIR/$BASE_VERSION $DIR/$NEW_VERSION
101 COPY+=" $DIR/$NEW_VERSION"
102 done
103
104 echo "Replacing $BASE_VERSION by $NEW_VERSION in the copied files"
105 updateVersion $(find $COPY -type f)
106 updateLicenceDates $(find $COPY -type f)
107
108 echo "Update implementation and VTS generic code"
109 local -r FILES="*/all-versions/default/Android.bp */all-versions/vts/functional/Android.bp"
110 updateVersion -v original_before=1 -v RS= -v ORS='\n\n' $FILES
111 sed -i '${/^$/d}' $FILES # Remove \n at the end of the files
112
113 updateVersion -v original_before=1 $HAL_SERVICE_DIRECTORY/Android.bp
114
115 updateVersion -e "audio::.*$BASE_VERSION_REGEX" -v original_after=1 \
116 $HAL_SERVICE_DIRECTORY/$HAL_SERVICE_CPP
117 updateVersion -e "audio\/.*$BASE_VERSION_REGEX" -v original_before=1 \
118 $HAL_SERVICE_DIRECTORY/$HAL_SERVICE_CPP
119
120 local -r HAL_VTS_PATH=$HAL_VTS_DIRECTORY/$NEW_VERSION/$HAL_VTS_FILE
121 mkdir -p $(dirname $HAL_VTS_PATH)
122 cat > $HAL_VTS_PATH <<EOF
123/*
124 * Copyright (C) $(date +"%Y") The Android Open Source Project
125 *
126 * Licensed under the Apache License, Version 2.0 (the "License");
127 * you may not use this file except in compliance with the License.
128 * You may obtain a copy of the License at
129 *
130 * http://www.apache.org/licenses/LICENSE-2.0
131 *
132 * Unless required by applicable law or agreed to in writing, software
133 * distributed under the License is distributed on an "AS IS" BASIS,
134 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
135 * See the License for the specific language governing permissions and
136 * limitations under the License.
137 */
138
139// pull in all the <= $BASE_VERSION tests
140#include "$BASE_VERSION/$(basename AudioPrimaryHidlHalTest.cpp)"
141EOF
142
143 echo "New HAL version $NEW_VERSION successfully created"
144}
145
146echo "Creating new audio HAL definition, default impl and VTS"
147runIfNeeded $HAL_DIRECTORY createHALVersion
148
149
150createFrameworkAdapter() {
151 updateVersion -v original_before=1 Android.bp
152 updateVersion -v original_before=1 -v RS= -v ORS='\n\n' $IMPL_FACTORYHAL/Android.bp
153 updateVersion -v original_after=1 $IMPL_FACTORYHAL
154}
155echo "Now creating the framework adapter version"
156runIfNeeded $FWK_DIRECTORY createFrameworkAdapter
157
158createVTSXML() {
159 cp -Tar V$BASE_VERSION_UNDERSCORE V$NEW_VERSION_UNDERSCORE
160 cp -Tar effect/{V$BASE_VERSION_UNDERSCORE,V$NEW_VERSION_UNDERSCORE}
161 local -r FILES=$(find {.,effect}/V$NEW_VERSION_UNDERSCORE -type f)
162 updateVersion $FILES
163 updateLicenceDates $FILES
164}
165echo "Now update VTS XML"
166runIfNeeded $VTS_DIRECTORY createVTSXML
167
168echo "Now register new VTS"
169runIfNeeded $(dirname $VTS_LIST) updateAudioVersion -v original_before=1 $(basename $VTS_LIST)
170
171echo "Now update watchdog"
172runIfNeeded $(dirname $WATCHDOG) updateAudioVersion -v original_before=1 $(basename $WATCHDOG)
173
174echo "Now update GSI current.txt"
175runIfNeeded $(dirname $GSI_CURRENT) update-vndk-list.sh
176
177if ! [ "$MODIFIED" ]; then
178 echo
179 echo "$NEW_VERSION already exist, nothing to do"
180 exit
181fi
182
183cat << EOF
184
185All File generated successfully. Please submit a patch in all those directories: $MODIFIED
186
187-----------------------------------------------------------
188WHAT WAS *NOT* DONE, and you need to do now:
189 1) You need to choose if the new HAL is optional or not for new devices.
190 Either add or replace $BASE_VERSION by $NEW_VERSION in
191 compatibility_matrices/compatibility_matrix.current.xml
192 Do not forget to update both the "audio" and "audio.effects" HAL'
193
194 2) Then you need to choose a device to update its audio HAL implementation:
195 a) Update the HAL manifest of your device: open your device manifest.xml
196 and replace $BASE_VERSION by $NEW_VERSION for both
197 - android.hardware.audio
198 - android.hardware.audio.effect
199 b) Go to your device device.mk (usually next to the manifest) and replace:
200 - android.hardware.audio@$BASE_VERSION-impl by
201 android.hardware.audio@$NEW_VERSION-impl
202 - android.hardware.audio.effect@$BASE_VERSION-impl by
203 android.hardware.audio.effect@$NEW_VERSION-impl
204EOF