diff --git a/examples/rust/blink/src/lib.rs b/examples/rust/blink/src/lib.rs index 4903558f..c6529d5b 100644 --- a/examples/rust/blink/src/lib.rs +++ b/examples/rust/blink/src/lib.rs @@ -17,6 +17,10 @@ //! The board must possess at least one LED and one timer. The applet indefinitely cycles through //! all LEDs in order with a period of 1 second and blinks them for 500 milli-seconds. +// DO NOT EDIT MANUALLY: +// - Edit book/src/applet/prelude/led.rs instead. +// - Then use ./scripts/sync.sh to generate this file. + #![no_std] wasefire::applet!(); diff --git a/examples/rust/button/src/lib.rs b/examples/rust/button/src/lib.rs index 57b9136b..243e17dc 100644 --- a/examples/rust/button/src/lib.rs +++ b/examples/rust/button/src/lib.rs @@ -16,6 +16,10 @@ //! //! The applet prints the button state to the debug output on any button event. +// DO NOT EDIT MANUALLY: +// - Edit book/src/applet/prelude/button1.rs instead. +// - Then use ./scripts/sync.sh to generate this file. + #![no_std] wasefire::applet!(); diff --git a/examples/rust/button_abort/src/lib.rs b/examples/rust/button_abort/src/lib.rs index 14b78b89..4363184e 100644 --- a/examples/rust/button_abort/src/lib.rs +++ b/examples/rust/button_abort/src/lib.rs @@ -20,6 +20,10 @@ //! If the button is released before the timer runs out, then the LED will blink until next button //! press. +// DO NOT EDIT MANUALLY: +// - Edit book/src/applet/prelude/timer.rs instead. +// - Then use ./scripts/sync.sh to generate this file. + #![no_std] wasefire::applet!(); diff --git a/examples/rust/led/src/lib.rs b/examples/rust/led/src/lib.rs index afeddcf1..c18f4b64 100644 --- a/examples/rust/led/src/lib.rs +++ b/examples/rust/led/src/lib.rs @@ -20,6 +20,10 @@ //! is toggled. After a button is released, it becomes associated with the next LED (wrapping back //! to the first LED after the last LED). +// DO NOT EDIT MANUALLY: +// - Edit book/src/applet/prelude/button2.rs instead. +// - Then use ./scripts/sync.sh to generate this file. + #![no_std] wasefire::applet!(); diff --git a/examples/rust/memory_game/src/lib.rs b/examples/rust/memory_game/src/lib.rs index 1db71fbc..78762189 100644 --- a/examples/rust/memory_game/src/lib.rs +++ b/examples/rust/memory_game/src/lib.rs @@ -18,6 +18,10 @@ //! serial. It essentially shows a random base32 string (the length representing the level in the //! game) for 3 seconds and gives 7 seconds to type it back. +// DO NOT EDIT MANUALLY: +// - Edit book/src/applet/prelude/usb.rs instead. +// - Then use ./scripts/sync.sh to generate this file. + #![no_std] wasefire::applet!(); diff --git a/examples/rust/store/src/lib.rs b/examples/rust/store/src/lib.rs index e9dab63f..9cad00e1 100644 --- a/examples/rust/store/src/lib.rs +++ b/examples/rust/store/src/lib.rs @@ -17,6 +17,10 @@ //! The applet additionally relies on USB serial. It describes its own usage when connecting on the //! USB serial. +// DO NOT EDIT MANUALLY: +// - Edit book/src/applet/prelude/store.rs instead. +// - Then use ./scripts/sync.sh to generate this file. + #![no_std] wasefire::applet!(); diff --git a/scripts/log.sh b/scripts/log.sh index 80a506d4..087a0dad 100644 --- a/scripts/log.sh +++ b/scripts/log.sh @@ -14,6 +14,8 @@ x() { ( set -x; "$@"; ); } i() { _log '1;36' Info "$*"; } +w() { _log '1;33' Warn "$*"; } +t() { _log '1;33' Todo "$*"; } d() { _log '1;32' Done "$*"; exit 0; } e() { _log '1;31' Error "$*"; exit 1; } diff --git a/scripts/sync.sh b/scripts/sync.sh index 0ee7558c..0225d1ce 100755 --- a/scripts/sync.sh +++ b/scripts/sync.sh @@ -21,7 +21,25 @@ set -e cargo xtask update-apis book_example() { - sed '/ANCHOR/d' book/src/applet/prelude/$1.rs > examples/rust/$2/src/lib.rs + local src=book/src/applet/prelude/$1.rs + local dst=examples/rust/$2/src/lib.rs + # We only check that the destination is newer by more than one second, because when cloning the + # repository or switching branches, it may happen that the destination is slightly newer. + if [ $(stat -c%Y $dst) -gt $(($(stat -c%Y $src) + 1)) ]; then + t "Update $src instead of $dst" + e "$dst seems to have been manually modified" + fi + # Besides removing all anchors, we insert a warning before the #![no_std] line, which all examples + # should have near the beginning of the file. + sed '/ANCHOR/d;/^#!\[no_std\]$/{i \'" +// DO NOT EDIT MANUALLY:\\ +// - Edit $src instead.\\ +// - Then use ./scripts/sync.sh to generate this file.\\ + +}" $src > $dst + # Now that the destination has been updated, it is newer than the source. So we touch the source + # to preserve the invariant that the destination is never newer than the source. + touch $src } book_example led blink