Vagrantfile 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. Vagrant.configure(2) do |config|
  2. # NOTE: XTESTS ARE DEPRECATED DO NOT USE THEM
  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. if hash fish &>/dev/null; then
  26. echo "Tools are already installed"
  27. else
  28. trap 'exit' ERR
  29. echo "Installing tools"
  30. apt-get update -qq
  31. apt-get install -qq -o=Dpkg::Use-Pty=0 \
  32. git gcc curl attr libgit2-dev zip \
  33. fish zsh bash bash-completion
  34. fi
  35. EOF
  36. # Install Rust.
  37. # This is done as vagrant, not root, because it’s vagrant
  38. # who actually uses it. Sent to /dev/null because the progress
  39. # bar produces a ton of output.
  40. config.vm.provision :shell, privileged: false, inline: <<-EOF
  41. if hash rustc &>/dev/null; then
  42. echo "Rust is already installed"
  43. else
  44. trap 'exit' ERR
  45. echo "Installing Rust"
  46. curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --profile minimal --component rustc,rust-std,cargo,clippy -y > /dev/null
  47. source $HOME/.cargo/env
  48. echo "Installing cargo-hack"
  49. cargo install -q cargo-hack
  50. echo "Installing specsheet"
  51. cargo install -q --git https://github.com/ogham/specsheet
  52. fi
  53. EOF
  54. # Privileged installation and setup scripts.
  55. config.vm.provision :shell, privileged: true, inline: <<-EOF
  56. # Install Just, the command runner.
  57. if hash just &>/dev/null; then
  58. echo "just is already installed"
  59. else
  60. trap 'exit' ERR
  61. echo "Installing just"
  62. wget -q "https://github.com/casey/just/releases/download/v0.8.3/just-v0.8.3-x86_64-unknown-linux-musl.tar.gz"
  63. tar -xf "just-v0.8.3-x86_64-unknown-linux-musl.tar.gz"
  64. cp just /usr/local/bin
  65. fi
  66. # Guarantee that the timezone is UTC — some of the tests
  67. # depend on this (for now).
  68. timedatectl set-timezone UTC
  69. # Use a different ‘target’ directory on the VM than on the host.
  70. # By default it just uses the one in /vagrant/target, which can
  71. # cause problems if it has different permissions than the other
  72. # directories, or contains object files compiled for the host.
  73. echo 'PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/#{developer}/.cargo/bin"' > /etc/environment
  74. echo 'CARGO_TARGET_DIR="/home/#{developer}/target"' >> /etc/environment
  75. # Create a variety of misc scripts.
  76. ln -sf /vagrant/devtools/dev-run-debug.sh /usr/bin/exa
  77. ln -sf /vagrant/devtools/dev-run-release.sh /usr/bin/rexa
  78. echo -e "#!/bin/sh\ncargo build --manifest-path /vagrant/Cargo.toml \\$@" > /usr/bin/build-exa
  79. ln -sf /usr/bin/build-exa /usr/bin/b
  80. echo -e "#!/bin/sh\ncargo test --manifest-path /vagrant/Cargo.toml \\$@ -- --quiet" > /usr/bin/test-exa
  81. ln -sf /usr/bin/test-exa /usr/bin/t
  82. echo -e "#!/bin/sh\n/vagrant/xtests/run.sh" > /usr/bin/run-xtests
  83. ln -sf /usr/bin/run-xtests /usr/bin/x
  84. echo -e "#!/bin/sh\nbuild-exa && test-exa && run-xtests" > /usr/bin/compile-exa
  85. ln -sf /usr/bin/compile-exa /usr/bin/c
  86. echo -e "#!/bin/sh\nbash /vagrant/devtools/dev-package-for-linux.sh \\$@" > /usr/bin/package-exa
  87. echo -e "#!/bin/sh\ncat /etc/motd" > /usr/bin/halp
  88. chmod +x /usr/bin/{exa,rexa,b,t,x,c,build-exa,test-exa,run-xtests,compile-exa,package-exa,halp}
  89. # Configure the welcoming text that gets shown:
  90. # Capture the help text so it gets displayed first
  91. rm -f /etc/update-motd.d/*
  92. bash /vagrant/devtools/dev-help.sh > /etc/motd
  93. # Tell bash to execute a bunch of stuff when a session starts
  94. echo "source /vagrant/devtools/dev-bash.sh" > /home/#{developer}/.bash_profile
  95. chown #{developer} /home/#{developer}/.bash_profile
  96. # Disable last login date in sshd
  97. sed -i '/PrintLastLog yes/c\PrintLastLog no' /etc/ssh/sshd_config
  98. systemctl restart sshd
  99. # Link the completion files so they’re “installed”:
  100. # bash
  101. test -h /etc/bash_completion.d/exa \
  102. || ln -s /vagrant/contrib/completions.bash /etc/bash_completion.d/exa
  103. # zsh
  104. test -h /usr/share/zsh/vendor-completions/_exa \
  105. || ln -s /vagrant/contrib/completions.zsh /usr/share/zsh/vendor-completions/_exa
  106. # fish
  107. test -h /usr/share/fish/completions/exa.fish \
  108. || ln -s /vagrant/contrib/completions.fish /usr/share/fish/completions/exa.fish
  109. EOF
  110. # Install kcov for test coverage
  111. # This doesn’t run coverage over the xtests so it’s less useful for now
  112. if ENV.key?('INSTALL_KCOV')
  113. config.vm.provision :shell, privileged: false, inline: <<-EOF
  114. trap 'exit' ERR
  115. test -e ~/.cargo/bin/cargo-kcov \
  116. || cargo install cargo-kcov
  117. sudo apt-get install -qq -o=Dpkg::Use-Pty=0 -y \
  118. cmake g++ pkg-config \
  119. libcurl4-openssl-dev libdw-dev binutils-dev libiberty-dev
  120. cargo kcov --print-install-kcov-sh | sudo sh
  121. EOF
  122. end
  123. config.vm.provision :shell, privileged: true, path: 'devtools/dev-set-up-environment.sh'
  124. config.vm.provision :shell, privileged: false, path: 'devtools/dev-create-test-filesystem.sh'
  125. end
  126. end