From a2f70a35445b38123ee8a1dffbbce365fc1caafe Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 20 Jul 2018 15:17:56 -0700 Subject: [PATCH] Update to cranelift's formatting and testing scripts. --- .gitignore | 5 +-- .rustfmt.toml | 0 .travis.yml | 37 +++++++++++++++------ check-clippy.sh | 10 ++++++ clippy-all.sh | 7 ++++ clippy.toml | 1 + format-all.sh | 13 +++----- test-all.sh | 86 +++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 139 insertions(+), 20 deletions(-) create mode 100644 .rustfmt.toml create mode 100755 check-clippy.sh create mode 100755 clippy-all.sh create mode 100644 clippy.toml create mode 100755 test-all.sh diff --git a/.gitignore b/.gitignore index 0872b9b585..a481ff48e8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,10 @@ *.pyc -**/*.rs.bk +*.bk *.swp *.swo +*.swx tags -/target/ +target Cargo.lock .*.rustfmt cretonne.dbg* diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/.travis.yml b/.travis.yml index 03dd6f76e6..614364ae42 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,18 +1,37 @@ +# Travis CI script. See https://travis-ci.org/ for more info. + language: rust rust: - stable + # The version of rust in the latest Ubuntu LTS, currently Bionic. + - 1.25.0 - beta + - nightly +matrix: + allow_failures: + # We try to be compatible with beta and nightly, but they occasionally + # fail, so we don't allow them to hold up people using stable. + - rust: beta + - rust: nightly dist: trusty sudo: false -addons: - apt: - packages: - - python3-pip -install: - - pip3 install --user --upgrade mypy flake8 - - travis_wait ./check-rustfmt.sh --install +before_script: + # If an old version of rustfmt from cargo is already installed, uninstall + # it, since it can prevent the installation of the new version from rustup. + - cargo uninstall rustfmt || true + - cargo install --list + # If we're testing beta or nightly, we still need to install the stable + # toolchain so that we can run the stable version of rustfmt. + - rustup toolchain install stable + # Install the stable version of rustfmt. + - rustup component add --toolchain=stable rustfmt-preview + - rustup component list --toolchain=stable + - rustup show + - rustfmt +stable --version || echo fail + # Sometimes the component isn't actually ready after being installed, and + # rustup update makes it ready. + - rustup update + - rustfmt +stable --version script: ./test-all.sh cache: cargo: true - directories: - - $HOME/.cache/pip diff --git a/check-clippy.sh b/check-clippy.sh new file mode 100755 index 0000000000..072069cb9b --- /dev/null +++ b/check-clippy.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -euo pipefail + +# Usage: check-clippy.sh + +if cargo install --list | tee /dev/null | grep -q "^clippy v0"; then + exit 0 +else + exit 1 +fi diff --git a/clippy-all.sh b/clippy-all.sh new file mode 100755 index 0000000000..ba840b1d00 --- /dev/null +++ b/clippy-all.sh @@ -0,0 +1,7 @@ +#!/bin/bash +set -euo pipefail + +# Check all sources with clippy. +# In the clif-util crate (root dir) clippy will only work with nightly cargo - +# there is a bug where it will reject the commands passed to it by cargo 0.25.0 +exec cargo +nightly clippy --all diff --git a/clippy.toml b/clippy.toml new file mode 100644 index 0000000000..ce7f17cc64 --- /dev/null +++ b/clippy.toml @@ -0,0 +1 @@ +doc-valid-idents = [ "WebAssembly", "NaN" ] diff --git a/format-all.sh b/format-all.sh index d9e97f1026..64c967ad24 100755 --- a/format-all.sh +++ b/format-all.sh @@ -1,17 +1,12 @@ #!/bin/bash +set -euo pipefail # Format all sources using rustfmt. -# Exit immediately on errors. -set -e - -cd $(dirname "$0") -src=$(pwd) +topdir=$(dirname "$0") +cd "$topdir" # Make sure we can find rustfmt. export PATH="$PATH:$HOME/.cargo/bin" -for crate in $(find "$src" -name Cargo.toml); do - cd $(dirname "$crate") - cargo fmt -- "$@" -done +exec cargo +stable fmt --all -- "$@" diff --git a/test-all.sh b/test-all.sh new file mode 100755 index 0000000000..4fb44d6a15 --- /dev/null +++ b/test-all.sh @@ -0,0 +1,86 @@ +#!/bin/bash +set -euo pipefail + +# This is the top-level test script: +# +# - Check code formatting. +# - Make a debug build. +# - Make a release build. +# - Run unit tests for all Rust crates (including the filetests) +# - Build API documentation. +# - Optionally, run clippy and fuzzing. +# +# All tests run by this script should be passing at all times. + +# Disable generation of .pyc files because they cause trouble for vendoring +# scripts, and this is a build step that isn't run very often anyway. +export PYTHONDONTWRITEBYTECODE=1 + +# Repository top-level directory. +topdir=$(dirname "$0") +cd "$topdir" + +function banner { + echo "====== $* ======" +} + +# Run rustfmt if we have it. +banner "Rust formatting" +if type rustfmt > /dev/null; then + # In newer versions of rustfmt, replace --write-mode=diff with --check. + if ! "$topdir/format-all.sh" --write-mode=diff ; then + echo "Formatting diffs detected! Run \"cargo fmt --all\" to correct." + exit 1 + fi +else + echo "rustfmt not available; formatting not checked!" + echo + echo "If you are using rustup, rustfmt can be installed via" + echo "\"rustup component add --toolchain=stable rustfmt-preview\", or see" + echo "https://github.com/rust-lang-nursery/rustfmt for more information." +fi + +# Make sure the code builds in release mode. +banner "Rust release build" +cargo build --release + +# Make sure the code builds in debug mode. +banner "Rust debug build" +cargo build + +# Run the tests. We run these in debug mode so that assertions are enabled. +banner "Rust unit tests" +cargo test --all + +# Make sure the documentation builds. +banner "Rust documentation: $topdir/target/doc/wasmtime/index.html" +cargo doc + +# Run clippy if we have it. +banner "Rust linter" +if "$topdir/check-clippy.sh"; then + "$topdir/clippy-all.sh" --write-mode=diff +else + echo "\`cargo +nightly install clippy\` for optional rust linting" +fi + +# Ensure fuzzer works by running it with a single input +# Note LSAN is disabled due to https://github.com/google/sanitizers/issues/764 +banner "cargo fuzz check" +if rustup toolchain list | grep -q nightly; then + if cargo install --list | grep -q cargo-fuzz; then + echo "cargo-fuzz found" + else + echo "installing cargo-fuzz" + cargo +nightly install cargo-fuzz + fi + + fuzz_module="ffaefab69523eb11935a9b420d58826c8ea65c4c" + ASAN_OPTIONS=detect_leaks=0 \ + cargo +nightly fuzz run fuzz_translate_module \ + "$topdir/fuzz/corpus/fuzz_translate_module/$fuzz_module" +else + echo "nightly toolchain not found, skipping fuzz target integration test" +fi + +banner "OK"