Merge branch 'devtools'

This commit is contained in:
Benjamin Sago 2017-10-01 12:38:25 +02:00
commit d5f990e2ac
10 changed files with 325 additions and 80 deletions

11
.gitignore vendored
View File

@ -1,6 +1,13 @@
# Rust stuff
target
/exa-linux-x86_64
/exa-linux-x86_64.zip
# Vagrant stuff
.vagrant
ubuntu-xenial-16.04-cloudimg-console.log
# Compiled artifacts
# (see devtools/*-package-for-*.sh)
/exa-linux-x86_64
/exa-linux-x86_64-*.zip
/exa-macos-x86_64
/exa-macos-x86_64-*.zip

108
Vagrantfile vendored
View File

@ -78,27 +78,7 @@ Vagrant.configure(2) do |config|
echo -e "#!/bin/sh\nbuild-exa && test-exa && run-xtests" > /usr/bin/compile-exa
ln -sf /usr/bin/compile-exa /usr/bin/c
echo "#!/bin/bash" > /usr/bin/package-exa
echo "set -e" >> /usr/bin/package-exa
echo 'echo -e "\nCompiling release version of exa..."' >> /usr/bin/package-exa
echo "cargo build --release --manifest-path /vagrant/Cargo.toml" >> /usr/bin/package-exa
echo "cargo test --release --manifest-path /vagrant/Cargo.toml --lib" >> /usr/bin/package-exa
echo "/vagrant/xtests/run.sh --release" >> /usr/bin/package-exa
echo "cp /home/ubuntu/target/release/exa /vagrant/exa-linux-x86_64" >> /usr/bin/package-exa
echo 'echo -e "\nStripping binary..."' >> /usr/bin/package-exa
echo "strip /vagrant/exa-linux-x86_64" >> /usr/bin/package-exa
echo 'echo -e "\nZipping binary..."' >> /usr/bin/package-exa
echo "rm -f /vagrant/exa-linux-x86_64.zip" >> /usr/bin/package-exa
echo "zip -j /vagrant/exa-linux-x86_64.zip /vagrant/exa-linux-x86_64" >> /usr/bin/package-exa
echo 'echo -e "\nLibraries linked:"' >> /usr/bin/package-exa
echo "ldd /vagrant/exa-linux-x86_64" >> /usr/bin/package-exa
echo 'echo -e "\nAll done!"' >> /usr/bin/package-exa
echo '/vagrant/exa-linux-x86_64 /vagrant/exa-linux-x86_64* -lB' >> /usr/bin/package-exa
echo -e "#!/bin/sh\nbash /vagrant/devtools/dev-package-for-linux.sh" > /usr/bin/package-exa
chmod +x /usr/bin/{exa,rexa,b,t,x,c,build-exa,test-exa,run-xtests,compile-exa,package-exa}
EOF
@ -130,66 +110,15 @@ Vagrant.configure(2) do |config|
# actually works.
# Write some welcoming text.
# Configure the welcoming text that gets shown.
config.vm.provision :shell, privileged: true, inline: <<-EOF
rm -f /etc/update-motd.d/*
echo -e "" > /etc/motd
echo -e "\033[1;33mThe exa development environment!\033[0m" >> /etc/motd
echo -e "exa's source is available at \033[33m/vagrant\033[0m." >> /etc/motd
echo -e "Binaries get built into \033[33m/home/ubuntu/target\033[0m." >> /etc/motd
echo -e "" >> /etc/motd
echo -e "\033[4mCommands\033[0m" >> /etc/motd
echo -e "\033[32;1mb\033[0m or \033[32;1mbuild-exa\033[0m to run \033[1mcargo build\033[0m" >> /etc/motd
echo -e "\033[32;1mt\033[0m or \033[32;1mtest-exa\033[0m to run \033[1mcargo test\033[0m" >> /etc/motd
echo -e "\033[32;1mx\033[0m or \033[32;1mrun-xtests\033[0m to run \033[1m/vagrant/xtests/run.sh\033[0m" >> /etc/motd
echo -e "\033[32;1mc\033[0m or \033[32;1mcompile-exa\033[0m to run all three" >> /etc/motd
echo -e "\033[32;1mdebug\033[0m to toggle printing logs" >> /etc/motd
echo -e "\033[32;1mstrict\033[0m to toggle strict mode" >> /etc/motd
echo -e "\033[32;1mcolors\033[0m to toggle custom colours\n" >> /etc/motd
# Capture the help text so it gets displayed first
bash /vagrant/devtools/dev-help.sh > /etc/motd
# help banner
echo 'echo -e "\\033[4mVersions\\033[0m"' > /home/ubuntu/.bash_profile
echo "rustc --version" >> /home/ubuntu/.bash_profile
echo "cargo --version" >> /home/ubuntu/.bash_profile
echo "echo" >> /home/ubuntu/.bash_profile
# cool prompt
echo 'function nonzero_return() { RETVAL=$?; [ $RETVAL -ne 0 ] && echo "$RETVAL "; }' >> /home/ubuntu/.bash_profile
echo 'function debug_mode() { [ -n "$EXA_DEBUG" ] && echo "debug "; }' >> /home/ubuntu/.bash_profile
echo 'function strict_mode() { [ -n "$EXA_STRICT" ] && echo "strict "; }' >> /home/ubuntu/.bash_profile
echo 'function lsc_mode() { [ -n "$LS_COLORS" ] && echo "lsc "; }' >> /home/ubuntu/.bash_profile
echo 'function exac_mode() { [ -n "$EXA_COLORS" ] && echo "exac "; }' >> /home/ubuntu/.bash_profile
echo 'export PS1="\\[\\e[1;36m\\]\\h \\[\\e[32m\\]\\w \\[\\e[31m\\]\\`nonzero_return\\`\\[\\e[35m\\]\\`debug_mode\\`\\[\\e[32m\\]\\`lsc_mode\\`\\[\\e[1;32m\\]\\`exac_mode\\`\\[\\e[33m\\]\\`strict_mode\\`\\[\\e[36m\\]\\\\$\\[\\e[0m\\] "' >> /home/ubuntu/.bash_profile
# environment setting
echo 'function debug () {' >> /home/ubuntu/.bash_profile
echo ' case "$1" in "on") export EXA_DEBUG=1 ;;' >> /home/ubuntu/.bash_profile
echo ' "off") export EXA_DEBUG= ;;' >> /home/ubuntu/.bash_profile
echo ' "") [ -n "$EXA_DEBUG" ] && echo "debug on" || echo "debug off" ;;' >> /home/ubuntu/.bash_profile
echo ' *) echo "Usage: debug on|off"; return 1 ;; esac; }' >> /home/ubuntu/.bash_profile
echo 'function strict () {' >> /home/ubuntu/.bash_profile
echo ' case "$1" in "on") export EXA_STRICT=1 ;;' >> /home/ubuntu/.bash_profile
echo ' "off") export EXA_STRICT= ;;' >> /home/ubuntu/.bash_profile
echo ' "") [ -n "$EXA_STRICT" ] && echo "strict on" || echo "strict off" ;;' >> /home/ubuntu/.bash_profile
echo ' *) echo "Usage: strict on|off"; return 1 ;; esac; }' >> /home/ubuntu/.bash_profile
echo 'function colors () {' >> /home/ubuntu/.bash_profile
echo ' case "$1" in ' >> /home/ubuntu/.bash_profile
echo ' "ls")' >> /home/ubuntu/.bash_profile
echo ' export LS_COLORS="di=34:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43"' >> /home/ubuntu/.bash_profile
echo ' export EXA_COLORS="" ;;' >> /home/ubuntu/.bash_profile
echo ' "hacker")' >> /home/ubuntu/.bash_profile
echo ' export LS_COLORS="di=32:ex=32:fi=32:pi=32:so=32:bd=32:cd=32:ln=32:or=32:mi=32"' >> /home/ubuntu/.bash_profile
echo ' export EXA_COLORS="ur=32:uw=32:ux=32:ue=32:gr=32:gw=32:gx=32:tr=32:tw=32:tx=32:su=32:sf=32:xa=32:sn=32:sb=32:df=32:ds=32:uu=32:un=32:gu=32:gn=32:lc=32:lm=32:ga=32:gm=32:gd=32:gv=32:gt=32:xx=32:da=32:in=32:bl=32:hd=32:lp=32:cc=32:" ;;' >> /home/ubuntu/.bash_profile
echo ' "off")' >> /home/ubuntu/.bash_profile
echo ' export LS_COLORS=' >> /home/ubuntu/.bash_profile
echo ' export EXA_COLORS= ;;' >> /home/ubuntu/.bash_profile
echo ' "")' >> /home/ubuntu/.bash_profile
echo ' [ -n "$LS_COLORS" ] && echo "LS_COLORS=$LS_COLORS" || echo "ls-colors off"' >> /home/ubuntu/.bash_profile
echo ' [ -n "$EXA_COLORS" ] && echo "EXA_COLORS=$EXA_COLORS" || echo "exa-colors off" ;;' >> /home/ubuntu/.bash_profile
echo ' *) echo "Usage: ls-colors ls|hacker|off"; return 1 ;; esac; }' >> /home/ubuntu/.bash_profile
# Tell bash to execute a bunch of stuff when a session starts
echo "source /vagrant/devtools/dev-bash.sh" > /home/ubuntu/.bash_profile
# Disable last login date in sshd
sed -i '/PrintLastLog yes/c\PrintLastLog no' /etc/ssh/sshd_config
@ -639,5 +568,30 @@ Vagrant.configure(2) do |config|
v.memory = 384
v.cpus = 1
end
# Well, we do need *one* dependency...
config.vm.provision :shell, privileged: true, inline: <<-EOF
set -xe
apt-get install -qq -o=Dpkg::Use-Pty=0 -y unzip
EOF
# This thing also has its own welcoming text.
config.vm.provision :shell, privileged: true, inline: <<-EOF
rm -f /etc/update-motd.d/*
# Capture the help text so it gets displayed first
bash /vagrant/devtools/dev-help-testvm.sh > /etc/motd
# Disable last login date in sshd
sed -i '/PrintLastLog yes/c\PrintLastLog no' /etc/ssh/sshd_config
systemctl restart sshd
EOF
# Make the checker script a command.
config.vm.provision :shell, privileged: true, inline: <<-EOF
set -xe
echo -e "#!/bin/sh\nbash /vagrant/devtools/dev-download-and-check-release.sh \"\\$*\"" > /usr/bin/check-release
chmod +x /usr/bin/check-release
EOF
end
end

56
devtools/dev-bash.sh Normal file
View File

@ -0,0 +1,56 @@
# This file gets executed when a user starts a `bash` shell, usually because
# theyve just started a new Vagrant session with `vagrant ssh`. It configures
# some (but not all) of the commands that you can use.
# Display the installed versions of tools.
# help banner
bash /vagrant/devtools/dev-versions.sh
# Configure the Cool Prompt™ (not actually trademarked).
# The Cool Prompt tells you whether youre in debug or strict mode, whether
# you have colours configured, and whether your last command failed.
function nonzero_return() { RETVAL=$?; [ $RETVAL -ne 0 ] && echo "$RETVAL "; }
function debug_mode() { [ -n "$EXA_DEBUG" ] && echo "debug "; }
function strict_mode() { [ -n "$EXA_STRICT" ] && echo "strict "; }
function lsc_mode() { [ -n "$LS_COLORS" ] && echo "lsc "; }
function exac_mode() { [ -n "$EXA_COLORS" ] && echo "exac "; }
export PS1="\[\e[1;36m\]\h \[\e[32m\]\w \[\e[31m\]\`nonzero_return\`\[\e[35m\]\`debug_mode\`\[\e[32m\]\`lsc_mode\`\[\e[1;32m\]\`exac_mode\`\[\e[33m\]\`strict_mode\`\[\e[36m\]\\$\[\e[0m\] "
# The debug function lets you switch debug mode on and off.
# Turn it on if you need to see exas debugging logs.
function debug () {
case "$1" in "on") export EXA_DEBUG=1 ;;
"off") export EXA_DEBUG= ;;
"") [ -n "$EXA_DEBUG" ] && echo "debug on" || echo "debug off" ;;
*) echo "Usage: debug on|off"; return 1 ;; esac; }
# The strict function lets you switch strict mode on and off.
# Turn it on if youd like exas command-line arguments checked.
function strict () {
case "$1" in "on") export EXA_STRICT=1 ;;
"off") export EXA_STRICT= ;;
"") [ -n "$EXA_STRICT" ] && echo "strict on" || echo "strict off" ;;
*) echo "Usage: strict on|off"; return 1 ;; esac; }
# The colors function sets or unsets the LS_COLORS and EXA_COLORS
# environment variables. Theres also a hacker theme which turns everything
# green, which is usually used for checking that all colour codes work, and
# for looking cool while you phreak some mainframes or whatever.
function colors () {
case "$1" in
"ls")
export LS_COLORS="di=34:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43"
export EXA_COLORS="" ;;
"hacker")
export LS_COLORS="di=32:ex=32:fi=32:pi=32:so=32:bd=32:cd=32:ln=32:or=32:mi=32"
export EXA_COLORS="ur=32:uw=32:ux=32:ue=32:gr=32:gw=32:gx=32:tr=32:tw=32:tx=32:su=32:sf=32:xa=32:sn=32:sb=32:df=32:ds=32:uu=32:un=32:gu=32:gn=32:lc=32:lm=32:ga=32:gm=32:gd=32:gv=32:gt=32:xx=32:da=32:in=32:bl=32:hd=32:lp=32:cc=32:" ;;
"off")
export LS_COLORS=
export EXA_COLORS= ;;
"")
[ -n "$LS_COLORS" ] && echo "LS_COLORS=$LS_COLORS" || echo "ls-colors off"
[ -n "$EXA_COLORS" ] && echo "EXA_COLORS=$EXA_COLORS" || echo "exa-colors off" ;;
*) echo "Usage: ls-colors ls|hacker|off"; return 1 ;; esac; }

View File

@ -0,0 +1,51 @@
# This script downloads the published versions of exa from GitHub and my site,
# checks that the checksums match, and makes sure the files at least unzip and
# execute okay.
#
# The argument should be of the form “0.8.0”, no v. That version was the
# first one to offer checksums, so its the minimum version that can be tested.
set +x
trap 'exit' ERR
exa_version=$1
if [[ -z "$exa_version" ]]; then
echo "Please specify a version, such as '$0 0.8.0'"
exit 1
fi
# Delete anything that already exists
rm -rfv "/tmp/${exa_version}-downloads"
# Create a temporary directory and download exa into it
mkdir "/tmp/${exa_version}-downloads"
cd "/tmp/${exa_version}-downloads"
echo -e "\n\033[4mDownloading stuff...\033[0m"
wget --quiet --show-progress "https://github.com/ogham/exa/releases/download/v${exa_version}/exa-macos-x86_64-${exa_version}.zip"
wget --quiet --show-progress "https://github.com/ogham/exa/releases/download/v${exa_version}/exa-linux-x86_64-${exa_version}.zip"
wget --quiet --show-progress "https://github.com/ogham/exa/releases/download/v${exa_version}/MD5SUMS"
wget --quiet --show-progress "https://github.com/ogham/exa/releases/download/v${exa_version}/SHA1SUMS"
# Unzip the zips and check the sums
echo -e "\n\033[4mExtracting that stuff...\033[0m"
unzip "exa-macos-x86_64-${exa_version}.zip"
unzip "exa-linux-x86_64-${exa_version}.zip"
echo -e "\n\033[4mValidating MD5 checksums...\033[0m"
md5sum -c MD5SUMS
echo -e "\n\033[4mValidating SHA1 checksums...\033[0m"
sha1sum -c SHA1SUMS
# Finally, give the Linux version a go
echo -e "\n\033[4mChecking it actually runs...\033[0m"
./"exa-linux-x86_64" --version
./"exa-linux-x86_64" --long
echo -e "\n\033[1;32mAll's lookin' good!\033[0m"

View File

@ -0,0 +1,12 @@
# This file is like the other one, except for the testing VM.
# It also gets dumped into /etc/motd.
echo -e "
\033[1;33mThe exa testing environment!\033[0m
This machine is dependency-free, and can be used to test that
released versions of exa still work on vanilla Linux installs.
\033[4mCommands\033[0m
\033[32;1mcheck-release\033[0m to download and verify released binaries
"

19
devtools/dev-help.sh Normal file
View File

@ -0,0 +1,19 @@
# This file prints out some help text that says which commands are available
# in the VM. It gets executed during Vagrant provisioning and its output gets
# dumped into /etc/motd, to print it when a user starts a new Vagrant session.
echo -e "
\033[1;33mThe exa development environment!\033[0m
exa's source is available at \033[33m/vagrant\033[0m.
Binaries get built into \033[33m/home/ubuntu/target\033[0m.
\033[4mCommands\033[0m
\033[32;1mb\033[0m or \033[32;1mbuild-exa\033[0m to run \033[1mcargo build\033[0m
\033[32;1mt\033[0m or \033[32;1mtest-exa\033[0m to run \033[1mcargo test\033[0m
\033[32;1mx\033[0m or \033[32;1mrun-xtests\033[0m to run \033[1m/vagrant/xtests/run.sh\033[0m
\033[32;1mc\033[0m or \033[32;1mcompile-exa\033[0m to run all three
\033[32;1mdebug\033[0m to toggle printing logs
\033[32;1mstrict\033[0m to toggle strict mode
\033[32;1mcolors\033[0m to toggle custom colours
"

View File

@ -0,0 +1,65 @@
set -e
# This script builds a publishable release-worthy version of exa.
# It gets the version number, builds exa using cargo, tests it, strips the
# binary, compresses it into a zip, then puts it in /vagrant so its
# accessible from the host machine.
#
# If youre in the VM, you can run it using the package-exa command.
# Linux check!
uname=`uname -s`
if [[ "$uname" != "Linux" ]]; then
echo "Gotta be on Linux to run this (detected '$uname')!"
exit 1
fi
# First, we need to get the version number to figure out what to call the zip.
# We do this by getting the first line from the Cargo.toml that matches
# /version/, removing its whitespace, and building a command out of it, so the
# shell executes something like `exa_version="0.8.0"`, which it understands as
# a variable definition. Hey, its not a hack if it works.
toml_file="/vagrant/Cargo.toml"
eval exa_$(grep version $toml_file | head -n 1 | sed "s/ //g")
if [ -z "$exa_version" ]; then
echo "Failed to parse version number! Can't build exa!"
exit 1
else
echo "Building exa v$exa_version"
fi
# Compilation is done in --release mode, which takes longer but produces a
# faster binary. This binary gets built to a different place, so the extended
# tests script needs to be told which one to use.
echo -e "\n\033[4mCompiling release version of exa...\033[0m"
exa_linux_binary="/vagrant/exa-linux-x86_64"
rm -vf "$exa_linux_binary"
cargo build --release --manifest-path "$toml_file"
cargo test --release --manifest-path "$toml_file" --lib -- --quiet
/vagrant/xtests/run.sh --release
cp /home/ubuntu/target/release/exa "$exa_linux_binary"
# Stripping the binary before distributing it removes a bunch of debugging
# symbols, saving some space.
echo -e "\n\033[4mStripping binary...\033[0m"
strip -v "$exa_linux_binary"
# Compress the binary for upload. The -j flag is necessary to avoid the
# /vagrant path being in the zip too. Only the zip gets the version number, so
# the binaries can have consistent names, and its still possible to tell
# different *downloads* apart.
echo -e "\n\033[4mZipping binary...\033[0m"
exa_linux_zip="/vagrant/exa-linux-x86_64-${exa_version}.zip"
rm -vf "$exa_linux_zip"
zip -j "$exa_linux_zip" "$exa_linux_binary"
# There was a problem a while back where a library was getting unknowingly
# *dynamically* linked, which broke the whole self-contained binary concept.
# So dump the linker table, in case anything unscrupulous shows up.
echo -e "\n\033[4mLibraries linked:\033[0m"
ldd "$exa_linux_binary" | sed "s/\t//"
# Might as well use it to test itself, right?
echo -e "\n\033[4mAll done! Files produced:\033[0m"
"$exa_linux_binary" "$exa_linux_binary" "$exa_linux_zip" -lB

8
devtools/dev-versions.sh Normal file
View File

@ -0,0 +1,8 @@
# Displays the installed versions of Rust and Cargo.
# This gets run from dev-bash.sh, which gets run from ~/.bash_profile, so
# the versions gets displayed after the help text for a new Vagrant session.
echo -e "\\033[4mVersions\\033[0m"
rustc --version
cargo --version
echo

View File

@ -0,0 +1,73 @@
set -e
# This script builds a publishable release-worthy version of exa.
# It gets the version number, builds exa using cargo, tests it, strips the
# binary, and compresses it into a zip.
#
# Its *mostly* the same as dev-package-for-linux.sh, except with some
# Mach-specific things (otool instead of ldd), BSD-coreutils-specific things,
# and it doesnt run the xtests.
# Virtualising macOS is a legal minefield, so this script is local instead
# of dev: I run it from my actual machine, rather than from a VM.
uname=`uname -s`
if [[ "$uname" != "Darwin" ]]; then
echo "Gotta be on Darwin to run this (detected '$uname')!"
exit 1
fi
# First, we need to get the version number to figure out what to call the zip.
# We do this by getting the first line from the Cargo.toml that matches
# /version/, removing its whitespace, and building a command out of it, so the
# shell executes something like `exa_version="0.8.0"`, which it understands as
# a variable definition. Hey, its not a hack if it works.
#
# Because this cant use the absolute /vagrant path, this has to use what this
# SO answer calls a “quoting disaster”: https://stackoverflow.com/a/20196098/3484614
# You will also need GNU coreutils: https://stackoverflow.com/a/4031502/3484614
exa_root="$(dirname "$(dirname "$(greadlink -fm "$0")")")"
toml_file="$exa_root"/Cargo.toml
eval exa_$(grep version $toml_file | head -n 1 | sed "s/ //g")
if [ -z "$exa_version" ]; then
echo "Failed to parse version number! Can't build exa!"
exit 1
else
echo "Building exa v$exa_version"
fi
# Compilation is done in --release mode, which takes longer but produces a
# faster binary.
echo -e "\n\033[4mCompiling release version of exa...\033[0m"
exa_macos_binary="$exa_root/exa-macos-x86_64"
rm -vf "$exa_macos_binary" | sed 's/^/removing /'
cargo build --release --manifest-path "$toml_file"
cargo test --release --manifest-path "$toml_file" --lib -- --quiet
# we cant run the xtests outside the VM!
#/vagrant/xtests/run.sh --release
cp "$exa_root"/target/release/exa "$exa_macos_binary"
# Stripping the binary before distributing it removes a bunch of debugging
# symbols, saving some space.
echo -e "\n\033[4mStripping binary...\033[0m"
strip "$exa_macos_binary"
echo "strip $exa_macos_binary"
# Compress the binary for upload. The -j flag is necessary to avoid the
# current path being in the zip too. Only the zip gets the version number, so
# the binaries can have consistent names, and its still possible to tell
# different *downloads* apart.
echo -e "\n\033[4mZipping binary...\033[0m"
exa_macos_zip="$exa_root/exa-macos-x86_64-${exa_version}.zip"
rm -vf "$exa_macos_zip" | sed 's/^/removing /'
zip -j "$exa_macos_zip" "$exa_macos_binary"
# There was a problem a while back where a library was getting unknowingly
# *dynamically* linked, which broke the whole self-contained binary concept.
# So dump the linker table, in case anything unscrupulous shows up.
echo -e "\n\033[4mLibraries linked:\033[0m"
otool -L "$exa_macos_binary" | sed 's/^[[:space:]]*//'
# Might as well use it to test itself, right?
echo -e "\n\033[4mAll done! Files produced:\033[0m"
"$exa_macos_binary" "$exa_macos_binary" "$exa_macos_zip" -lB

View File

@ -4,7 +4,7 @@ set +xe
# Release mode
case "$1" in
"--release") echo "Testing release exa..."; exa_binary="$HOME/target/release/exa" ;;
"--release") exa_binary="$HOME/target/release/exa" ;;
*) exa_binary="$HOME/target/debug/exa" ;;
esac