local-package-for-macos.sh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. set -e
  2. # This script builds a publishable release-worthy version of exa.
  3. # It gets the version number, builds exa using cargo, tests it, strips the
  4. # binary, and compresses it into a zip.
  5. #
  6. # It’s *mostly* the same as dev-package-for-linux.sh, except with some
  7. # Mach-specific things (otool instead of ldd), BSD-coreutils-specific things,
  8. # and it doesn’t run the xtests.
  9. # Virtualising macOS is a legal minefield, so this script is ‘local’ instead
  10. # of ‘dev’: I run it from my actual machine, rather than from a VM.
  11. uname=$(uname -s)
  12. if [[ "$uname" != "Darwin" ]]; then
  13. echo "Gotta be on Darwin to run this (detected '$uname')!"
  14. exit 1
  15. fi
  16. # First, we need to get the version number to figure out what to call the zip.
  17. # We do this by getting the first line from the Cargo.toml that matches
  18. # /version/, removing its whitespace, and building a command out of it, so the
  19. # shell executes something like `exa_version="0.8.0"`, which it understands as
  20. # a variable definition. Hey, it’s not a hack if it works.
  21. #
  22. # Because this can’t use the absolute /vagrant path, this has to use what this
  23. # SO answer calls a “quoting disaster”: https://stackoverflow.com/a/20196098/3484614
  24. # You will also need GNU coreutils: https://stackoverflow.com/a/4031502/3484614
  25. exa_root="$(dirname "$(dirname "$(greadlink -fm "$0")")")"
  26. toml_file="$exa_root"/Cargo.toml
  27. eval exa_$(grep version $toml_file | head -n 1 | sed "s/ //g")
  28. if [ -z "$exa_version" ]; then
  29. echo "Failed to parse version number! Can't build exa!"
  30. exit 1
  31. fi
  32. # Weekly builds have a bit more information in their version number (see build.rs).
  33. if [[ "$1" == "--weekly" ]]; then
  34. git_hash=$(GIT_DIR=$exa_root/.git git rev-parse --short --verify HEAD)
  35. date=$(date +"%Y-%m-%d")
  36. echo "Building exa weekly v$exa_version, date $date, Git hash $git_hash"
  37. else
  38. echo "Building exa v$exa_version"
  39. fi
  40. # Compilation is done in --release mode, which takes longer but produces a
  41. # faster binary.
  42. echo -e "\n\033[4mCompiling release version of exa...\033[0m"
  43. exa_macos_binary="$exa_root/exa-macos-x86_64"
  44. rm -vf "$exa_macos_binary" | sed 's/^/removing /'
  45. cargo build --release --manifest-path "$toml_file"
  46. cargo test --release --manifest-path "$toml_file" --lib -- --quiet
  47. # we can’t run the xtests outside the VM!
  48. #/vagrant/xtests/run.sh --release
  49. cp "$exa_root"/target/release/exa "$exa_macos_binary"
  50. # Stripping the binary before distributing it removes a bunch of debugging
  51. # symbols, saving some space.
  52. echo -e "\n\033[4mStripping binary...\033[0m"
  53. strip "$exa_macos_binary"
  54. echo "strip $exa_macos_binary"
  55. # Compress the binary for upload. The ‘-j’ flag is necessary to avoid the
  56. # current path being in the zip too. Only the zip gets the version number, so
  57. # the binaries can have consistent names, and it’s still possible to tell
  58. # different *downloads* apart.
  59. echo -e "\n\033[4mZipping binary...\033[0m"
  60. if [[ "$1" == "--weekly" ]]; then
  61. exa_macos_zip="$exa_root/exa-macos-x86_64-${exa_version}-${date}-${git_hash}.zip"
  62. else
  63. exa_macos_zip="$exa_root/exa-macos-x86_64-${exa_version}.zip"
  64. fi
  65. rm -vf "$exa_macos_zip" | sed 's/^/removing /'
  66. zip -j "$exa_macos_zip" "$exa_macos_binary"
  67. # There was a problem a while back where a library was getting unknowingly
  68. # *dynamically* linked, which broke the whole ‘self-contained binary’ concept.
  69. # So dump the linker table, in case anything unscrupulous shows up.
  70. echo -e "\n\033[4mLibraries linked:\033[0m"
  71. otool -L "$exa_macos_binary" | sed 's/^[[:space:]]*//'
  72. # Might as well use it to test itself, right?
  73. echo -e "\n\033[4mAll done! Files produced:\033[0m"
  74. "$exa_macos_binary" "$exa_macos_binary" "$exa_macos_zip" -lB