eowyn.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. delete_progress() {
  16. progress_file=".progress.txt"
  17. if [ -f $progress_file ]; then
  18. rm $progress_file
  19. fi
  20. }
  21. set -e
  22. # We check ourselves before we wreck ourselves.
  23. if [ ! -f patches/eowyn.sh ]
  24. then
  25. echo "But I must be run from the project root directory."
  26. exit 1
  27. fi
  28. # Which version we have?
  29. echo "Zig version" $(zig version)
  30. echo "Eowyn version 25.1.9, let's try our magic power."
  31. echo ""
  32. # Remove progress file
  33. delete_progress
  34. # Create directory of healing if it doesn't already exist.
  35. mkdir -p patches/healed
  36. # Cycle through all the little broken Zig applications.
  37. for broken in exercises/*.zig
  38. do
  39. # Remove the dir and extension, rendering the True Name.
  40. true_name=$(basename "$broken" .zig)
  41. patch_name="patches/patches/$true_name.patch"
  42. if [ -f "$patch_name" ]
  43. then
  44. # Apply the bandages to the wounds, grow new limbs, let
  45. # new life spring into the broken bodies of the fallen.
  46. echo Healing "$true_name"...
  47. cp "$broken" "patches/healed/$true_name.zig"
  48. patch -i "$patch_name" "patches/healed/$true_name.zig"
  49. else
  50. echo Cannot heal "$true_name". No patch found.
  51. fi
  52. done
  53. echo "Looking for non-conforming code formatting..."
  54. zig fmt --check patches/healed
  55. # Test the healed exercises. May the compiler have mercy upon us.
  56. zig build -Dhealed
  57. # Remove progress file again
  58. delete_progress