Vagrantfile 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. require 'date'
  2. Vagrant.configure(2) do |config|
  3. # We use Ubuntu instead of Debian because the image comes with two-way
  4. # shared folder support by default.
  5. UBUNTU = 'hashicorp/bionic64'
  6. config.vm.define(:exa) do |config|
  7. config.vm.provider :virtualbox do |v|
  8. v.name = 'exa'
  9. v.memory = 2048
  10. v.cpus = `nproc`.chomp.to_i
  11. end
  12. config.vm.provider :vmware_desktop do |v|
  13. v.vmx['memsize'] = '2048'
  14. v.vmx['numvcpus'] = `nproc`.chomp
  15. end
  16. config.vm.box = UBUNTU
  17. config.vm.hostname = 'exa'
  18. # Make sure we know the VM image’s default user name. The ‘cassowary’ user
  19. # (specified later) is used for most of the test *output*, but we still
  20. # need to know where the ‘target’ and ‘.cargo’ directories go.
  21. developer = 'vagrant'
  22. # Install the dependencies needed for exa to build, as quietly as
  23. # apt can do.
  24. config.vm.provision :shell, privileged: true, inline: <<-EOF
  25. trap 'exit' ERR
  26. apt-get update
  27. apt-get install -qq -o=Dpkg::Use-Pty=0 -y \
  28. git cmake curl attr libgit2-dev zip \
  29. fish zsh bash bash-completion
  30. EOF
  31. # Guarantee that the timezone is UTC -- some of the tests
  32. # depend on this (for now).
  33. config.vm.provision :shell, privileged: true, inline:
  34. %[timedatectl set-timezone UTC]
  35. # Install Rust.
  36. # This is done as vagrant, not root, because it’s vagrant
  37. # who actually uses it. Sent to /dev/null because the progress
  38. # bar produces a ton of output.
  39. config.vm.provision :shell, privileged: false, inline: <<-EOF
  40. if hash rustc &>/dev/null; then
  41. echo "Rust is already installed"
  42. else
  43. trap 'exit' ERR
  44. curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
  45. source $HOME/.cargo/env
  46. cargo install cargo-hack
  47. fi
  48. EOF
  49. # Install Just, the command runner.
  50. config.vm.provision :shell, privileged: true, inline: <<-EOF
  51. if hash just &>/dev/null; then
  52. echo "just is already installed"
  53. else
  54. wget "https://github.com/casey/just/releases/download/v0.8.0/just-v0.8.0-x86_64-unknown-linux-musl.tar.gz"
  55. tar -xf "just-v0.8.0-x86_64-unknown-linux-musl.tar.gz"
  56. cp just /usr/local/bin
  57. fi
  58. EOF
  59. # Use a different ‘target’ directory on the VM than on the host.
  60. # By default it just uses the one in /vagrant/target, which can
  61. # cause problems if it has different permissions than the other
  62. # directories, or contains object files compiled for the host.
  63. config.vm.provision :shell, privileged: true, inline: <<-EOF
  64. echo 'PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/#{developer}/.cargo/bin"' > /etc/environment
  65. echo 'CARGO_TARGET_DIR="/home/#{developer}/target"' >> /etc/environment
  66. EOF
  67. # Create a variety of misc scripts.
  68. config.vm.provision :shell, privileged: true, inline: <<-EOF
  69. trap 'exit' ERR
  70. ln -sf /vagrant/devtools/dev-run-debug.sh /usr/bin/exa
  71. ln -sf /vagrant/devtools/dev-run-release.sh /usr/bin/rexa
  72. echo -e "#!/bin/sh\ncargo build --manifest-path /vagrant/Cargo.toml \\$@" > /usr/bin/build-exa
  73. ln -sf /usr/bin/build-exa /usr/bin/b
  74. echo -e "#!/bin/sh\ncargo test --manifest-path /vagrant/Cargo.toml \\$@ -- --quiet" > /usr/bin/test-exa
  75. ln -sf /usr/bin/test-exa /usr/bin/t
  76. echo -e "#!/bin/sh\n/vagrant/xtests/run.sh" > /usr/bin/run-xtests
  77. ln -sf /usr/bin/run-xtests /usr/bin/x
  78. echo -e "#!/bin/sh\nbuild-exa && test-exa && run-xtests" > /usr/bin/compile-exa
  79. ln -sf /usr/bin/compile-exa /usr/bin/c
  80. echo -e "#!/bin/sh\nbash /vagrant/devtools/dev-package-for-linux.sh \\$@" > /usr/bin/package-exa
  81. echo -e "#!/bin/sh\ncat /etc/motd" > /usr/bin/halp
  82. chmod +x /usr/bin/{exa,rexa,b,t,x,c,build-exa,test-exa,run-xtests,compile-exa,package-exa,halp}
  83. EOF
  84. # Configure the welcoming text that gets shown.
  85. config.vm.provision :shell, privileged: true, inline: <<-EOF
  86. trap 'exit' ERR
  87. rm -f /etc/update-motd.d/*
  88. # Capture the help text so it gets displayed first
  89. bash /vagrant/devtools/dev-help.sh > /etc/motd
  90. # Tell bash to execute a bunch of stuff when a session starts
  91. echo "source /vagrant/devtools/dev-bash.sh" > /home/#{developer}/.bash_profile
  92. chown #{developer} /home/#{developer}/.bash_profile
  93. # Disable last login date in sshd
  94. sed -i '/PrintLastLog yes/c\PrintLastLog no' /etc/ssh/sshd_config
  95. systemctl restart sshd
  96. EOF
  97. # Link the completion files so they’re “installed”.
  98. config.vm.provision :shell, privileged: true, inline: <<-EOF
  99. trap 'exit' ERR
  100. test -h /etc/bash_completion.d/exa \
  101. || ln -s /vagrant/contrib/completions.bash /etc/bash_completion.d/exa
  102. test -h /usr/share/zsh/vendor-completions/_exa \
  103. || ln -s /vagrant/contrib/completions.zsh /usr/share/zsh/vendor-completions/_exa
  104. test -h /usr/share/fish/completions/exa.fish \
  105. || ln -s /vagrant/contrib/completions.fish /usr/share/fish/completions/exa.fish
  106. EOF
  107. # Install kcov for test coverage
  108. # This doesn’t run coverage over the xtests so it’s less useful for now
  109. if ENV.key?('INSTALL_KCOV')
  110. config.vm.provision :shell, privileged: false, inline: <<-EOF
  111. trap 'exit' ERR
  112. test -e ~/.cargo/bin/cargo-kcov \
  113. || cargo install cargo-kcov
  114. sudo apt-get install -qq -o=Dpkg::Use-Pty=0 -y \
  115. cmake g++ pkg-config \
  116. libcurl4-openssl-dev libdw-dev binutils-dev libiberty-dev
  117. cargo kcov --print-install-kcov-sh | sudo sh
  118. EOF
  119. end
  120. config.vm.provision :shell, privileged: true, path: 'devtools/dev-set-up-environment.sh'
  121. config.vm.provision :shell, privileged: false, path: 'devtools/dev-create-test-filesystem.sh'
  122. end
  123. end