Vagrantfile 5.8 KB

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