-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #46207 - kennytm:kill-grep, r=alexcrichton
Replace most call to grep in run-make by a script that cat the input. Introduced a new `src/etc/cat-and-grep.sh` script (called in run-make as `$(CGREP)`), which prints the input and do a grep simultaneously. This is mainly used to debug spurious failures in run-make, such as the spurious error in #45810, as well as real errors such as #46126. (cc #40713) Some `grep` still remains, mainly the `grep -c` calls that count the number of matches and print the result to stdout.
- Loading branch information
Showing
47 changed files
with
244 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#!/bin/sh | ||
set -eu | ||
|
||
# Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
# file at the top-level directory of this distribution and at | ||
# http://rust-lang.org/COPYRIGHT. | ||
# | ||
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
# option. This file may not be copied, modified, or distributed | ||
# except according to those terms. | ||
|
||
# Performs `cat` and `grep` simultaneously for `run-make` tests in the Rust CI. | ||
# | ||
# This program will read lines from stdin and print them to stdout immediately. | ||
# At the same time, it will check if the input line contains the substring or | ||
# regex specified in the command line. If any match is found, the program will | ||
# set the exit code to 0, otherwise 1. | ||
# | ||
# This is written to simplify debugging runmake tests. Since `grep` swallows all | ||
# output, when a test involving `grep` failed, it is impossible to know the | ||
# reason just by reading the failure log. While it is possible to `tee` the | ||
# output into another stream, it becomes pretty annoying to do this for all test | ||
# cases. | ||
|
||
USAGE=' | ||
cat-and-grep.sh [-v] [-e] [-i] s1 s2 s3 ... < input.txt | ||
Prints the stdin, and exits successfully only if all of `sN` can be found in | ||
some lines of the input. | ||
Options: | ||
-v Invert match, exits successfully only if all of `sN` cannot be found | ||
-e Regex search, search using extended Regex instead of fixed string | ||
-i Case insensitive search. | ||
' | ||
|
||
GREPPER=fgrep | ||
INVERT=0 | ||
GREPFLAGS='q' | ||
while getopts ':vieh' OPTION; do | ||
case "$OPTION" in | ||
v) | ||
INVERT=1 | ||
ERROR_MSG='should not be found' | ||
;; | ||
i) | ||
GREPFLAGS="i$GREPFLAGS" | ||
;; | ||
e) | ||
GREPPER=egrep | ||
;; | ||
h) | ||
echo "$USAGE" | ||
exit 2 | ||
;; | ||
*) | ||
break | ||
;; | ||
esac | ||
done | ||
|
||
shift $((OPTIND - 1)) | ||
|
||
LOG=$(mktemp -t cgrep.XXXXXX) | ||
trap "rm -f $LOG" EXIT | ||
|
||
printf "[[[ begin stdout ]]]\n\033[90m" | ||
tee "$LOG" | ||
echo >> "$LOG" # ensure at least 1 line of output, otherwise `grep -v` may unconditionally fail. | ||
printf "\033[0m\n[[[ end stdout ]]]\n" | ||
|
||
HAS_ERROR=0 | ||
for MATCH in "$@"; do | ||
if "$GREPPER" "-$GREPFLAGS" -- "$MATCH" "$LOG"; then | ||
if [ "$INVERT" = 1 ]; then | ||
printf "\033[1;31mError: should not match: %s\033[0m\n" "$MATCH" | ||
HAS_ERROR=1 | ||
fi | ||
else | ||
if [ "$INVERT" = 0 ]; then | ||
printf "\033[1;31mError: cannot match: %s\033[0m\n" "$MATCH" | ||
HAS_ERROR=1 | ||
fi | ||
fi | ||
done | ||
|
||
exit "$HAS_ERROR" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
-include ../tools.mk | ||
|
||
all: | ||
echo a | $(CGREP) a | ||
! echo b | $(CGREP) a | ||
echo xyz | $(CGREP) x y z | ||
! echo abc | $(CGREP) b c d | ||
printf "x\ny\nz" | $(CGREP) x y z | ||
|
||
echo AbCd | $(CGREP) -i a b C D | ||
! echo AbCd | $(CGREP) a b C D | ||
|
||
true | $(CGREP) -v nothing | ||
! echo nothing | $(CGREP) -v nothing | ||
! echo xyz | $(CGREP) -v w x y | ||
! echo xyz | $(CGREP) -v x y z | ||
echo xyz | $(CGREP) -v a b c | ||
|
||
! echo 'foo bar baz' | $(CGREP) 'foo baz' | ||
echo 'foo bar baz' | $(CGREP) foo baz | ||
echo 'x a `b` c y z' | $(CGREP) 'a `b` c' | ||
|
||
echo baaac | $(CGREP) -e 'ba*c' | ||
echo bc | $(CGREP) -e 'ba*c' | ||
! echo aaac | $(CGREP) -e 'ba*c' | ||
|
||
echo aaa | $(CGREP) -e 'a+' | ||
! echo bbb | $(CGREP) -e 'a+' | ||
|
||
echo abc | $(CGREP) -e 'a|e|i|o|u' | ||
! echo fgh | $(CGREP) -e 'a|e|i|o|u' | ||
echo abc | $(CGREP) -e '[aeiou]' | ||
! echo fgh | $(CGREP) -e '[aeiou]' | ||
! echo abc | $(CGREP) -e '[^aeiou]{3}' | ||
echo fgh | $(CGREP) -e '[^aeiou]{3}' | ||
echo ab cd ef gh | $(CGREP) -e '\bcd\b' | ||
! echo abcdefgh | $(CGREP) -e '\bcd\b' | ||
echo xyz | $(CGREP) -e '...' | ||
! echo xy | $(CGREP) -e '...' | ||
! echo xyz | $(CGREP) -e '\.\.\.' | ||
echo ... | $(CGREP) -e '\.\.\.' | ||
|
||
echo foo bar baz | $(CGREP) -e 'foo.*baz' | ||
! echo foo bar baz | $(CGREP) -ve 'foo.*baz' | ||
! echo foo bar baz | $(CGREP) -e 'baz.*foo' | ||
echo foo bar baz | $(CGREP) -ve 'baz.*foo' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,31 @@ | ||
-include ../tools.mk | ||
|
||
LOG = $(TMPDIR)/log.txt | ||
|
||
all: | ||
#Option taking a number | ||
$(RUSTC) -C codegen-units dummy.rs 2>&1 | tee $(LOG) | ||
grep 'codegen option `codegen-units` requires a number' $(LOG) | ||
$(RUSTC) -C codegen-units= dummy.rs 2>&1 | tee $(LOG) | ||
grep 'incorrect value `` for codegen option `codegen-units` - a number was expected' $(LOG) | ||
$(RUSTC) -C codegen-units=foo dummy.rs 2>&1 | tee $(LOG) | ||
grep 'incorrect value `foo` for codegen option `codegen-units` - a number was expected' $(LOG) | ||
$(RUSTC) -C codegen-units dummy.rs 2>&1 | \ | ||
$(CGREP) 'codegen option `codegen-units` requires a number' | ||
$(RUSTC) -C codegen-units= dummy.rs 2>&1 | \ | ||
$(CGREP) 'incorrect value `` for codegen option `codegen-units` - a number was expected' | ||
$(RUSTC) -C codegen-units=foo dummy.rs 2>&1 | \ | ||
$(CGREP) 'incorrect value `foo` for codegen option `codegen-units` - a number was expected' | ||
$(RUSTC) -C codegen-units=1 dummy.rs | ||
#Option taking a string | ||
$(RUSTC) -C extra-filename dummy.rs 2>&1 | tee $(LOG) | ||
grep 'codegen option `extra-filename` requires a string' $(LOG) | ||
$(RUSTC) -C extra-filename dummy.rs 2>&1 | \ | ||
$(CGREP) 'codegen option `extra-filename` requires a string' | ||
$(RUSTC) -C extra-filename= dummy.rs 2>&1 | ||
$(RUSTC) -C extra-filename=foo dummy.rs 2>&1 | ||
#Option taking no argument | ||
$(RUSTC) -C lto= dummy.rs 2>&1 | tee $(LOG) | ||
grep 'codegen option `lto` takes no value' $(LOG) | ||
$(RUSTC) -C lto=1 dummy.rs 2>&1 | tee $(LOG) | ||
grep 'codegen option `lto` takes no value' $(LOG) | ||
$(RUSTC) -C lto=foo dummy.rs 2>&1 | tee $(LOG) | ||
grep 'codegen option `lto` takes no value' $(LOG) | ||
$(RUSTC) -C lto= dummy.rs 2>&1 | \ | ||
$(CGREP) 'codegen option `lto` takes no value' | ||
$(RUSTC) -C lto=1 dummy.rs 2>&1 | \ | ||
$(CGREP) 'codegen option `lto` takes no value' | ||
$(RUSTC) -C lto=foo dummy.rs 2>&1 | \ | ||
$(CGREP) 'codegen option `lto` takes no value' | ||
$(RUSTC) -C lto dummy.rs | ||
|
||
# Should not link dead code... | ||
$(RUSTC) -Z print-link-args dummy.rs 2>&1 | \ | ||
grep -e '--gc-sections' -e '-z[^ ]* [^ ]*\<ignore\>' -e '-dead_strip' -e '/OPT:REF' | ||
$(CGREP) -e '--gc-sections|-z[^ ]* [^ ]*<ignore>|-dead_strip|/OPT:REF' | ||
# ... unless you specifically ask to keep it | ||
$(RUSTC) -Z print-link-args -C link-dead-code dummy.rs 2>&1 | \ | ||
(! grep -e '--gc-sections' -e '-z[^ ]* [^ ]*\<ignore\>' -e '-dead_strip' -e '/OPT:REF') | ||
$(CGREP) -ve '--gc-sections|-z[^ ]* [^ ]*<ignore>|-dead_strip|/OPT:REF' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
-include ../tools.mk | ||
|
||
all: | ||
TMP=fake TMPDIR=fake $(RUSTC) foo.rs 2>&1 | grep "couldn't create a temp dir:" | ||
TMP=fake TMPDIR=fake $(RUSTC) foo.rs 2>&1 | $(CGREP) "couldn't create a temp dir:" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
-include ../tools.mk | ||
|
||
all: | ||
$(RUSTC) -o "" blank.rs 2>&1 | \ | ||
grep -i 'No such file or directory' | ||
$(RUSTC) -o "" blank.rs 2>&1 | $(CGREP) -i 'No such file or directory' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
-include ../tools.mk | ||
|
||
all: | ||
$(RUSTC) --target x86_64_unknown-linux-musl main.rs 2>&1 | \ | ||
grep "error: Error loading target specification: Could not find specification for target" | ||
$(RUSTC) --target x86_64_unknown-linux-musl main.rs 2>&1 | $(CGREP) \ | ||
"error: Error loading target specification: Could not find specification for target" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
-include ../tools.mk | ||
|
||
all: | ||
$(RUSTC) main.rs --error-format json 2>&1 | grep -q '"byte_start":490.*"byte_end":496' | ||
$(RUSTC) main.rs --error-format json 2>&1 | $(CGREP) -e '"byte_start":490\b' '"byte_end":496\b' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
-include ../tools.mk | ||
|
||
# The ICE occurred in the following situation: | ||
# * `foo` declares `extern crate bar, baz`, depends only on `bar` (forgetting `baz` in `Cargo.toml`) | ||
# * `bar` declares and depends on `extern crate baz` | ||
# * All crates built in metadata-only mode (`cargo check`) | ||
all: | ||
# cc https://github.com/rust-lang/rust/issues/40623 | ||
$(RUSTC) baz.rs --emit=metadata --out-dir=$(TMPDIR) | ||
$(RUSTC) bar.rs --emit=metadata --extern baz=$(TMPDIR)/libbaz.rmeta --out-dir=$(TMPDIR) | ||
$(RUSTC) foo.rs --emit=metadata --extern bar=$(TMPDIR)/libbar.rmeta --out-dir=$(TMPDIR) 2>&1 | \ | ||
grep -vq "unexpectedly panicked" | ||
$(RUSTC) baz.rs --emit=metadata | ||
$(RUSTC) bar.rs --emit=metadata --extern baz=$(TMPDIR)/libbaz.rmeta | ||
$(RUSTC) foo.rs --emit=metadata --extern bar=$(TMPDIR)/libbar.rmeta 2>&1 | \ | ||
$(CGREP) -v "unexpectedly panicked" | ||
# ^ Succeeds if it doesn't find the ICE message |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.