Skip to content

Commit 9680135

Browse files
committed
refactor(build-system): Tons of improvements and some bugfix
1 parent 4cfff4f commit 9680135

File tree

4 files changed

+123
-81
lines changed

4 files changed

+123
-81
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
/tmp
33
/ghome
44
/out
5+
/.patch_sum

.last_sync

-1
This file was deleted.

makeme

+114-72
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function gslr() {
1616
echo -e "~ Error [gslr:$RETC], could not find any line containing ${RED}$2${RC}" && return $RETC
1717
fi;
1818
else
19-
if test -z "$NPUT"; then
19+
if test -z "$1"; then
2020
echo -e "~ Error [gslr:3], lack of input" && return 1
2121
fi;
2222
fi
@@ -151,69 +151,113 @@ function build.main() {
151151
};
152152

153153
function patch.aosp_root() {
154-
files_to_patch=(
155-
"device/generic/common/device.mk"
156-
"bootable/newinstaller/Android.mk"
157-
"bootable/newinstaller/initrd/init"
158-
"bootable/newinstaller/install/scripts/1-install"
159-
"bootable/newinstaller/install/grub2/efi/boot/android.cfg"
160-
)
154+
if test -n "$BIGDROID_PROJECT"; then
155+
files_to_patch=(
156+
"initial_ramdisk/init"
157+
"install_ramdisk/scripts/1-install"
158+
"install_ramdisk/grub2/efi/boot/android.cfg"
159+
)
160+
else
161+
files_to_patch=(
162+
"device/generic/common/device.mk"
163+
"bootable/newinstaller/Android.mk"
164+
"bootable/newinstaller/initrd/init"
165+
"bootable/newinstaller/install/scripts/1-install"
166+
"bootable/newinstaller/install/grub2/efi/boot/android.cfg"
167+
)
168+
fi
169+
170+
# function get.patch_file() {
171+
# local patch_file="$1"
172+
# local line
173+
# for line in "${files_to_patch[@]}"; do
174+
# echo "$line" | grep -q ".*${patch_file}\$" && break
175+
# done
176+
# echo "$aosp_root/$line"
177+
# }
161178

162179
function patch.apply() {
163-
local FILE="$1"
180+
local FILE="${1##*/}"
181+
local FILE_PATH="$1"
164182
echo -e "==== Applying GearLock patches to $FILE"
165-
case "$FILE" in
166-
"${files_to_patch[0]}")
167-
local _dir="$(echo "$0" | grep -q 'vendor' && echo 'vendor' || echo 'bootable')"
168-
gslr "$aosp_root/$FILE" \
169-
'PRODUCT_COPY_FILES := \\' \
170-
"PRODUCT_COPY_FILES := \\\n $_dir\/gearlock\/out\/gri\/gearlock:gearlock \\" \
171-
|| handleError "Failed to patch $aosp_root/$FILE"
172-
;;
173-
174-
"${files_to_patch[1]}")
175-
line="$(grep -n 'BUILT_IMG.*:=.*$(.*)' "$aosp_root/$FILE" | head -n1 \
176-
| sed 's|/|\\/|g; s|initrd.img|initrd.img gearlock|')"
177-
178-
sed -i "${line%%:*}s/.*/${line#*:}/" "$aosp_root/$FILE" \
179-
|| handleError "Failed to patch $aosp_root/$FILE"
180-
;;
181-
182-
"${files_to_patch[2]}")
183-
gslr "$aosp_root/$FILE" "mount_sdcard" "mount_sdcard; hook_gearinit" \
184-
|| handleError "Failed to patch $aosp_root/$FILE"
185-
;;
183+
184+
if [ "${FILE}" == "device.mk" ]; then
185+
local _dir="$(echo "$0" | grep -q 'vendor' && echo 'vendor' || echo 'bootable')"
186+
gslr "$FILE_PATH" \
187+
'PRODUCT_COPY_FILES := \\' \
188+
"PRODUCT_COPY_FILES := \\\\\n $_dir\/gearlock\/out\/gri\/gearlock:gearlock \\\\" \
189+
|| handleError "Failed to patch $FILE"
190+
191+
elif [ "${FILE}" == "Android.mk" ]; then
192+
line="$(grep -n 'BUILT_IMG.*:=.*$(.*)' "$FILE_PATH" | head -n1 \
193+
| sed 's|/|\\/|g; s| gearlock||; s|initrd.img|initrd.img gearlock|')"
194+
195+
sed -i "${line%%:*}s/.*/${line#*:}/" "$FILE_PATH" \
196+
|| handleError "Failed to patch $FILE"
197+
198+
elif [ "${FILE}" == "init" ]; then
199+
gslr "$FILE_PATH" "mount_sdcard" "mount_sdcard; hook_gearinit" \
200+
|| handleError "Failed to patch $FILE"
186201

187-
"${files_to_patch[3]}")
188-
line="$(grep -n 'files=.*".*initrd.img.*"' "$aosp_root/$FILE" | head -n1 \
189-
| sed 's|initrd.img|initrd.img /mnt/$SRC/gearlock|; s|/|\\/|g')"
202+
elif [ "${FILE}" == "1-install" ]; then
203+
line="$(grep -n 'files=.*".*initrd.img.*"' "$FILE_PATH" | head -n1 \
204+
| sed 's| /mnt/$SRC/gearlock||; s|initrd.img|initrd.img /mnt/$SRC/gearlock|; s|/|\\/|g')"
190205

191-
sed -i "${line%%:*}s/.*/${line#*:}/" "$aosp_root/$FILE" \
192-
|| handleError "Failed to patch $aosp_root/$FILE"
193-
;;
206+
sed -i "${line%%:*}s/.*/${line#*:}/" "$FILE_PATH" \
207+
|| handleError "Failed to patch $FILE"
194208

195-
"${files_to_patch[4]}")
196-
sed -i 's/add_entry.*$/& NORECOVERY=1/g' "$aosp_root/$FILE"
209+
elif [ "${FILE}" == "android.cfg" ]; then
210+
sed -i 's/add_entry.*$/& NORECOVERY=1/g' "$FILE_PATH"
197211
sed -i 's|submenu "Advanced options -> ".*$|& \
198212
add_entry "$live - Boot into GearLock recovery mode" ALWAYSRECOVERY=1\
199213
add_entry "$live - Boot into GearLock recovery mode with NOGFX=1 flag" ALWAYSRECOVERY=1 NOGFX=1\
200-
add_entry "$live - Boot with Auto-ExtFs-Repair flag" quiet FIXFS=1|' "$aosp_root/$FILE"
201-
;;
202-
esac
203-
(
204-
cd "$aosp_root/${FILE%/*}" || handleError "Failed to change dir to $aosp_root/${FILE%/*}"
205-
git commit -a -m "Update/apply GearLock patches for $FILE" --author="AXON <axonasif@gmail.com>" 1>/dev/null
206-
)
214+
add_entry "$live - Boot with Auto-ExtFs-Repair flag" quiet FIXFS=1|' "$FILE_PATH"
215+
fi
216+
217+
if test -z "$BIGDROID_PROJECT"; then
218+
local ORIG_PWD="$(pwd)"
219+
FILE="$FILE_PATH"
220+
cd "${FILE%/*}" || handleError "Failed to change dir to ${FILE%/*}"
221+
git commit -a -m "Update/apply GearLock patches for ${FILE/"$aosp_root"/}" --author="AXON <axonasif@gmail.com>" 1>/dev/null
222+
cd "$ORIG_PWD"
223+
fi
207224
}
208225

209226
# Start with updating/placing hook script
210-
local HOOK_PATH="$aosp_root/bootable/newinstaller/initrd/scripts/0-hook"
211-
rsync "$_execDir/installer/hook" "$HOOK_PATH" || handleError "Failed to copy hook into $HOOK_PATH"
227+
HOOK_PATH="$(
228+
if test -n "$BIGDROID_PROJECT"; then
229+
echo "$aosp_root/initial_ramdisk/scripts/0-hook"
230+
else
231+
echo "$aosp_root/bootable/newinstaller/initrd/scripts/0-hook"
232+
fi
233+
)" && {
234+
rsync "$_execDir/installer/hook" "$HOOK_PATH" || handleError "Failed to copy hook into $HOOK_PATH"
235+
(
236+
test -z "$BIGDROID_PROJECT" && {
237+
cd "${HOOK_PATH%/*}" || return 1
238+
cd ../../ || return 1
239+
git commit -a -m "Update/apply GearLock hook" --author="AXON <axonasif@gmail.com>" 1>/dev/null
240+
}
241+
)
242+
}
212243

213244
# Now let's find which files we need to patch
214245
for _file in "${files_to_patch[@]}"; do
215-
! grep -i -E -q 'gearlock|gearinit' "$aosp_root/$_file" \
216-
&& patch.apply "$_file"
246+
local patch_sum_file="$_execDir/.patch_sum"
247+
local _sel_file="$aosp_root/$_file"
248+
test -e "$_sel_file" && {
249+
if test -z "$NO_PATCH_SUM" && test -e "$patch_sum_file"; then
250+
test "$(sha256sum "$_sel_file" | awk '{print $1}')" != "$(echo "$(< "$patch_sum_file")" | grep "${_sel_file##*/}" | awk '{print $2}')" && {
251+
patch.apply "$_sel_file" && \
252+
sed -i "s|${_sel_file##*/}.*|${_sel_file##*/} $(sha256sum "$_sel_file" | awk '{print $1}')|" "$patch_sum_file"
253+
}
254+
else
255+
export NO_PATCH_SUM=true
256+
! grep -i -E -q 'gearlock|gearinit' "$_sel_file" \
257+
&& patch.apply "$_sel_file" && \
258+
echo "${_sel_file##*/} $(sha256sum "$_sel_file" | awk '{print $1}')" >> "$patch_sum_file"
259+
fi
260+
}
217261
done
218262
}
219263

@@ -225,34 +269,29 @@ function gen.newVersion() {
225269
"$SEMVER_BIN" "$@"
226270
}
227271
# Gather the data we need
228-
local CURRENT_VERSION PATCH_VERSION MINOR_VERSION VERSION_FILE LAST_SYNC_FILE
272+
local CURRENT_VERSION PATCH_VERSION MINOR_VERSION VERSION_FILE
229273

230-
LAST_SYNC_FILE="${_execDir}/.last_sync"
231-
LAST_SYNC_HARSH="$(git log --all --ancestry-path ^$(< "$LAST_SYNC_FILE") --format=format:%H | tail -n 1)" || return
232-
LAST_COMMIT_HARSH="$(git rev-parse HEAD)"
233-
NEW_COMMITS="$(git rev-list --no-merges ${LAST_SYNC_HARSH}...${LAST_COMMIT_HARSH} | wc -l)"
274+
NEW_COMMITS="$(git log --no-merges --pretty=format:"%s" | sed '/Update version code/Q' | grep -v -i '^Update.*' | wc -l)"
234275
VERSION_FILE="${_execDir}/core/version"
235276

236277
# Handling what we need to do
237278
for times in $(seq $NEW_COMMITS); do
238279
CURRENT_VERSION="$(< "$VERSION_FILE")" || return
239-
PATCH_VERSION="$(semver get patch $CURRENT_VERSION)" || return
240-
MINOR_VERSION="$(semver get minor $CURRENT_VERSION)" || return
280+
PATCH_VERSION="$(semver get patch "$CURRENT_VERSION")" || return
281+
MINOR_VERSION="$(semver get minor "$CURRENT_VERSION")" || return
241282

242283
# Version updating logic
243284
local bumpPoint="40"
244285
local bumpPointMajor="10"
245286
if [ "$PATCH_VERSION" != "$bumpPoint" ] && [ "$PATCH_VERSION" -lt "$bumpPoint" ]; then
246-
echo "$(semver bump patch $CURRENT_VERSION)" > "$VERSION_FILE"
287+
echo "$(semver bump patch "$CURRENT_VERSION")" > "$VERSION_FILE"
247288
elif [ "$MINOR_VERSION" == "$bumpPointMajor" ]; then
248-
echo "$(semver bump major $CURRENT_VERSION)" > "$VERSION_FILE"
289+
echo "$(semver bump major "$CURRENT_VERSION")" > "$VERSION_FILE"
249290
elif [ "$PATCH_VERSION" == "$bumpPoint" ]; then
250-
echo "$(semver bump minor $CURRENT_VERSION)" > "$VERSION_FILE"
291+
echo "$(semver bump minor "$CURRENT_VERSION")" > "$VERSION_FILE"
251292
fi
252293
done
253294

254-
# Update last commit hash cache file
255-
echo "$LAST_COMMIT_HARSH" > "$LAST_SYNC_FILE"
256295

257296
}
258297

@@ -272,29 +311,29 @@ function gen.conventionalChangelog() {
272311
# Now lets phrase them
273312
for log in "$featLog" "$fixLog" "$perfLog" "$refactorLog" "$choreLog" "$buildLog" "$ciLog"; do
274313
if test -n "$log"; then
275-
logName="$(echo "$log" | head -n1 | sed 's|(.*)||g' | cut -d ':' -f1)"
314+
logName="$(echo "$log" | head -n1 | cut -d ':' -f1 | sed 's|(.*)||g')"
276315
# Create H1
277316
case "$logName" in
278317
"feat")
279-
echo "# Feature" >> "$output"
318+
echo "### New Features" >> "$output"
280319
;;
281320
"fix")
282-
echo -e "\n\n# Bugfix" >> "$output"
321+
echo -e "\n\n### Bug Fixes" >> "$output"
283322
;;
284323
"perf")
285-
echo -e "\n\n# Performance Improvements" >> "$output"
324+
echo -e "\n\n### Performance Improvements" >> "$output"
286325
;;
287326
"refactor")
288-
echo -e "\n\n# Refactoring" >> "$output"
327+
echo -e "\n\n### Refactors" >> "$output"
289328
;;
290329
"chore")
291-
echo -e "\n\n# Chore" >> "$output"
330+
echo -e "\n\n### Chores" >> "$output"
292331
;;
293332
"build")
294-
echo -e "\n\n# Build" >> "$output"
333+
echo -e "\n\n### Build System" >> "$output"
295334
;;
296335
"ci")
297-
echo -e "\n\n# Ci" >> "$output"
336+
echo -e "\n\n### Continuous Integration" >> "$output"
298337
;;
299338
esac
300339

@@ -343,7 +382,7 @@ function setup.devEnv() {
343382
\033[0;31msudo chroot \"$NEW_ROOT\" /gearlock/bin/env GDEBUG=true /gearlock/bin/bash\033[0m"
344383
}
345384

346-
385+
# CLAP
347386
case "$1" in
348387
--aosp-project-makefile)
349388
aosp_root="$(pwd)" || handleError "Failed to locate \$aosp_root"
@@ -352,7 +391,6 @@ case "$1" in
352391
patch.aosp_root
353392
build.main "-mx23"
354393
;;
355-
356394
--aosp-project-vendorsetup)
357395
shift
358396
test -z "$1" && handleError "Failed to locate \$aosp_root"
@@ -362,7 +400,11 @@ case "$1" in
362400
patch.aosp_root
363401
build.main "-mx23"
364402
;;
365-
403+
--bigdroid-project-hook)
404+
export BIGDROID_PROJECT=true
405+
test -z "$SYSTEM_DIR" && exit 1
406+
exec "$0" --aosp-project-vendorsetup "$MOUNT_DIR"
407+
;;
366408
--run-check)
367409
RUN_CHECK=true
368410
build.setVars

vendorsetup.sh

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# Hook makeme on source trigger
22
makefile="$(pwd)/vendor/gearlock/makeme"
33
chmod +x "$makefile" || { echo -e 'Error: Failed to make gearlock makefile executable' && exit 1; }
4-
"$makefile" --aosp-project-vendorsetup "$(pwd)"
4+
#"$makefile" --aosp-project-vendorsetup "$(pwd)"
55

6-
# save the official lunch command to aosp_lunch() and source it
7-
tmp_lunch=`mktemp`
8-
sed '/ lunch()/,/^}/!d' build/envsetup.sh | sed 's/function lunch/function aosp_lunch/' > ${tmp_lunch}
9-
source ${tmp_lunch}
10-
rm -f ${tmp_lunch}
6+
# Save the official lunch command to aosp_lunch() and source it
7+
tmp_lunch="$(mktemp)"
8+
sed '/ lunch()/,/^}/!d' build/envsetup.sh | sed 's/function lunch/function aosp_lunch/' > "${tmp_lunch}"
9+
source "${tmp_lunch}"
10+
rm -f "${tmp_lunch}"
1111

1212
# Override lunch function to filter lunch targets
1313
function lunch
1414
{
15-
local T=$(gettop)
15+
local T="$(gettop)"
1616
if [ ! "$T" ]; then
1717
echo "[lunch] Couldn't locate the top of the tree. Try setting TOP." >&2
18-
return
18+
return 1
1919
fi
2020

2121
aosp_lunch $*

0 commit comments

Comments
 (0)