├── mks
├── aospa.mk
├── du.mk
├── aicp.mk
├── aokp.mk
├── xpe.mk
├── aex.mk
├── bliss.mk
├── havoc.mk
└── aosip.mk
├── README.md
├── apply-patches.sh
└── adv-build.sh
/mks/aospa.mk:
--------------------------------------------------------------------------------
1 | $(call inherit-product, vendor/pa/main.mk)
2 |
--------------------------------------------------------------------------------
/mks/du.mk:
--------------------------------------------------------------------------------
1 | $(call inherit-product, vendor/du/config/common_full_phone.mk)
2 |
--------------------------------------------------------------------------------
/mks/aicp.mk:
--------------------------------------------------------------------------------
1 | $(call inherit-product, vendor/aicp/config/common_full_phone.mk)
2 |
--------------------------------------------------------------------------------
/mks/aokp.mk:
--------------------------------------------------------------------------------
1 | $(call inherit-product, vendor/aokp/configs/common_full_phone.mk)
2 |
--------------------------------------------------------------------------------
/mks/xpe.mk:
--------------------------------------------------------------------------------
1 | $(call inherit-product, vendor/xperience/config/common_full_phone.mk)
2 | $(call inherit-product, device/xperience/sepolicy/common/sepolicy.mk)
3 |
--------------------------------------------------------------------------------
/mks/aex.mk:
--------------------------------------------------------------------------------
1 | $(call inherit-product, $(SRC_TARGET_DIR)/product/full_base_telephony.mk)
2 | $(call inherit-product, vendor/aosp/common.mk)
3 | TARGET_BOOT_ANIMATION_RES := 720
4 |
--------------------------------------------------------------------------------
/mks/bliss.mk:
--------------------------------------------------------------------------------
1 | $(call inherit-product, vendor/bliss/config/common.mk)
2 |
3 | PRODUCT_COPY_FILES += \
4 | vendor/bliss/prebuilt/common/etc/init.bliss.rc:system/etc/init/init.bliss.rc
5 |
--------------------------------------------------------------------------------
/mks/havoc.mk:
--------------------------------------------------------------------------------
1 | $(call inherit-product, vendor/havoc/config/common.mk)
2 | #$(call inherit-product, device/havoc/sepolicy/common/sepolicy.mk)
3 | -include vendor/havoc/build/core/config.mk
4 |
--------------------------------------------------------------------------------
/mks/aosip.mk:
--------------------------------------------------------------------------------
1 | $(call inherit-product, vendor/aosip/config/common_full_phone.mk)
2 | $(call inherit-product, device/aosip/sepolicy/common/sepolicy.mk)
3 | -include vendor/aosip/build/core/config.mk
4 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Advanced GSI ROM Build Script
2 |
3 | ## Info:
4 | * This script is a custom version of ``build-dakkar`` from [here](https://github.com/phhusson/treble_experimentations), With lot of optimizations, fixes, improvemets and more features.
5 | - **Current Version:** V2
6 | - **Current Stable Version:** 1.5
7 | - **Current Features:**
8 | * Automaticly sync, patch and build!:
9 | - Faster and stable syncing.
10 | - Patching from HEAD, always updated.
11 | - Prompting and take user choice for every step.
12 | * Fixes some common build errors, lot of roms are supported! (not for all android versions)
13 |
14 | ## Usage Info:
15 | - Make a folder (sperated location from where this tool is cloned) of the ROM you want to collect.
16 | lets say: ``/home/username/aex``, and ``/home/username/adv-script/`` is where the script was cloned.
17 | - Navigate to ``aex``, and run:
18 | ``bash ../adv*.sh aex81 arm-aonly-vanilla-nosu``
19 | * This is for making a rom for a ``arm-aonly`` treblized device without ``gapps`` and ``su``.
20 | - Run ``bash adv-build.sh --help`` for commend syntax guide.
21 |
22 | ## Aknowledgement:
23 | | User |
24 | | ---- |
25 | | phhusson |
26 | | nathanchance (base apply-patches code) |
27 |
--------------------------------------------------------------------------------
/apply-patches.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright (C) 2017 Nathan Chancellor
4 | # Copyright (C) 2019-2022 SaMad SegMne
5 | #
6 | # This program is free software: you can redistribute it and/or modify
7 | # it under the terms of the GNU General Public License as published by
8 | # the Free Software Foundation, either version 3 of the License, or
9 | # (at your option) any later version.
10 | #
11 | # This program is distributed in the hope that it will be useful,
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | # GNU General Public License for more details.
15 | #
16 | # You should have received a copy of the GNU General Public License
17 | # along with this program. If not, see
18 |
19 | set -e
20 | trap 'reportError "An unexpected error occurred!" _' ERR
21 |
22 | ###########
23 | # #
24 | # USAGE #
25 | # #
26 | ###########
27 |
28 | #
29 | # PURPOSE: Merge GSI patches and changes from phhusson git into your rom repos
30 | #
31 |
32 | ############
33 | # #
34 | # COLORS #
35 | # #
36 | ############
37 |
38 | # FORMATS THE TIME
39 | function format_time() {
40 | MINS=$(((${1}-${2})/60))
41 | SECS=$(((${1}-${2})%60))
42 | if [[ ${MINS} -ge 60 ]]; then
43 | HOURS=$((${MINS}/60))
44 | MINS=$((${MINS}%60))
45 | fi
46 |
47 | if [[ ${HOURS} -eq 1 ]]; then
48 | TIME_STRING+="1 HOUR, "
49 | elif [[ ${HOURS} -ge 2 ]]; then
50 | TIME_STRING+="${HOURS} HOURS, "
51 | fi
52 |
53 | if [[ ${MINS} -eq 1 ]]; then
54 | TIME_STRING+="1 MINUTE"
55 | else
56 | TIME_STRING+="${MINS} MINUTES"
57 | fi
58 |
59 | if [[ ${SECS} -eq 1 && -n ${HOURS} ]]; then
60 | TIME_STRING+=", AND 1 SECOND"
61 | elif [[ ${SECS} -eq 1 && -z ${HOURS} ]]; then
62 | TIME_STRING+=" AND 1 SECOND"
63 | elif [[ ${SECS} -ne 1 && -n ${HOURS} ]]; then
64 | TIME_STRING+=", AND ${SECS} SECONDS"
65 | elif [[ ${SECS} -ne 1 && -z ${HOURS} ]]; then
66 | TIME_STRING+=" AND ${SECS} SECONDS"
67 | fi
68 |
69 | echo ${TIME_STRING}
70 | }
71 |
72 | # PRINTS A HELP MENU
73 | function help_menu() {
74 | echo -e "\n${BLD}OVERVIEW:${RST} Merges full GSI changes from phhusson into a ROM set of repos\n"
75 | echo -e "${BLD}USAGE:${RST} bash apply_patches.sh \n"
76 | echo -e "${BLD}EXAMPLE:${RST} bash apply_patches.sh ~/Android/Lineage android-10.0\n"
77 | echo -e "${BLD}Required options:${RST}"
78 | echo -e " source_dir: Location of the ROM tree; this needs to exist for the script to properly proceed\n"
79 | echo -e " branch_name: Android version, a string that starts with \"android-\" and followed by version:"
80 | echo -e " 8.1, 9.0, 10.0, 11.0, 12.1\n"
81 | }
82 |
83 | # CREATES A NEW LINE IN TERMINAL
84 | function newLine() {
85 | echo -e ""
86 | }
87 |
88 | ###############
89 | # #
90 | # VARIABLES #
91 | # #
92 | ###############
93 | BASE_REPOS="external/selinux frameworks/base frameworks/native frameworks/av frameworks/opt/telephony system/bt system/core system/netd system/vold"
94 | COMMON_REPOS="bionic packages/apps/Settings"
95 | EXTRA_REPOS="bootable/recovery"
96 | NEW_REPOS="packages/apps/Bluetooth system/extras system/linkerconfig system/nfc"
97 |
98 | if [[ ! $# -eq 2 ]]; then
99 | help_menu && exit 1
100 | fi
101 |
102 | SOURCE_DIR=${1}
103 | BRANCH_VERSION=${2}
104 | if [[ ! -d ${SOURCE_DIR} ]]; then
105 | reportError "Source directory not found!"
106 | elif [[ ! -d ${SOURCE_DIR}/.repo ]]; then
107 | reportError "This is not a valid Android source folder as there is no .repo folder!"
108 | fi
109 |
110 | case "${BRANCH_VERSION}" in
111 | android-8.1) REPOS="build system/libvintf system/sepolicy ${BASE_REPOS}";;
112 | android-9.0) REPOS="build frameworks/opt/net/wifi packages/services/Telephony system/sepolicy system/libvintf ${BASE_REPOS} ${COMMON_REPOS}";;
113 | android-10.0) REPOS="build packages/services/Telephony external/skia frameworks/opt/net/wifi system/bpf system/sepolicy ${BASE_REPOS} ${COMMON_REPOS} ${EXTRA_REPOS}";;
114 | android-11.0) REPOS="external/skia frameworks/opt/net/wifi packages/services/Telephony system/memory/lmkd ${BASE_REPOS} ${COMMON_REPOS} ${EXTRA_REPOS} ${NEW_REPOS}";;
115 | android-12.1) REPOS="frameworks/opt/net/ims hardware/interfaces packages/modules/Wifi system/bpf system/security ${BASE_REPOS} ${COMMON_REPOS} ${EXTRA_REPOS} ${NEW_REPOS}";;
116 | android-*.*) reportError "Unsupported android tag ($2)";;
117 | *) reportError "Unknown tag format ($2)";;
118 | esac
119 |
120 | unset RESULT_STRING
121 |
122 | ################
123 | # #
124 | # SCRIPT START #
125 | # #
126 | ################
127 |
128 | # START TRACKING TIME
129 | START=$( date +%s )
130 | # SET BRANCH NAME (might break in future :0)
131 | BRANCH=$( git ls-remote https://github.com/phhusson/platform_frameworks_base | awk -F'/' "(match(\$3, /^${BRANCH_VERSION}\.0_r([0-9]+)(-r[0-9]+)?-phh$/, r) && r[1]>m) { m=r[1]; l=\$3 } END { print l }" )
132 | # ABORT IF NO BRANCH WAS MATCHED
133 | [ -z "$BRANCH" ] && reportError "Failed to fetch upstream branch!"
134 |
135 | echo -e "Targeting: \n\t ${YLW}$(echo ${REPOS} | sed -e 's/\(\w\+\)\s/\1\n\t /g') ${RST}\nfrom branch: \n\t ${GRN}${BRANCH}${RST}"
136 | for FOLDER in ${REPOS}; do
137 | # GIT LOG QUERY OPTIONS
138 | GIT_OPTIONS="--format=%H --committer=\"Pierre-Hugues\" --invert-grep -E --grep=\"^(Merge tag|Update SPL)\" FETCH_HEAD"
139 | # PRINT TO THE USER WHAT WE ARE DOING
140 | newLine; printText "Merging ${FOLDER}"
141 |
142 | # SHIFT TO PROPER FOLDER
143 | cd ${SOURCE_DIR}
144 |
145 | if [[ ${FOLDER} = "build" ]]; then
146 | # build is build/make
147 | cd ${FOLDER}/make
148 | else
149 | cd ${FOLDER}
150 | fi
151 |
152 | # SET PROPER URL
153 | URL=platform_$( echo ${FOLDER} | sed "s/\//_/g" )
154 |
155 | # FETCH THE REPO
156 | newLine; echo "Fetching phh HEAD..."
157 | git fetch https://github.com/phhusson/${URL} ${BRANCH} >/dev/null 2>&1 || reportError "! Failed to fetch ${URL} branch ${BRANCH}"
158 |
159 | # GIT GYMNASTICS (GETS MESSY, BEWARE)
160 | # HEAD HASH WILL ALWAYS BE THE FETCH HEAD (LATEST COMMIT)
161 | HEAD_HASH=$( eval git log -1 ${GIT_OPTIONS} )
162 |
163 | # TAIL HASH WILL BE THE **FIRST** THING PHH COMMITTED
164 | NUMBER_OF_COMMITS=$( eval git log ${GIT_OPTIONS} | wc -l )
165 |
166 | if [[ "${NUMBER_OF_COMMITS}" -eq 0 ]]; then
167 | newLine; reportWarning "SKKIPED ${FOLDER}"
168 | RESULT_STRING+="${FOLDER}: ${YLW}SKIPPED${RST}\n"
169 | continue
170 | fi
171 |
172 | # NOW, SET TAIL_HASH
173 | TAIL_HASH=$( eval git log ${GIT_OPTIONS}~${NUMBER_OF_COMMITS}^..FETCH_HEAD~${NUMBER_OF_COMMITS} )
174 |
175 | # TAIL HASH CRYING?
176 | [ -z "${TAIL_HASH}" ] && TAIL_HASH=$( eval git log ${GIT_OPTIONS} | tail -1 )
177 |
178 | # RESET ANY LOCAL CHANGES
179 | git reset --hard HEAD
180 |
181 | LAST_COMMIT_MSG=$(git show -s --format=%s $HEAD_HASH)
182 | FIRST_COMMIT_MSG=$(git show -s --format=%s $TAIL_HASH)
183 | echo -e "${GRN}Applying ${NUMBER_OF_COMMITS} patch(es)${RST}:\n from: ${FIRST_COMMIT_MSG}\n to: ${LAST_COMMIT_MSG}"
184 |
185 | # PICK THE COMMITS
186 | # ON ERROR CONTINUE
187 | CHERRY_PICK="${TAIL_HASH}^..${HEAD_HASH}"
188 | [[ ${NUMBER_OF_COMMITS} -eq 1 ]] && CHERRY_PICK="${TAIL_HASH}"
189 | eval git cherry-pick --allow-empty-message --keep-redundant-commits -X thiers ${CHERRY_PICK} || true
190 |
191 | # ADD TO RESULT STRING
192 | if [[ $? -ne 0 ]]; then
193 | RESULT_STRING+="${FOLDER}: ${RED}FAILED${RST}\n"
194 | CLR="${RED}"
195 | else
196 | RESULT_STRING+="${FOLDER}: ${GRN}SUCCESS${RST}\n"
197 | CLR="${GRN}"
198 | fi
199 |
200 | newLine; printText "DONE ${FOLDER}" ${CLR}
201 | done
202 |
203 | # SHIFT BACK TO THE TOP OF THE REPO
204 | cd ${SOURCE_DIR}
205 |
206 | # PRINT RESULTS
207 | printText "RESULTS"
208 | echo -e ${RESULT_STRING}
209 |
210 | # STOP TRACKING TIME
211 | END=$( date +%s )
212 |
213 | # PRINT RESULT TO USER
214 | printText "PATCHING COMPLETED!"
215 | echo -e ${RED}"TIME: $(format_time ${END} ${START})"${RST}; newLine
216 |
--------------------------------------------------------------------------------
/adv-build.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | #
4 | # Copyright (C) 2019-2022 by SaMad SegMane (svoboda18)
5 | #
6 | # This program is free software: you can redistribute it and/or modify
7 | # it under the terms of the GNU General Public License as published by
8 | # the Free Software Foundation, either version 3 of the License, or
9 | # (at your option) any later version.
10 | #
11 | # This program is distributed in the hope that it will be useful,
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | # GNU General Public License for more details.
15 | #
16 | # You should have received a copy of the GNU General Public License
17 | # along with this program. If not, see [...]
100 |
101 | Symbol [...] signify optional arguments, and <...> signifies required ones.
102 |
103 | Each variant will be built respectivly to the arguments order, with unique fingerprint, variant duplications are ignored and the output is set inside "release" folder created in the working directory.
104 | ${BLD}
105 | Options:
106 | ${RST}
107 | -j ,--jobs ,j=N,--jobs=N\t\tnumber of threads used. (defaults to $jobs)
108 | ${BLD}
109 | ROM types:
110 | ${RST}
111 | aosp81
112 | aosp90
113 | aosp100
114 | aosp110
115 | aosp121
116 | aospa81
117 | aospa90
118 | aosip81
119 | aosip90
120 | aicp81
121 | aicp90
122 | aokp81
123 | aokp90
124 | aex81
125 | aex90
126 | bliss81
127 | bliss90
128 | carbon81
129 | carbon90
130 | crdroid81
131 | crdroid90
132 | dot81
133 | dot90
134 | du81
135 | du90
136 | e-pie
137 | e-oreo
138 | evox90
139 | havoc81
140 | havoc90
141 | lineage151
142 | lineage160
143 | mokee81
144 | mokee90
145 | pixel81
146 | pixel90
147 | rr81
148 | rr90
149 | slim81
150 | slim90
151 | xpe81
152 | xpe90
153 | ${BLD}
154 | Variants syntax:
155 | ${RST}
156 | Variants are dash-joined combinations of (in order):
157 | - Processor type
158 | * "arm" for ARM 32 bit (android 11 and below)
159 | * "arm64" for ARM 64 bit
160 | * "a64" for ARM 32 bit system with 64 bit binder
161 | - A or A/B partition layout ("aonly" or "ab")
162 | * "aonly" only available for android 10 and below.
163 | - GApps selection
164 | * "vanilla" to not include GApps.
165 | * "gapps" to include gapps.
166 | * "gappsgo" to include go gapps.
167 | * "foss" to include foss apps.
168 | ! SU selection (android 9 and below)
169 | * "su" with root permissions
170 | * "nosu" without root permissions
171 | - Build variant selection (optional)
172 | * "eng" for eng build.
173 | * "user" for prod build (some errors are expected).
174 | * "userdebug" for debug build (default).
175 | ${BLD}
176 | Note:
177 | ${RST}
178 | * For secure, vndk-lite and a-only builds for andorid 11, use scripts
179 | located in repo "sas-creator" folder.
180 |
181 | Examples:
182 | - GSI ROM for ARM-A without Gapps and SU:
183 | * arm-aonly-vanilla-nosu"
184 | }
185 |
186 | function get_rom_type() {
187 | case "$1" in
188 | aosp81)
189 | mainrepo="https://android.googlesource.com/platform/manifest.git"
190 | mainbranch="android-8.1.0_r65"
191 | localManifestBranch="android-8.1"
192 | treble_generate=""
193 | extra_make_options=""
194 | ;;
195 | aosp90)
196 | mainrepo="https://android.googlesource.com/platform/manifest.git"
197 | mainbranch="android-9.0.0_r53"
198 | localManifestBranch="android-9.0"
199 | treble_generate=""
200 | extra_make_options=""
201 | ;;
202 | aosp100)
203 | mainrepo="https://android.googlesource.com/platform/manifest.git"
204 | mainbranch="android-10.0.0_r41"
205 | localManifestBranch="android-10.0"
206 | treble_generate=""
207 | extra_make_options=""
208 | ;;
209 | aosp110)
210 | mainrepo="https://android.googlesource.com/platform/manifest.git"
211 | mainbranch="android-11.0.0_r48"
212 | localManifestBranch="android-11.0"
213 | treble_generate=""
214 | extra_make_options=""
215 | ;;
216 | aosp121)
217 | mainrepo="https://android.googlesource.com/platform/manifest.git"
218 | mainbranch="android-12.1.0_r11"
219 | localManifestBranch="android-12.1"
220 | treble_generate=""
221 | extra_make_options=""
222 | ;;
223 | evox90)
224 | mainrepo="https://github.com/Evolution-X/platform_manifest.git"
225 | mainbranch="pie"
226 | localManifestBranch="android-9.0"
227 | treble_generate=""
228 | extra_make_options=""
229 | ;;
230 | aosip81)
231 | mainrepo="https://github.com/AOSiP/platform_manifest.git"
232 | mainbranch="oreo-mr1"
233 | localManifestBranch="android-8.1"
234 | treble_generate="aosip"
235 | extra_make_options=""
236 | ;;
237 | aosip90)
238 | mainrepo="https://github.com/AOSiP/platform_manifest.git"
239 | mainbranch="pie"
240 | localManifestBranch="android-9.0"
241 | treble_generate="aosip"
242 | extra_make_options=""
243 | ;;
244 | ces100)
245 | mainrepo="https://github.com/CesiumOS/manifest"
246 | mainbranch="ten"
247 | localManifestBranch="android-10.0"
248 | treble_generate=""
249 | gen_mk="cesuim"
250 | gen_target="treble"
251 | gen_config='$(call inherit-product, vendor/aosp/config/common_full_phone.mk)'
252 | gen_sepolicy=''
253 | extra_make_options="WITHOUT_CHECK_API=true"
254 | ;;
255 | carbon81)
256 | mainrepo="https://github.com/CarbonROM/android.git"
257 | mainbranch="cr-6.1"
258 | localManifestBranch="android-8.1"
259 | treble_generate="carbon"
260 | extra_make_options="WITHOUT_CHECK_API=true"
261 | ;;
262 | carbon90)
263 | mainrepo="https://github.com/CarbonROM/android.git"
264 | mainbranch="cr-7.0"
265 | localManifestBranch="android-9.0"
266 | treble_generate="carbon"
267 | extra_make_options="WITHOUT_CHECK_API=true"
268 | ;;
269 | e-oreo)
270 | mainrepo="https://gitlab.e.foundation/e/os/android/"
271 | mainbranch="v1-oreo"
272 | localManifestBranch="android-8.1"
273 | treble_generate="lineage"
274 | extra_make_options="WITHOUT_CHECK_API=true"
275 | ;;
276 | e-pie)
277 | mainrepo="https://gitlab.e.foundation/e/os/android/"
278 | mainbranch="v1-pie"
279 | localManifestBranch="android-9.0"
280 | treble_generate="lineage"
281 | extra_make_options="WITHOUT_CHECK_API=true"
282 | ;;
283 | lineage151)
284 | mainrepo="https://github.com/LineageOS/android.git"
285 | mainbranch="lineage-15.1"
286 | localManifestBranch="android-8.1"
287 | treble_generate="lineage"
288 | extra_make_options="WITHOUT_CHECK_API=true"
289 | ;;
290 | lineage160)
291 | mainrepo="https://github.com/LineageOS/android.git"
292 | mainbranch="lineage-16.0"
293 | localManifestBranch="android-9.0"
294 | treble_generate="lineage"
295 | extra_make_options="WITHOUT_CHECK_API=true"
296 | ;;
297 | rr81)
298 | mainrepo="https://github.com/ResurrectionRemix/platform_manifest.git"
299 | mainbranch="oreo"
300 | localManifestBranch="android-8.1"
301 | treble_generate="rr"
302 | extra_make_options="WITHOUT_CHECK_API=true"
303 | ;;
304 | rr90)
305 | mainrepo="https://github.com/ResurrectionRemix/platform_manifest.git"
306 | mainbranch="pie"
307 | localManifestBranch="android-9.0"
308 | treble_generate="rr"
309 | extra_make_options="WITHOUT_CHECK_API=true"
310 | ;;
311 | dot81)
312 | mainrepo="https://github.com/DotOS/manifest.git"
313 | mainbranch="dot-o"
314 | localManifestBranch="android-8.1"
315 | treble_generate=""
316 | gen_mk="dot"
317 | gen_target="treble"
318 | gen_config='$(call inherit-product, vendor/dot/config/common.mk)'
319 | gen_sepolicy='$(call inherit-product, device/aosp/sepolicy/common/sepolicy.mk)'
320 | extra_make_options="WITHOUT_CHECK_API=true"
321 | ;;
322 | dot90)
323 | mainrepo="https://github.com/DotOS/manifest.git"
324 | mainbranch="dot-p"
325 | localManifestBranch="android-9.0"
326 | treble_generate=""
327 | gen_mk="dot"
328 | gen_target="treble"
329 | gen_config='$(call inherit-product, vendor/dot/config/common.mk)'
330 | gen_sepolicy=''
331 | extra_make_options="WITHOUT_CHECK_API=true"
332 | ;;
333 | aospa81)
334 | mainrepo="https://github.com/AOSPA/manifest.git"
335 | mainbranch="oreo-mr1"
336 | localManifestBranch="android-8.1"
337 | treble_generate="aospa"
338 | extra_make_options="WITHOUT_CHECK_API=true"
339 | ;;
340 | aospa90)
341 | mainrepo="https://github.com/AOSPA/manifest.git"
342 | mainbranch="pie"
343 | localManifestBranch="android-9.0"
344 | treble_generate="aospa"
345 | extra_make_options="WITHOUT_CHECK_API=true"
346 | ;;
347 | du81)
348 | mainrepo="https://github.com/DirtyUnicorns/android_manifest.git"
349 | mainbranch="o8x"
350 | localManifestBranch="android-8.1"
351 | treble_generate="du"
352 | extra_make_options="WITHOUT_CHECK_API=true"
353 | ;;
354 | du90)
355 | mainrepo="https://github.com/DirtyUnicorns/android_manifest.git"
356 | mainbranch="p9x"
357 | localManifestBranch="android-9.0"
358 | treble_generate="du"
359 | extra_make_options="WITHOUT_CHECK_API=true"
360 | ;;
361 | bliss81)
362 | mainrepo="https://github.com/BlissRoms/platform_manifest.git"
363 | mainbranch="o8.1"
364 | localManifestBranch="android-8.1"
365 | treble_generate="bliss"
366 | extra_make_options="WITHOUT_CHECK_API=true"
367 | ;;
368 | bliss90)
369 | mainrepo="https://github.com/BlissRoms/platform_manifest.git"
370 | mainbranch="p9.0"
371 | localManifestBranch="android-9.0"
372 | treble_generate="bliss"
373 | extra_make_options="WITHOUT_CHECK_API=true"
374 | ;;
375 | xpe81)
376 | mainrepo="https://github.com/TheXPerienceProject/Manifest.git"
377 | mainbranch="xpe-12.1"
378 | localManifestBranch="android-8.1"
379 | treble_generate="xpe"
380 | extra_make_options="WITHOUT_CHECK_API=true"
381 | ;;
382 | xpe90)
383 | mainrepo="https://github.com/TheXPerienceProject/Manifest.git"
384 | mainbranch="xpe-13.0"
385 | localManifestBranch="android-9.0"
386 | treble_generate="xpe"
387 | extra_make_options="WITHOUT_CHECK_API=true"
388 | ;;
389 | pixel81)
390 | mainrepo="https://github.com/PixelExperience/manifest.git"
391 | mainbranch="oreo-mr1"
392 | localManifestBranch="android-8.1"
393 | treble_generate="pixel"
394 | extra_make_options="WITHOUT_CHECK_API=true"
395 | ;;
396 | pixel90)
397 | mainrepo="https://github.com/PixelExperience-P/manifest.git"
398 | mainbranch="pie"
399 | localManifestBranch="android-9.0"
400 | treble_generate="pixel"
401 | extra_make_options="WITHOUT_CHECK_API=true"
402 | ;;
403 | crdroid81)
404 | mainrepo="https://github.com/crdroidandroid/android.git"
405 | mainbranch="8.1"
406 | localManifestBranch="android-8.1"
407 | treble_generate="lineage"
408 | extra_make_options="WITHOUT_CHECK_API=true"
409 | ;;
410 | crdroid90)
411 | mainrepo="https://github.com/crdroidandroid/android.git"
412 | mainbranch="9.0"
413 | localManifestBranch="android-9.0"
414 | treble_generate="lineage"
415 | extra_make_options="WITHOUT_CHECK_API=true"
416 | ;;
417 | mokee81)
418 | mainrepo="https://github.com/MoKee/android.git"
419 | mainbranch="mko-mr1"
420 | localManifestBranch="android-8.1"
421 | treble_generate="mokee"
422 | extra_make_options="WITHOUT_CHECK_API=true"
423 | ;;
424 | mokee90)
425 | mainrepo="https://github.com/MoKee/android.git"
426 | mainbranch="mkp"
427 | localManifestBranch="android-9.0"
428 | treble_generate="mokee"
429 | extra_make_options="WITHOUT_CHECK_API=true"
430 | ;;
431 | aicp81)
432 | mainrepo="https://github.com/AICP/platform_manifest.git"
433 | mainbranch="o8.1"
434 | localManifestBranch="android-8.1"
435 | treble_generate="aicp"
436 | extra_make_options="WITHOUT_CHECK_API=true"
437 | ;;
438 | aicp90)
439 | mainrepo="https://github.com/AICP/platform_manifest.git"
440 | mainbranch="p9.0"
441 | localManifestBranch="android-9.0"
442 | treble_generate="aicp"
443 | extra_make_options="WITHOUT_CHECK_API=true"
444 | ;;
445 | aokp81)
446 | mainrepo="https://github.com/AOKP/platform_manifest.git"
447 | mainbranch="oreo"
448 | localManifestBranch="android-8.1"
449 | treble_generate="aokp"
450 | extra_make_options="WITHOUT_CHECK_API=true"
451 | ;;
452 | aokp90)
453 | mainrepo="https://github.com/AOKP/platform_manifest.git"
454 | mainbranch="9.0"
455 | localManifestBranch="android-9.0"
456 | treble_generate="aokp"
457 | extra_make_options="WITHOUT_CHECK_API=true"
458 | ;;
459 | aex90)
460 | mainrepo="https://github.com/AospExtended/manifest.git"
461 | mainbranch="9.x"
462 | localManifestBranch="android-9.0"
463 | treble_generate="aex"
464 | extra_make_options="WITHOUT_CHECK_API=true"
465 | ;;
466 | aex81)
467 | mainrepo="https://github.com/AospExtended/manifest.git"
468 | mainbranch="8.1.x"
469 | localManifestBranch="android-8.1"
470 | treble_generate="aex"
471 | extra_make_options="WITHOUT_CHECK_API=true"
472 | ;;
473 | slim81)
474 | mainrepo="https://github.com/SlimRoms/platform_manifest.git"
475 | mainbranch="or8.1"
476 | localManifestBranch="android-8.1"
477 | treble_generate="slim"
478 | extra_make_options="WITHOUT_CHECK_API=true"
479 | ;;
480 | slim90)
481 | mainrepo="https://github.com/SlimRoms/platform_manifest.git"
482 | mainbranch="9.0"
483 | localManifestBranch="android-9.0"
484 | treble_generate="slim"
485 | extra_make_options="WITHOUT_CHECK_API=true"
486 | ;;
487 | havoc81)
488 | mainrepo="https://github.com/Havoc-OS/android_manifest.git"
489 | mainbranch="oreo"
490 | localManifestBranch="android-8.1"
491 | treble_generate="havoc"
492 | extra_make_options="WITHOUT_CHECK_API=true"
493 | ;;
494 | havoc90)
495 | mainrepo="https://github.com/Havoc-OS/android_manifest.git"
496 | mainbranch="pie"
497 | localManifestBranch="android-9.0"
498 | treble_generate="havoc"
499 | extra_make_options="WITHOUT_CHECK_API=true"
500 | ;;
501 | *)
502 | reportError "Unknown ROM type: $1"
503 | ;;
504 | esac
505 | }
506 |
507 | function parse_variant() {
508 | local -A partition_layout_map
509 | partition_layout_map[aonly]=a
510 | partition_layout_map[ab]=b
511 |
512 | local -A apps_selection_map
513 | apps_selection_map[vanilla]=v
514 | apps_selection_map[gapps]=g
515 | apps_selection_map[gappsgo]=o
516 | apps_selection_map[foss]=f
517 |
518 | local -A su_selection_map
519 | su_selection_map[su]=S
520 | su_selection_map[nosu]=N
521 |
522 | IFS=-
523 | local -a pieces=( $1 )
524 | local nb_pieces=(${#pieces[*]}-1)
525 | local processor_type=${pieces[0]}
526 | local partition_layout=${partition_layout_map[${pieces[1]}]}
527 |
528 | local apps_selection=${apps_selection_map[${pieces[2]}]}
529 | local su_selection=${su_selection_map[${pieces[3]}]}
530 | local build_type_selection=${pieces[$nb_pieces]}
531 |
532 | if [[ -z "$processor_type" || -z "$partition_layout" || -z "$apps_selection" ]] ||
533 | [[ $(get_android_version) -gt 10 && "$partition_layout" == "a" ]] ||
534 | [[ $(get_android_version) -gt 11 && "$processor_type" == "arm" ]] ||
535 | [[ $(get_android_version) -gt 9 && -n "$su_selection" ]] ||
536 | [[ $(get_android_version) -le 9 && -z "$su_selection" ]]; then
537 | >&2 reportError "Invalid defined variant: $1 (android version $(get_android_version))"
538 | fi
539 |
540 | [[ $(get_android_version) -gt 9 ]] && su_selection="S"
541 |
542 | echo "treble_${processor_type}_${partition_layout}${apps_selection}${su_selection}-${build_type_selection}"
543 | }
544 |
545 | function get_variants() {
546 | declare -a -g variant_codes
547 | declare -a -g variant_names
548 | declare -A -g variants_map
549 |
550 | local -A build_map
551 | build_map[android-12.1]=squeak
552 | build_map[android-11.0]=roar
553 | build_map[android-10.0]=quack
554 | build_map[android-9.0]=pie
555 | build_map[android-8.1]=oreo
556 |
557 | local idx=${#variant_codes[*]}
558 |
559 | variant_names[$idx]="${build_map[$localManifestBranch]}-$1"
560 | variants_map["$1"]=$idx
561 |
562 | case "$1" in
563 | *-*-*-*-*|*-*-*-[ue]*)
564 | variant_codes[$idx]=$(parse_variant "$1");;
565 | *-*-*-*|*-*-*)
566 | variant_codes[$idx]=$(parse_variant "$1-userdebug");;
567 | *) reportError "Invalid defined variant: $1";;
568 | esac
569 | }
570 |
571 | function init_release() {
572 | [ ! -d release/"$rom_fp" ] && mkdir -p release/"$rom_fp"
573 | }
574 |
575 | function init_main_repo() {
576 | repo init -u "$mainrepo" -b "$mainbranch"
577 | }
578 |
579 | function force_clone() {
580 | local dir="$1"
581 | local repo="$2"
582 |
583 | [ -d "$dir" ] && rm -rf "$dir"
584 | git clone https://github.com/phhusson/"$repo" "$dir" -b "$( ([[ -z $3 ]] && echo $localManifestBranch) || echo $3)"
585 | }
586 |
587 | function g_clone() {
588 | local brn="$3"
589 | local dir="$2"
590 | local repo="$1"
591 |
592 | [ -d "$dir" ] && rm -rf "$dir"
593 | git -c advice.detachedHead=false clone --depth=1 $([ -n "$brn" ] && echo "--branch $brn") "$repo" "$dir"
594 | [ "$(get_android_version)" -le 9 ] && (cd "$dir"; git lfs fetch && git lfs checkout)
595 | }
596 |
597 | function get_android_version() {
598 | awk -F'[-.]' '{ print $2 }' <<< $localManifestBranch
599 | }
600 |
601 | function init_local_manifest() {
602 | local overlay_branch="master"
603 | local interfaces_branch="master"
604 | local device_branch="${localManifestBranch}"
605 | local vndk_branch="master"
606 | local magisk_branch="master"
607 | local vndk_path="vendor/vndk"
608 | local sas_target=false
609 | local magisk_target=false
610 | local lptools_target=false
611 | local android_version=$(get_android_version)
612 |
613 | if [[ "${android_version}" -ge 9 ]]; then
614 | overlay_branch="pie"
615 | interfaces_branch="pie"
616 | magisk_target=true
617 | if [[ "${android_version}" -ge 10 ]]; then
618 | vndk_branch="android-10.0"
619 | magisk_branch="android-10.0"
620 | if [[ "${android_version}" -ge 11 ]]; then
621 | sas_target=true
622 | vndk_path=phh_sas
623 | interfaces_branch="android-11.0"
624 |
625 | if [[ "${android_version}" -eq 12 ]]; then
626 | device_branch="android-12.0"
627 | lptools_target=true
628 | fi
629 | fi
630 | fi
631 | fi
632 | force_clone device/phh/treble device_phh_treble ${device_branch}
633 | force_clone vendor/hardware_overlay vendor_hardware_overlay ${overlay_branch}
634 |
635 | force_clone vendor/interfaces vendor_interfaces ${interfaces_branch}
636 | force_clone vendor/vndk-tests vendor_vndk-tests master
637 | force_clone vendor/gapps-go gapps-go master
638 | force_clone vendor/foss vendor_foss master
639 | force_clone ${vndk_path} vendor_vndk ${vndk_branch}
640 | g_clone https://gitlab.com/fdroid/privileged-extension.git packages/apps/FDroidPrivilegedExtension 0.2.7 || true
641 | $sas_target && force_clone phh_sas sas-creator master
642 | $magisk_target && force_clone vendor/magisk vendor_magisk ${magisk_branch}
643 | $lptools_target && force_clone vendor/lptools vendor_lptools master
644 |
645 | reportMessage "- Do you want to sync gapps packages? (y/N) "
646 | if $YES;then
647 | if [[ "${android_version}" -le 9 ]]; then
648 | g_clone https://github.com/opengapps/aosp_build vendor/opengapps/build
649 | g_clone https://gitlab.opengapps.org/opengapps/all vendor/opengapps/sources/all
650 | g_clone https://gitlab.opengapps.org/opengapps/arm vendor/opengapps/sources/arm
651 | g_clone https://gitlab.opengapps.org/opengapps/arm64 vendor/opengapps/sources/arm64
652 | elif [[ "${android_version}" -eq 10 ]]; then
653 | g_clone https://gitlab.com/gms-mirror/gmsexpress vendor/google
654 | rm -f vendor/gapps/interfaces/wifi_ext/Android.bp || true
655 | elif [[ "${android_version}" -eq 11 ]]; then
656 | g_clone https://gitlab.com/00p513-dev/partner_gms vendor/partner_gms 11
657 | elif [[ "${android_version}" -eq 12 ]]; then
658 | g_clone https://gitlab.com/davi.sh/gms-android-12 vendor/partner_gms
659 | fi
660 | fi
661 | }
662 |
663 | function sync_repo() {
664 | repo sync -c -j"$jobs" --no-clone-bundle --no-tags
665 | }
666 |
667 | function clean_repo_folder() {
668 | rm -rf .repo *
669 | }
670 |
671 | function add_mks() {
672 | cp -r $(dirname "$0")/mks/* device/phh/treble
673 | }
674 |
675 | function fix_missings() {
676 | if [[ "${android_version}" -gt 8 ]]; then
677 | # fix kernel source missing
678 | sed 's;.*KERNEL_;//&;' -i vendor/*/build/soong/Android.bp 2>/dev/null || true
679 | rm -rf vendor/*/packages/overlays/NoCutout*
680 | fi
681 | mkdir -p device/sample/etc
682 | wget --output-document=device/sample/etc/apns-full-conf.xml https://github.com/LineageOS/android_vendor_lineage/raw/lineage-17.0/prebuilt/common/etc/apns-conf.xml 2>/dev/null
683 |
684 | mkdir -p device/generic/common/nfc
685 | wget --output-document=device/generic/common/nfc/libnfc-nci.conf https://android.googlesource.com/device/generic/common/+/master/nfc/libnfc-nci.conf?format=TEXT 2>/dev/null
686 | }
687 |
688 | function patch_things() {
689 | repodir="${PWD}"
690 | rm -f device/*/sepolicy/common/private/genfs_contexts
691 | if [ "${android_version}" -eq 12 ] && grep -q lottie packages/apps/Launcher3/Android.bp; then
692 | [ -d vendor/partner_gms ] && (cd vendor/partner_gms; wget --output-document=search.patch https://github.com/phhusson/treble_experimentations/raw/master/0001-Fix-SearchLauncher-for-Android-12.1.patch; git am search.patch || true)
693 | fi
694 | (cd device/phh/treble; git clean -fdx; bash generate.sh "$treble_generate")
695 | . ./"$(dirname "$0")/apply-patches.sh" "$repodir" "$localManifestBranch" | tee -a release/"$rom_fp"/patch-"$rom_fp".log || false
696 | }
697 |
698 | function check_dex() {
699 | reportMessage "* Do you want to disable pre-opt rom apps? (y/N) "
700 | if $YES; then
701 | reportWarning "! Disabling pre-opt results in slower first boot"
702 | echo -e "
703 | WITH_DEXPREOPT := false
704 | DISABLE_DEXPREOPT := true
705 | DONT_DEXPREOPT_PREBUILTS := true
706 | LOCAL_DEX_PREOPT := false" >> device/phh/treble/board-base.mk
707 | else
708 | (cd device/phh/treble; git checkout -- board-base.mk)
709 | fi
710 | }
711 |
712 | function gen_mk() {
713 | if [[ -n "$gen_mk" ]]; then
714 | declare -g gen_lunch="${gen_mk}_${gen_target}"
715 | local gen="${gen_mk}"
716 | [ $(get_android_version) -gt 8 ] && gen="$gen_lunch"
717 | (cd device/phh/treble;
718 | cat << EOF > $gen.mk
719 | $gen_config
720 | $gen_sepolicy
721 | `cat $target_name.mk`
722 | EOF
723 | cat << EOF >> AndroidProducts.mk
724 | PRODUCT_MAKEFILES += \\
725 | \$(LOCAL_DIR)/$gen.mk
726 | COMMON_LUNCH_CHOICES := \\
727 | ${gen_lunch}-${build_type}
728 | EOF
729 | sed "s@PRODUCT_NAME.*@PRODUCT_NAME := ${gen_lunch}@" -i $gen.mk)
730 | #sed "s@PRODUCT_MODEL.*@PRODUCT_MODEL := ${gen_lunch}@" -i $gen.mk
731 | fi
732 | }
733 |
734 | function build_variant() {
735 | reportMessage "* Do you want to clean before starting build? (y/N) "
736 | if $YES; then
737 | make installclean
738 | fi
739 | [[ -n "$gen_lunch" ]] && lunch "$gen_lunch"-"$build_type" || lunch "$1"
740 | make $extra_make_options BUILD_NUMBER="$rom_fp" -j "$jobs" systemimage
741 | make $extra_make_options BUILD_NUMBER="$rom_fp" vndk-test-sepolicy
742 |
743 | [ ! -f "$OUT"/system.img ] && reportError "! BUILD FAILED" _
744 |
745 | echo -e "* ROM built sucessfully (release/$rom_fp)"
746 |
747 | # TO-DO
748 | #reportMessage "* Do you want to securize the built gsi? (y/N) "
749 | #if $YES; then
750 | # (cd phh-sas; bash securize.sh "$OUT"/system.img)
751 | #fi
752 |
753 | cp "$OUT"/system.img release/"$rom_fp"/"$rom_type"-system-"$2".img
754 |
755 | reportMessage "* Do you want to compress the built gsi? (y/N) "
756 | if $YES; then
757 | cd release/"$rom_fp"; zip -r9 $rom_type-$target_name-"$rom_fp".zip $rom_type-*.img 2>/dev/null
758 | fi
759 |
760 | reportMessage "* Do you want to upload the built gsi? (y/N) "
761 | if $YES; then
762 | gdrive upload --share $rom_type-$target_name-"$rom_fp".zip || echo "Please, install gdrive tool!"
763 | fi
764 | }
765 |
766 | function jack_env() {
767 | RAM=$(free | awk '/^Mem:/{ printf("%0.f", $2/(1024^2))}')
768 | if [[ "$RAM" -lt 16 ]]; then
769 | export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx$(($RAM-1))G"
770 | fi
771 | }
772 |
773 | ################
774 | # #
775 | # SCRIPT START #
776 | # #
777 | ################
778 |
779 | function set_jobs_number() {
780 | [[ "$1" =~ ^[0-9]+$ ]] && jobs=$1 || reportError "Not a jobs number: $([[ -z $1 ]] && echo "(null)" || echo $1)"
781 | }
782 |
783 | prepre_env
784 |
785 | while [[ $# -gt 0 ]]; do
786 | case "$1" in
787 | -h|--help) help; exit 1 ;;
788 | -j|--jobs) shift; set_jobs_number "$1";;
789 | -j=*|--jobs=*) set_jobs_number "${1#*=}";;
790 | *-*) [ -z "${variants_map["$1"]}" ] && get_variants "$1";;
791 | *) [ -z "$mainrepo" ] && get_rom_type "$1";;
792 | esac
793 | shift
794 | done
795 |
796 | if [ -z "$mainrepo" ]; then
797 | reportError "Unknown ROM type: (null)"
798 | elif [[ "${#variant_codes[*]}" -eq 0 ]]; then
799 | reportError "Invalid defined variant: (null)"
800 | fi
801 |
802 | echo "Using jobs: $jobs"
803 |
804 | say_welcome
805 |
806 | reportMessage "- Do you want to sync? (y/N) "
807 | if $YES; then
808 | reportMessage "* Do you want to clean before sync? (y/N) "
809 | if $YES; then
810 | clean_repo_folder
811 | fi
812 | init_main_repo
813 | init_release
814 | sync_repo
815 | init_local_manifest
816 | else
817 | [ ! -d ".repo" ] && reportWarning "! ROM sources cannot be found."
818 | fi
819 |
820 | reportMessage "- Do you want to patch? (y/N) "
821 | if $YES; then
822 | fix_missings
823 | add_mks
824 | patch_things
825 | else
826 | reportWarning "! Patching is required, if this is the first time build."
827 | fi
828 |
829 | reportMessage "- Do you want to start build now? (y/N) "
830 | if $YES; then
831 | check_dex
832 | jack_env
833 | init_release
834 | source build/envsetup.sh 2>&1 || false
835 | for (( idx=0; idx < ${#variant_codes[*]}; idx++ )); do
836 | declare -g target_name=${variant_codes[$idx]%-*}
837 | declare -g build_type=${variant_codes[$idx]#*-}
838 | gen_mk
839 |
840 | printText "Building process started ($((1+$idx))/${#variant_codes[*]})"
841 | build_variant "${variant_codes[$idx]}" "${variant_names[$idx]}"
842 | done
843 | fi
844 |
--------------------------------------------------------------------------------