Alex Buynytskyy | afddc07 | 2023-02-09 22:40:53 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | set -ex |
| 4 | |
Alex Buynytskyy | bdcef7b | 2023-02-19 18:40:44 +0000 | [diff] [blame] | 5 | function apply_droidstubs_hack() { |
Alex Buynytskyy | 775ad5f | 2023-02-21 19:28:48 +0000 | [diff] [blame] | 6 | if ! grep -q 'STOPSHIP: RESTORE THIS LOGIC WHEN DECLARING "REL" BUILD' "$top/build/soong/java/droidstubs.go" ; then |
Alex Buynytskyy | 00a88ec | 2023-05-05 22:10:53 +0000 | [diff] [blame] | 7 | local build_soong_git_root="$(readlink -f $top/build/soong)" |
Alex Buynytskyy | bce1a51 | 2023-06-16 20:06:38 +0000 | [diff] [blame] | 8 | patch --strip=1 --no-backup-if-mismatch --directory="$build_soong_git_root" --input=../../build/make/tools/finalization/build_soong_java_droidstubs.go.apply_hack.diff |
Alex Buynytskyy | bdcef7b | 2023-02-19 18:40:44 +0000 | [diff] [blame] | 9 | fi |
| 10 | } |
| 11 | |
Alex Buynytskyy | f7a5e2f | 2023-04-14 11:50:04 -0700 | [diff] [blame] | 12 | function apply_resources_sdk_int_fix() { |
| 13 | if ! grep -q 'public static final int RESOURCES_SDK_INT = SDK_INT;' "$top/frameworks/base/core/java/android/os/Build.java" ; then |
Alex Buynytskyy | 00a88ec | 2023-05-05 22:10:53 +0000 | [diff] [blame] | 14 | local base_git_root="$(readlink -f $top/frameworks/base)" |
Alex Buynytskyy | bce1a51 | 2023-06-16 20:06:38 +0000 | [diff] [blame] | 15 | patch --strip=1 --no-backup-if-mismatch --directory="$base_git_root" --input=../../build/make/tools/finalization/frameworks_base.apply_resource_sdk_int.diff |
Alex Buynytskyy | f7a5e2f | 2023-04-14 11:50:04 -0700 | [diff] [blame] | 16 | fi |
| 17 | } |
| 18 | |
Alex Buynytskyy | bdcef7b | 2023-02-19 18:40:44 +0000 | [diff] [blame] | 19 | function finalize_bionic_ndk() { |
| 20 | # Adding __ANDROID_API_<>__. |
| 21 | # If this hasn't done then it's not used and not really needed. Still, let's check and add this. |
| 22 | local api_level="$top/bionic/libc/include/android/api-level.h" |
| 23 | if ! grep -q "\__.*$((${FINAL_PLATFORM_SDK_VERSION}))" $api_level ; then |
| 24 | local tmpfile=$(mktemp /tmp/finalization.XXXXXX) |
| 25 | echo " |
| 26 | /** Names the \"${FINAL_PLATFORM_CODENAME:0:1}\" API level ($FINAL_PLATFORM_SDK_VERSION), for comparison against \`__ANDROID_API__\`. */ |
| 27 | #define __ANDROID_API_${FINAL_PLATFORM_CODENAME:0:1}__ $FINAL_PLATFORM_SDK_VERSION" > "$tmpfile" |
| 28 | |
| 29 | local api_level="$top/bionic/libc/include/android/api-level.h" |
| 30 | sed -i -e "/__.*$((${FINAL_PLATFORM_SDK_VERSION}-1))/r""$tmpfile" $api_level |
| 31 | |
| 32 | rm "$tmpfile" |
| 33 | fi |
| 34 | } |
| 35 | |
Alex Buynytskyy | 221c723 | 2023-02-15 16:58:58 +0000 | [diff] [blame] | 36 | function finalize_modules_utils() { |
| 37 | local shortCodename="${FINAL_PLATFORM_CODENAME:0:1}" |
| 38 | local methodPlaceholder="INSERT_NEW_AT_LEAST_${shortCodename}_METHOD_HERE" |
| 39 | |
| 40 | local tmpfile=$(mktemp /tmp/finalization.XXXXXX) |
| 41 | echo " /** Checks if the device is running on a release version of Android $FINAL_PLATFORM_CODENAME or newer */ |
| 42 | @ChecksSdkIntAtLeast(api = $FINAL_PLATFORM_SDK_VERSION /* BUILD_VERSION_CODES.$FINAL_PLATFORM_CODENAME */) |
| 43 | public static boolean isAtLeast${FINAL_PLATFORM_CODENAME:0:1}() { |
| 44 | return SDK_INT >= $FINAL_PLATFORM_SDK_VERSION; |
| 45 | }" > "$tmpfile" |
| 46 | |
| 47 | local javaFuncRegex='\/\*\*[^{]*isAtLeast'"${shortCodename}"'() {[^{}]*}' |
| 48 | local javaFuncReplace="N;N;N;N;N;N;N;N; s/$javaFuncRegex/$methodPlaceholder/; /$javaFuncRegex/!{P;D};" |
| 49 | |
| 50 | local javaSdkLevel="$top/frameworks/libs/modules-utils/java/com/android/modules/utils/build/SdkLevel.java" |
| 51 | sed -i "$javaFuncReplace" $javaSdkLevel |
| 52 | |
| 53 | sed -i "/${methodPlaceholder}"'/{ |
| 54 | r '"$tmpfile"' |
| 55 | d}' $javaSdkLevel |
| 56 | |
| 57 | echo "// Checks if the device is running on release version of Android ${FINAL_PLATFORM_CODENAME:0:1} or newer. |
| 58 | inline bool IsAtLeast${FINAL_PLATFORM_CODENAME:0:1}() { return android_get_device_api_level() >= $FINAL_PLATFORM_SDK_VERSION; }" > "$tmpfile" |
| 59 | |
| 60 | local cppFuncRegex='\/\/[^{]*IsAtLeast'"${shortCodename}"'() {[^{}]*}' |
| 61 | local cppFuncReplace="N;N;N;N;N;N; s/$cppFuncRegex/$methodPlaceholder/; /$cppFuncRegex/!{P;D};" |
| 62 | |
| 63 | local cppSdkLevel="$top/frameworks/libs/modules-utils/build/include/android-modules-utils/sdk_level.h" |
| 64 | sed -i "$cppFuncReplace" $cppSdkLevel |
| 65 | sed -i "/${methodPlaceholder}"'/{ |
| 66 | r '"$tmpfile"' |
| 67 | d}' $cppSdkLevel |
| 68 | |
| 69 | rm "$tmpfile" |
| 70 | } |
| 71 | |
Alex Buynytskyy | df63357 | 2023-11-07 01:14:47 +0000 | [diff] [blame] | 72 | function bumpSdkExtensionsVersion() { |
| 73 | local SDKEXT="packages/modules/SdkExtensions/" |
| 74 | |
| 75 | # This used to call bump_sdk.sh utility. |
| 76 | # However due to TS, we have to build the gen_sdk with a correct set of settings. |
| 77 | |
| 78 | # "$top/packages/modules/SdkExtensions/gen_sdk/bump_sdk.sh" ${FINAL_MAINLINE_EXTENSION} |
| 79 | # Leave the last commit as a set of modified files. |
| 80 | # The code to create a finalization topic will pick it up later. |
| 81 | # git -C ${SDKEXT} reset HEAD~1 |
| 82 | |
| 83 | local sdk="${FINAL_MAINLINE_EXTENSION}" |
| 84 | local modules_arg= |
| 85 | |
| 86 | TARGET_PRODUCT=aosp_arm64 \ |
| 87 | TARGET_RELEASE=fina_1 \ |
| 88 | TARGET_BUILD_VARIANT=userdebug \ |
| 89 | DIST_DIR=out/dist \ |
| 90 | $top/build/soong/soong_ui.bash --make-mode --soong-only gen_sdk |
| 91 | |
| 92 | ANDROID_BUILD_TOP="$top" out/soong/host/linux-x86/bin/gen_sdk \ |
| 93 | --database ${SDKEXT}/gen_sdk/extensions_db.textpb \ |
| 94 | --action new_sdk \ |
| 95 | --sdk "$sdk" \ |
| 96 | $modules_arg |
| 97 | } |
| 98 | |
Alex Buynytskyy | afddc07 | 2023-02-09 22:40:53 +0000 | [diff] [blame] | 99 | function finalize_aidl_vndk_sdk_resources() { |
| 100 | local top="$(dirname "$0")"/../../../.. |
| 101 | source $top/build/make/tools/finalization/environment.sh |
| 102 | |
Alex Buynytskyy | 0fa58fa | 2023-02-13 20:22:10 +0000 | [diff] [blame] | 103 | local SDK_CODENAME="public static final int $FINAL_PLATFORM_CODENAME_JAVA = CUR_DEVELOPMENT;" |
| 104 | local SDK_VERSION="public static final int $FINAL_PLATFORM_CODENAME_JAVA = $FINAL_PLATFORM_SDK_VERSION;" |
Alex Buynytskyy | afddc07 | 2023-02-09 22:40:53 +0000 | [diff] [blame] | 105 | |
Alex Buynytskyy | afddc07 | 2023-02-09 22:40:53 +0000 | [diff] [blame] | 106 | # The full process can be found at (INTERNAL) go/android-sdk-finalization. |
| 107 | |
Alex Buynytskyy | bdcef7b | 2023-02-19 18:40:44 +0000 | [diff] [blame] | 108 | # apply droidstubs hack to prevent tools from incrementing an API version |
| 109 | apply_droidstubs_hack |
Alex Buynytskyy | 0fa58fa | 2023-02-13 20:22:10 +0000 | [diff] [blame] | 110 | |
| 111 | # bionic/NDK |
Alex Buynytskyy | bdcef7b | 2023-02-19 18:40:44 +0000 | [diff] [blame] | 112 | finalize_bionic_ndk |
Alex Buynytskyy | afddc07 | 2023-02-09 22:40:53 +0000 | [diff] [blame] | 113 | |
Alex Buynytskyy | b1f263c | 2023-11-08 19:26:25 +0000 | [diff] [blame] | 114 | # pre-finalization build target (trunk) |
| 115 | local aidl_m="$top/build/soong/soong_ui.bash --make-mode TARGET_PRODUCT=aosp_arm64 TARGET_RELEASE=trunk TARGET_BUILD_VARIANT=userdebug DIST_DIR=out/dist" |
| 116 | AIDL_TRANSITIVE_FREEZE=true $aidl_m aidl-freeze-api |
Alex Buynytskyy | afddc07 | 2023-02-09 22:40:53 +0000 | [diff] [blame] | 117 | |
Alex Buynytskyy | 3fa5db0 | 2023-11-09 01:18:03 +0000 | [diff] [blame] | 118 | # TODO(b/309880485) |
| 119 | # Add back create_reference_dumps and $top/build/make/target/product/gsi/current.txt |
| 120 | |
Alex Buynytskyy | afddc07 | 2023-02-09 22:40:53 +0000 | [diff] [blame] | 121 | # Finalize SDK |
| 122 | |
Alex Buynytskyy | 221c723 | 2023-02-15 16:58:58 +0000 | [diff] [blame] | 123 | # frameworks/libs/modules-utils |
| 124 | finalize_modules_utils |
| 125 | |
Alex Buynytskyy | d873b0e | 2023-04-27 18:18:57 +0000 | [diff] [blame] | 126 | # development/sdk |
| 127 | local platform_source="$top/development/sdk/platform_source.prop_template" |
| 128 | sed -i -e 's/Pkg\.Revision.*/Pkg\.Revision=1/g' $platform_source |
| 129 | local build_tools_source="$top/development/sdk/build_tools_source.prop_template" |
| 130 | sed -i -e 's/Pkg\.Revision.*/Pkg\.Revision=${PLATFORM_SDK_VERSION}.0.0/g' $build_tools_source |
| 131 | |
Alex Buynytskyy | afddc07 | 2023-02-09 22:40:53 +0000 | [diff] [blame] | 132 | # build/make |
Alex Buynytskyy | 0fa58fa | 2023-02-13 20:22:10 +0000 | [diff] [blame] | 133 | sed -i -e "s/sepolicy_major_vers := .*/sepolicy_major_vers := ${FINAL_PLATFORM_SDK_VERSION}/g" "$top/build/make/core/config.mk" |
| 134 | cp "$top/build/make/target/product/gsi/current.txt" "$top/build/make/target/product/gsi/$FINAL_PLATFORM_SDK_VERSION.txt" |
Alex Buynytskyy | afddc07 | 2023-02-09 22:40:53 +0000 | [diff] [blame] | 135 | |
Cole Faust | cdb1a45 | 2023-04-28 14:23:46 -0700 | [diff] [blame] | 136 | # build/bazel |
| 137 | local codename_version="\"${FINAL_PLATFORM_CODENAME}\": ${FINAL_PLATFORM_SDK_VERSION}" |
| 138 | if ! grep -q "$codename_version" "$top/build/bazel/rules/common/api_constants.bzl" ; then |
| 139 | sed -i -e "/:.*$((${FINAL_PLATFORM_SDK_VERSION}-1)),/a \\ $codename_version," "$top/build/bazel/rules/common/api_constants.bzl" |
Alex Buynytskyy | f7a5e2f | 2023-04-14 11:50:04 -0700 | [diff] [blame] | 140 | fi |
Alex Buynytskyy | afddc07 | 2023-02-09 22:40:53 +0000 | [diff] [blame] | 141 | |
| 142 | # cts |
Alex Buynytskyy | 0fa58fa | 2023-02-13 20:22:10 +0000 | [diff] [blame] | 143 | echo ${FINAL_PLATFORM_VERSION} > "$top/cts/tests/tests/os/assets/platform_releases.txt" |
| 144 | sed -i -e "s/EXPECTED_SDK = $((${FINAL_PLATFORM_SDK_VERSION}-1))/EXPECTED_SDK = ${FINAL_PLATFORM_SDK_VERSION}/g" "$top/cts/tests/tests/os/src/android/os/cts/BuildVersionTest.java" |
Alex Buynytskyy | afddc07 | 2023-02-09 22:40:53 +0000 | [diff] [blame] | 145 | |
| 146 | # libcore |
| 147 | sed -i "s%$SDK_CODENAME%$SDK_VERSION%g" "$top/libcore/dalvik/src/main/java/dalvik/annotation/compat/VersionCodes.java" |
| 148 | |
| 149 | # platform_testing |
| 150 | local version_codes="$top/platform_testing/libraries/compatibility-common-util/src/com/android/compatibility/common/util/VersionCodes.java" |
Alex Buynytskyy | 0fa58fa | 2023-02-13 20:22:10 +0000 | [diff] [blame] | 151 | sed -i -e "/=.*$((${FINAL_PLATFORM_SDK_VERSION}-1));/a \\ ${SDK_VERSION}" $version_codes |
Alex Buynytskyy | afddc07 | 2023-02-09 22:40:53 +0000 | [diff] [blame] | 152 | |
Alex Buynytskyy | 48d64b8 | 2023-12-04 23:13:39 +0000 | [diff] [blame] | 153 | # tools/platform-compat |
| 154 | local class2nonsdklist="$top/tools/platform-compat/java/com/android/class2nonsdklist/Class2NonSdkList.java" |
| 155 | if ! grep -q "\.*map.put($((${FINAL_PLATFORM_SDK_VERSION}))" $class2nonsdklist ; then |
| 156 | local sdk_version="map.put(${FINAL_PLATFORM_SDK_VERSION}, FLAG_UNSUPPORTED);" |
| 157 | sed -i -e "/.*map.put($((${FINAL_PLATFORM_SDK_VERSION}-1))/a \\ ${sdk_version}" $class2nonsdklist |
| 158 | fi |
| 159 | |
Alex Buynytskyy | afddc07 | 2023-02-09 22:40:53 +0000 | [diff] [blame] | 160 | # Finalize resources |
| 161 | "$top/frameworks/base/tools/aapt2/tools/finalize_res.py" \ |
| 162 | "$top/frameworks/base/core/res/res/values/public-staging.xml" \ |
| 163 | "$top/frameworks/base/core/res/res/values/public-final.xml" |
| 164 | |
| 165 | # frameworks/base |
| 166 | sed -i "s%$SDK_CODENAME%$SDK_VERSION%g" "$top/frameworks/base/core/java/android/os/Build.java" |
Alex Buynytskyy | f7a5e2f | 2023-04-14 11:50:04 -0700 | [diff] [blame] | 167 | apply_resources_sdk_int_fix |
Alex Buynytskyy | 0fa58fa | 2023-02-13 20:22:10 +0000 | [diff] [blame] | 168 | sed -i -e "/=.*$((${FINAL_PLATFORM_SDK_VERSION}-1)),/a \\ SDK_${FINAL_PLATFORM_CODENAME_JAVA} = ${FINAL_PLATFORM_SDK_VERSION}," "$top/frameworks/base/tools/aapt/SdkConstants.h" |
| 169 | sed -i -e "/=.*$((${FINAL_PLATFORM_SDK_VERSION}-1)),/a \\ SDK_${FINAL_PLATFORM_CODENAME_JAVA} = ${FINAL_PLATFORM_SDK_VERSION}," "$top/frameworks/base/tools/aapt2/SdkConstants.h" |
Alex Buynytskyy | afddc07 | 2023-02-09 22:40:53 +0000 | [diff] [blame] | 170 | |
| 171 | # Bump Mainline SDK extension version. |
Alex Buynytskyy | df63357 | 2023-11-07 01:14:47 +0000 | [diff] [blame] | 172 | bumpSdkExtensionsVersion |
Alex Buynytskyy | f7a5e2f | 2023-04-14 11:50:04 -0700 | [diff] [blame] | 173 | |
Alex Buynytskyy | df63357 | 2023-11-07 01:14:47 +0000 | [diff] [blame] | 174 | # target to build SDK |
| 175 | local sdk_m="$top/build/soong/soong_ui.bash --make-mode TARGET_PRODUCT=aosp_arm64 TARGET_RELEASE=fina_1 TARGET_BUILD_VARIANT=userdebug DIST_DIR=out/dist" |
Alex Buynytskyy | afddc07 | 2023-02-09 22:40:53 +0000 | [diff] [blame] | 176 | |
| 177 | # Force update current.txt |
Alex Buynytskyy | df63357 | 2023-11-07 01:14:47 +0000 | [diff] [blame] | 178 | $sdk_m clobber |
| 179 | $sdk_m update-api |
Alex Buynytskyy | afddc07 | 2023-02-09 22:40:53 +0000 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | finalize_aidl_vndk_sdk_resources |
| 183 | |