Make travis.sh and Makefile "nicer"

Slightly easier to reason about the code via some code movement, printing some
banners to make it more obvious when cargo is being run since it is run so many
times.
This commit is contained in:
Brandon W Maister 2019-09-15 20:44:37 -04:00
parent e8c708d81b
commit 5b72ef3ed6
2 changed files with 89 additions and 40 deletions

View File

@ -1,6 +1,8 @@
# this Makefile is mostly for the packaging convenience. # this Makefile is mostly for the packaging convenience.
# casual users should use `cargo` to retrieve the appropriate version of Chrono. # casual users should use `cargo` to retrieve the appropriate version of Chrono.
CHANNEL=stable
.PHONY: all .PHONY: all
all: all:
@echo 'Try `cargo build` instead.' @echo 'Try `cargo build` instead.'
@ -20,11 +22,8 @@ README.md: src/lib.rs
.PHONY: test .PHONY: test
test: test:
TZ=UTC0 cargo test --features 'serde rustc-serialize bincode' --lib CHANNEL=$(CHANNEL) ./ci/travis.sh
TZ=ACST-9:30 cargo test --features 'serde rustc-serialize bincode' --lib
TZ=EST4 cargo test --features 'serde rustc-serialize bincode'
.PHONY: doc .PHONY: doc
doc: authors readme doc: authors readme
cargo doc --features 'serde rustc-serialize bincode' cargo doc --features 'serde rustc-serialize bincode'

View File

@ -7,37 +7,81 @@ set -e
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
main() {
if [[ -n $CHANNEL ]] ; then
if [[ $CHANNEL == 1.13.0 ]]; then
banner "Building $CHANNEL"
build_only
else
banner "Building/testing $CHANNEL"
#build_and_test
banner "Testing Core $CHANNEL"
build_core_test
fi
else
CHANNEL=nightly
matching_banner "Test $CHANNEL"
if [ "x${CLIPPY}" = xy ] ; then
run_clippy
else
build_and_test
fi
CHANNEL=beta
matching_banner "Test $CHANNEL"
build_and_test
CHANNEL=stable
matching_banner "Test $CHANNEL"
build_and_test
build_core_test
CHANNEL=1.13.0
matching_banner "Test $CHANNEL"
build_only
fi
}
channel() { channel() {
channel_run cargo "$@" channel_run cargo "$@"
} }
channel_run() { channel_run() {
if [ -n "${TRAVIS}" ]; then if channel_matches ; then
if [ "${TRAVIS_RUST_VERSION}" = "${CHANNEL}" ]; then pwd
pwd local the_cmd="$ $*"
echo "$ $*" echo "$the_cmd"
"$@" "$@"
fi
elif [ -n "${APPVEYOR}" ]; then
if [ "${APPVEYOR_RUST_CHANNEL}" = "${CHANNEL}" ]; then
pwd
echo "$ $*"
"$@"
fi
else else
pwd pwd
local cmd="$1" local cmd="$1"
shift shift
if [[ $cmd = cargo ]] ; then if [[ $cmd == cargo || $cmd == rustc ]] ; then
echo "$ $cmd +${CHANNEL} $*" underline "$ $cmd +${CHANNEL} $*"
"$cmd" "+${CHANNEL}" "$@" "$cmd" "+${CHANNEL}" "$@"
else else
echo "$ $cmd $*" underline "$ $cmd $*"
"$cmd" "$@" "$cmd" "$@"
fi fi
fi fi
} }
channel_matches() {
if [ -n "${TRAVIS}" ]; then
if [ "${TRAVIS_RUST_VERSION}" = "${CHANNEL}" ]; then
return 0
fi
elif [ -n "${APPVEYOR}" ]; then
if [ "${APPVEYOR_RUST_CHANNEL}" = "${CHANNEL}" ]; then
return 0
fi
else
return 1
fi
}
build_and_test() { build_and_test() {
# interleave building and testing in hope that it saves time # interleave building and testing in hope that it saves time
# also vary the local time zone to (hopefully) catch tz-dependent bugs # also vary the local time zone to (hopefully) catch tz-dependent bugs
@ -76,6 +120,9 @@ build_and_test_nonwasm() {
TZ=UTC0 channel test -v --no-default-features --features serde --lib TZ=UTC0 channel test -v --no-default-features --features serde --lib
channel build -v --no-default-features --features std,serde,rustc-serialize channel build -v --no-default-features --features std,serde,rustc-serialize
TZ=Asia/Katmandu channel test -v --no-default-features --features std,serde,rustc-serialize --lib TZ=Asia/Katmandu channel test -v --no-default-features --features std,serde,rustc-serialize --lib
channel build -v --no-default-features --features 'alloc serde'
TZ=UTC0 channel test -v --no-default-features --features 'alloc serde' --lib
} }
build_and_test_wasm() { build_and_test_wasm() {
@ -95,15 +142,16 @@ build_only() {
cargo clean cargo clean
channel build -v channel build -v
channel build -v --features rustc-serialize channel build -v --features rustc-serialize
channel build -v --features 'serde bincode' channel build -v --features serde
channel build -v --no-default-features --features std channel build -v --no-default-features --features std
channel build -v --no-default-features --features 'std serde_std'
} }
build_core_test() { build_core_test() {
channel_run rustup target add thumbv6m-none-eabi --toolchain "$CHANNEL" channel_run rustup target add thumbv6m-none-eabi --toolchain "$CHANNEL"
( (
cd ci/core-test cd ci/core-test
channel build -v --target thumbv6m-none-eabi channel build -v --features alloc --target thumbv6m-none-eabi
) )
} }
@ -114,7 +162,7 @@ run_clippy() {
exit exit
fi fi
cargo clippy --features 'serde bincode rustc-serialize' -- -Dclippy cargo clippy --features 'serde rustc-serialize' -- -Dclippy
} }
check_readme() { check_readme() {
@ -122,23 +170,25 @@ check_readme() {
(set -x; git diff --exit-code -- README.md) ; echo $? (set -x; git diff --exit-code -- README.md) ; echo $?
} }
rustc --version banner() {
cargo --version echo "======================================================================"
echo "$*"
echo "======================================================================"
}
underline() {
echo "$*"
echo "${*//?/^}"
}
matching_banner() {
if channel_matches || [[ -z $TRAVIS && -z $APPVEYOR ]] ; then
banner "$*"
fi
}
channel_run rustc --version
channel_run cargo --version
node --version node --version
CHANNEL=nightly main
if [ "x${CLIPPY}" = xy ] ; then
run_clippy
else
build_and_test
fi
CHANNEL=beta
build_and_test
CHANNEL=stable
build_and_test
build_core_test
CHANNEL=1.13.0
build_only