1
0

Vagrantfile 5.9 KB

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