Check for multirust, rustfmt, clean up some things

This commit is contained in:
Adam Wright
2016-02-17 18:18:22 -08:00
parent 17d800b8a8
commit 3462451256
2 changed files with 45 additions and 21 deletions

View File

@@ -8,6 +8,12 @@
# Pre-commit hook for the tarpc repository. To use this hook, copy it to .git/hooks in your
# repository root.
#
# This precommit checks the following:
# 1. All filenames are ascii
# 2. There is no bad whitespace
# 3. rustfmt is installed
# 4. rustfmt is a noop on files that are in the index
#
# Options:
#
# - TARPC_SKIP_RUSTFMT, default = 0
@@ -63,6 +69,18 @@ else
printf "${SUCCESS}\n"
fi
printf "${PREFIX} Checking for rustfmt ... "
command -v rustfmt &>/dev/null
if [ $? == 0 ]; then
printf "${SUCCESS}\n"
else
printf "${FAILURE}\n"
exit 1
fi
# Just check that running rustfmt doesn't do anything to the file. I do this instead of
# modifying the file because I don't want to mess with the developer's index, which may
# not only contain discrete files.
printf "${PREFIX} Checking formatting ... "
FMTRESULT=0
for file in $(git diff --name-only --cached);

View File

@@ -40,56 +40,68 @@ SUCCESS="${GREEN}ok${NC}"
printf "${PREFIX} Clean working copy ... "
git diff --exit-code &>/dev/null
if [ "$?" == 0 ];
then
if [ "$?" == 0 ]; then
printf "${SUCCESS}\n"
else
printf "${FAILURE}\n"
if [ "${TARPC_ALLOW_DIRTY}" == "1" ]
then
echo ${WARNING} Running with unclean working directory
printf "${WARNING} Running with unclean working directory\n"
else
exit 1
fi
fi
TEST_RESULT=0
PREPUSH_RESULT=0
# args:
# 1 - cargo command to run (build/test)
# 2 - directory name of crate to build
# 3 - rust toolchain (nightly/stable/beta)
function run_cargo() {
if [ "$1" == "build" ]
then
if [ "$1" == "build" ]; then
VERB=Building
else
VERB=Testing
fi
if [ "$3" != "" ]
then
if [ "$3" != "" ]; then
printf "${PREFIX} $VERB $2 on $3 ... "
multirust run $3 cargo $1 --manifest-path $2/Cargo.toml &>/dev/null
else
printf "${PREFIX} $VERB $2 ... "
cargo $1 --manifest-path $2/Cargo.toml &>/dev/null
fi
if [ "$?" != "0" ];
then
if [ "$?" != "0" ]; then
printf "${FAILURE}\n"
#printf "${OUTPUT}\n"
TEST_RESULT=1
PREPUSH_RESULT=1
else
printf "${SUCCESS}\n"
fi
}
TOOLCHAIN_RESULT=0
check_toolchain() {
printf "${PREFIX} Checking for $1 toolchain ... "
if [[ $(multirust list-toolchain) =~ $1 ]]; then
printf "${SUCCESS}\n"
else
TOOLCHAIN_RESULT=1
PREPUSH_RESULT=1
printf "${FAILURE}\n"
fi
PREPUSH_RESULT=1
}
printf "${PREFIX} Checking for multirust ... "
command -v multirust &>/dev/null
if [ "$?" == 0 ] && [ "${TARPC_USE_CURRENT_TOOLCHAIN}" == "" ];
then
if [ "$?" == 0 ] && [ "${TARPC_USE_CURRENT_TOOLCHAIN}" == "" ]; then
printf "${SUCCESS}\n"
check_toolchain stable
check_toolchain beta
check_toolchain nightly
[ ${TOOLCHAIN_RESULT} ] && exit 1
# No need to build on nightly, the tests will do that
run_cargo build tarpc stable
run_cargo build tarpc_examples stable
@@ -108,10 +120,4 @@ else
run_cargo test tarpc_examples
fi
RESULT=0
if [ "$TEST_RESULT" == "1" ];
then
RESULT=1
fi
exit $RESULT
exit $PREPUSH_RESULT