Add check command to patches script

This commit is contained in:
Julien Cretin
2022-06-21 19:15:44 +02:00
parent 2544afbfee
commit b14ed0e742
2 changed files with 54 additions and 14 deletions

View File

@@ -770,6 +770,8 @@ class OpenSKInstaller:
info("Nothing to do.") info("Nothing to do.")
return 0 return 0
subprocess.run(["./maintainers/patches", "check"])
# Compile what needs to be compiled # Compile what needs to be compiled
board_props = SUPPORTED_BOARDS[self.args.board] board_props = SUPPORTED_BOARDS[self.args.board]
if self.args.tockos: if self.args.tockos:

View File

@@ -7,12 +7,12 @@ PROGRAM="$0"
MODULES=(tock libtock-rs) MODULES=(tock libtock-rs)
success() { success() {
echo -e "\e[1;32mDone:\e[m $1" echo -e "\r\e[1;32mDone:\e[m $1"
exit 0 exit 0
} }
fail() { fail() {
echo -e "\e[1;31mError:\e[m $1" echo -e "\r\e[1;31mError:\e[m $1"
exit 1 exit 1
} }
@@ -34,7 +34,7 @@ get_head() {
help() { help() {
local root="$(get_root)" local root="$(get_root)"
cat <<EOF cat <<EOF
Usage: ${PROGRAM} {apply|save} Usage: ${PROGRAM} {apply|save|restore|check}
apply Applies the patches to the submodules regardless of their state. apply Applies the patches to the submodules regardless of their state.
As a consequence this can always be called to get to a clean state As a consequence this can always be called to get to a clean state
@@ -51,6 +51,11 @@ Usage: ${PROGRAM} {apply|save}
clean state but may result in data loss if there are unsaved clean state but may result in data loss if there are unsaved
changes. changes.
check Checks whether the submodules and the patches are in sync. This
may fail in two cases:
- when the patches were updated but not restored/applied, and
- when the submodules have been modified but not saved.
Example: Example:
1. Enter the edit state from the normal state: 1. Enter the edit state from the normal state:
@@ -85,6 +90,20 @@ EOF
exit 0 exit 0
} }
apply_module() {
local root="$1" module="$2" file
git checkout -q "${root}"
if [[ "${module}" == tock ]]; then
cp -a ../../boards .
commit '00-boards'
fi
for file in ../../patches/"${module}"/*; do
git apply "${file}"
commit "$(basename "${file}" .patch)"
echo -n .
done
}
apply() { apply() {
for module in "${MODULES[@]}"; do for module in "${MODULES[@]}"; do
local root="$(get_root "${module}")" local root="$(get_root "${module}")"
@@ -92,15 +111,7 @@ apply() {
cd third_party/"${module}" cd third_party/"${module}"
git reset -q --hard git reset -q --hard
git clean -qfxd git clean -qfxd
git checkout -q "${root}" apply_module "${root}" "${module}"
if [[ "${module}" == tock ]]; then
cp -a ../../boards .
commit '00-boards'
fi
for file in ../../patches/"${module}"/*; do
git apply "${file}"
commit "$(basename "${file}" .patch)"
done
) )
done done
} }
@@ -119,7 +130,7 @@ save() {
| sed '/^-- $/,$d' > "../../patches/${module}/${file#*-}" | sed '/^-- $/,$d' > "../../patches/${module}/${file#*-}"
done done
git clean -qfxd git clean -qfxd
top="$(get_head)" local top="$(get_head)"
git checkout -q "${root}" git checkout -q "${root}"
if [[ "${module}" == tock ]]; then if [[ "${module}" == tock ]]; then
rm -r boards rm -r boards
@@ -135,6 +146,29 @@ save() {
done done
} }
check() {
# Overwrite the commit function to do nothing.
commit() { true; }
for module in "${MODULES[@]}"; do
local root="$(get_root "${module}")"
( set -e
cd third_party/"${module}"
git add .
git commit --allow-empty -qmx
local top="$(get_head)"
apply_module "${root}" "${module}"
git add .
git commit --allow-empty -qmy
# We need to cleanup (and not exit) regardless of a diff.
local r; if git diff "${top}" --quiet; then r=0; else r=1; fi
git checkout -q "${top}"
git reset -q HEAD~
[[ "${r}" -eq 0 ]] \
|| fail "The ${module} submodule differs from its patches."
)
done
}
grep -q third_party/tock .gitmodules 2>/dev/null \ grep -q third_party/tock .gitmodules 2>/dev/null \
|| fail 'Not running from OpenSK directory.' || fail 'Not running from OpenSK directory.'
[[ $# -eq 1 ]] || help [[ $# -eq 1 ]] || help
@@ -148,10 +182,14 @@ case $1 in
success 'Saved the submodules to the patches.' success 'Saved the submodules to the patches.'
;; ;;
restore) restore)
# Ovewrite the commit function to do nothing. # Overwrite the commit function to do nothing.
commit() { true; } commit() { true; }
apply apply
success 'Restored the submodules.' success 'Restored the submodules.'
;; ;;
check)
check
success 'The submodules and patches are in sync.'
;;
*) fail 'Unexpected argument. Run without argument for help.' ;; *) fail 'Unexpected argument. Run without argument for help.' ;;
esac esac