|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +## set defaults |
| 5 | + |
| 6 | +rom_fp="$(date +%y%m%d)" |
| 7 | + |
| 8 | +myname="$(basename "$0")" |
| 9 | +if [[ $(uname -s) = "Darwin" ]];then |
| 10 | + jobs=$(sysctl -n hw.ncpu) |
| 11 | +elif [[ $(uname -s) = "Linux" ]];then |
| 12 | + jobs=$(nproc) |
| 13 | +fi |
| 14 | + |
| 15 | +## handle command line arguments |
| 16 | + |
| 17 | +function help() { |
| 18 | + cat <<EOF |
| 19 | +Syntax: |
| 20 | +
|
| 21 | + $myname [-j 2] <rom type> <variant>... |
| 22 | +
|
| 23 | +Options: |
| 24 | +
|
| 25 | + -j number of parallel make workers (defaults to $jobs) |
| 26 | +
|
| 27 | +ROM types: |
| 28 | +
|
| 29 | + aosp80 |
| 30 | + aosp81 |
| 31 | + carbon |
| 32 | + lineage |
| 33 | + rr |
| 34 | +
|
| 35 | +Variants are dash-joined combinations of (in order): |
| 36 | +* processor type |
| 37 | + * "arm" for ARM 32 bit |
| 38 | + * "arm64" for ARM 64 bit |
| 39 | +* A or A/B partition layout ("aonly" or "ab") |
| 40 | +* GApps selection |
| 41 | + * "vanilla" to not include GApps |
| 42 | + * "gapps" to include opengapps |
| 43 | + * "go" to include gapps go |
| 44 | +* SU selection ("su" or "nosu") |
| 45 | +
|
| 46 | +for example: |
| 47 | +
|
| 48 | +* arm-aonly-vanilla-nosu |
| 49 | +* arm64-ab-gapps-su |
| 50 | +EOF |
| 51 | +} |
| 52 | + |
| 53 | +function get_rom_type() { |
| 54 | + while [[ $# -gt 0 ]]; do |
| 55 | + case "$1" in |
| 56 | + aosp80) |
| 57 | + mainrepo="https://android.googlesource.com/platform/manifest" |
| 58 | + mainbranch="android-vts-8.0_r4" |
| 59 | + localManifestBranch="master" |
| 60 | + treble_generate="" |
| 61 | + extra_make_options="" |
| 62 | + ;; |
| 63 | + aosp81) |
| 64 | + mainrepo="https://android.googlesource.com/platform/manifest" |
| 65 | + mainbranch="android-8.1_r29" |
| 66 | + localManifestBranch="android-8.1" |
| 67 | + treble_generate="" |
| 68 | + extra_make_options="" |
| 69 | + ;; |
| 70 | + carbon) |
| 71 | + mainrepo="https://github.com/CarbonROM/android" |
| 72 | + mainbranch="cr-6.1" |
| 73 | + localManifestBranch="android-8.1" |
| 74 | + treble_generate="carbon" |
| 75 | + extra_make_options="WITHOUT_CHECK_API=true" |
| 76 | + ;; |
| 77 | + lineage) |
| 78 | + mainrepo="https://github.com/LineageOS/android.git" |
| 79 | + mainbranch="lineage-5.1" |
| 80 | + localManifestBranch="android-8.1" |
| 81 | + treble_generate="lineage" |
| 82 | + extra_make_options="WITHOUT_CHECK_API=true" |
| 83 | + ;; |
| 84 | + rr) |
| 85 | + mainrepo="https://github.com/ResurrectionRemix/platform_manifest.git" |
| 86 | + mainbranch="oreo" |
| 87 | + localManifestBranch="android-8.1" |
| 88 | + treble_generate="rr" |
| 89 | + extra_make_options="WITHOUT_CHECK_API=true" |
| 90 | + ;; |
| 91 | + esac |
| 92 | + shift |
| 93 | + done |
| 94 | +} |
| 95 | + |
| 96 | +function parse_options() { |
| 97 | + while [[ $# -gt 0 ]]; do |
| 98 | + case "$1" in |
| 99 | + -j) |
| 100 | + jobs="$2"; |
| 101 | + shift; |
| 102 | + ;; |
| 103 | + esac |
| 104 | + shift |
| 105 | + done |
| 106 | +} |
| 107 | + |
| 108 | +declare -A processor_type_map |
| 109 | +processor_type_map[arm]=arm |
| 110 | +processor_type_map[arm64]=arm64 |
| 111 | + |
| 112 | +declare -A partition_layout_map |
| 113 | +partition_layout_map[aonly]=a |
| 114 | +partition_layout_map[ab]=b |
| 115 | + |
| 116 | +declare -A gapps_selection_map |
| 117 | +gapps_selection_map[vanilla]=v |
| 118 | +gapps_selection_map[gapps]=g |
| 119 | +gapps_selection_map[go]=o |
| 120 | + |
| 121 | +declare -A su_selection_map |
| 122 | +su_selection_map[su]=S |
| 123 | +su_selection_map[nosu]=N |
| 124 | + |
| 125 | +function parse_variant() { |
| 126 | + local -a pieces |
| 127 | + IFS=- pieces=( $1 ) |
| 128 | + |
| 129 | + local processor_type=${processor_type_map[${pieces[0]}]} |
| 130 | + local partition_layout=${partition_layout_map[${pieces[1]}]} |
| 131 | + local gapps_selection=${gapps_selection_map[${pieces[2]}]} |
| 132 | + local su_selection=${su_selection_map[${pieces[3]}]} |
| 133 | + |
| 134 | + if [[ -z "$processor_type" || -z "$partition_layout" || -z "$gapps_selection" || -z "$su_selection" ]]; then |
| 135 | + >&2 echo "Invalid variant '$1'" |
| 136 | + >&2 help |
| 137 | + exit 2 |
| 138 | + fi |
| 139 | + |
| 140 | + echo "treble_${processor_type}_${partition_layout}${gapps_selection}${su_selection}-userdebug" |
| 141 | +} |
| 142 | + |
| 143 | +declare -a variant_codes |
| 144 | +declare -a variant_names |
| 145 | +function get_variants() { |
| 146 | + while [[ $# -gt 0 ]]; do |
| 147 | + case "$1" in |
| 148 | + *-*-*-*) |
| 149 | + variant_codes[${#variant_codes[*]}]=$(parse_variant "$1") |
| 150 | + variant_names[${#variant_names[*]}]="$1" |
| 151 | + ;; |
| 152 | + esac |
| 153 | + shift |
| 154 | + done |
| 155 | +} |
| 156 | + |
| 157 | +## function that actually do things |
| 158 | + |
| 159 | +function init_release() { |
| 160 | + mkdir -p release/"$rom_fp" |
| 161 | +} |
| 162 | + |
| 163 | +function init_main_repo() { |
| 164 | + repo init -u "$mainrepo" -b "$mainbranch" |
| 165 | +} |
| 166 | + |
| 167 | +function clone_or_checkout() { |
| 168 | + local dir="$1" |
| 169 | + local repo="$2" |
| 170 | + |
| 171 | + if [[ -d "$dir" ]];then |
| 172 | + ( |
| 173 | + cd "$dir" |
| 174 | + git fetch |
| 175 | + git reset --hard |
| 176 | + git checkout origin/"$localManifestBranch" |
| 177 | + ) |
| 178 | + else |
| 179 | + git clone https://github.com/phhusson/"$repo" "$dir" -b "$localManifestBranch" |
| 180 | + fi |
| 181 | +} |
| 182 | + |
| 183 | +function init_local_manifest() { |
| 184 | + clone_or_checkout .repo/local_manifests treble_manifest |
| 185 | +} |
| 186 | + |
| 187 | +function init_patches() { |
| 188 | + if [[ -n "$treble_generate" ]]; then |
| 189 | + clone_or_checkout patches treble_patches |
| 190 | + |
| 191 | + # We don't want to replace from AOSP since we'll be applying |
| 192 | + # patches by hand |
| 193 | + rm -f .repo/local_manifests/replace.xml |
| 194 | + |
| 195 | + # should I do this? will it interfere with building non-gapps images? |
| 196 | + # rm -f .repo/local_manifests/opengapps.xml |
| 197 | + fi |
| 198 | +} |
| 199 | + |
| 200 | +function sync_repo() { |
| 201 | + repo sync -c -j "$jobs" --force-sync |
| 202 | +} |
| 203 | + |
| 204 | +function patch_things() { |
| 205 | + if [[ -n "$treble_generate" ]]; then |
| 206 | + rm -f device/*/sepolicy/common/private/genfs_contexts |
| 207 | + ( |
| 208 | + cd device/phh/treble |
| 209 | + git clean -fdx |
| 210 | + bash generate.sh "$treble_generate" |
| 211 | + ) |
| 212 | + bash "$(dirname "$0")/apply-patches.sh" patches |
| 213 | + else |
| 214 | + ( |
| 215 | + cd device/phh/treble |
| 216 | + git clean -fdx |
| 217 | + bash generate.sh |
| 218 | + ) |
| 219 | + repo manifest -r > release/"$rom_fp"/manifest.xml |
| 220 | + bash "$(dirname "$0")"/list-patches.sh |
| 221 | + cp patches.zip release/"$rom_fp"/patches.zip |
| 222 | + fi |
| 223 | +} |
| 224 | + |
| 225 | +function build_variant() { |
| 226 | + lunch "$1" |
| 227 | + make $extra_make_options BUILD_NUMBER="$rom_fp" installclean |
| 228 | + make $extra_make_options BUILD_NUMBER="$rom_fp" -j "$jobs" systemimage |
| 229 | + make $extra_make_options BUILD_NUMBER="$rom_fp" vndk-test-sepolicy |
| 230 | + cp "$OUT"/system.img release/"$rom_fp"/system-"$2".img |
| 231 | +} |
| 232 | + |
| 233 | +parse_options "$@" |
| 234 | +get_rom_type "$@" |
| 235 | +get_variants "$@" |
| 236 | + |
| 237 | +if [[ -z "$mainrepo" || ${#variant_codes[*]} -eq 0 ]]; then |
| 238 | + >&2 help |
| 239 | + exit 1 |
| 240 | +fi |
| 241 | + |
| 242 | +init_release |
| 243 | +init_main_repo |
| 244 | +init_local_manifest |
| 245 | +init_patches |
| 246 | +sync_repo |
| 247 | +patch_things |
| 248 | + |
| 249 | +. build/envsetup.sh |
| 250 | + |
| 251 | +for (( idx=0; idx < ${#variant_codes[*]}; idx++ )); do |
| 252 | + build_variant "${variant_codes[$idx]}" "${variant_names[$idx]}" |
| 253 | +done |
0 commit comments