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