Skip to content

Commit 1ce44aa

Browse files
committed
build: improve script and travis config
* fix a diff failure on windows See https://travis-ci.com/rust-lang/rust-clippy/jobs/245971932#L1625 for an example. * use cmp instead of diff > /dev/null * clone single branch instead of clone then checking out * do not decrypt key if have no diff change
1 parent 07c0673 commit 1ce44aa

9 files changed

+104
-107
lines changed

.github/deploy.sh

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ SSH_REPO=${REPO/https:\/\/github.com\//git@github.com:}
1313
SHA=$(git rev-parse --verify HEAD)
1414

1515
# Clone the existing gh-pages for this repo into out/
16-
(
17-
git clone "$REPO" out
18-
cd out
19-
git checkout $TARGET_BRANCH
20-
)
16+
git clone --quiet --single-branch --branch "$TARGET_BRANCH" "$REPO" out
2117

2218
echo "Removing the current docs for master"
2319
rm -rf out/master/ || exit 0
@@ -27,35 +23,41 @@ mkdir out/master/
2723
cp util/gh-pages/index.html out/master
2824
python ./util/export.py out/master/lints.json
2925

30-
if [ -n "$TRAVIS_TAG" ]; then
26+
if [[ -n "$TRAVIS_TAG" ]]; then
3127
echo "Save the doc for the current tag ($TRAVIS_TAG) and point current/ to it"
3228
cp -r out/master "out/$TRAVIS_TAG"
3329
rm -f out/current
3430
ln -s "$TRAVIS_TAG" out/current
3531
fi
3632

3733
# Generate version index that is shown as root index page
38-
(
39-
cp util/gh-pages/versions.html out/index.html
40-
41-
cd out
42-
python -c '\
43-
import os, json;\
44-
print json.dumps([\
45-
dir for dir in os.listdir(".")\
46-
if not dir.startswith(".") and os.path.isdir(dir)\
47-
])' > versions.json
48-
)
34+
cp util/gh-pages/versions.html out/index.html
35+
cat <<-EOF | python - > out/versions.json
36+
import os, json
37+
print json.dumps([
38+
dir for dir in os.listdir(".") if not dir.startswith(".") and os.path.isdir(dir)
39+
])
40+
EOF
4941

5042
# Pull requests and commits to other branches shouldn't try to deploy, just build to verify
51-
if [ "$TRAVIS_PULL_REQUEST" != "false" ] || [ "$TRAVIS_BRANCH" != "$SOURCE_BRANCH" ]; then
43+
if [[ "$TRAVIS_PULL_REQUEST" != "false" ]] || [[ "$TRAVIS_BRANCH" != "$SOURCE_BRANCH" ]]; then
5244
# Tags should deploy
53-
if [ -z "$TRAVIS_TAG" ]; then
45+
if [[ -z "$TRAVIS_TAG" ]]; then
5446
echo "Generated, won't push"
5547
exit 0
5648
fi
5749
fi
5850

51+
# Now let's go have some fun with the cloned repo
52+
cd out
53+
git config user.name "Travis CI"
54+
git config user.email "travis@ci.invalid"
55+
56+
if git diff --exit-code --quiet; then
57+
echo "No changes to the output on this push; exiting."
58+
exit 0
59+
fi
60+
5961
# Get the deploy key by using Travis's stored variables to decrypt deploy_key.enc
6062
ENCRYPTION_LABEL=e3a2d77100be
6163
ENCRYPTED_KEY_VAR="encrypted_${ENCRYPTION_LABEL}_key"
@@ -64,19 +66,9 @@ ENCRYPTED_KEY=${!ENCRYPTED_KEY_VAR}
6466
ENCRYPTED_IV=${!ENCRYPTED_IV_VAR}
6567
openssl aes-256-cbc -K "$ENCRYPTED_KEY" -iv "$ENCRYPTED_IV" -in .github/deploy_key.enc -out .github/deploy_key -d
6668
chmod 600 .github/deploy_key
67-
eval $(ssh-agent -s)
69+
eval "$(ssh-agent -s)"
6870
ssh-add .github/deploy_key
6971

70-
# Now let's go have some fun with the cloned repo
71-
cd out
72-
git config user.name "Travis CI"
73-
git config user.email "travis@ci.invalid"
74-
75-
if [ -z "$(git diff --exit-code)" ]; then
76-
echo "No changes to the output on this push; exiting."
77-
exit 0
78-
fi
79-
8072
git add .
8173
git commit -m "Automatic deploy to GitHub Pages: ${SHA}"
8274

.travis.yml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@ before_install:
2323
- export PATH="$HOME/.cargo/bin:$PATH"
2424
install:
2525
- |
26-
if [ -z ${INTEGRATION} ]; then
27-
rustup component add rustfmt || cargo install --git https://github.com/rust-lang/rustfmt/ --force
28-
if [ "$TRAVIS_OS_NAME" == "linux" ]; then
26+
if [[ -z ${INTEGRATION} ]]; then
27+
if ! rustup component add rustfmt; then
28+
cargo install --git https://github.com/rust-lang/rustfmt --bin rustfmt
29+
fi
30+
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
2931
. $HOME/.nvm/nvm.sh
3032
nvm install stable
3133
nvm use stable
3234
npm install remark-cli remark-lint
33-
fi
34-
if [ "$TRAVIS_OS_NAME" == "windows" ]; then
35+
elif [[ "$TRAVIS_OS_NAME" == "windows" ]]; then
3536
choco install windows-sdk-10.1
3637
fi
3738
fi
@@ -95,42 +96,42 @@ matrix:
9596

9697
before_script:
9798
- |
98-
if [ "$TRAVIS_BRANCH" == "auto" ] || [ "$TRAVIS_BRANCH" == "try" ]; then
99-
pr=$(echo $TRAVIS_COMMIT_MESSAGE | grep -o "#[0-9]*" | head -1 | sed 's/^#//g')
100-
output=$(curl -H "Authorization: token $GITHUB_API_TOKEN" -s "https://api.github.com/repos/rust-lang/rust-clippy/pulls/$pr" | \
99+
if [[ "$TRAVIS_BRANCH" == "auto" ]] || [[ "$TRAVIS_BRANCH" == "try" ]]; then
100+
PR=$(echo "$TRAVIS_COMMIT_MESSAGE" | grep -o "#[0-9]*" | head -1 | sed 's/^#//g')
101+
output=$(curl -H "Authorization: token $GITHUB_API_TOKEN" -s "https://api.github.com/repos/rust-lang/rust-clippy/pulls/$PR" | \
101102
python -c "import sys, json; print(json.load(sys.stdin)['body'])" | \
102103
grep "^changelog: " | \
103104
sed "s/changelog: //g")
104-
if [ -z "$output" ]; then
105+
if [[ -z "$output" ]]; then
105106
echo "ERROR: PR body must contain 'changelog: ...'"
106107
exit 1
107-
elif [ "$output" = "none" ]; then
108+
elif [[ "$output" = "none" ]]; then
108109
echo "WARNING: changelog is 'none'"
109110
fi
110111
fi
111112
- |
112113
rm rust-toolchain
113114
./setup-toolchain.sh
114115
- |
115-
if [ "$TRAVIS_OS_NAME" == "windows" ]; then
116+
if [[ "$TRAVIS_OS_NAME" == "windows" ]]; then
116117
export PATH=$PATH:$(rustc --print sysroot)/bin
117118
else
118119
export LD_LIBRARY_PATH=$(rustc --print sysroot)/lib
119120
fi
120121
121122
script:
122123
- |
123-
if [ -z ${INTEGRATION} ]; then
124+
if [[ -z ${INTEGRATION} ]]; then
124125
travis_wait 30 ./ci/base-tests.sh && sleep 5
125126
else
126127
./ci/integration-tests.sh && sleep 5
127128
fi
128129
129130
after_success:
130131
- |
131-
if [ "$TRAVIS_OS_NAME" == "linux" ]; then
132+
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
132133
set -e
133-
if [ -z ${INTEGRATION} ]; then
134+
if [[ -z ${INTEGRATION} ]]; then
134135
./.github/deploy.sh
135136
else
136137
echo "Not deploying, because we're in an integration test run"

ci/base-tests.sh

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1+
#!/usr/bin/env bash
12
set -ex
23

34
echo "Running clippy base tests"
45

56
PATH=$PATH:./node_modules/.bin
6-
if [ "$TRAVIS_OS_NAME" == "linux" ]; then
7-
remark -f *.md -f doc/*.md > /dev/null
7+
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
8+
remark -f ./*.md -f doc/*.md > /dev/null
89
fi
910
# build clippy in debug mode and run tests
1011
cargo build --features "debugging deny-warnings"
1112
cargo test --features "debugging deny-warnings"
1213
# for faster build, share target dir between subcrates
13-
export CARGO_TARGET_DIR=`pwd`/target/
14+
CARGO_TARGET_DIR=$(pwd)/target/
15+
export CARGO_TARGET_DIR
1416
(cd clippy_lints && cargo test)
1517
(cd rustc_tools_util && cargo test)
1618
(cd clippy_dev && cargo test)
@@ -29,26 +31,27 @@ export CARGO_TARGET_DIR=`pwd`/target/
2931
(
3032
# Check sysroot handling
3133
sysroot=$(./target/debug/clippy-driver --print sysroot)
32-
test $sysroot = $(rustc --print sysroot)
34+
test "$sysroot" = "$(rustc --print sysroot)"
3335

34-
if [ -z $OS_WINDOWS ]; then
36+
if [[ -z "$OS_WINDOWS" ]]; then
3537
desired_sysroot=/tmp
3638
else
3739
desired_sysroot=C:/tmp
3840
fi
3941
sysroot=$(./target/debug/clippy-driver --sysroot $desired_sysroot --print sysroot)
40-
test $sysroot = $desired_sysroot
42+
test "$sysroot" = $desired_sysroot
4143

4244
sysroot=$(SYSROOT=$desired_sysroot ./target/debug/clippy-driver --print sysroot)
43-
test $sysroot = $desired_sysroot
45+
test "$sysroot" = $desired_sysroot
4446

4547
# Make sure this isn't set - clippy-driver should cope without it
4648
unset CARGO_MANIFEST_DIR
4749

4850
# Run a lint and make sure it produces the expected output. It's also expected to exit with code 1
49-
# XXX How to match the clippy invocation in compile-test.rs?
50-
! ./target/debug/clippy-driver -Dwarnings -Aunused -Zui-testing --emit metadata --crate-type bin tests/ui/cstring.rs 2> cstring.stderr
51-
diff <(sed -e 's,tests/ui,$DIR,' -e '/= help/d' cstring.stderr) tests/ui/cstring.stderr
51+
# FIXME: How to match the clippy invocation in compile-test.rs?
52+
./target/debug/clippy-driver -Dwarnings -Aunused -Zui-testing --emit metadata --crate-type bin tests/ui/cstring.rs 2> cstring.stderr
53+
sed -e 's,tests/ui,$DIR,' -e '/= help/d' cstring.stderr > normalized.stderr
54+
diff normalized.stderr tests/ui/cstring.stderr
5255

5356
# TODO: CLIPPY_CONF_DIR / CARGO_MANIFEST_DIR
5457
)

ci/integration-tests.sh

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
1+
#!/usr/bin/env bash
12
set -x
3+
4+
if [[ -z "${INTEGRATION}" ]]; then
5+
exit 0
6+
fi
7+
28
rm ~/.cargo/bin/cargo-clippy
39
cargo install --force --path .
410

511
echo "Running integration test for crate ${INTEGRATION}"
612

7-
git clone --depth=1 https://github.com/${INTEGRATION}.git checkout
8-
cd checkout
13+
git clone --depth=1 "https://github.com/${INTEGRATION}.git" checkout
14+
cd checkout || exit 1
915

10-
function check() {
1116
# run clippy on a project, try to be verbose and trigger as many warnings as possible for greater coverage
12-
RUST_BACKTRACE=full cargo clippy --all-targets --all-features -- --cap-lints warn -W clippy::pedantic -W clippy::nursery &> clippy_output
13-
cat clippy_output
14-
! cat clippy_output | grep -q "internal compiler error\|query stack during panic\|E0463"
15-
if [[ $? != 0 ]]; then
16-
return 1
17-
fi
18-
}
17+
RUST_BACKTRACE=full \
18+
cargo clippy \
19+
--all-targets \
20+
--all-features \
21+
-- \
22+
--cap-lints warn -W clippy::pedantic -W clippy::nursery \
23+
> clippy_output 2>&1
1924

20-
case ${INTEGRATION} in
21-
*)
22-
check
23-
;;
24-
esac
25+
cat clippy_output
26+
if grep -q "internal compiler error\|query stack during panic\|E0463" clippy_output; then
27+
exit 1
28+
fi

tests/ui-toml/update-all-references.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ if [[ "$1" == "--help" || "$1" == "-h" ]]; then
1313
fi
1414

1515
BUILD_DIR=$PWD/target/debug/test_build_base
16-
MY_DIR=$(dirname $0)
17-
cd $MY_DIR
18-
find . -name '*.rs' | xargs ./update-references.sh $BUILD_DIR
16+
MY_DIR=$(dirname "$0")
17+
cd "$MY_DIR" || exit
18+
find . -name '*.rs' -exec ./update-references.sh "$BUILD_DIR" {} +

tests/ui-toml/update-references.sh

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if [[ "$1" == "--help" || "$1" == "-h" || "$1" == "" || "$2" == "" ]]; then
1616
echo " $0 ../../../build/x86_64-apple-darwin/test/ui *.rs */*.rs"
1717
fi
1818

19-
MYDIR=$(dirname $0)
19+
MYDIR=$(dirname "$0")
2020

2121
BUILD_DIR="$1"
2222
shift
@@ -25,16 +25,14 @@ while [[ "$1" != "" ]]; do
2525
STDERR_NAME="${1/%.rs/.stderr}"
2626
STDOUT_NAME="${1/%.rs/.stdout}"
2727
shift
28-
if [ -f $BUILD_DIR/$STDOUT_NAME ] && \
29-
! (diff $BUILD_DIR/$STDOUT_NAME $MYDIR/$STDOUT_NAME >& /dev/null); then
30-
echo updating $MYDIR/$STDOUT_NAME
31-
cp $BUILD_DIR/$STDOUT_NAME $MYDIR/$STDOUT_NAME
28+
if [[ -f "$BUILD_DIR"/"$STDOUT_NAME" ]] && \
29+
! (cmp -s -- "$BUILD_DIR"/"$STDOUT_NAME" "$MYDIR"/"$STDOUT_NAME"); then
30+
echo updating "$MYDIR"/"$STDOUT_NAME"
31+
cp "$BUILD_DIR"/"$STDOUT_NAME" "$MYDIR"/"$STDOUT_NAME"
3232
fi
33-
if [ -f $BUILD_DIR/$STDERR_NAME ] && \
34-
! (diff $BUILD_DIR/$STDERR_NAME $MYDIR/$STDERR_NAME >& /dev/null); then
35-
echo updating $MYDIR/$STDERR_NAME
36-
cp $BUILD_DIR/$STDERR_NAME $MYDIR/$STDERR_NAME
33+
if [[ -f "$BUILD_DIR"/"$STDERR_NAME" ]] && \
34+
! (cmp -s -- "$BUILD_DIR"/"$STDERR_NAME" "$MYDIR"/"$STDERR_NAME"); then
35+
echo updating "$MYDIR"/"$STDERR_NAME"
36+
cp "$BUILD_DIR"/"$STDERR_NAME" "$MYDIR"/"$STDERR_NAME"
3737
fi
3838
done
39-
40-

tests/ui/update-all-references.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ if [[ "$1" == "--help" || "$1" == "-h" ]]; then
1313
fi
1414

1515
BUILD_DIR=$PWD/target/debug/test_build_base
16-
MY_DIR=$(dirname $0)
17-
cd $MY_DIR
18-
find . -name '*.rs' | xargs ./update-references.sh $BUILD_DIR
16+
MY_DIR=$(dirname "$0")
17+
cd "$MY_DIR" || exit
18+
find . -name '*.rs' -exec ./update-references.sh "$BUILD_DIR" {} +

tests/ui/update-references.sh

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if [[ "$1" == "--help" || "$1" == "-h" || "$1" == "" || "$2" == "" ]]; then
1616
echo " $0 ../../../build/x86_64-apple-darwin/test/ui *.rs */*.rs"
1717
fi
1818

19-
MYDIR=$(dirname $0)
19+
MYDIR=$(dirname "$0")
2020

2121
BUILD_DIR="$1"
2222
shift
@@ -26,21 +26,19 @@ while [[ "$1" != "" ]]; do
2626
STDOUT_NAME="${1/%.rs/.stdout}"
2727
FIXED_NAME="${1/%.rs/.fixed}"
2828
shift
29-
if [ -f $BUILD_DIR/$STDOUT_NAME ] && \
30-
! (diff $BUILD_DIR/$STDOUT_NAME $MYDIR/$STDOUT_NAME >& /dev/null); then
31-
echo updating $MYDIR/$STDOUT_NAME
32-
cp $BUILD_DIR/$STDOUT_NAME $MYDIR/$STDOUT_NAME
29+
if [[ -f "$BUILD_DIR"/"$STDOUT_NAME" ]] && \
30+
! (cmp -s -- "$BUILD_DIR"/"$STDOUT_NAME" "$MYDIR"/"$STDOUT_NAME"); then
31+
echo updating "$MYDIR"/"$STDOUT_NAME"
32+
cp "$BUILD_DIR"/"$STDOUT_NAME" "$MYDIR"/"$STDOUT_NAME"
3333
fi
34-
if [ -f $BUILD_DIR/$STDERR_NAME ] && \
35-
! (diff $BUILD_DIR/$STDERR_NAME $MYDIR/$STDERR_NAME >& /dev/null); then
36-
echo updating $MYDIR/$STDERR_NAME
37-
cp $BUILD_DIR/$STDERR_NAME $MYDIR/$STDERR_NAME
34+
if [[ -f "$BUILD_DIR"/"$STDERR_NAME" ]] && \
35+
! (cmp -s -- "$BUILD_DIR"/"$STDERR_NAME" "$MYDIR"/"$STDERR_NAME"); then
36+
echo updating "$MYDIR"/"$STDERR_NAME"
37+
cp "$BUILD_DIR"/"$STDERR_NAME" "$MYDIR"/"$STDERR_NAME"
3838
fi
39-
if [ -f $BUILD_DIR/$FIXED_NAME ] && \
40-
! (diff $BUILD_DIR/$FIXED_NAME $MYDIR/$FIXED_NAME >& /dev/null); then
41-
echo updating $MYDIR/$FIXED_NAME
42-
cp $BUILD_DIR/$FIXED_NAME $MYDIR/$FIXED_NAME
39+
if [[ -f "$BUILD_DIR"/"$FIXED_NAME" ]] && \
40+
! (cmp -s -- "$BUILD_DIR"/"$FIXED_NAME" "$MYDIR"/"$FIXED_NAME"); then
41+
echo updating "$MYDIR"/"$FIXED_NAME"
42+
cp "$BUILD_DIR"/"$FIXED_NAME" "$MYDIR"/"$FIXED_NAME"
4343
fi
4444
done
45-
46-

util/fetch_prs_between.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

33
# Fetches the merge commits between two git commits and prints the PR URL
44
# together with the full commit message
@@ -12,14 +12,15 @@ last=$2
1212
IFS='
1313
'
1414
for pr in $(git log --oneline --grep "Merge #" --grep "Merge pull request" --grep "Auto merge of" --grep "Rollup merge of" "$first...$last" | sort -rn | uniq); do
15-
id=$(echo $pr | rg -o '#[0-9]{3,5}' | cut -c 2-)
16-
commit=$(echo $pr | cut -d' ' -f 1)
17-
message=$(git --no-pager show --pretty=medium $commit)
18-
if [ ! -z $(echo "$message" | rg "^[\s]{4}changelog: [nN]one\.*$") ]; then
15+
id=$(echo "$pr" | rg -o '#[0-9]{3,5}' | cut -c 2-)
16+
commit=$(echo "$pr" | cut -d' ' -f 1)
17+
message=$(git --no-pager show --pretty=medium "$commit")
18+
if [[ -n $(echo "$message" | rg "^[\s]{4}changelog: [nN]one\.*$") ]]; then
1919
continue
2020
fi
2121

2222
echo "URL: https://github.com/rust-lang/rust-clippy/pull/$id"
2323
echo "$message"
24-
echo "---------------------------------------------------------\n"
24+
echo "---------------------------------------------------------"
25+
echo
2526
done

0 commit comments

Comments
 (0)