From e37d79efa7bb41e2ad08c5a4b5ad64a389a74427 Mon Sep 17 00:00:00 2001 From: dakkar Date: Sun, 3 Jun 2018 12:55:49 +0100 Subject: [PATCH 1/2] [userfriendly] build instructions in README also, make it markdown --- README | 8 -------- README.md | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 8 deletions(-) delete mode 100644 README create mode 100644 README.md diff --git a/README b/README deleted file mode 100644 index df60e267..00000000 --- a/README +++ /dev/null @@ -1,8 +0,0 @@ -Conventions for commit messages: - -[UGLY] Please make this patch disappear as soon as possible -[master] tag means that the commit should be dropped in a future rebase -[device] tag means this change is device-specific workaround -::device name:: will try to describe which devices are concerned by this change - -[userfriendly] This commit is NOT used for hardware support, but to make the rom more user friendly diff --git a/README.md b/README.md new file mode 100644 index 00000000..4d71ef92 --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +# How to build + +* clone this repository +* call the build scripts from a separate directory + +For example: + + git clone https://github.com/phhusson/treble_experimentations + mkdir Lineage; cd Lineage + bash ../treble_experimentations/build-rom.sh android-8.1 lineage + +# Conventions for commit messages: + +* `[UGLY]` Please make this patch disappear as soon as possible +* `[master]` tag means that the commit should be dropped in a future + rebase +* `[device]` tag means this change is device-specific workaround +* `::device name::` will try to describe which devices are concerned + by this change +* `[userfriendly]` This commit is NOT used for hardware support, but + to make the rom more user friendly From 102d5025c58a604694fa1c96b787d3853b65b8b7 Mon Sep 17 00:00:00 2001 From: dakkar Date: Sun, 3 Jun 2018 13:55:27 +0100 Subject: [PATCH 2/2] [userfriendly] more flexible build script --- README.md | 11 +++ build-dakkar.sh | 253 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 264 insertions(+) create mode 100644 build-dakkar.sh diff --git a/README.md b/README.md index 4d71ef92..76bd30a3 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,17 @@ For example: mkdir Lineage; cd Lineage bash ../treble_experimentations/build-rom.sh android-8.1 lineage +## More flexible build script + +(this has been tested much less) + + bash ../treble_experimentations/build-dakkar.sh rr \ + arm-aonly-gapps-su \ + arm64-ab-go-nosu + +The script should provide a help message if you pass something it +doesn't understand + # Conventions for commit messages: * `[UGLY]` Please make this patch disappear as soon as possible diff --git a/build-dakkar.sh b/build-dakkar.sh new file mode 100644 index 00000000..3b132f9e --- /dev/null +++ b/build-dakkar.sh @@ -0,0 +1,253 @@ +#!/bin/bash +set -e + +## set defaults + +rom_fp="$(date +%y%m%d)" + +myname="$(basename "$0")" +if [[ $(uname -s) = "Darwin" ]];then + jobs=$(sysctl -n hw.ncpu) +elif [[ $(uname -s) = "Linux" ]];then + jobs=$(nproc) +fi + +## handle command line arguments + +function help() { + cat < ... + +Options: + + -j number of parallel make workers (defaults to $jobs) + +ROM types: + + aosp80 + aosp81 + carbon + lineage + rr + +Variants are dash-joined combinations of (in order): +* processor type + * "arm" for ARM 32 bit + * "arm64" for ARM 64 bit +* A or A/B partition layout ("aonly" or "ab") +* GApps selection + * "vanilla" to not include GApps + * "gapps" to include opengapps + * "go" to include gapps go +* SU selection ("su" or "nosu") + +for example: + +* arm-aonly-vanilla-nosu +* arm64-ab-gapps-su +EOF +} + +function get_rom_type() { + while [[ $# -gt 0 ]]; do + case "$1" in + aosp80) + mainrepo="https://android.googlesource.com/platform/manifest" + mainbranch="android-vts-8.0_r4" + localManifestBranch="master" + treble_generate="" + extra_make_options="" + ;; + aosp81) + mainrepo="https://android.googlesource.com/platform/manifest" + mainbranch="android-8.1_r29" + localManifestBranch="android-8.1" + treble_generate="" + extra_make_options="" + ;; + carbon) + mainrepo="https://github.com/CarbonROM/android" + mainbranch="cr-6.1" + localManifestBranch="android-8.1" + treble_generate="carbon" + extra_make_options="WITHOUT_CHECK_API=true" + ;; + lineage) + mainrepo="https://github.com/LineageOS/android.git" + mainbranch="lineage-5.1" + localManifestBranch="android-8.1" + treble_generate="lineage" + extra_make_options="WITHOUT_CHECK_API=true" + ;; + rr) + mainrepo="https://github.com/ResurrectionRemix/platform_manifest.git" + mainbranch="oreo" + localManifestBranch="android-8.1" + treble_generate="rr" + extra_make_options="WITHOUT_CHECK_API=true" + ;; + esac + shift + done +} + +function parse_options() { + while [[ $# -gt 0 ]]; do + case "$1" in + -j) + jobs="$2"; + shift; + ;; + esac + shift + done +} + +declare -A processor_type_map +processor_type_map[arm]=arm +processor_type_map[arm64]=arm64 + +declare -A partition_layout_map +partition_layout_map[aonly]=a +partition_layout_map[ab]=b + +declare -A gapps_selection_map +gapps_selection_map[vanilla]=v +gapps_selection_map[gapps]=g +gapps_selection_map[go]=o + +declare -A su_selection_map +su_selection_map[su]=S +su_selection_map[nosu]=N + +function parse_variant() { + local -a pieces + IFS=- pieces=( $1 ) + + local processor_type=${processor_type_map[${pieces[0]}]} + local partition_layout=${partition_layout_map[${pieces[1]}]} + local gapps_selection=${gapps_selection_map[${pieces[2]}]} + local su_selection=${su_selection_map[${pieces[3]}]} + + if [[ -z "$processor_type" || -z "$partition_layout" || -z "$gapps_selection" || -z "$su_selection" ]]; then + >&2 echo "Invalid variant '$1'" + >&2 help + exit 2 + fi + + echo "treble_${processor_type}_${partition_layout}${gapps_selection}${su_selection}-userdebug" +} + +declare -a variant_codes +declare -a variant_names +function get_variants() { + while [[ $# -gt 0 ]]; do + case "$1" in + *-*-*-*) + variant_codes[${#variant_codes[*]}]=$(parse_variant "$1") + variant_names[${#variant_names[*]}]="$1" + ;; + esac + shift + done +} + +## function that actually do things + +function init_release() { + mkdir -p release/"$rom_fp" +} + +function init_main_repo() { + repo init -u "$mainrepo" -b "$mainbranch" +} + +function clone_or_checkout() { + local dir="$1" + local repo="$2" + + if [[ -d "$dir" ]];then + ( + cd "$dir" + git fetch + git reset --hard + git checkout origin/"$localManifestBranch" + ) + else + git clone https://github.com/phhusson/"$repo" "$dir" -b "$localManifestBranch" + fi +} + +function init_local_manifest() { + clone_or_checkout .repo/local_manifests treble_manifest +} + +function init_patches() { + if [[ -n "$treble_generate" ]]; then + clone_or_checkout patches treble_patches + + # We don't want to replace from AOSP since we'll be applying + # patches by hand + rm -f .repo/local_manifests/replace.xml + + # should I do this? will it interfere with building non-gapps images? + # rm -f .repo/local_manifests/opengapps.xml + fi +} + +function sync_repo() { + repo sync -c -j "$jobs" --force-sync +} + +function patch_things() { + if [[ -n "$treble_generate" ]]; then + rm -f device/*/sepolicy/common/private/genfs_contexts + ( + cd device/phh/treble + git clean -fdx + bash generate.sh "$treble_generate" + ) + bash "$(dirname "$0")/apply-patches.sh" patches + else + ( + cd device/phh/treble + git clean -fdx + bash generate.sh + ) + repo manifest -r > release/"$rom_fp"/manifest.xml + bash "$(dirname "$0")"/list-patches.sh + cp patches.zip release/"$rom_fp"/patches.zip + fi +} + +function build_variant() { + lunch "$1" + make $extra_make_options BUILD_NUMBER="$rom_fp" installclean + make $extra_make_options BUILD_NUMBER="$rom_fp" -j "$jobs" systemimage + make $extra_make_options BUILD_NUMBER="$rom_fp" vndk-test-sepolicy + cp "$OUT"/system.img release/"$rom_fp"/system-"$2".img +} + +parse_options "$@" +get_rom_type "$@" +get_variants "$@" + +if [[ -z "$mainrepo" || ${#variant_codes[*]} -eq 0 ]]; then + >&2 help + exit 1 +fi + +init_release +init_main_repo +init_local_manifest +init_patches +sync_repo +patch_things + +. build/envsetup.sh + +for (( idx=0; idx < ${#variant_codes[*]}; idx++ )); do + build_variant "${variant_codes[$idx]}" "${variant_names[$idx]}" +done