Files

96 lines
3.9 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# build.sh — PawletOS Lawnchair build dispatcher
#
# Usage:
# ./build.sh prebuilt # known-good flow: plain Gradle, vendored AIDL + stub jars
# ./build.sh aosp # build against a local AOSP checkout (requires one on THIS machine)
# ./build.sh aosp --skip-jars # AIDL swap only, keep Lawnchair's vendored framework-16.jar
# ./build.sh aosp --wmshell # also swap WindowManager-Shell-16.jar (heavier, see README)
# ./build.sh aosp --clean # restore originals first, then re-apply swaps and build
# ./build.sh restore # undo all AOSP-bridge changes, back to pristine prebuilt state
# ./build.sh clone # clone the Lawnchair repo next to this folder if missing
#
# Env vars:
# AOSP_ROOT AOSP checkout root. If unset, auto-detected (including the
# case where this repo is checked out inside the AOSP tree at
# external/build-tools/lawnchair/build).
# LAWNCHAIR_ROOT Lawnchair checkout. If unset, first existing of
# ../source (in-tree manifest layout) or ../lawnchair
# (PawletOS Windows working-copy layout).
# GRADLE_TASK Gradle task (default: assembleLawnWithQuickstepGithubRelease)
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
MODE="${1:-}"
shift || true
if [ -z "${LAWNCHAIR_ROOT:-}" ]; then
if [ -d "$SCRIPT_DIR/../source" ]; then
LAWNCHAIR_ROOT="$SCRIPT_DIR/../source"
else
LAWNCHAIR_ROOT="$SCRIPT_DIR/../lawnchair"
fi
fi
export LAWNCHAIR_ROOT
export GRADLE_TASK="${GRADLE_TASK:-assembleLawnWithQuickstepGithubRelease}"
LAWNCHAIR_REMOTE="https://git.oxmc.me/PawletOS/Lawnchair"
LAWNCHAIR_BRANCH="16-dev"
log() { printf '\033[1;36m[build.sh]\033[0m %s\n' "$*"; }
die() { printf '\033[1;31m[build.sh]\033[0m %s\n' "$*" >&2; exit 1; }
# Find an AOSP build environment on this machine. AOSP mode only works where
# the tree (and ideally its build output) actually lives — on any other
# machine we error out rather than half-work. When this repo is checked out
# in-tree (external/build-tools/lawnchair/build), the tree root is 4 levels up.
detect_aosp_root() {
local candidates=(
"${AOSP_ROOT:-}"
"$SCRIPT_DIR/../../../.."
"$HOME/PawletOS-Build/AOSP-Source"
"/mnt/ssd/AOSP-Source"
)
for c in "${candidates[@]}"; do
[ -n "$c" ] && [ -f "$c/build/envsetup.sh" ] && { cd "$c" && pwd; return 0; }
done
return 1
}
case "$MODE" in
aosp)
AOSP_ROOT="$(detect_aosp_root)" || die \
"No AOSP build environment found on this machine.
Checked: \$AOSP_ROOT, 4 dirs above this script (in-tree checkout),
~/PawletOS-Build/AOSP-Source, /mnt/ssd/AOSP-Source.
AOSP mode must run where the PawletOS AOSP tree lives (ubuntu-server-01);
use './build.sh prebuilt' for a purely local build."
export AOSP_ROOT
[ -d "$LAWNCHAIR_ROOT" ] || die "Lawnchair checkout not found at $LAWNCHAIR_ROOT — run './build.sh clone' or set LAWNCHAIR_ROOT"
log "AOSP env: $AOSP_ROOT"
exec "$SCRIPT_DIR/build-aosp.sh" "$@"
;;
prebuilt)
[ -d "$LAWNCHAIR_ROOT" ] || die "Lawnchair checkout not found at $LAWNCHAIR_ROOT — run './build.sh clone' or set LAWNCHAIR_ROOT"
log "Prebuilt mode: vendored AIDL + stub jars (no AOSP checkout needed)"
exec "$SCRIPT_DIR/build-prebuilt.sh" "$@"
;;
restore)
[ -d "$LAWNCHAIR_ROOT" ] || die "Lawnchair checkout not found at $LAWNCHAIR_ROOT"
"$SCRIPT_DIR/aosp-bridge/gen-aidl-sourceset.sh" --restore
"$SCRIPT_DIR/aosp-bridge/gen-framework-jars.sh" --restore
rm -f "$LAWNCHAIR_ROOT/aosp-bridge.state"
log "All AOSP-bridge changes restored."
;;
clone)
[ -d "$LAWNCHAIR_ROOT" ] && die "Lawnchair already exists at $LAWNCHAIR_ROOT"
log "Cloning $LAWNCHAIR_REMOTE ($LAWNCHAIR_BRANCH) -> $LAWNCHAIR_ROOT"
git clone --branch "$LAWNCHAIR_BRANCH" "$LAWNCHAIR_REMOTE" "$LAWNCHAIR_ROOT"
;;
*)
die "usage: $0 [aosp|prebuilt|restore|clone] [flags]"
;;
esac