exa/Vagrantfile

167 lines
5.9 KiB
Ruby
Raw Normal View History

Vagrant.configure(2) do |config|
# We use Ubuntu instead of Debian because the image comes with two-way
# shared folder support by default.
UBUNTU = 'hashicorp/bionic64'
config.vm.define(:exa) do |config|
config.vm.provider :virtualbox do |v|
v.name = 'exa'
v.memory = 2048
v.cpus = `nproc`.chomp.to_i
end
config.vm.provider :vmware_desktop do |v|
v.vmx['memsize'] = '2048'
v.vmx['numvcpus'] = `nproc`.chomp
end
config.vm.box = UBUNTU
config.vm.hostname = 'exa'
2017-05-06 18:38:34 +00:00
# Make sure we know the VM images default user name. The cassowary user
# (specified later) is used for most of the test *output*, but we still
# need to know where the target and .cargo directories go.
developer = 'vagrant'
# Install the dependencies needed for exa to build, as quietly as
# apt can do.
2017-05-06 19:34:59 +00:00
config.vm.provision :shell, privileged: true, inline: <<-EOF
if hash fish &>/dev/null; then
echo "Tools are already installed"
else
trap 'exit' ERR
echo "Installing tools"
apt-get update -qq
apt-get install -qq -o=Dpkg::Use-Pty=0 \
git gcc curl attr libgit2-dev zip \
fish zsh bash bash-completion
fi
2017-05-06 19:34:59 +00:00
EOF
# Install Rust.
# This is done as vagrant, not root, because its vagrant
# who actually uses it. Sent to /dev/null because the progress
# bar produces a ton of output.
config.vm.provision :shell, privileged: false, inline: <<-EOF
if hash rustc &>/dev/null; then
echo "Rust is already installed"
else
trap 'exit' ERR
echo "Installing Rust"
2021-01-08 16:45:59 +00:00
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --profile minimal --component rustc,rust-std,cargo,clippy -y > /dev/null
source $HOME/.cargo/env
2021-01-08 16:45:59 +00:00
echo "Installing cargo-hack"
cargo install -q cargo-hack
2021-01-08 16:45:59 +00:00
echo "Installing specsheet"
cargo install -q --git https://github.com/ogham/specsheet
fi
EOF
# Privileged installation and setup scripts.
config.vm.provision :shell, privileged: true, inline: <<-EOF
# Install Just, the command runner.
if hash just &>/dev/null; then
echo "just is already installed"
else
trap 'exit' ERR
echo "Installing just"
2021-01-08 16:45:59 +00:00
wget -q "https://github.com/casey/just/releases/download/v0.8.3/just-v0.8.3-x86_64-unknown-linux-musl.tar.gz"
tar -xf "just-v0.8.3-x86_64-unknown-linux-musl.tar.gz"
cp just /usr/local/bin
fi
# Guarantee that the timezone is UTC — some of the tests
# depend on this (for now).
timedatectl set-timezone UTC
# Use a different target directory on the VM than on the host.
# By default it just uses the one in /vagrant/target, which can
# cause problems if it has different permissions than the other
# directories, or contains object files compiled for the host.
echo 'PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/#{developer}/.cargo/bin"' > /etc/environment
echo 'CARGO_TARGET_DIR="/home/#{developer}/target"' >> /etc/environment
2017-05-06 19:34:59 +00:00
# Create a variety of misc scripts.
2017-05-07 19:25:53 +00:00
ln -sf /vagrant/devtools/dev-run-debug.sh /usr/bin/exa
ln -sf /vagrant/devtools/dev-run-release.sh /usr/bin/rexa
echo -e "#!/bin/sh\ncargo build --manifest-path /vagrant/Cargo.toml \\$@" > /usr/bin/build-exa
ln -sf /usr/bin/build-exa /usr/bin/b
echo -e "#!/bin/sh\ncargo test --manifest-path /vagrant/Cargo.toml \\$@ -- --quiet" > /usr/bin/test-exa
ln -sf /usr/bin/test-exa /usr/bin/t
echo -e "#!/bin/sh\n/vagrant/xtests/run.sh" > /usr/bin/run-xtests
ln -sf /usr/bin/run-xtests /usr/bin/x
echo -e "#!/bin/sh\nbuild-exa && test-exa && run-xtests" > /usr/bin/compile-exa
ln -sf /usr/bin/compile-exa /usr/bin/c
2017-10-08 19:44:34 +00:00
echo -e "#!/bin/sh\nbash /vagrant/devtools/dev-package-for-linux.sh \\$@" > /usr/bin/package-exa
echo -e "#!/bin/sh\ncat /etc/motd" > /usr/bin/halp
2017-10-02 08:26:39 +00:00
chmod +x /usr/bin/{exa,rexa,b,t,x,c,build-exa,test-exa,run-xtests,compile-exa,package-exa,halp}
# Configure the welcoming text that gets shown:
# Capture the help text so it gets displayed first
rm -f /etc/update-motd.d/*
bash /vagrant/devtools/dev-help.sh > /etc/motd
# Tell bash to execute a bunch of stuff when a session starts
echo "source /vagrant/devtools/dev-bash.sh" > /home/#{developer}/.bash_profile
chown #{developer} /home/#{developer}/.bash_profile
# Disable last login date in sshd
sed -i '/PrintLastLog yes/c\PrintLastLog no' /etc/ssh/sshd_config
systemctl restart sshd
# Link the completion files so theyre “installed”:
2017-05-07 19:25:53 +00:00
# bash
test -h /etc/bash_completion.d/exa \
|| ln -s /vagrant/contrib/completions.bash /etc/bash_completion.d/exa
2017-05-06 20:56:40 +00:00
# zsh
test -h /usr/share/zsh/vendor-completions/_exa \
|| ln -s /vagrant/contrib/completions.zsh /usr/share/zsh/vendor-completions/_exa
2017-05-06 19:50:24 +00:00
# fish
test -h /usr/share/fish/completions/exa.fish \
|| ln -s /vagrant/contrib/completions.fish /usr/share/fish/completions/exa.fish
2017-05-06 19:34:59 +00:00
EOF
2017-05-07 19:25:53 +00:00
# Install kcov for test coverage
# This doesnt run coverage over the xtests so its less useful for now
if ENV.key?('INSTALL_KCOV')
config.vm.provision :shell, privileged: false, inline: <<-EOF
trap 'exit' ERR
test -e ~/.cargo/bin/cargo-kcov \
|| cargo install cargo-kcov
sudo apt-get install -qq -o=Dpkg::Use-Pty=0 -y \
cmake g++ pkg-config \
libcurl4-openssl-dev libdw-dev binutils-dev libiberty-dev
cargo kcov --print-install-kcov-sh | sudo sh
EOF
end
config.vm.provision :shell, privileged: true, path: 'devtools/dev-set-up-environment.sh'
config.vm.provision :shell, privileged: false, path: 'devtools/dev-create-test-filesystem.sh'
end
end