You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
145 lines
2.5 KiB
145 lines
2.5 KiB
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
build_directory="/build"
|
|
output_directory="$build_directory/out"
|
|
|
|
date="$(date '+%Y%m%d%H%M')"
|
|
|
|
function initializeSourceTree() {
|
|
manifest="$1"
|
|
branch="$2"
|
|
repo init -u "$manifest" -b "$branch"
|
|
}
|
|
|
|
function repoSync() {
|
|
repo sync "$@"
|
|
}
|
|
|
|
function getPrebuilts() {
|
|
cd "$build_directory"
|
|
# TODO: Add persistence for the gpg keyring and avoid
|
|
# pulling keys when unecessary
|
|
gpg \
|
|
--keyserver pool.sks-keyservers.net \
|
|
--recv-key 7A029E54DD5DCE7A
|
|
gpg \
|
|
--keyserver pool.sks-keyservers.net \
|
|
--recv-key A801183E69B37AA9
|
|
bash ./vendor/replicant/get-prebuilts
|
|
}
|
|
|
|
function buildToolchain() {
|
|
cd "$build_directory"
|
|
./vendor/replicant/build-toolchain
|
|
}
|
|
|
|
function loadBuildVars() {
|
|
source "$build_directory"/build/envsetup.sh
|
|
}
|
|
|
|
function lunchDevice() {
|
|
device="$1"
|
|
mode="$2"
|
|
lunch replicant_"$device"-"${mode:-userdebug}"
|
|
}
|
|
|
|
function buildPackage() {
|
|
device="$1"
|
|
mode="$2"
|
|
loadBuildVars
|
|
lunchDevice "$device" "$mode"
|
|
getPrebuilts
|
|
cd "$build_directory"
|
|
make -j ${threads:-4} bacon
|
|
}
|
|
|
|
function partialBuildPackage() {
|
|
device="$2"
|
|
sub_project="$3"
|
|
cd "$build_directory"/"$sub_project"
|
|
mm -B
|
|
make -j ${threads:-4} snod
|
|
}
|
|
|
|
function cleanBuild() {
|
|
cd "$build_directory"
|
|
loadBuildVars
|
|
make clean
|
|
}
|
|
|
|
function createBuildBundle() {
|
|
device="$1"
|
|
device_output_directory="$output_directory/target/product/$device"
|
|
cd "$device_output_directory"
|
|
tar \
|
|
-C "$device_output_directory" \
|
|
-cvf "$output_directory/$device-replicant-$date.tar.xz" \
|
|
"boot.img" \
|
|
"system.img" \
|
|
"userdata.img" \
|
|
"recovery.img" \
|
|
replicant_*.root.zip
|
|
}
|
|
|
|
cd "$build_directory"
|
|
|
|
if [ $# -eq 0 ]; then
|
|
echo -e "No parameter specified."
|
|
exit 1
|
|
else
|
|
while [ $# -ne 0 ]; do
|
|
case $1 in
|
|
|
|
-j | --threads )
|
|
threads="$2"
|
|
shift
|
|
;;
|
|
|
|
-i | --initialize )
|
|
manifest="$2"
|
|
branch="$3"
|
|
initializeSourceTree "$manifest" "$branch"
|
|
shift
|
|
shift
|
|
;;
|
|
|
|
-p | --pull )
|
|
options="${@:2}"
|
|
repoSync "$options"
|
|
;;
|
|
|
|
-t | --build-toolchain )
|
|
buildToolchain
|
|
;;
|
|
|
|
-b | --build )
|
|
device="$2"
|
|
buildPackage "$device"
|
|
shift
|
|
;;
|
|
|
|
-B | --partial )
|
|
device="$2"
|
|
sub_project="$3"
|
|
partialBuildPackage "$device" "$sub_project"
|
|
shift
|
|
;;
|
|
|
|
-c | --clean )
|
|
cleanBuild
|
|
;;
|
|
|
|
-P | --package )
|
|
device="$2"
|
|
createBuildBundle "$device"
|
|
shift
|
|
;;
|
|
|
|
esac
|
|
shift
|
|
done
|
|
fi
|
|
|