Files
android/libwvdrmengine/apex/device/build.sh
Kyle Zhang 8defa640ff Add java path to args of dev_sign_bundle
Bug: 339855197
Change-Id: I61d2ea24570857c96fe0b1d273efc5c288386888
(cherry picked from commit 925fa55b4340cc57ced3da52e7d9d4a99ea5405d)
2024-07-16 06:26:25 +00:00

130 lines
3.4 KiB
Bash
Executable File

#!/bin/bash -eux
#
# Copyright (C) 2023 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This script is used to build widevine apex bundle
readonly -a ARCHS=(
"arm"
"arm64"
"arm64only"
"x86"
"x86_64"
"x86_64only"
)
function die() { format=$1; shift; printf >&2 "$format\n" $@; exit 1; }
# $@: additional build targets
# inputs: none
# outputs: ${DIST_DIR}/${arch}/${apex}-base.zip
function build_modules() {
# keep DIST_DIR to override for each arch
local dist_dir="${DIST_DIR}"
for arch in "${ARCHS[@]}"; do
# override DIST_DIR for each arch
DIST_DIR="${dist_dir}/${arch}" \
TARGET_PRODUCT="widevine_generic" \
TARGET_BASE_PRODUCT="build/target/product/module_${arch}.mk" \
build/soong/soong_ui.bash --make-mode "$@" \
ALWAYS_EMBED_NOTICES=true \
apps_only \
dist \
lint-check
done
# restore DIST_DIR
DIST_DIR="${dist_dir}"
}
# $1: apex
# inputs: ${DIST_DIR}/${arch}/${apex}-base.zip
# outputs: ${DIST_DIR}/${apex}.aab
function build_bundle() {
local -r apex=$1
# collect base.zip files
local -a zips
for arch in "${ARCHS[@]}"; do
zips+=("${DIST_DIR}/${arch}/${apex}-base.zip")
done
local -ra zips
# extract bundle_config.json from one of zip files
unzip -o -d "${TMPDIR}/${apex}" "${zips[0]}" bundle_config.json
# merge base.zip files
local -r base_zip="${TMPDIR}/${apex}/base.zip"
${MERGE_ZIPS} \
-ignore-duplicates \
-stripFile bundle_config.json \
"${base_zip}" \
"${zips[@]}"
# build bundle
${BUNDLETOOL} build-bundle \
--overwrite \
--modules "${base_zip}" \
--config "${TMPDIR}/${apex}/bundle_config.json" \
--output "${DIST_DIR}/${apex}.aab"
}
# inputs: ${DIST_DIR}/${arch}/${apex}-base.zip
# outputs: ${DIST_DIR}/${apex}.aab
function build_bundles() {
for app in ${TARGET_BUILD_APPS}; do
build_bundle "${app}"
done
}
# inputs: ${DIST_DIR}/${apex}.aab
# outputs: ${DIST_DIR}/dev_keys_signed/${apex}/${apex}.apks
function sign_bundles() {
${DEV_SIGN_BUNDLE} \
--java_binary_path "${ANDROID_JAVA_HOME}/bin/java" \
--input_dir "${DIST_DIR}" \
--output_dir "${DIST_DIR}/dev_keys_signed"
}
function configure_build() {
# Assign to a variable and eval that, since bash ignores any error status from
# the command substitution if it's directly on the eval line.
local -r vars="$(TARGET_PRODUCT='' build/soong/soong_ui.bash --dumpvars-mode \
--vars="ANDROID_JAVA_HOME TMPDIR OUT_DIR")"
eval "${vars}"
declare -gr BUNDLETOOL=${OUT_DIR}/host/linux-x86/bin/bundletool
declare -gr MERGE_ZIPS=${OUT_DIR}/host/linux-x86/bin/merge_zips
declare -gr DEV_SIGN_BUNDLE=${OUT_DIR}/host/linux-x86/bin/dev_sign_bundle
}
function main() {
[[ -e "build/make/core/Makefile" ]] || die "$0 must be run from the top of the Android source tree."
configure_build
build_modules bundletool merge_zips dev_sign_bundle
build_bundles # use bundletool & merge_zips
sign_bundles # use dev_sign_bundle
}
main