dev-package-for-linux.sh 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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, compresses it into a zip, then puts it in /vagrant so it’s
  5. # accessible from the host machine.
  6. #
  7. # If you’re in the VM, you can run it using the ‘package-exa’ command.
  8. # Linux check!
  9. uname=$(uname -s)
  10. if [[ "$uname" != "Linux" ]]; then
  11. echo "Gotta be on Linux to run this (detected '$uname')!"
  12. exit 1
  13. fi
  14. # First, we need to get the version number to figure out what to call the zip.
  15. # We do this by getting the first line from the Cargo.toml that matches
  16. # /version/, removing its whitespace, and building a command out of it, so the
  17. # shell executes something like `exa_version="0.8.0"`, which it understands as
  18. # a variable definition. Hey, it’s not a hack if it works.
  19. toml_file="/vagrant/Cargo.toml"
  20. eval exa_$(grep version $toml_file | head -n 1 | sed "s/ //g")
  21. if [ -z "$exa_version" ]; then
  22. echo "Failed to parse version number! Can't build exa!"
  23. exit 1
  24. fi
  25. # Weekly builds have a bit more information in their version number (see build.rs).
  26. if [[ "$1" == "--weekly" ]]; then
  27. git_hash=$(GIT_DIR=/vagrant/.git git rev-parse --short --verify HEAD)
  28. date=$(date +"%Y-%m-%d")
  29. echo "Building exa weekly v$exa_version, date $date, Git hash $git_hash"
  30. else
  31. echo "Building exa v$exa_version"
  32. fi
  33. # Compilation is done in --release mode, which takes longer but produces a
  34. # faster binary. This binary gets built to a different place, so the extended
  35. # tests script needs to be told which one to use.
  36. echo -e "\n\033[4mCompiling release version of exa...\033[0m"
  37. exa_linux_binary="/vagrant/exa-linux-x86_64"
  38. rm -vf "$exa_linux_binary"
  39. cargo build --release --manifest-path "$toml_file"
  40. cargo test --release --manifest-path "$toml_file" --lib -- --quiet
  41. /vagrant/xtests/run.sh --release
  42. cp /home/vagrant/target/release/exa "$exa_linux_binary"
  43. # Stripping the binary before distributing it removes a bunch of debugging
  44. # symbols, saving some space.
  45. echo -e "\n\033[4mStripping binary...\033[0m"
  46. strip -v "$exa_linux_binary"
  47. # Compress the binary for upload. The ‘-j’ flag is necessary to avoid the
  48. # /vagrant path being in the zip too. Only the zip gets the version number, so
  49. # the binaries can have consistent names, and it’s still possible to tell
  50. # different *downloads* apart.
  51. echo -e "\n\033[4mZipping binary...\033[0m"
  52. if [[ "$1" == "--weekly" ]]; then
  53. exa_linux_zip="/vagrant/exa-linux-x86_64-${exa_version}-${date}-${git_hash}.zip"
  54. else
  55. exa_linux_zip="/vagrant/exa-linux-x86_64.zip"
  56. fi
  57. rm -vf "$exa_linux_zip"
  58. zip -j "$exa_linux_zip" "$exa_linux_binary"
  59. # There was a problem a while back where a library was getting unknowingly
  60. # *dynamically* linked, which broke the whole ‘self-contained binary’ concept.
  61. # So dump the linker table, in case anything unscrupulous shows up.
  62. echo -e "\n\033[4mLibraries linked:\033[0m"
  63. ldd "$exa_linux_binary" | sed "s/\t//"
  64. # Might as well use it to test itself, right?
  65. echo -e "\n\033[4mAll done! Files produced:\033[0m"
  66. "$exa_linux_binary" "$exa_linux_binary" "$exa_linux_zip" -lB