From b14ed0e742a846736c222d27bbd52da5a496814b Mon Sep 17 00:00:00 2001 From: Julien Cretin Date: Tue, 21 Jun 2022 19:15:44 +0200 Subject: [PATCH] Add check command to patches script --- deploy.py | 2 ++ maintainers/patches | 66 +++++++++++++++++++++++++++++++++++---------- 2 files changed, 54 insertions(+), 14 deletions(-) diff --git a/deploy.py b/deploy.py index 7fe2449..f0e40c9 100755 --- a/deploy.py +++ b/deploy.py @@ -770,6 +770,8 @@ class OpenSKInstaller: info("Nothing to do.") return 0 + subprocess.run(["./maintainers/patches", "check"]) + # Compile what needs to be compiled board_props = SUPPORTED_BOARDS[self.args.board] if self.args.tockos: diff --git a/maintainers/patches b/maintainers/patches index 2360407..3687371 100755 --- a/maintainers/patches +++ b/maintainers/patches @@ -7,12 +7,12 @@ PROGRAM="$0" MODULES=(tock libtock-rs) success() { - echo -e "\e[1;32mDone:\e[m $1" + echo -e "\r\e[1;32mDone:\e[m $1" exit 0 } fail() { - echo -e "\e[1;31mError:\e[m $1" + echo -e "\r\e[1;31mError:\e[m $1" exit 1 } @@ -34,7 +34,7 @@ get_head() { help() { local root="$(get_root)" cat < "../../patches/${module}/${file#*-}" done git clean -qfxd - top="$(get_head)" + local top="$(get_head)" git checkout -q "${root}" if [[ "${module}" == tock ]]; then rm -r boards @@ -135,6 +146,29 @@ save() { 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 \ || fail 'Not running from OpenSK directory.' [[ $# -eq 1 ]] || help @@ -148,10 +182,14 @@ case $1 in success 'Saved the submodules to the patches.' ;; restore) - # Ovewrite the commit function to do nothing. + # Overwrite the commit function to do nothing. commit() { true; } apply success 'Restored the submodules.' ;; + check) + check + success 'The submodules and patches are in sync.' + ;; *) fail 'Unexpected argument. Run without argument for help.' ;; esac