eowyn.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. # Create directory of healing if it doesn't already exist.
  23. mkdir -p patches/healed
  24. # Cycle through all the little broken Zig applications.
  25. for broken in exercises/*.zig
  26. do
  27. # Remove the dir and extension, rendering the True Name.
  28. true_name=$(basename "$broken" .zig)
  29. patch_name="patches/patches/$true_name.patch"
  30. if [ -f "$patch_name" ]
  31. then
  32. # Apply the bandages to the wounds, grow new limbs, let
  33. # new life spring into the broken bodies of the fallen.
  34. echo Healing "$true_name"...
  35. patch --output="patches/healed/$true_name.zig" "$broken" "$patch_name"
  36. else
  37. echo Cannot heal "$true_name". No patch found.
  38. fi
  39. done
  40. # Test the correct formatting of the healed exercises.
  41. echo "Looking for non-conforming code formatting..."
  42. for healed in patches/healed/*.zig
  43. do
  44. echo Check $(basename "$healed")
  45. zig fmt --check "$healed"
  46. done
  47. # Test the healed exercises. May the compiler have mercy upon us.
  48. zig build -Dhealed