2023-02-09 23:40:53 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -ex
|
|
|
|
|
2023-02-19 19:40:44 +01:00
|
|
|
function apply_droidstubs_hack() {
|
2023-02-21 20:28:48 +01:00
|
|
|
if ! grep -q 'STOPSHIP: RESTORE THIS LOGIC WHEN DECLARING "REL" BUILD' "$top/build/soong/java/droidstubs.go" ; then
|
2023-02-19 19:40:44 +01:00
|
|
|
git -C "$top/build/soong" apply --allow-empty ../../build/make/tools/finalization/build_soong_java_droidstubs.go.apply_hack.diff
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-04-14 20:50:04 +02:00
|
|
|
function apply_resources_sdk_int_fix() {
|
|
|
|
if ! grep -q 'public static final int RESOURCES_SDK_INT = SDK_INT;' "$top/frameworks/base/core/java/android/os/Build.java" ; then
|
|
|
|
git -C "$top/frameworks/base" apply --allow-empty ../../build/make/tools/finalization/frameworks_base.apply_resource_sdk_int.diff
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-02-19 19:40:44 +01:00
|
|
|
function finalize_bionic_ndk() {
|
|
|
|
# Adding __ANDROID_API_<>__.
|
|
|
|
# If this hasn't done then it's not used and not really needed. Still, let's check and add this.
|
|
|
|
local api_level="$top/bionic/libc/include/android/api-level.h"
|
|
|
|
if ! grep -q "\__.*$((${FINAL_PLATFORM_SDK_VERSION}))" $api_level ; then
|
|
|
|
local tmpfile=$(mktemp /tmp/finalization.XXXXXX)
|
|
|
|
echo "
|
|
|
|
/** Names the \"${FINAL_PLATFORM_CODENAME:0:1}\" API level ($FINAL_PLATFORM_SDK_VERSION), for comparison against \`__ANDROID_API__\`. */
|
|
|
|
#define __ANDROID_API_${FINAL_PLATFORM_CODENAME:0:1}__ $FINAL_PLATFORM_SDK_VERSION" > "$tmpfile"
|
|
|
|
|
|
|
|
local api_level="$top/bionic/libc/include/android/api-level.h"
|
|
|
|
sed -i -e "/__.*$((${FINAL_PLATFORM_SDK_VERSION}-1))/r""$tmpfile" $api_level
|
|
|
|
|
|
|
|
rm "$tmpfile"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-02-15 17:58:58 +01:00
|
|
|
function finalize_modules_utils() {
|
|
|
|
local shortCodename="${FINAL_PLATFORM_CODENAME:0:1}"
|
|
|
|
local methodPlaceholder="INSERT_NEW_AT_LEAST_${shortCodename}_METHOD_HERE"
|
|
|
|
|
|
|
|
local tmpfile=$(mktemp /tmp/finalization.XXXXXX)
|
|
|
|
echo " /** Checks if the device is running on a release version of Android $FINAL_PLATFORM_CODENAME or newer */
|
|
|
|
@ChecksSdkIntAtLeast(api = $FINAL_PLATFORM_SDK_VERSION /* BUILD_VERSION_CODES.$FINAL_PLATFORM_CODENAME */)
|
|
|
|
public static boolean isAtLeast${FINAL_PLATFORM_CODENAME:0:1}() {
|
|
|
|
return SDK_INT >= $FINAL_PLATFORM_SDK_VERSION;
|
|
|
|
}" > "$tmpfile"
|
|
|
|
|
|
|
|
local javaFuncRegex='\/\*\*[^{]*isAtLeast'"${shortCodename}"'() {[^{}]*}'
|
|
|
|
local javaFuncReplace="N;N;N;N;N;N;N;N; s/$javaFuncRegex/$methodPlaceholder/; /$javaFuncRegex/!{P;D};"
|
|
|
|
|
|
|
|
local javaSdkLevel="$top/frameworks/libs/modules-utils/java/com/android/modules/utils/build/SdkLevel.java"
|
|
|
|
sed -i "$javaFuncReplace" $javaSdkLevel
|
|
|
|
|
|
|
|
sed -i "/${methodPlaceholder}"'/{
|
|
|
|
r '"$tmpfile"'
|
|
|
|
d}' $javaSdkLevel
|
|
|
|
|
|
|
|
echo "// Checks if the device is running on release version of Android ${FINAL_PLATFORM_CODENAME:0:1} or newer.
|
|
|
|
inline bool IsAtLeast${FINAL_PLATFORM_CODENAME:0:1}() { return android_get_device_api_level() >= $FINAL_PLATFORM_SDK_VERSION; }" > "$tmpfile"
|
|
|
|
|
|
|
|
local cppFuncRegex='\/\/[^{]*IsAtLeast'"${shortCodename}"'() {[^{}]*}'
|
|
|
|
local cppFuncReplace="N;N;N;N;N;N; s/$cppFuncRegex/$methodPlaceholder/; /$cppFuncRegex/!{P;D};"
|
|
|
|
|
|
|
|
local cppSdkLevel="$top/frameworks/libs/modules-utils/build/include/android-modules-utils/sdk_level.h"
|
|
|
|
sed -i "$cppFuncReplace" $cppSdkLevel
|
|
|
|
sed -i "/${methodPlaceholder}"'/{
|
|
|
|
r '"$tmpfile"'
|
|
|
|
d}' $cppSdkLevel
|
|
|
|
|
|
|
|
rm "$tmpfile"
|
|
|
|
}
|
|
|
|
|
2023-02-09 23:40:53 +01:00
|
|
|
function finalize_aidl_vndk_sdk_resources() {
|
|
|
|
local top="$(dirname "$0")"/../../../..
|
|
|
|
source $top/build/make/tools/finalization/environment.sh
|
|
|
|
|
2023-02-13 21:22:10 +01:00
|
|
|
local SDK_CODENAME="public static final int $FINAL_PLATFORM_CODENAME_JAVA = CUR_DEVELOPMENT;"
|
|
|
|
local SDK_VERSION="public static final int $FINAL_PLATFORM_CODENAME_JAVA = $FINAL_PLATFORM_SDK_VERSION;"
|
2023-02-09 23:40:53 +01:00
|
|
|
|
|
|
|
# default target to modify tree and build SDK
|
2023-03-06 11:26:08 +01:00
|
|
|
local m="$top/build/soong/soong_ui.bash --make-mode TARGET_PRODUCT=aosp_arm64 TARGET_BUILD_VARIANT=userdebug DIST_DIR=out/dist"
|
2023-02-09 23:40:53 +01:00
|
|
|
|
|
|
|
# The full process can be found at (INTERNAL) go/android-sdk-finalization.
|
|
|
|
|
2023-02-19 19:40:44 +01:00
|
|
|
# apply droidstubs hack to prevent tools from incrementing an API version
|
|
|
|
apply_droidstubs_hack
|
2023-02-13 21:22:10 +01:00
|
|
|
|
|
|
|
# bionic/NDK
|
2023-02-19 19:40:44 +01:00
|
|
|
finalize_bionic_ndk
|
2023-02-09 23:40:53 +01:00
|
|
|
|
|
|
|
# VNDK definitions for new SDK version
|
|
|
|
cp "$top/development/vndk/tools/definition-tool/datasets/vndk-lib-extra-list-current.txt" \
|
2023-02-13 21:22:10 +01:00
|
|
|
"$top/development/vndk/tools/definition-tool/datasets/vndk-lib-extra-list-$FINAL_PLATFORM_SDK_VERSION.txt"
|
2023-02-09 23:40:53 +01:00
|
|
|
|
|
|
|
AIDL_TRANSITIVE_FREEZE=true $m aidl-freeze-api create_reference_dumps
|
|
|
|
|
|
|
|
# Generate ABI dumps
|
2023-04-26 11:05:34 +02:00
|
|
|
ANDROID_BUILD_TOP="$top" out/host/linux-x86/bin/create_reference_dumps
|
2023-02-09 23:40:53 +01:00
|
|
|
|
|
|
|
echo "NOTE: THIS INTENTIONALLY MAY FAIL AND REPAIR ITSELF (until 'DONE')"
|
|
|
|
# Update new versions of files. See update-vndk-list.sh (which requires envsetup.sh)
|
|
|
|
$m check-vndk-list || \
|
|
|
|
{ cp $top/out/soong/vndk/vndk.libraries.txt $top/build/make/target/product/gsi/current.txt; }
|
|
|
|
echo "DONE: THIS INTENTIONALLY MAY FAIL AND REPAIR ITSELF"
|
|
|
|
|
|
|
|
# Finalize SDK
|
|
|
|
|
2023-02-15 17:58:58 +01:00
|
|
|
# frameworks/libs/modules-utils
|
|
|
|
finalize_modules_utils
|
|
|
|
|
2023-04-27 20:18:57 +02:00
|
|
|
# development/sdk
|
|
|
|
local platform_source="$top/development/sdk/platform_source.prop_template"
|
|
|
|
sed -i -e 's/Pkg\.Revision.*/Pkg\.Revision=1/g' $platform_source
|
|
|
|
local build_tools_source="$top/development/sdk/build_tools_source.prop_template"
|
|
|
|
sed -i -e 's/Pkg\.Revision.*/Pkg\.Revision=${PLATFORM_SDK_VERSION}.0.0/g' $build_tools_source
|
|
|
|
|
2023-02-09 23:40:53 +01:00
|
|
|
# build/make
|
|
|
|
local version_defaults="$top/build/make/core/version_defaults.mk"
|
2023-02-13 21:22:10 +01:00
|
|
|
sed -i -e "s/PLATFORM_SDK_VERSION := .*/PLATFORM_SDK_VERSION := ${FINAL_PLATFORM_SDK_VERSION}/g" $version_defaults
|
|
|
|
sed -i -e "s/PLATFORM_VERSION_LAST_STABLE := .*/PLATFORM_VERSION_LAST_STABLE := ${FINAL_PLATFORM_VERSION}/g" $version_defaults
|
|
|
|
sed -i -e "s/sepolicy_major_vers := .*/sepolicy_major_vers := ${FINAL_PLATFORM_SDK_VERSION}/g" "$top/build/make/core/config.mk"
|
|
|
|
cp "$top/build/make/target/product/gsi/current.txt" "$top/build/make/target/product/gsi/$FINAL_PLATFORM_SDK_VERSION.txt"
|
2023-02-09 23:40:53 +01:00
|
|
|
|
2023-04-28 23:23:46 +02:00
|
|
|
# build/bazel
|
|
|
|
local codename_version="\"${FINAL_PLATFORM_CODENAME}\": ${FINAL_PLATFORM_SDK_VERSION}"
|
|
|
|
if ! grep -q "$codename_version" "$top/build/bazel/rules/common/api_constants.bzl" ; then
|
|
|
|
sed -i -e "/:.*$((${FINAL_PLATFORM_SDK_VERSION}-1)),/a \\ $codename_version," "$top/build/bazel/rules/common/api_constants.bzl"
|
2023-04-14 20:50:04 +02:00
|
|
|
fi
|
2023-02-09 23:40:53 +01:00
|
|
|
|
|
|
|
# cts
|
2023-02-13 21:22:10 +01:00
|
|
|
echo ${FINAL_PLATFORM_VERSION} > "$top/cts/tests/tests/os/assets/platform_releases.txt"
|
|
|
|
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"
|
2023-02-09 23:40:53 +01:00
|
|
|
|
|
|
|
# libcore
|
|
|
|
sed -i "s%$SDK_CODENAME%$SDK_VERSION%g" "$top/libcore/dalvik/src/main/java/dalvik/annotation/compat/VersionCodes.java"
|
|
|
|
|
|
|
|
# platform_testing
|
|
|
|
local version_codes="$top/platform_testing/libraries/compatibility-common-util/src/com/android/compatibility/common/util/VersionCodes.java"
|
2023-02-13 21:22:10 +01:00
|
|
|
sed -i -e "/=.*$((${FINAL_PLATFORM_SDK_VERSION}-1));/a \\ ${SDK_VERSION}" $version_codes
|
2023-02-09 23:40:53 +01:00
|
|
|
|
|
|
|
# Finalize resources
|
|
|
|
"$top/frameworks/base/tools/aapt2/tools/finalize_res.py" \
|
|
|
|
"$top/frameworks/base/core/res/res/values/public-staging.xml" \
|
|
|
|
"$top/frameworks/base/core/res/res/values/public-final.xml"
|
|
|
|
|
|
|
|
# frameworks/base
|
|
|
|
sed -i "s%$SDK_CODENAME%$SDK_VERSION%g" "$top/frameworks/base/core/java/android/os/Build.java"
|
2023-04-14 20:50:04 +02:00
|
|
|
apply_resources_sdk_int_fix
|
2023-02-13 21:22:10 +01:00
|
|
|
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"
|
|
|
|
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"
|
2023-02-09 23:40:53 +01:00
|
|
|
|
|
|
|
# Bump Mainline SDK extension version.
|
2023-04-14 20:50:04 +02:00
|
|
|
local SDKEXT="packages/modules/SdkExtensions/"
|
2023-02-13 21:22:10 +01:00
|
|
|
"$top/packages/modules/SdkExtensions/gen_sdk/bump_sdk.sh" ${FINAL_MAINLINE_EXTENSION}
|
2023-04-14 20:50:04 +02:00
|
|
|
# Leave the last commit as a set of modified files.
|
|
|
|
# The code to create a finalization topic will pick it up later.
|
|
|
|
git -C ${SDKEXT} reset HEAD~1
|
|
|
|
|
2023-02-09 23:40:53 +01:00
|
|
|
local version_defaults="$top/build/make/core/version_defaults.mk"
|
2023-02-13 21:22:10 +01:00
|
|
|
sed -i -e "s/PLATFORM_SDK_EXTENSION_VERSION := .*/PLATFORM_SDK_EXTENSION_VERSION := ${FINAL_MAINLINE_EXTENSION}/g" $version_defaults
|
2023-02-09 23:40:53 +01:00
|
|
|
|
|
|
|
# Force update current.txt
|
|
|
|
$m clobber
|
|
|
|
$m update-api
|
|
|
|
}
|
|
|
|
|
|
|
|
finalize_aidl_vndk_sdk_resources
|
|
|
|
|