Files
android_vendor_pawlet/vendorsetup.sh

268 lines
8.4 KiB
Bash

#!/bin/bash
#
# Copyright (C) 2012 The CyanogenMod Project
# Copyright (C) 2017 The LineageOS Project
# Copyright (C) 2025 oxmc / PawletOS
#
# SPDX-License-Identifier: Apache-2.0
#
# PawletOS build environment helpers.
# Adapted from vendor/lineage/build/envsetup.sh (The LineageOS Project).
#
# ---------------------------------------------------------------------------
# check_product — verify the product is a pawlet_* target
# ---------------------------------------------------------------------------
function check_product()
{
local T=$(gettop)
if [ ! "$T" ]; then
echo "Couldn't locate the top of the tree. Try setting TOP." >&2
return
fi
if (echo -n $1 | grep -q -e "^pawlet_"); then
PAWLET_BUILD=$(echo -n $1 | sed -e 's/^pawlet_//g')
else
PAWLET_BUILD=
fi
export PAWLET_BUILD
TARGET_PRODUCT=$1 \
TARGET_BUILD_VARIANT= \
TARGET_BUILD_TYPE= \
TARGET_BUILD_APPS= \
_get_build_var_cached TARGET_DEVICE > /dev/null
}
# ---------------------------------------------------------------------------
# breakfast <device> [variant] — configure build for a PawletOS device
# ---------------------------------------------------------------------------
function breakfast()
{
local target=$1
local variant=$2
source ${ANDROID_BUILD_TOP}/vendor/pawlet/vars/aosp_target_release
if [ $# -eq 0 ]; then
lunch
else
if [[ "$target" =~ -(user|userdebug|eng)$ ]]; then
lunch $target
else
if [ -z "$variant" ]; then
variant="userdebug"
fi
lunch pawlet_${target}-${aosp_target_release}-${variant}
fi
fi
return $?
}
alias bib=breakfast
# ---------------------------------------------------------------------------
# brunch <device> — breakfast + make bacon
# ---------------------------------------------------------------------------
function brunch()
{
breakfast $*
if [ $? -eq 0 ]; then
mka bacon
else
echo "No such item in brunch menu. Try 'breakfast'"
return 1
fi
return $?
}
# ---------------------------------------------------------------------------
# mka — invoke the Android build system
# ---------------------------------------------------------------------------
function mka()
{
m "$@"
}
# ---------------------------------------------------------------------------
# cmka — clean + build a specific target
# ---------------------------------------------------------------------------
function cmka()
{
if [ ! -z "$1" ]; then
for i in "$@"; do
case $i in
bacon|otapackage|systemimage)
mka installclean
mka $i
;;
*)
mka clean-$i
mka $i
;;
esac
done
else
mka clean
mka
fi
}
# ---------------------------------------------------------------------------
# cout — cd to the output directory
# ---------------------------------------------------------------------------
function cout()
{
if [ "$OUT" ]; then
cd $OUT
else
echo "Couldn't locate out directory. Try setting OUT."
fi
}
# ---------------------------------------------------------------------------
# pawlet_img <device> — build the flashable SD-card image via mkimg.sh
# ---------------------------------------------------------------------------
function pawlet_img()
{
local device=${1:-${PAWLET_BUILD}}
if [[ -z "$device" ]]; then
echo "Usage: pawlet_img <device>"
return 1
fi
local mkimg="device/brcm/${device}/mkimg.sh"
if [[ ! -f "$mkimg" ]]; then
echo "mkimg.sh not found: $mkimg"
return 1
fi
bash "$mkimg"
}
# ---------------------------------------------------------------------------
# repopick — cherry-pick patches from a Gerrit-style review server
# ---------------------------------------------------------------------------
function repopick()
{
local T=$(gettop)
$T/vendor/pawlet/build/tools/repopick.py "$@"
}
# ---------------------------------------------------------------------------
# reposync — wrapper around 'repo sync'
# ---------------------------------------------------------------------------
function reposync()
{
repo sync -j4 "$@"
}
# ---------------------------------------------------------------------------
# repodiff — show diff across all repos between two refs
# ---------------------------------------------------------------------------
function repodiff()
{
if [ -z "$*" ]; then
echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
return
fi
diffopts=$* repo forall -c \
'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null;'
}
# ---------------------------------------------------------------------------
# pawlet_version — print current version info
# ---------------------------------------------------------------------------
function pawlet_version()
{
local ver=$(get_build_var PAWLET_VERSION 2>/dev/null)
local type=$(get_build_var PAWLET_BUILDTYPE 2>/dev/null)
echo "PawletOS ${ver:-unknown} (${type:-UNOFFICIAL})"
}
# ---------------------------------------------------------------------------
# pbuild — build the standard PawletOS partition images
# pbuild → boot + system + system_ext + vendor + product, all cores
# pbuild -j8 → same with custom parallelism
# ---------------------------------------------------------------------------
function pbuild()
{
m bootimage systemimage systemextimage vendorimage productimage -j$(nproc) "$@"
}
# ---------------------------------------------------------------------------
# pdist — build the dist target, producing a target_files zip for signing
# ---------------------------------------------------------------------------
function pdist()
{
m dist -j$(nproc) "$@"
}
# ---------------------------------------------------------------------------
# psign — sign a target_files zip with PawletOS release keys
# psign → auto-detects latest zip in dist/
# psign input.zip → sign specific zip → signed-target_files.zip
# psign input.zip output.zip → explicit input and output
#
# Presigned microG/FDroid APKs are excluded from re-signing automatically.
# ---------------------------------------------------------------------------
function psign()
{
local T=$(gettop)
local distdir="${DIST_DIR:-${OUT_DIR:-out}/dist}"
local input="${1:-$(ls -t "${distdir}"/*-target_files-*.zip 2>/dev/null | head -1)}"
local output="${2:-signed-target_files.zip}"
if [ -z "$input" ] || [ ! -f "$input" ]; then
echo "psign: no target_files zip found — run pdist first, or pass the path explicitly." >&2
return 1
fi
echo "psign: signing $input$output"
"${T}/build/make/tools/releasetools/sign_target_files_apks" \
-o \
--default_key_mappings ~/pawlet-certs \
--extra_apks GmsCore= \
--extra_apks GsfProxy= \
--extra_apks FakeStore= \
--extra_apks FDroid= \
--extra_apks FDroidPrivilegedExtension= \
"$input" "$output"
}
# ---------------------------------------------------------------------------
# pota — generate a full or incremental OTA package
# pota → full OTA from signed-target_files.zip
# pota -i prev-signed.zip → incremental OTA against a previous build
# pota signed.zip out.zip → explicit input/output
# pota -i prev.zip new.zip out.zip
# ---------------------------------------------------------------------------
function pota()
{
local T=$(gettop)
local incremental_flag=""
local input="signed-target_files.zip"
local output="pawlet-ota.zip"
local input_set=""
while [[ $# -gt 0 ]]; do
case $1 in
-i) incremental_flag="-i $2"; shift 2 ;;
*)
if [ -z "$input_set" ]; then
input=$1; input_set=1
else
output=$1
fi
shift ;;
esac
done
echo "pota: building OTA $input$output${incremental_flag:+ (incremental)}"
"${T}/build/make/tools/releasetools/ota_from_target_files" \
-k ~/pawlet-certs/releasekey \
$incremental_flag \
"$input" "$output"
echo "pota: done → $output"
}
echo "PawletOS build helpers loaded."