Add script for updating mainline module tag vars

The aml/update_mainline_tags.sh script updates the vars/aml_tags file
to include the latest available mainline (APEX) module tags in its
modules_to_tags array, based on the keys present in the modules_to_apps
associative array of vars/aml.

Issue: calyxos#298
Change-Id: Ibcb5472a6a48d3d8317ec616ba521b18b407602f
This commit is contained in:
Tommy Webb 2023-04-28 16:53:24 -04:00
parent b9d3003904
commit 5c2677da94
3 changed files with 141 additions and 0 deletions

86
aml/update_mainline_tags.sh Executable file
View File

@ -0,0 +1,86 @@
#!/bin/bash
# SPDX-FileCopyrightText: 2023 The Calyx Institute
#
# SPDX-License-Identifier: Apache-2.0
#
# update_mainline_tags.sh:
#
# Update the vars/aml_tags file to include the latest available mainline
# module tags in its modules_to_tags array, based on the keys present
# in the modules_to_apps associative array of vars/aml.
#
#
##############################################################################
### SET ###
# use bash strict mode
set -euo pipefail
### TRAPS ###
# trap signals for clean exit
trap 'exit $?' EXIT
trap 'error_m interrupted!' SIGINT
### CONSTANTS ###
readonly script_path="$(cd "$(dirname "$0")";pwd -P)"
readonly vars_path="${script_path}/../vars"
readonly top="${script_path}/../../.."
readonly aml_tags_path="${vars_path}/aml_tags"
readonly tags_header="# Updated automatically by aml/update_mainline_tags.sh"
source "${vars_path}/aml"
## HELP MESSAGE (USAGE INFO)
# TODO
### FUNCTIONS ###
get_all_aml_tags_sorted() {
# Sorted with the assumption that newer versions have version numbers that are
# alphanumerically greater.
git ls-remote --refs --tags "$android_manifest_url" 'aml_*' | cut -d$'\t' -f2- | \
sed -e 's!^refs/tags/!!' | sort
}
main() {
err=0
all_aml_tags="$(get_all_aml_tags_sorted)" || err=$?
if [ -z "$all_aml_tags" -o $err -ne 0 ]; then
[ $err -ne 0 ] || err=1
echo "Failed to retrieve mainline modules tags; quitting..." >&2
return $err
fi
local -a modules_and_tags_lines=()
for module in "${!modules_to_apps[@]}"; do
local tag="$(printf "%s" "$all_aml_tags" | grep -- "^aml_${module}_" | tail -n1)" || err=$?
if [ -z "$tag" -o $err -ne 0 ]; then
[ $err -ne 0 ] || err=1
echo "Failed to determine tag for $module; quitting..." >&2
return $err
fi
modules_and_tags_lines+=(" [$module]=\"$tag\"")
done
local sorted_modules_and_tags="$(printf "%s\n" "${modules_and_tags_lines[@]}" | sort)"
printf "%s\nreadonly -A modules_to_tags=(\n%s\n)\n" "$tags_header" "$sorted_modules_and_tags" \
| tee "$aml_tags_path"
echo "Successfully updated $aml_tags_path"
}
### RUN PROGRAM ###
main "$@"
##

31
vars/aml Normal file
View File

@ -0,0 +1,31 @@
readonly android_manifest_url="https://android.googlesource.com/platform/manifest"
# Updated manually
readonly -A modules_to_apps=(
[adb]="com.android.adbd"
[ads]="com.android.adservices"
[art]="com.android.art"
[ase]="com.android.appsearch"
[cbr]="com.android.cellbroadcast"
[con]="com.android.conscrypt"
# DocumentsUI is not currently handled modularly
# [doc]="com.android.documentsui"
[ext]="com.android.extservices"
[ips]="com.android.ipsec"
[med]="com.android.media"
[mpr]="com.android.mediaprovider"
# NetworkStack is not currently handled modularly
# [net]="NetworkStack CaptivePortalLogin"
[neu]="com.android.neuralnetworks"
[per]="com.android.permission"
[res]="com.android.resolv"
[sch]="com.android.scheduling"
[sdk]="com.android.sdkext"
[sta]="com.android.os.statsd"
[swc]="com.android.media.swcodec"
[tet]="com.android.tethering"
# Google uses numbered tzdata package names for different Android versions. AOSP does not.
[tz4]="com.android.tzdata"
[uwb]="com.android.uwb"
[wif]="com.android.wifi"
)

24
vars/aml_tags Normal file
View File

@ -0,0 +1,24 @@
# Updated automatically by aml/update_mainline_tags.sh
readonly -A modules_to_tags=(
[adb]="aml_adb_331610000"
[ads]="aml_ads_331611190"
[art]="aml_art_331612010"
[ase]="aml_ase_331112000"
[cbr]="aml_cbr_331610010"
[con]="aml_con_331411000"
[ext]="aml_ext_331412000"
[ips]="aml_ips_331310000"
[med]="aml_med_331612000"
[mpr]="aml_mpr_331613010"
[neu]="aml_neu_331310000"
[per]="aml_per_331611010"
[res]="aml_res_331611010"
[sch]="aml_sch_331111000"
[sdk]="aml_sdk_331410000"
[sta]="aml_sta_331610000"
[swc]="aml_swc_331612000"
[tet]="aml_tet_331511160"
[tz4]="aml_tz4_331314030"
[uwb]="aml_uwb_331611010"
[wif]="aml_wif_331613000"
)