Use bash, no rsync, add doc

This commit is contained in:
Julien Cretin
2021-08-06 15:17:32 +02:00
committed by Julien Cretin
parent 7a812a657b
commit 0f70a211ea

View File

@@ -1,37 +1,22 @@
#!/bin/zsh #!/bin/bash
set -e
PROGRAM=$0 PROGRAM="$0"
success() { success() {
echo "\e[1;32mDone:\e[m $1" echo -e "\e[1;32mDone:\e[m $1"
exit 0 exit 0
} }
fail() { fail() {
echo "\e[1;31mError:\e[m $1" echo -e "\e[1;31mError:\e[m $1"
exit 1 exit 1
} }
help() {
cat <<EOF
Usage: $PROGRAM {apply|save}
apply Applies the patches to the Tock submodule.
This resets Tock and can always be called.
save Saves the Tock submodule to the patches.
Should only be called after apply and when all changes have been
added to a commit. After saving, you can run ./setup.sh to return
to normal state. Otherwise you can continue editing Tock and
calling save.
EOF
exit 0
}
commit() { commit() {
local message=$1 local message="$1"
git add . git add .
git commit -qm$message git commit -qm"${message}"
} }
get_root() { get_root() {
@@ -42,44 +27,99 @@ get_head() {
git rev-parse HEAD git rev-parse HEAD
} }
help() {
local root="$(get_root)"
cat <<EOF
Usage: ${PROGRAM} {apply|save}
apply Applies the patches to the Tock submodule regardless of its state.
As a consequence this can always be called to get to a clean state
but may result in data loss if there are unsaved changes.
save Saves the Tock submodule to the patches.
This should only be called after apply and when all changes have
been added to a commit. After saving, you can run ./setup.sh to
return to normal state. Otherwise you can continue editing Tock
and calling save.
Example:
1. Enter the edit state from the normal state:
${PROGRAM} apply
2. Edit files in the Tock submodule:
cd third_party/tock
edit <files>
3. Create a fix commit per affected patch by repeating the following commands
until there are no more files to add:
git add -p
git commit -m'fix <patch#>'
4. Merge the fixes into their patches by moving their line below their patch
and changing their "edit" into "fixup":
git rebase -i ${root}
5. Save the changes:
cd ../..
${PROGRAM} save
6. Either continue repeating steps 2 to 5, or return to the normal state:
./setup.sh
EOF
exit 0
}
apply() { apply() {
git submodule -q update third_party/tock local root="$(get_root)"
( cd third_party/tock ( set -e
cd third_party/tock
git reset -q --hard git reset -q --hard
git clean -qfxd git clean -qfxd
rsync -a ../../boards . git checkout -q "${root}"
cp -a ../../boards .
commit '00-boards' commit '00-boards'
for file in ../../patches/tock/*; do for file in ../../patches/tock/*; do
patch -sp1 < $file git apply "${file}"
commit "${${file#../../patches/tock/}%.patch}" commit "$(basename "${file}" .patch)"
done done
) )
success 'Applied the patches to the Tock submodule.' success 'Applied the patches to the Tock submodule.'
} }
save() { save() {
local root=$(get_root) local root="$(get_root)"
( cd third_party/tock ( set -e
cd third_party/tock
[[ -z "$(git status -s)" ]] || fail 'The Tock submodule is not clean.' [[ -z "$(git status -s)" ]] || fail 'The Tock submodule is not clean.'
rm ../../patches/tock/*.patch rm ../../patches/tock/*.patch
for file in $(git format-patch $root); do for file in $(git format-patch "${root}"); do
sed -n '/^diff/,$p' $file | head -n-3 > ../../patches/tock/${file#*-} sed -n '/^diff/,$p' "${file}" \
| head -n-3 > "../../patches/tock/${file#*-}"
done done
git clean -qfxd git clean -qfxd
top=$(get_head) top="$(get_head)"
git checkout -q $root git checkout -q "${root}"
rm -r boards rm -r boards
patch -sp1 < ../../patches/tock/00-boards.patch git apply --whitespace=nowarn ../../patches/tock/00-boards.patch
rm ../../patches/tock/00-boards.patch rm ../../patches/tock/00-boards.patch
rsync -a --delete boards ../.. rm -r ../../boards
cp -a boards ../..
git reset -q --hard git reset -q --hard
git clean -qfxd git clean -qfxd
git checkout -q $top git checkout -q "${top}"
) || exit )
success 'Saved the Tock submodule to the patches.' success 'Saved the Tock submodule to the patches.'
} }
[[ $(basename $PWD) == OpenSK ]] || fail 'Not running from OpenSK directory.' grep -q third_party/tock .gitmodules 2>/dev/null \
|| fail 'Not running from OpenSK directory.'
[[ $# -eq 1 ]] || help [[ $# -eq 1 ]] || help
case $1 in case $1 in
apply) apply ;; apply) apply ;;