blob: 671b036e6010cc504d4f96503011c633fe408391 [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
Alex Buynytskyyf7a5e2f2023-04-14 11:50:04 -070012function 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 Buynytskyy00a88ec2023-05-05 22:10:53 +000014 local base_git_root="$(readlink -f $top/frameworks/base)"
Alex Buynytskyybce1a512023-06-16 20:06:38 +000015 patch --strip=1 --no-backup-if-mismatch --directory="$base_git_root" --input=../../build/make/tools/finalization/frameworks_base.apply_resource_sdk_int.diff
Alex Buynytskyyf7a5e2f2023-04-14 11:50:04 -070016 fi
17}
18
Alex Buynytskyybdcef7b2023-02-19 18:40:44 +000019function 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 Buynytskyy221c7232023-02-15 16:58:58 +000036function 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.
58inline 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 Buynytskyydf633572023-11-07 01:14:47 +000072function 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 Buynytskyyafddc072023-02-09 22:40:53 +000099function finalize_aidl_vndk_sdk_resources() {
100 local top="$(dirname "$0")"/../../../..
101 source $top/build/make/tools/finalization/environment.sh
102
Alex Buynytskyy0fa58fa2023-02-13 20:22:10 +0000103 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 Buynytskyyafddc072023-02-09 22:40:53 +0000105
Alex Buynytskyyafddc072023-02-09 22:40:53 +0000106 # The full process can be found at (INTERNAL) go/android-sdk-finalization.
107
Alex Buynytskyybdcef7b2023-02-19 18:40:44 +0000108 # apply droidstubs hack to prevent tools from incrementing an API version
109 apply_droidstubs_hack
Alex Buynytskyy0fa58fa2023-02-13 20:22:10 +0000110
111 # bionic/NDK
Alex Buynytskyybdcef7b2023-02-19 18:40:44 +0000112 finalize_bionic_ndk
Alex Buynytskyyafddc072023-02-09 22:40:53 +0000113
Alex Buynytskyyb1f263c2023-11-08 19:26:25 +0000114 # 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 Buynytskyyafddc072023-02-09 22:40:53 +0000117
Alex Buynytskyy3fa5db02023-11-09 01:18:03 +0000118 # TODO(b/309880485)
119 # Add back create_reference_dumps and $top/build/make/target/product/gsi/current.txt
120
Alex Buynytskyyafddc072023-02-09 22:40:53 +0000121 # Finalize SDK
122
Alex Buynytskyy221c7232023-02-15 16:58:58 +0000123 # frameworks/libs/modules-utils
124 finalize_modules_utils
125
Alex Buynytskyyd873b0e2023-04-27 18:18:57 +0000126 # 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 Buynytskyyafddc072023-02-09 22:40:53 +0000132 # build/make
Alex Buynytskyy0fa58fa2023-02-13 20:22:10 +0000133 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 Buynytskyyafddc072023-02-09 22:40:53 +0000135
Cole Faustcdb1a452023-04-28 14:23:46 -0700136 # 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 Buynytskyyf7a5e2f2023-04-14 11:50:04 -0700140 fi
Alex Buynytskyyafddc072023-02-09 22:40:53 +0000141
142 # cts
Alex Buynytskyy0fa58fa2023-02-13 20:22:10 +0000143 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 Buynytskyyafddc072023-02-09 22:40:53 +0000145
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 Buynytskyy0fa58fa2023-02-13 20:22:10 +0000151 sed -i -e "/=.*$((${FINAL_PLATFORM_SDK_VERSION}-1));/a \\ ${SDK_VERSION}" $version_codes
Alex Buynytskyyafddc072023-02-09 22:40:53 +0000152
Alex Buynytskyy48d64b82023-12-04 23:13:39 +0000153 # 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 Buynytskyyafddc072023-02-09 22:40:53 +0000160 # 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 Buynytskyyf7a5e2f2023-04-14 11:50:04 -0700167 apply_resources_sdk_int_fix
Alex Buynytskyy0fa58fa2023-02-13 20:22:10 +0000168 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 Buynytskyyafddc072023-02-09 22:40:53 +0000170
171 # Bump Mainline SDK extension version.
Alex Buynytskyydf633572023-11-07 01:14:47 +0000172 bumpSdkExtensionsVersion
Alex Buynytskyyf7a5e2f2023-04-14 11:50:04 -0700173
Alex Buynytskyydf633572023-11-07 01:14:47 +0000174 # 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 Buynytskyyafddc072023-02-09 22:40:53 +0000176
177 # Force update current.txt
Alex Buynytskyydf633572023-11-07 01:14:47 +0000178 $sdk_m clobber
179 $sdk_m update-api
Alex Buynytskyyafddc072023-02-09 22:40:53 +0000180}
181
182finalize_aidl_vndk_sdk_resources
183