eowyn.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/bash
  2. #
  3. # "I will be a shieldmaiden no longer,
  4. # nor vie with the great Riders, nor
  5. # take joy only in the songs of slaying.
  6. # I will be a healer, and love all things
  7. # that grow and are not barren."
  8. # Éowyn, The Return of the King
  9. #
  10. #
  11. # This script shall heal the little broken programs
  12. # using the patches in this directory and convey them
  13. # to convalesce in the healed directory.
  14. #
  15. set -e
  16. # We check ourselves before we wreck ourselves.
  17. if [ ! -f patches/eowyn.sh ]
  18. then
  19. echo "But I must be run from the project root directory."
  20. exit 1
  21. fi
  22. # Which version we have?
  23. echo "I am in version 23.4.25.1, let's try our magic power."
  24. # Create directory of healing if it doesn't already exist.
  25. mkdir -p patches/healed
  26. # Cycle through all the little broken Zig applications.
  27. for broken in exercises/*.zig
  28. do
  29. # Remove the dir and extension, rendering the True Name.
  30. true_name=$(basename "$broken" .zig)
  31. patch_name="patches/patches/$true_name.patch"
  32. if [ -f "$patch_name" ]
  33. then
  34. # Apply the bandages to the wounds, grow new limbs, let
  35. # new life spring into the broken bodies of the fallen.
  36. echo Healing "$true_name"...
  37. patch --output="patches/healed/$true_name.zig" "$broken" "$patch_name"
  38. else
  39. echo Cannot heal "$true_name". No patch found.
  40. fi
  41. done
  42. echo "Looking for non-conforming code formatting..."
  43. zig fmt --check patches/healed
  44. # Test the healed exercises. May the compiler have mercy upon us.
  45. zig build -Dhealed