Skip to content

Instantly share code, notes, and snippets.

@nikomatsakis
Created August 6, 2012 21:00
Show Gist options
  • Save nikomatsakis/3278417 to your computer and use it in GitHub Desktop.
Save nikomatsakis/3278417 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Script which finds an appropriate rustc to execute based on the current
# directory. We begin by walking up the set of directories until we find
# one that contains "src/comp/rustc.rc".
# Walk up directories looking for the main rust directory. Don't walk
# past the home directory of the current user, just seems unsanitary.
if [ -z "$1" ]; then
STAGES="stage2 stage1"
else
STAGES="$1"
fi
DIR="$PWD"
while [[ "$DIR" != "/" && "$DIR" != "$HOME" ]]; do
if [[ -r "$DIR/src/rustc/rustc.rc" ]]; then
for stage in ${STAGES}; do
# Use glob to search through all architectures.
# But if some stage doesn't exist, then
# the glob will keep the "*" rather than return the
# empty set, so we have to check within the for loop
# too.
for rustc in "$DIR"/build/*/$stage/bin/rustc; do
if [[ -x "$rustc" ]]; then
echo "$rustc"
exit 0
fi
done
done
break
fi
DIR=$(dirname "$DIR")
done
# Fallback to /usr/local/bin/rustc, if any:
echo /usr/local/bin/rustc
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment