Skip to content

Commit 1f59885

Browse files
committed
Merge bitcoin#17361: script: Lint Gitian descriptors with ShellCheck
17f81e9 script: Enable SC2001 rule for Gitian scripts (Hennadii Stepanov) 61bb21b script: Enable SC2155 rule for Gitian scripts (Hennadii Stepanov) 577682d script: Enable SC2006 rule for Gitian scripts (Hennadii Stepanov) 14aded4 script: Lint Gitian descriptors with ShellCheck (Hennadii Stepanov) Pull request description: This PR extracts shell scripts from Gitian descriptors (`contrib/gitian-descriptors/`) and checks for ShellCheck warnings as any other one. Some non-controversial warnings are fixed. ACKs for top commit: practicalswift: ACK 17f81e9 -- diff looks correct Tree-SHA512: bdfa3d35bbb65ff634c90835d75c3df63e958b558599771d21366724f5cf64da83a68957d926e926a99c3704b9529e96a17697dc8d9ff3adf7154d9cb1999a8d
2 parents d8a6662 + 17f81e9 commit 1f59885

File tree

8 files changed

+65
-32
lines changed

8 files changed

+65
-32
lines changed

ci/lint/04_install.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#!/usr/bin/env bash
22
#
3-
# Copyright (c) 2018 The Bitcoin Core developers
3+
# Copyright (c) 2018-2019 The Bitcoin Core developers
44
# Distributed under the MIT software license, see the accompanying
55
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
66

77
export LC_ALL=C
88

99
travis_retry pip3 install codespell==1.15.0
1010
travis_retry pip3 install flake8==3.7.8
11+
travis_retry pip3 install yq
1112

1213
SHELLCHECK_VERSION=v0.6.0
1314
curl -s "https://storage.googleapis.com/shellcheck/shellcheck-${SHELLCHECK_VERSION}.linux.x86_64.tar.xz" | tar --xz -xf - --directory /tmp/

contrib/gitian-descriptors/gitian-linux.yml

+8-7
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ script: |
5151
export QT_RCC_TEST=1
5252
export QT_RCC_SOURCE_DATE_OVERRIDE=1
5353
export TZ="UTC"
54-
export BUILD_DIR=`pwd`
54+
export BUILD_DIR="$PWD"
5555
mkdir -p ${WRAP_DIR}
5656
if test -n "$GBUILD_CACHE_ENABLED"; then
5757
export SOURCES_PATH=${GBUILD_COMMON_CACHE}
@@ -108,7 +108,7 @@ script: |
108108
rm -f ${WRAP_DIR}/${prog}
109109
cat << EOF > ${WRAP_DIR}/${prog}
110110
#!/usr/bin/env bash
111-
REAL="`which -a ${prog}-8 | grep -v ${WRAP_DIR}/${prog} | head -1`"
111+
REAL="$(which -a ${prog}-8 | grep -v ${WRAP_DIR}/${prog} | head -1)"
112112
for var in "\$@"
113113
do
114114
if [ "\$var" = "-m32" ]; then
@@ -123,7 +123,7 @@ script: |
123123
done
124124
125125
cd bitcoin
126-
BASEPREFIX=`pwd`/depends
126+
BASEPREFIX="${PWD}/depends"
127127
# Build dependencies for each host
128128
for i in $HOSTS; do
129129
EXTRA_INCLUDES="$EXTRA_INCLUDES_BASE/$i"
@@ -142,10 +142,11 @@ script: |
142142
143143
# Create the release tarball using (arbitrarily) the first host
144144
./autogen.sh
145-
CONFIG_SITE=${BASEPREFIX}/`echo "${HOSTS}" | awk '{print $1;}'`/share/config.site ./configure --prefix=/
145+
CONFIG_SITE=${BASEPREFIX}/$(echo "${HOSTS}" | awk '{print $1;}')/share/config.site ./configure --prefix=/
146146
make dist
147-
SOURCEDIST=`echo bitcoin-*.tar.gz`
148-
DISTNAME=`echo ${SOURCEDIST} | sed 's/.tar.*//'`
147+
SOURCEDIST=$(echo bitcoin-*.tar.gz)
148+
DISTNAME=${SOURCEDIST/%.tar.gz}
149+
149150
# Correct tar file order
150151
mkdir -p temp
151152
pushd temp
@@ -169,7 +170,7 @@ script: |
169170
fi
170171
mkdir -p distsrc-${i}
171172
cd distsrc-${i}
172-
INSTALLPATH=`pwd`/installed/${DISTNAME}
173+
INSTALLPATH="${PWD}/installed/${DISTNAME}"
173174
mkdir -p ${INSTALLPATH}
174175
tar --strip-components=1 -xf ../$SOURCEDIST
175176

contrib/gitian-descriptors/gitian-osx-signer.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ script: |
1717
1818
WRAP_DIR=$HOME/wrapped
1919
mkdir -p ${WRAP_DIR}
20-
export PATH=`pwd`:$PATH
20+
export PATH="$PWD":$PATH
2121
FAKETIME_PROGS="dmg genisoimage"
2222
2323
# Create global faketime wrappers

contrib/gitian-descriptors/gitian-osx.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ script: |
4545
export QT_RCC_TEST=1
4646
export QT_RCC_SOURCE_DATE_OVERRIDE=1
4747
export TZ="UTC"
48-
export BUILD_DIR=`pwd`
48+
export BUILD_DIR="$PWD"
4949
mkdir -p ${WRAP_DIR}
5050
if test -n "$GBUILD_CACHE_ENABLED"; then
5151
export SOURCES_PATH=${GBUILD_COMMON_CACHE}
@@ -87,7 +87,7 @@ script: |
8787
export PATH=${WRAP_DIR}:${PATH}
8888
8989
cd bitcoin
90-
BASEPREFIX=`pwd`/depends
90+
BASEPREFIX="${PWD}/depends"
9191
9292
mkdir -p ${BASEPREFIX}/SDKs
9393
tar -C ${BASEPREFIX}/SDKs -xf ${BUILD_DIR}/MacOSX10.11.sdk.tar.gz
@@ -105,10 +105,10 @@ script: |
105105
106106
# Create the release tarball using (arbitrarily) the first host
107107
./autogen.sh
108-
CONFIG_SITE=${BASEPREFIX}/`echo "${HOSTS}" | awk '{print $1;}'`/share/config.site ./configure --prefix=/
108+
CONFIG_SITE=${BASEPREFIX}/$(echo "${HOSTS}" | awk '{print $1;}')/share/config.site ./configure --prefix=/
109109
make dist
110-
SOURCEDIST=`echo bitcoin-*.tar.gz`
111-
DISTNAME=`echo ${SOURCEDIST} | sed 's/.tar.*//'`
110+
SOURCEDIST=$(echo bitcoin-*.tar.gz)
111+
DISTNAME=${SOURCEDIST/%.tar.gz}
112112
113113
# Correct tar file order
114114
mkdir -p temp
@@ -126,7 +126,7 @@ script: |
126126
export PATH=${BASEPREFIX}/${i}/native/bin:${ORIGPATH}
127127
mkdir -p distsrc-${i}
128128
cd distsrc-${i}
129-
INSTALLPATH=`pwd`/installed/${DISTNAME}
129+
INSTALLPATH="${PWD}/installed/${DISTNAME}"
130130
mkdir -p ${INSTALLPATH}
131131
tar --strip-components=1 -xf ../$SOURCEDIST
132132

contrib/gitian-descriptors/gitian-win-signer.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ files:
1919
script: |
2020
set -e -o pipefail
2121
22-
BUILD_DIR=`pwd`
22+
BUILD_DIR="$PWD"
2323
SIGDIR=${BUILD_DIR}/signature/win
2424
UNSIGNED_DIR=${BUILD_DIR}/unsigned
2525
@@ -35,7 +35,7 @@ script: |
3535
./configure --without-gsf --without-curl --disable-dependency-tracking
3636
make
3737
find ${UNSIGNED_DIR} -name "*-unsigned.exe" | while read i; do
38-
INFILE="`basename "${i}"`"
39-
OUTFILE="`echo "${INFILE}" | sed s/-unsigned//`"
38+
INFILE="$(basename "${i}")"
39+
OUTFILE="${INFILE/%-unsigned}"
4040
./osslsigncode attach-signature -in "${i}" -out "${OUTDIR}/${OUTFILE}" -sigin "${SIGDIR}/${INFILE}.pem"
4141
done

contrib/gitian-descriptors/gitian-win.yml

+7-6
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ script: |
4040
export QT_RCC_TEST=1
4141
export QT_RCC_SOURCE_DATE_OVERRIDE=1
4242
export TZ="UTC"
43-
export BUILD_DIR=`pwd`
43+
export BUILD_DIR="$PWD"
4444
mkdir -p ${WRAP_DIR}
4545
if test -n "$GBUILD_CACHE_ENABLED"; then
4646
export SOURCES_PATH=${GBUILD_COMMON_CACHE}
@@ -97,7 +97,7 @@ script: |
9797
export PATH=${WRAP_DIR}:${PATH}
9898
9999
cd bitcoin
100-
BASEPREFIX=`pwd`/depends
100+
BASEPREFIX="${PWD}/depends"
101101
# Build dependencies for each host
102102
for i in $HOSTS; do
103103
make ${MAKEOPTS} -C ${BASEPREFIX} HOST="${i}"
@@ -112,10 +112,11 @@ script: |
112112
113113
# Create the release tarball using (arbitrarily) the first host
114114
./autogen.sh
115-
CONFIG_SITE=${BASEPREFIX}/`echo "${HOSTS}" | awk '{print $1;}'`/share/config.site ./configure --prefix=/
115+
CONFIG_SITE=${BASEPREFIX}/$(echo "${HOSTS}" | awk '{print $1;}')/share/config.site ./configure --prefix=/
116116
make dist
117-
SOURCEDIST=`echo bitcoin-*.tar.gz`
118-
DISTNAME=`echo ${SOURCEDIST} | sed 's/.tar.*//'`
117+
SOURCEDIST=$(echo bitcoin-*.tar.gz)
118+
DISTNAME=${SOURCEDIST/%.tar.gz}
119+
119120
# Correct tar file order
120121
mkdir -p temp
121122
pushd temp
@@ -132,7 +133,7 @@ script: |
132133
export PATH=${BASEPREFIX}/${i}/native/bin:${ORIGPATH}
133134
mkdir -p distsrc-${i}
134135
cd distsrc-${i}
135-
INSTALLPATH=`pwd`/installed/${DISTNAME}
136+
INSTALLPATH="${PWD}/installed/${DISTNAME}"
136137
mkdir -p ${INSTALLPATH}
137138
tar --strip-components=1 -xf ../$SOURCEDIST
138139

test/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ Use the `-v` option for verbose output.
258258
|-----------|:----------:|:-------------------------------------------:|--------------
259259
| [`lint-python.sh`](lint/lint-python.sh) | [flake8](https://gitlab.com/pycqa/flake8) | [3.7.8](https://github.com/bitcoin/bitcoin/pull/15257) | `pip3 install flake8==3.7.8`
260260
| [`lint-shell.sh`](lint/lint-shell.sh) | [ShellCheck](https://github.com/koalaman/shellcheck) | [0.6.0](https://github.com/bitcoin/bitcoin/pull/15166) | [details...](https://github.com/koalaman/shellcheck#installing)
261+
| [`lint-shell.sh`](lint/lint-shell.sh) | [yq](https://github.com/kislyuk/yq) | default | `pip3 install yq`
261262
| [`lint-spelling.sh`](lint/lint-spelling.sh) | [codespell](https://github.com/codespell-project/codespell) | [1.15.0](https://github.com/bitcoin/bitcoin/pull/16186) | `pip3 install codespell==1.15.0`
262263

263264
Please be aware that on Linux distributions all dependencies are usually available as packages, but could be outdated.

test/lint/lint-shell.sh

+37-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
#
3-
# Copyright (c) 2018 The Bitcoin Core developers
3+
# Copyright (c) 2018-2019 The Bitcoin Core developers
44
# Distributed under the MIT software license, see the accompanying
55
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
66
#
@@ -16,16 +16,45 @@ if [ "$TRAVIS" = "true" ]; then
1616
unset LC_ALL
1717
fi
1818

19-
if ! command -v shellcheck > /dev/null; then
20-
echo "Skipping shell linting since shellcheck is not installed."
21-
exit 0
22-
fi
23-
2419
# Disabled warnings:
2520
disabled=(
2621
SC2046 # Quote this to prevent word splitting.
2722
SC2086 # Double quote to prevent globbing and word splitting.
2823
SC2162 # read without -r will mangle backslashes.
2924
)
30-
shellcheck -e "$(IFS=","; echo "${disabled[*]}")" \
31-
$(git ls-files -- "*.sh" | grep -vE 'src/(secp256k1|univalue)/')
25+
disabled_gitian=(
26+
SC2094 # Make sure not to read and write the same file in the same pipeline.
27+
SC2129 # Consider using { cmd1; cmd2; } >> file instead of individual redirects.
28+
SC2230 # which is non-standard. Use builtin 'command -v' instead.
29+
)
30+
31+
EXIT_CODE=0
32+
33+
if ! command -v shellcheck > /dev/null; then
34+
echo "Skipping shell linting since shellcheck is not installed."
35+
exit $EXIT_CODE
36+
fi
37+
38+
EXCLUDE="--exclude=$(IFS=','; echo "${disabled[*]}")"
39+
if ! shellcheck "$EXCLUDE" $(git ls-files -- '*.sh' | grep -vE 'src/(leveldb|secp256k1|univalue)/'); then
40+
EXIT_CODE=1
41+
fi
42+
43+
if ! command -v yq > /dev/null; then
44+
echo "Skipping Gitian desriptor scripts checking since yq is not installed."
45+
exit $EXIT_CODE
46+
fi
47+
48+
EXCLUDE_GITIAN=${EXCLUDE}",$(IFS=','; echo "${disabled_gitian[*]}")"
49+
for descriptor in $(git ls-files -- 'contrib/gitian-descriptors/*.yml')
50+
do
51+
echo
52+
echo "$descriptor"
53+
# Use #!/bin/bash as gitian-builder/bin/gbuild does to complete a script.
54+
SCRIPT=$'#!/bin/bash\n'$(yq -r .script "$descriptor")
55+
if ! echo "$SCRIPT" | shellcheck "$EXCLUDE_GITIAN" -; then
56+
EXIT_CODE=1
57+
fi
58+
done
59+
60+
exit $EXIT_CODE

0 commit comments

Comments
 (0)