|
| 1 | +#!/bin/bash |
| 2 | +set -eu # fail on non-zero retcode or undefined variable |
| 3 | +print_usage() { |
| 4 | + printf "usage: $(basename $0) [-x] [-e] [-f] [-t] [-h]\n\n" |
| 5 | + printf "print rustc UI test sources which satisfy certain criteria; by default those that are:\n" |
| 6 | + printf "normal, passing, contain a non-empty main function, and compile in reasonable time\n\n" |
| 7 | + printf "options:\n" |
| 8 | + printf "x\tinclude fixed tests [may contain run-rustfix header]\n" |
| 9 | + printf "e\tinclude tests with empty/missing main function\n" |
| 10 | + printf "f\tinclude failing tests [may NOT contain run-pass header] (implies -t)\n" |
| 11 | + printf "t\tinclude tests that fail to generate MIR within 30s\n" |
| 12 | + printf "h\tprint this usage and exit\n\n" |
| 13 | + printf "if -t unset:\n" |
| 14 | + printf " set environment variable RUSTC_MIR_VERBOSE to see raw rustc invocation and CLI output\n" |
| 15 | + printf " set environment variable RUSTC_MIR_NOFILEOPTS to skip //@ compile-flags: ...\n\n" |
| 16 | + [ $# -ne 0 ] && echo "ERROR: $*" |
| 17 | + exit 1 |
| 18 | +} |
| 19 | + |
| 20 | +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) |
| 21 | + |
| 22 | +# setup time mir filter |
| 23 | +# NOTE: temp file is needed because rustc chokes when writing directly to /dev/null |
| 24 | +# NOTE: this filter does not work natively on mac due to no timeout command |
| 25 | +RUSTC_MIR=$SCRIPT_DIR/rustc_mir.sh |
| 26 | +TMPMIR=$SCRIPT_DIR/temp.mir |
| 27 | +RUSTOPT=('-C' 'overflow-checks=off') |
| 28 | +TIMEMIR=('-execdir' 'timeout' '30s' "$RUSTC_MIR" '{}' "$TMPMIR" "${RUSTOPT[@]}" ';') |
| 29 | + |
| 30 | +# setup grep filters |
| 31 | +HAS_MATCH=$SCRIPT_DIR/has_match.sh |
| 32 | +RUSTFIX=('-execdir' "$HAS_MATCH" 'n' '//@[[:space:]]*run-rustfix' '{}' ';') |
| 33 | +RUNPASS=('-execdir' "$HAS_MATCH" 'y' '//@[[:space:]]*run-pass' '{}' ';') |
| 34 | +HASMAIN=('-execdir' "$HAS_MATCH" 'y' 'fn[[:space:]]\{1,\}main[[:space:]]*([[:space:]]*)' '{}' ';') |
| 35 | +EMPMAIN=('-execdir' "$HAS_MATCH" 'n' 'fn[[:space:]]\{1,\}main[[:space:]]*([[:space:]]*)[[:space:]]*{[[:space:]]*}' '{}' ';') |
| 36 | + |
| 37 | +# parse opts |
| 38 | +while getopts 'xfet' opt; do |
| 39 | + case "${opt}" in |
| 40 | + x) RUSTFIX=() ;; |
| 41 | + e) HASMAIN=() |
| 42 | + EMPMAIN=() ;; |
| 43 | + f) RUNPASS=() |
| 44 | + TIMEMIR=() ;; |
| 45 | + t) TIMEMIR=() ;; |
| 46 | + ?|h) print_usage "environment variable RUST_TOP must point to a valid rustc distribution" ;; |
| 47 | + esac |
| 48 | +done |
| 49 | + |
| 50 | +# check test dir |
| 51 | +# NOTE: ${var:-default} expands to default if var unset |
| 52 | +[ -z "${RUST_TOP:-}" ] && print_usage "set RUST_TOP environment variable to your local Rust compiler source directory before running this script" |
| 53 | +RUST_TESTS=${RUST_TOP}/tests |
| 54 | +[ ! -d "${RUST_TESTS}" ] && print_usage "RUST_TOP environment variable does not appear to point to a local Rust compiler source directory" |
| 55 | + |
| 56 | +# clean temp mir file whenever timing mir, ignore errors |
| 57 | +if [ -n "${TIMEMIR[*]}" ]; then |
| 58 | + trap "rm \"$TMPMIR\" &> /dev/null" SIGINT SIGTERM EXIT |
| 59 | +fi |
| 60 | + |
| 61 | +# find test source files that pass filters |
| 62 | +( cd "${RUST_TOP}"; |
| 63 | + find tests/ui \ |
| 64 | + -name '*.rs' \ |
| 65 | + "${RUSTFIX[@]}" \ |
| 66 | + "${RUNPASS[@]}" \ |
| 67 | + "${HASMAIN[@]}" \ |
| 68 | + "${EMPMAIN[@]}" \ |
| 69 | + "${TIMEMIR[@]}" \ |
| 70 | + -print ) |
0 commit comments