blob: 10266ed1da15cb81452a1d2fa1b567a0f5455c06 [file] [log] [blame]
Alex Buynytskyyafddc072023-02-09 22:40:53 +00001#!/bin/bash
2
3set -ex
4
Alex Buynytskyybdcef7b2023-02-19 18:40:44 +00005function apply_droidstubs_hack() {
Alex Buynytskyy775ad5f2023-02-21 19:28:48 +00006 if ! grep -q 'STOPSHIP: RESTORE THIS LOGIC WHEN DECLARING "REL" BUILD' "$top/build/soong/java/droidstubs.go" ; then
Alex Buynytskyy00a88ec2023-05-05 22:10:53 +00007 local build_soong_git_root="$(readlink -f $top/build/soong)"
Alex Buynytskyybce1a512023-06-16 20:06:38 +00008 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 Buynytskyybdcef7b2023-02-19 18:40:44 +00009 fi
10}
11
12function finalize_bionic_ndk() {
13 # Adding __ANDROID_API_<>__.
14 # If this hasn't done then it's not used and not really needed. Still, let's check and add this.
15 local api_level="$top/bionic/libc/include/android/api-level.h"
16 if ! grep -q "\__.*$((${FINAL_PLATFORM_SDK_VERSION}))" $api_level ; then
17 local tmpfile=$(mktemp /tmp/finalization.XXXXXX)
18 echo "
19/** Names the \"${FINAL_PLATFORM_CODENAME:0:1}\" API level ($FINAL_PLATFORM_SDK_VERSION), for comparison against \`__ANDROID_API__\`. */
20#define __ANDROID_API_${FINAL_PLATFORM_CODENAME:0:1}__ $FINAL_PLATFORM_SDK_VERSION" > "$tmpfile"
21
22 local api_level="$top/bionic/libc/include/android/api-level.h"
23 sed -i -e "/__.*$((${FINAL_PLATFORM_SDK_VERSION}-1))/r""$tmpfile" $api_level
24
25 rm "$tmpfile"
26 fi
27}
28
Alex Buynytskyy221c7232023-02-15 16:58:58 +000029function finalize_modules_utils() {
30 local shortCodename="${FINAL_PLATFORM_CODENAME:0:1}"
31 local methodPlaceholder="INSERT_NEW_AT_LEAST_${shortCodename}_METHOD_HERE"
32
33 local tmpfile=$(mktemp /tmp/finalization.XXXXXX)
34 echo " /** Checks if the device is running on a release version of Android $FINAL_PLATFORM_CODENAME or newer */
35 @ChecksSdkIntAtLeast(api = $FINAL_PLATFORM_SDK_VERSION /* BUILD_VERSION_CODES.$FINAL_PLATFORM_CODENAME */)
36 public static boolean isAtLeast${FINAL_PLATFORM_CODENAME:0:1}() {
Alex Buynytskyyf05c2492024-03-13 18:29:25 +000037 return SDK_INT >= $FINAL_PLATFORM_SDK_VERSION ||
38 (SDK_INT == $(($FINAL_PLATFORM_SDK_VERSION - 1)) && isAtLeastPreReleaseCodename(\"$FINAL_PLATFORM_CODENAME\"));
Alex Buynytskyy221c7232023-02-15 16:58:58 +000039 }" > "$tmpfile"
40
41 local javaFuncRegex='\/\*\*[^{]*isAtLeast'"${shortCodename}"'() {[^{}]*}'
42 local javaFuncReplace="N;N;N;N;N;N;N;N; s/$javaFuncRegex/$methodPlaceholder/; /$javaFuncRegex/!{P;D};"
43
44 local javaSdkLevel="$top/frameworks/libs/modules-utils/java/com/android/modules/utils/build/SdkLevel.java"
45 sed -i "$javaFuncReplace" $javaSdkLevel
46
47 sed -i "/${methodPlaceholder}"'/{
48 r '"$tmpfile"'
49 d}' $javaSdkLevel
50
51 echo "// Checks if the device is running on release version of Android ${FINAL_PLATFORM_CODENAME:0:1} or newer.
Alex Buynytskyyf05c2492024-03-13 18:29:25 +000052inline bool IsAtLeast${FINAL_PLATFORM_CODENAME:0:1}() {
53 return android_get_device_api_level() >= $FINAL_PLATFORM_SDK_VERSION ||
54 (android_get_device_api_level() == $(($FINAL_PLATFORM_SDK_VERSION - 1)) &&
55 detail::IsAtLeastPreReleaseCodename(\"$FINAL_PLATFORM_CODENAME\"));
56}" > "$tmpfile"
Alex Buynytskyy221c7232023-02-15 16:58:58 +000057
58 local cppFuncRegex='\/\/[^{]*IsAtLeast'"${shortCodename}"'() {[^{}]*}'
59 local cppFuncReplace="N;N;N;N;N;N; s/$cppFuncRegex/$methodPlaceholder/; /$cppFuncRegex/!{P;D};"
60
61 local cppSdkLevel="$top/frameworks/libs/modules-utils/build/include/android-modules-utils/sdk_level.h"
62 sed -i "$cppFuncReplace" $cppSdkLevel
63 sed -i "/${methodPlaceholder}"'/{
64 r '"$tmpfile"'
65 d}' $cppSdkLevel
66
67 rm "$tmpfile"
68}
69
Alex Buynytskyydf633572023-11-07 01:14:47 +000070function bumpSdkExtensionsVersion() {
71 local SDKEXT="packages/modules/SdkExtensions/"
72
73 # This used to call bump_sdk.sh utility.
74 # However due to TS, we have to build the gen_sdk with a correct set of settings.
75
76 # "$top/packages/modules/SdkExtensions/gen_sdk/bump_sdk.sh" ${FINAL_MAINLINE_EXTENSION}
77 # Leave the last commit as a set of modified files.
78 # The code to create a finalization topic will pick it up later.
79 # git -C ${SDKEXT} reset HEAD~1
80
81 local sdk="${FINAL_MAINLINE_EXTENSION}"
82 local modules_arg=
83
84 TARGET_PRODUCT=aosp_arm64 \
85 TARGET_RELEASE=fina_1 \
86 TARGET_BUILD_VARIANT=userdebug \
87 DIST_DIR=out/dist \
88 $top/build/soong/soong_ui.bash --make-mode --soong-only gen_sdk
89
90 ANDROID_BUILD_TOP="$top" out/soong/host/linux-x86/bin/gen_sdk \
91 --database ${SDKEXT}/gen_sdk/extensions_db.textpb \
92 --action new_sdk \
93 --sdk "$sdk" \
94 $modules_arg
95}
96
Steven Morelandaf6c94a2024-01-29 17:59:03 +000097function finalize_sdk_resources() {
Alex Buynytskyyafddc072023-02-09 22:40:53 +000098 local top="$(dirname "$0")"/../../../..
99 source $top/build/make/tools/finalization/environment.sh
100
Alex Buynytskyy0fa58fa2023-02-13 20:22:10 +0000101 local SDK_CODENAME="public static final int $FINAL_PLATFORM_CODENAME_JAVA = CUR_DEVELOPMENT;"
102 local SDK_VERSION="public static final int $FINAL_PLATFORM_CODENAME_JAVA = $FINAL_PLATFORM_SDK_VERSION;"
Alex Buynytskyyafddc072023-02-09 22:40:53 +0000103
Alex Buynytskyyafddc072023-02-09 22:40:53 +0000104 # The full process can be found at (INTERNAL) go/android-sdk-finalization.
105
Alex Buynytskyybdcef7b2023-02-19 18:40:44 +0000106 # apply droidstubs hack to prevent tools from incrementing an API version
107 apply_droidstubs_hack
Alex Buynytskyy0fa58fa2023-02-13 20:22:10 +0000108
109 # bionic/NDK
Alex Buynytskyybdcef7b2023-02-19 18:40:44 +0000110 finalize_bionic_ndk
Alex Buynytskyyafddc072023-02-09 22:40:53 +0000111
Alex Buynytskyyafddc072023-02-09 22:40:53 +0000112 # Finalize SDK
113
Alex Buynytskyy221c7232023-02-15 16:58:58 +0000114 # frameworks/libs/modules-utils
115 finalize_modules_utils
116
Alex Buynytskyyd873b0e2023-04-27 18:18:57 +0000117 # development/sdk
118 local platform_source="$top/development/sdk/platform_source.prop_template"
119 sed -i -e 's/Pkg\.Revision.*/Pkg\.Revision=1/g' $platform_source
120 local build_tools_source="$top/development/sdk/build_tools_source.prop_template"
121 sed -i -e 's/Pkg\.Revision.*/Pkg\.Revision=${PLATFORM_SDK_VERSION}.0.0/g' $build_tools_source
122
Cole Faustf13fd592024-04-09 09:54:23 -0700123 # build/soong
124 local codename_version="\"${FINAL_PLATFORM_CODENAME}\": ${FINAL_PLATFORM_SDK_VERSION}"
125 if ! grep -q "$codename_version" "$top/build/soong/android/api_levels.go" ; then
126 sed -i -e "/:.*$((${FINAL_PLATFORM_SDK_VERSION}-1)),/a \\\t\t$codename_version," "$top/build/soong/android/api_levels.go"
Alex Buynytskyyf7a5e2f2023-04-14 11:50:04 -0700127 fi
Alex Buynytskyyafddc072023-02-09 22:40:53 +0000128
129 # cts
Alex Buynytskyy4fb99d82024-03-11 18:14:52 +0000130 if ! grep -q "${FINAL_PLATFORM_VERSION}" "$top/cts/tests/tests/os/assets/platform_releases.txt" ; then
131 echo ${FINAL_PLATFORM_VERSION} >> "$top/cts/tests/tests/os/assets/platform_releases.txt"
132 fi
133 if ! grep -q "$((${FINAL_PLATFORM_SDK_VERSION}-1)), ${FINAL_PLATFORM_VERSION}" "$top/cts/tests/tests/os/src/android/os/cts/BuildVersionTest.java" ; then
134 sed -i -e "s/.*EXPECTED_SDKS = List.of(.*$((${FINAL_PLATFORM_SDK_VERSION}-1))/&, $FINAL_PLATFORM_SDK_VERSION/" "$top/cts/tests/tests/os/src/android/os/cts/BuildVersionTest.java"
135 fi
Alex Buynytskyyafddc072023-02-09 22:40:53 +0000136
137 # libcore
138 sed -i "s%$SDK_CODENAME%$SDK_VERSION%g" "$top/libcore/dalvik/src/main/java/dalvik/annotation/compat/VersionCodes.java"
139
140 # platform_testing
141 local version_codes="$top/platform_testing/libraries/compatibility-common-util/src/com/android/compatibility/common/util/VersionCodes.java"
Alex Buynytskyy0fa58fa2023-02-13 20:22:10 +0000142 sed -i -e "/=.*$((${FINAL_PLATFORM_SDK_VERSION}-1));/a \\ ${SDK_VERSION}" $version_codes
Alex Buynytskyyafddc072023-02-09 22:40:53 +0000143
Alex Buynytskyy48d64b82023-12-04 23:13:39 +0000144 # tools/platform-compat
145 local class2nonsdklist="$top/tools/platform-compat/java/com/android/class2nonsdklist/Class2NonSdkList.java"
146 if ! grep -q "\.*map.put($((${FINAL_PLATFORM_SDK_VERSION}))" $class2nonsdklist ; then
147 local sdk_version="map.put(${FINAL_PLATFORM_SDK_VERSION}, FLAG_UNSUPPORTED);"
148 sed -i -e "/.*map.put($((${FINAL_PLATFORM_SDK_VERSION}-1))/a \\ ${sdk_version}" $class2nonsdklist
149 fi
150
Alex Buynytskyyafddc072023-02-09 22:40:53 +0000151 # Finalize resources
152 "$top/frameworks/base/tools/aapt2/tools/finalize_res.py" \
153 "$top/frameworks/base/core/res/res/values/public-staging.xml" \
154 "$top/frameworks/base/core/res/res/values/public-final.xml"
155
156 # frameworks/base
157 sed -i "s%$SDK_CODENAME%$SDK_VERSION%g" "$top/frameworks/base/core/java/android/os/Build.java"
Alex Buynytskyy0fa58fa2023-02-13 20:22:10 +0000158 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"
159 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 Buynytskyyafddc072023-02-09 22:40:53 +0000160
161 # Bump Mainline SDK extension version.
Alex Buynytskyydf633572023-11-07 01:14:47 +0000162 bumpSdkExtensionsVersion
Alex Buynytskyyf7a5e2f2023-04-14 11:50:04 -0700163
Alex Buynytskyydf633572023-11-07 01:14:47 +0000164 # target to build SDK
165 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 Buynytskyyafddc072023-02-09 22:40:53 +0000166
167 # Force update current.txt
Alex Buynytskyydf633572023-11-07 01:14:47 +0000168 $sdk_m clobber
169 $sdk_m update-api
Alex Buynytskyyafddc072023-02-09 22:40:53 +0000170}
171
Steven Morelandaf6c94a2024-01-29 17:59:03 +0000172finalize_sdk_resources
Alex Buynytskyyafddc072023-02-09 22:40:53 +0000173