export-argsparser-manpages.sh 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/bin/sh
  2. set -e
  3. script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
  4. cd "${script_path}/.."
  5. if ! command -v tar >/dev/null 2>&1 ; then
  6. echo "Please install tar!"
  7. exit 1
  8. fi
  9. if [ "$#" = "0" ]; then
  10. VERIFY_GIT_STATE=n
  11. elif [ "$#" = "1" ] && [ "$1" = "--verify-git-state" ]; then
  12. VERIFY_GIT_STATE=y
  13. else
  14. echo "USAGE: $0 [--verify-git-state]"
  15. echo "This script runs Serenity and exports a set of manpages through ArgsParser,"
  16. echo "and places them in Base/usr/share/man/."
  17. echo "If --verify-git-state is given, this script verifies that this does not modify"
  18. echo "the git state, i.e. that all exported manpages already were in the repository"
  19. echo "with the exact same content."
  20. exit 1
  21. fi
  22. echo "This script assumes passwordless sudo."
  23. sudo true
  24. if [ -z "$BUILD_DIR" ]; then
  25. if [ -z "$SERENITY_ARCH" ]; then
  26. export SERENITY_ARCH="i686"
  27. echo "SERENITY_ARCH not given. Assuming ${SERENITY_ARCH}."
  28. fi
  29. BUILD_DIR=Build/"$SERENITY_ARCH"
  30. echo "BUILD_DIR not given. Assuming ${BUILD_DIR}."
  31. fi
  32. if [ -e fsmount ]; then
  33. echo "Directory 'fsmount' already exists."
  34. echo "Manual cleanup needed. You might also need to unmount first."
  35. exit 1
  36. fi
  37. if ! [ -d Base/usr/share/man/ ]; then
  38. echo "Base/usr/share/man/ does not exist. How did that happen?! o.O"
  39. exit 1
  40. fi
  41. echo "Using 'ninja run' to generate manpages ..."
  42. export SERENITY_RUN="ci"
  43. export SERENITY_KERNEL_CMDLINE="fbdev=off panic=shutdown system_mode=generate-manpages"
  44. # The 'sed' gets rid of the clear-screen escape sequence.
  45. ninja -C "$BUILD_DIR" -- run | sed -re 's,''c,,'
  46. echo
  47. echo "Extracting generated manpages ..."
  48. mkdir fsmount
  49. sudo mount -t ext2 -o loop,rw "$BUILD_DIR"/_disk_image fsmount
  50. # 'cp' would create the new files as root, but we don't want that.
  51. sudo tar -C fsmount/root/generated_manpages --create . | tar -C Base/usr/share/man/ --extract
  52. sudo umount fsmount
  53. rmdir fsmount
  54. echo "Successfully (re-)generated manpages in Base/usr/share/man/"
  55. if [ "$VERIFY_GIT_STATE" = "y" ]; then
  56. echo "Verifying git state ..."
  57. if [ "" != "$(git clean -n Base/usr/share/man)" ] || ! git diff --quiet Base/usr/share/man; then
  58. echo "Failed: There are missing and/or outdated manpages."
  59. echo "$ git status Base/usr/share/man"
  60. git status Base/usr/share/man
  61. echo "$ git diff Base/usr/share/man"
  62. git diff Base/usr/share/man
  63. echo "You may need to run ./Meta/export-argsparser-manpages.sh on your system and commit/squash the resulting changes."
  64. exit 1
  65. else
  66. echo "Verified: No missing or outdated manpages. Great!"
  67. fi
  68. fi