set -e
thisdir="$(readlink -f "$(dirname "$0")")"
release_name="$(date +%y%m%d)"
mkdir -p release/"$release_name"
jobs=$(nproc)
repo init -u https://github.com/LineageOS/android.git -b lineage-15.1
function clone_or_checkout() {
local dir="$1"
local repo="$2"
local branch="$3"
if [[ -d "$dir" ]];then
(
cd "$dir"
git fetch
git reset --hard
git checkout origin/"$branch"
)
else
git clone "$repo" "$dir" -b "$branch"
fi
}
clone_or_checkout .repo/local_manifests "$thisdir" master
clone_or_checkout dakkar-patches "$thisdir" master
clone_or_checkout patches https://github.com/phhusson/treble_patches android-8.1
repo sync -c -j$jobs --force-sync
rm -f device/*/sepolicy/common/private/genfs_contexts
bash "$thidir/apply-patches.sh" patches
bash "$thidir/apply-patches.sh" dakkar-patches
. build/envsetup.sh
lunch treble_dakkar_m5
make WITHOUT_CHECK_API=true BUILD_NUMBER="$release_name" installclean
make WITHOUT_CHECK_API=true BUILD_NUMBER="$release_name" -j$jobs systemimage
make WITHOUT_CHECK_API=true BUILD_NUMBER="$release_name" vndk-test-sepolicy
cp $OUT/system.img release/"$release_name"/system-dakkar-m5.img