bromite-buildtools/apply-single-patch.sh

103 lines
2.3 KiB
Bash
Raw Normal View History

2020-11-26 13:23:00 +05:30
#!/bin/bash
PATCH=$1
2021-04-28 16:32:53 +05:30
LOG_FILE=~/build.log
2020-11-26 13:23:00 +05:30
dos2unix $PATCH
2021-04-28 16:32:53 +05:30
OK=0
DOBUILD=1
DOEXPORT=1
2020-11-26 13:23:00 +05:30
2022-01-10 21:00:33 +05:30
TEST=0
git log | grep FILE:$(basename -- $PATCH) && TEST=1
if [[ TEST -eq 1 ]]; then
echo "Patch $PATCH already exists. skipped." | tee -a ${LOG_FILE}
exit 0
fi
2021-04-28 16:32:53 +05:30
echo "" | tee -a ${LOG_FILE}
echo "Applying patch $PATCH" | tee -a ${LOG_FILE}
git apply --reject --whitespace=fix $PATCH && OK=1
2020-11-26 13:23:00 +05:30
if [[ OK -eq 0 ]]; then
2021-07-31 17:45:32 +05:30
OK=1
for file in $(grep '+++ b/' $PATCH | sed -e 's#+++ [ab]/##'); do
test -f $file || OK=0
done
2021-04-28 16:32:53 +05:30
for file in $(find . -name *.rej); do
echo " -> Check $file" | tee -a ${LOG_FILE};
2021-07-31 17:45:32 +05:30
wiggle --no-ignore --replace ${file::-4} $file && rm $file && rm ${file::-4}.porig && echo " OK" || OK=0
2021-04-28 16:32:53 +05:30
done
for file in $(find . -name *.rej); do
echo "---Found: $file" | tee -a ${LOG_FILE};
git add ${file::-4}
OK=0
done
if [[ OK -eq 0 ]]; then
DOBUILD=1
echo "Current patch $PATCH" | tee -a ${LOG_FILE}
echo "Patch not apply cleanly. Please fix... (next phase: build)" | tee -a ${LOG_FILE}
echo "Press return"
read -n 1
else
echo "Patch not apply cleanly. Wiggle done!" | tee -a ${LOG_FILE}
fi
2020-11-26 13:23:00 +05:30
2021-04-28 16:32:53 +05:30
echo " Deleting rej"
find . -type f -name '*.rej' -delete
find . -type f -name '*.porig' -delete
2020-11-26 13:23:00 +05:30
2021-04-28 16:32:53 +05:30
else
echo "Patch apply cleanly." | tee -a ${LOG_FILE}
DOBUILD=0
2020-11-26 13:23:00 +05:30
fi
2021-04-28 16:32:53 +05:30
if [[ DOBUILD -eq 1 ]]; then
OK=0
2022-01-10 21:00:33 +05:30
#echo "Building ${PATCH}: chrome_public_apk" | tee -a ${LOG_FILE}
#date "+%Y%m%d %H.%M.%S" | tee -a ${LOG_FILE}
#autoninja -C out/arm64 chrome_public_apk && OK=1
#date "+%Y%m%d %H.%M.%S" | tee -a ${LOG_FILE}
2020-11-26 13:23:00 +05:30
2022-01-10 21:00:33 +05:30
#DOEXPORT=1
2020-11-26 13:23:00 +05:30
2021-04-28 16:32:53 +05:30
fi
2020-11-26 13:23:00 +05:30
2021-04-28 16:32:53 +05:30
if [[ OK -eq 0 ]]; then
echo "Read to add $PATCH. Press return"
read -n 1
2020-11-26 13:23:00 +05:30
2021-04-28 16:32:53 +05:30
DOEXPORT=1
fi
2020-11-26 13:23:00 +05:30
2021-04-28 16:32:53 +05:30
if [[ DOEXPORT -eq 1 ]]; then
2022-01-10 21:00:33 +05:30
until false
do
bash ~/bromite-buildtools/create-from-patch.sh $PATCH $2
rm /tmp/1 /tmp/2 || true
lsdiff $PATCH >/tmp/1
lsdiff ../../bromite/build/patches-new/$(basename -- $PATCH) >/tmp/2
STATUS="$(cmp --silent /tmp/1 /tmp/2; echo $?)"
if [[ $STATUS -ne 0 ]]; then
git reset HEAD^
diff /tmp/1 /tmp/2
echo "Some files are missing. Check again." | tee -a ${LOG_FILE}
read -r -p "y to continue [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
bash ~/bromite-buildtools/create-from-patch.sh $PATCH $2
break
fi
bash
else
break
fi
done
2021-04-28 16:32:53 +05:30
fi