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. if hash fish &>/dev/null; then
  25. echo "Tools are already installed"
  26. else
  27. trap 'exit' ERR
  28. echo "Installing tools"
  29. apt-get update -qq
  30. apt-get install -qq -o=Dpkg::Use-Pty=0 \
  31. git gcc curl attr libgit2-dev zip \
  32. fish zsh bash bash-completion
  33. fi
  34. EOF
  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. echo "Installing Rust"
  45. curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --profile minimal --component rustc,rust-std,cargo,clippy -y
  46. source $HOME/.cargo/env
  47. cargo install -q cargo-hack
  48. fi
  49. EOF
  50. # Privileged installation and setup scripts.
  51. config.vm.provision :shell, privileged: true, inline: <<-EOF
  52. # Install Just, the command runner.
  53. if hash just &>/dev/null; then
  54. echo "just is already installed"
  55. else
  56. trap 'exit' ERR
  57. echo "Installing just"
  58. wget -q "https://github.com/casey/just/releases/download/v0.8.0/just-v0.8.0-x86_64-unknown-linux-musl.tar.gz"
  59. tar -xf "just-v0.8.0-x86_64-unknown-linux-musl.tar.gz"
  60. cp just /usr/local/bin
  61. fi
  62. # Guarantee that the timezone is UTC — some of the tests
  63. # depend on this (for now).
  64. timedatectl set-timezone UTC
  65. # Use a different ‘target’ directory on the VM than on the host.
  66. # By default it just uses the one in /vagrant/target, which can
  67. # cause problems if it has different permissions than the other
  68. # directories, or contains object files compiled for the host.
  69. echo 'PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/#{developer}/.cargo/bin"' > /etc/environment
  70. echo 'CARGO_TARGET_DIR="/home/#{developer}/target"' >> /etc/environment
  71. # Create a variety of misc scripts.
  72. ln -sf /vagrant/devtools/dev-run-debug.sh /usr/bin/exa
  73. ln -sf /vagrant/devtools/dev-run-release.sh /usr/bin/rexa
  74. echo -e "#!/bin/sh\ncargo build --manifest-path /vagrant/Cargo.toml \\$@" > /usr/bin/build-exa
  75. ln -sf /usr/bin/build-exa /usr/bin/b
  76. echo -e "#!/bin/sh\ncargo test --manifest-path /vagrant/Cargo.toml \\$@ -- --quiet" > /usr/bin/test-exa
  77. ln -sf /usr/bin/test-exa /usr/bin/t
  78. echo -e "#!/bin/sh\n/vagrant/xtests/run.sh" > /usr/bin/run-xtests
  79. ln -sf /usr/bin/run-xtests /usr/bin/x
  80. echo -e "#!/bin/sh\nbuild-exa && test-exa && run-xtests" > /usr/bin/compile-exa
  81. ln -sf /usr/bin/compile-exa /usr/bin/c
  82. echo -e "#!/bin/sh\nbash /vagrant/devtools/dev-package-for-linux.sh \\$@" > /usr/bin/package-exa
  83. echo -e "#!/bin/sh\ncat /etc/motd" > /usr/bin/halp
  84. chmod +x /usr/bin/{exa,rexa,b,t,x,c,build-exa,test-exa,run-xtests,compile-exa,package-exa,halp}
  85. # Configure the welcoming text that gets shown:
  86. # Capture the help text so it gets displayed first
  87. rm -f /etc/update-motd.d/*
  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. # Link the completion files so they’re “installed”:
  96. # bash
  97. test -h /etc/bash_completion.d/exa \
  98. || ln -s /vagrant/contrib/completions.bash /etc/bash_completion.d/exa
  99. # zsh
  100. test -h /usr/share/zsh/vendor-completions/_exa \
  101. || ln -s /vagrant/contrib/completions.zsh /usr/share/zsh/vendor-completions/_exa
  102. # fish
  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