diff --git a/maintainers/patches b/maintainers/patches index eaa58db..2360407 100755 --- a/maintainers/patches +++ b/maintainers/patches @@ -1,7 +1,10 @@ #!/bin/bash set -e +shopt -s nullglob + PROGRAM="$0" +MODULES=(tock libtock-rs) success() { echo -e "\e[1;32mDone:\e[m $1" @@ -20,7 +23,8 @@ commit() { } get_root() { - git ls-tree HEAD:third_party | sed -En 's/^.* ([^ ]+)\ttock$/\1/p' + local module="$1" + git ls-tree HEAD:third_party | sed -En 's/^.* ([^ ]+)\t'"${module}"'$/\1/p' } get_head() { @@ -32,17 +36,17 @@ help() { cat < edit - 3. Create a fix commit per affected patch by repeating the following commands - until there are no more files to add: + 3. For each edited submodule, 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 ' - 4. Merge the fixes into their patches by moving their line below their patch - and changing their "edit" into "fixup": + 4. For each edited submodule, merge the fixes into their patches by moving + their line below their patch and changing their "edit" into "fixup": git rebase -i ${root} @@ -82,43 +86,53 @@ EOF } apply() { - local root="$(get_root)" - ( set -e - cd third_party/tock - git reset -q --hard - git clean -qfxd - git checkout -q "${root}" - cp -a ../../boards . - commit '00-boards' - for file in ../../patches/tock/*; do - git apply "${file}" - commit "$(basename "${file}" .patch)" - done - ) + for module in "${MODULES[@]}"; do + local root="$(get_root "${module}")" + ( set -e + cd third_party/"${module}" + git reset -q --hard + git clean -qfxd + 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)" + done + ) + done } save() { - local root="$(get_root)" - ( set -e - cd third_party/tock - [[ -z "$(git status -s)" ]] || fail 'The Tock submodule is not clean.' - rm ../../patches/tock/*.patch - for file in $(git format-patch "${root}"); do - sed -n '/^diff/,$p' "${file}" \ - | sed '/^-- $/,$d' > "../../patches/tock/${file#*-}" - done - git clean -qfxd - top="$(get_head)" - git checkout -q "${root}" - rm -r boards - git apply --whitespace=nowarn ../../patches/tock/00-boards.patch - rm ../../patches/tock/00-boards.patch - rm -r ../../boards - cp -a boards ../.. - git reset -q --hard - git clean -qfxd - git checkout -q "${top}" - ) + for module in "${MODULES[@]}"; do + local root="$(get_root "${module}")" + ( set -e + cd third_party/"${module}" + [[ -z "$(git status -s)" ]] \ + || fail "The ${module} submodule is not clean." + rm -rf ../../patches/"${module}" + mkdir ../../patches/"${module}" + for file in $(git format-patch "${root}"); do + sed -n '/^diff/,$p' "${file}" \ + | sed '/^-- $/,$d' > "../../patches/${module}/${file#*-}" + done + git clean -qfxd + top="$(get_head)" + git checkout -q "${root}" + if [[ "${module}" == tock ]]; then + rm -r boards + git apply --whitespace=nowarn ../../patches/"${module}"/00-boards.patch + rm ../../patches/tock/00-boards.patch + rm -r ../../boards + cp -a boards ../.. + fi + git reset -q --hard + git clean -qfxd + git checkout -q "${top}" + ) + done } grep -q third_party/tock .gitmodules 2>/dev/null \ @@ -127,17 +141,17 @@ grep -q third_party/tock .gitmodules 2>/dev/null \ case $1 in apply) apply - success 'Applied the patches to the Tock submodule.' + success 'Applied the patches to the submodules.' ;; save) save - success 'Saved the Tock submodule to the patches.' + success 'Saved the submodules to the patches.' ;; restore) # Ovewrite the commit function to do nothing. commit() { true; } apply - success 'Restored the Tock submodule.' + success 'Restored the submodules.' ;; *) fail 'Unexpected argument. Run without argument for help.' ;; esac diff --git a/patches/libtock-rs/01-macos.patch b/patches/libtock-rs/01-macos.patch new file mode 100644 index 0000000..5f25664 --- /dev/null +++ b/patches/libtock-rs/01-macos.patch @@ -0,0 +1,12 @@ +diff --git a/core/src/stack_size.rs b/core/src/stack_size.rs +index 9145393..ef55383 100644 +--- a/core/src/stack_size.rs ++++ b/core/src/stack_size.rs +@@ -14,6 +14,7 @@ macro_rules! stack_size { + {$size:expr} => { + #[no_mangle] + #[link_section = ".stack_buffer"] ++ #[cfg(not(target_os = "macos"))] + pub static mut STACK_MEMORY: [u8; $size] = [0; $size]; + } + } diff --git a/patches/tock/03-additional-boards.patch b/patches/tock/03-additional-boards.patch index 754c64a..97774b9 100644 --- a/patches/tock/03-additional-boards.patch +++ b/patches/tock/03-additional-boards.patch @@ -1,5 +1,5 @@ diff --git a/Cargo.toml b/Cargo.toml -index 06acc26d2..e5db0740b 100644 +index 06acc26d2..bd1bbd58f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,13 @@ members = [ diff --git a/setup-submodules.sh b/setup-submodules.sh index 7ed9288..2f6c273 100755 --- a/setup-submodules.sh +++ b/setup-submodules.sh @@ -18,6 +18,7 @@ export TERM=${TERM:-vt100} done_text="$(tput bold)DONE.$(tput sgr0)" set -e +shopt -s nullglob # Ensure the submodules are pulled and up-to-date git submodule update --init @@ -40,35 +41,19 @@ echo -n '[-] Copying additional boards to Tock... ' cp -r boards/* third_party/tock/boards echo $done_text -# Apply patches to kernel. Do that in a sub-shell. -( - cd third_party/tock/ && \ - for p in ../../patches/tock/*.patch - do - echo -n '[-] Applying patch "'$(basename $p)'"... ' - if git apply "$p" - then - echo $done_text - else - patch_conflict_detected - fi - done -) - -# Now apply patches to libtock-rs. Do that in a sub-shell. -# -# Commented out as there are not patches at the moment, and the pattern fails in -# that case. -#( -# cd third_party/libtock-rs/ && \ -# for p in ../../patches/libtock-rs/*.patch -# do -# echo -n '[-] Applying patch "'$(basename $p)'"... ' -# if git apply "$p" -# then -# echo $done_text -# else -# patch_conflict_detected -# fi -# done -#) +for module in tock libtock-rs; do + # Apply patches to the submodule. Do that in a sub-shell. + ( + cd third_party/"${module}"/ && \ + for p in ../../patches/"${module}"/*.patch + do + echo -n '[-] Applying patch "'$(basename $p)'"... ' + if git apply "$p" + then + echo $done_text + else + patch_conflict_detected + fi + done + ) +done