Skip to content

Commit 87536f0

Browse files
committed
Auto merge of #4675 - lzutao:improve-shellscript, r=phansch
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 changelog: none
2 parents 850dfda + 088d528 commit 87536f0

10 files changed

+107
-113
lines changed

.github/deploy.sh

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ SSH_REPO=${REPO/https:\/\/github.com\//[email protected]:}
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,44 @@ 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+
pushd out
36+
37+
cat <<-EOF | python - > versions.json
38+
import os, json
39+
print json.dumps([
40+
dir for dir in os.listdir(".") if not dir.startswith(".") and os.path.isdir(dir)
41+
])
42+
EOF
43+
popd
4944

5045
# 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
46+
if [[ "$TRAVIS_PULL_REQUEST" != "false" ]] || [[ "$TRAVIS_BRANCH" != "$SOURCE_BRANCH" ]]; then
5247
# Tags should deploy
53-
if [ -z "$TRAVIS_TAG" ]; then
48+
if [[ -z "$TRAVIS_TAG" ]]; then
5449
echo "Generated, won't push"
5550
exit 0
5651
fi
5752
fi
5853

54+
# Now let's go have some fun with the cloned repo
55+
cd out
56+
git config user.name "Travis CI"
57+
git config user.email "[email protected]"
58+
59+
if git diff --exit-code --quiet; then
60+
echo "No changes to the output on this push; exiting."
61+
exit 0
62+
fi
63+
5964
# Get the deploy key by using Travis's stored variables to decrypt deploy_key.enc
6065
ENCRYPTION_LABEL=e3a2d77100be
6166
ENCRYPTED_KEY_VAR="encrypted_${ENCRYPTION_LABEL}_key"
@@ -64,19 +69,9 @@ ENCRYPTED_KEY=${!ENCRYPTED_KEY_VAR}
6469
ENCRYPTED_IV=${!ENCRYPTED_IV_VAR}
6570
openssl aes-256-cbc -K "$ENCRYPTED_KEY" -iv "$ENCRYPTED_IV" -in .github/deploy_key.enc -out .github/deploy_key -d
6671
chmod 600 .github/deploy_key
67-
eval $(ssh-agent -s)
72+
eval "$(ssh-agent -s)"
6873
ssh-add .github/deploy_key
6974

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 "[email protected]"
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-
8075
git add .
8176
git commit -m "Automatic deploy to GitHub Pages: ${SHA}"
8277

.travis.yml

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
dist: xenial
22
language: bash
33

4-
os:
5-
- linux
6-
- osx
7-
- windows
8-
94
branches:
105
# Don't build these branches
116
except:
@@ -34,13 +29,12 @@ install:
3429
if ! rustup component add rustfmt; then
3530
cargo install -Z install-upgrade --git https://github.com/rust-lang/rustfmt --bin rustfmt
3631
fi
37-
if [ "$TRAVIS_OS_NAME" == "linux" ]; then
32+
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
3833
. $HOME/.nvm/nvm.sh
3934
nvm install stable
4035
nvm use stable
4136
npm install remark-cli remark-lint
42-
fi
43-
if [ "$TRAVIS_OS_NAME" == "windows" ]; then
37+
elif [[ "$TRAVIS_OS_NAME" == "windows" ]]; then
4438
choco install windows-sdk-10.1
4539
fi
4640
fi
@@ -53,11 +47,9 @@ matrix:
5347
include:
5448
# Builds that are executed for every PR
5549
- os: osx # run base tests on both platforms
56-
env: BASE_TESTS=true
5750
- os: linux
58-
env: BASE_TESTS=true
5951
- os: windows
60-
env: CARGO_INCREMENTAL=0 BASE_TESTS=true OS_WINDOWS=true
52+
env: CARGO_INCREMENTAL=0 OS_WINDOWS=true
6153

6254
# Builds that are only executed when a PR is r+ed or a try build is started
6355
# We don't want to run these always because they go towards
@@ -95,51 +87,51 @@ matrix:
9587
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
9688
allow_failures:
9789
- os: windows
98-
env: CARGO_INCREMENTAL=0 BASE_TESTS=true OS_WINDOWS=true
99-
# prevent these jobs with default env vars
100-
exclude:
101-
- os: linux
102-
- os: osx
103-
- os: windows
90+
env: CARGO_INCREMENTAL=0 OS_WINDOWS=true
10491

10592
before_script:
10693
- |
107-
if [ "$TRAVIS_BRANCH" == "auto" ] || [ "$TRAVIS_BRANCH" == "try" ]; then
108-
pr=$(echo $TRAVIS_COMMIT_MESSAGE | grep -o "#[0-9]*" | head -1 | sed 's/^#//g')
109-
output=$(curl -H "Authorization: token $GITHUB_API_TOKEN" -s "https://api.github.com/repos/rust-lang/rust-clippy/pulls/$pr" | \
94+
if [[ "$TRAVIS_BRANCH" == "auto" ]] || [[ "$TRAVIS_BRANCH" == "try" ]]; then
95+
PR=$(echo "$TRAVIS_COMMIT_MESSAGE" | grep -o "#[0-9]*" | head -1 | sed 's/^#//g')
96+
output=$(curl -H "Authorization: token $GITHUB_API_TOKEN" -s "https://api.github.com/repos/rust-lang/rust-clippy/pulls/$PR" | \
11097
python -c "import sys, json; print(json.load(sys.stdin)['body'])" | \
11198
grep "^changelog: " | \
11299
sed "s/changelog: //g")
113-
if [ -z "$output" ]; then
100+
if [[ -z "$output" ]]; then
114101
echo "ERROR: PR body must contain 'changelog: ...'"
115102
exit 1
116-
elif [ "$output" = "none" ]; then
103+
elif [[ "$output" = "none" ]]; then
117104
echo "WARNING: changelog is 'none'"
118105
fi
119106
fi
120107
- |
121108
rm rust-toolchain
122109
./setup-toolchain.sh
123110
- |
124-
if [ "$TRAVIS_OS_NAME" == "windows" ]; then
125-
export PATH=$PATH:$(rustc --print sysroot)/bin
126-
else
127-
export LD_LIBRARY_PATH=$(rustc --print sysroot)/lib
128-
fi
111+
SYSROOT=$(rustc --print sysroot)
112+
case "$TRAVIS_OS_NAME" in
113+
windows ) export PATH="${SYSROOT}/bin:${PATH}" ;;
114+
linux ) export LD_LIBRARY_PATH="${SYSROOT}/lib" ;;
115+
osx )
116+
# See <https://github.com/nteract/nteract/issues/1523#issuecomment-301623519>
117+
sudo mkdir -p /usr/local/lib
118+
sudo find "$SYSROOT/lib" -maxdepth 1 -name '*.dylib' -exec ln -s {} /usr/local/lib \;
119+
;;
120+
esac
129121
130122
script:
131123
- |
132-
if [ -z ${INTEGRATION} ]; then
133-
travis_wait 30 ./ci/base-tests.sh && sleep 5
134-
else
124+
if [[ -n ${INTEGRATION} ]]; then
135125
./ci/integration-tests.sh && sleep 5
126+
else
127+
./ci/base-tests.sh && sleep 5
136128
fi
137129
138130
after_success:
139131
- |
140-
if [ "$TRAVIS_OS_NAME" == "linux" ]; then
132+
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
141133
set -e
142-
if [ -z ${INTEGRATION} ]; then
134+
if [[ -z ${INTEGRATION} ]]; then
143135
./.github/deploy.sh
144136
else
145137
echo "Not deploying, because we're in an integration test run"

ci/base-tests.sh

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

4+
# for faster build, share target dir between subcrates
5+
CARGO_TARGET_DIR=$(pwd)/target/
6+
export CARGO_TARGET_DIR
7+
38
echo "Running clippy base tests"
49

510
PATH=$PATH:./node_modules/.bin
6-
if [ "$TRAVIS_OS_NAME" == "linux" ]; then
7-
remark -f *.md -f doc/*.md > /dev/null
11+
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
12+
remark -f ./*.md -f doc/*.md > /dev/null
813
fi
914
# build clippy in debug mode and run tests
1015
cargo build --features "debugging deny-warnings"
1116
cargo test --features "debugging deny-warnings"
12-
# for faster build, share target dir between subcrates
13-
export CARGO_TARGET_DIR=`pwd`/target/
17+
1418
(cd clippy_lints && cargo test)
1519
(cd rustc_tools_util && cargo test)
1620
(cd clippy_dev && cargo test)
@@ -29,26 +33,27 @@ export CARGO_TARGET_DIR=`pwd`/target/
2933
(
3034
# Check sysroot handling
3135
sysroot=$(./target/debug/clippy-driver --print sysroot)
32-
test $sysroot = $(rustc --print sysroot)
36+
test "$sysroot" = "$(rustc --print sysroot)"
3337

34-
if [ -z $OS_WINDOWS ]; then
38+
if [[ -z "$OS_WINDOWS" ]]; then
3539
desired_sysroot=/tmp
3640
else
3741
desired_sysroot=C:/tmp
3842
fi
3943
sysroot=$(./target/debug/clippy-driver --sysroot $desired_sysroot --print sysroot)
40-
test $sysroot = $desired_sysroot
44+
test "$sysroot" = $desired_sysroot
4145

4246
sysroot=$(SYSROOT=$desired_sysroot ./target/debug/clippy-driver --print sysroot)
43-
test $sysroot = $desired_sysroot
47+
test "$sysroot" = $desired_sysroot
4448

4549
# Make sure this isn't set - clippy-driver should cope without it
4650
unset CARGO_MANIFEST_DIR
4751

4852
# 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
53+
# FIXME: How to match the clippy invocation in compile-test.rs?
54+
./target/debug/clippy-driver -Dwarnings -Aunused -Zui-testing --emit metadata --crate-type bin tests/ui/cstring.rs 2> cstring.stderr && exit 1
55+
sed -e 's,tests/ui,$DIR,' -e '/= help/d' cstring.stderr > normalized.stderr
56+
diff normalized.stderr tests/ui/cstring.stderr
5257

5358
# TODO: CLIPPY_CONF_DIR / CARGO_MANIFEST_DIR
5459
)

ci/integration-tests.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#!/usr/bin/env bash
2-
set -x
2+
set -ex
33

44
if [[ -z "$INTEGRATION" ]]; then
55
exit 0
66
fi
77

8+
CARGO_TARGET_DIR=$(pwd)/target/
9+
export CARGO_TARGET_DIR
10+
811
rm ~/.cargo/bin/cargo-clippy
912
cargo install --force --debug --path .
1013

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/dev

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
#!/bin/sh
2+
CARGO_TARGET_DIR=$(pwd)/target/
3+
export CARGO_TARGET_DIR
24

3-
cd clippy_dev && cargo run -- $@
5+
cd clippy_dev && cargo run -- "$@"

0 commit comments

Comments
 (0)