aboutsummaryrefslogtreecommitdiff
path: root/presubmit.sh
diff options
context:
space:
mode:
authorKevin Brodsky <kevin.brodsky@linaro.org>2017-01-06 11:48:45 +0000
committerKevin Brodsky <kevin.brodsky@linaro.org>2017-01-25 10:39:41 +0000
commitf77fec676cbb2729fa6757ea8fc1d936c3ec5ecc (patch)
tree4253c0e74c79b6c31b8fb5220f28d7899721dad4 /presubmit.sh
parenta33974f97445f61e1623784ea4dba3eea6986383 (diff)
Use the latest shellcheck
Move to using the latest shellcheck as our presubmit checker, as it has been greatly improved since the current 0.3.3 version. Since the latest version (0.4.5) is not available on Ubuntu and compiling it from source is not practical (ghc is a huge dependency), we now host a prebuilt version on git.linaro.org. Summary of the changes: * Modify presubmit.sh so that it fetches the latest version from a repo in git.linaro.org to shellcheck/shellcheck. To avoid redownloading the binary (~15 MB) every time, the repo provides a checksum, to know whether a newer version has been pushed. * Update README.md accordingly. * Pass --color to shellcheck for a fancy output! * Fix new warnings (either with disable directives or by fixing the code). Globally disable some of them that can't (or don't need to) be fixed. * In sourced files defining variables (in devices/), we can finally use a file-scoped disable for SC2034 (which can't be easily fixed). At last, readable config files! * Review all of the existing disable directives. shellcheck got smarter and some were not needed anymore; in other cases they could be fixed with minor code changes. Change-Id: I772b8d0de061842d3aa880b1176c02c72bd3650d
Diffstat (limited to 'presubmit.sh')
-rwxr-xr-xpresubmit.sh45
1 files changed, 30 insertions, 15 deletions
diff --git a/presubmit.sh b/presubmit.sh
index 0d356f1..227ce92 100755
--- a/presubmit.sh
+++ b/presubmit.sh
@@ -5,11 +5,14 @@
readonly local_path=$(dirname "$0")
source "${local_path}/utils/utils.sh"
-readonly shellcheck_version=" 0.3.3"
+readonly shellcheck_path="${local_path}/shellcheck/shellcheck"
+readonly shellcheck_url="https://git.linaro.org/people/kevin.brodsky/shellcheck-prebuilt.git/plain/shellcheck"
# Globally excluded shellcheck "checks"
-# SC2102 - https://github.com/koalaman/shellcheck/issues/682
-readonly shellcheck_exclude_list="SC2102"
+# SC1090: shellcheck can't source files whose path is determined at runtime
+# (we almost always use ${local_path} when sourcing)
+# SC2155: almost never an actual problem
+readonly shellcheck_exclude_list="SC1090,SC2155"
declare -a shell_files
@@ -20,23 +23,35 @@ find_shell_files() {
readonly shell_files
}
-# Run shellcheck on all the .sh files.
-shellcheck_tests() {
- if ! exists shellcheck; then
- log E "No \"shellcheck\" available in your path. apt-get install shellcheck ?"
- log E "You can also find shellcheck here: https://github.com/koalaman/shellcheck ."
- log E "Please note that the scripts have only been tested with version ${shellcheck_version}."
- return 1
+# Fetch shellcheck from our own prebuilt shellcheck repo.
+fetch_shellcheck() {
+ # We use a sha1 checksum to know whether we need to download a newer version.
+ local -r remote_sha1=$(safe curl -s "${shellcheck_url}.sha1")
+ local -r sha1_regex='[0-9a-f]+\s+shellcheck'
+ if ! [[ ${remote_sha1} =~ $sha1_regex ]]; then
+ log E "Invalid remote sha1: ${remote_sha1}"
+ abort
fi
- local current_shellcheck_version=$(shellcheck -V | grep -i "version:")
- if [[ ! ${current_shellcheck_version} =~ ${shellcheck_version} ]]; then
- log W "The scripts have only been tested with shellcheck version ${shellcheck_version}."
- log W "Things might fail!"
+ if [[ -e "${shellcheck_path}" && -e "${shellcheck_path}.sha1" && \
+ $(< "${shellcheck_path}.sha1") == "${remote_sha1}" ]]; then
+ # We already have the latest shellcheck
+ return
fi
+ # Download the latest shellcheck
+ mkdir -p "$(dirname "${shellcheck_path}")"
+ log I "Downloading shellcheck to ${shellcheck_path}"
+ safe curl -s -o "${shellcheck_path}" "${shellcheck_url}"
+ chmod +x "${shellcheck_path}"
+ # Update the sha1
+ echo "${remote_sha1}" > "${shellcheck_path}.sha1"
+}
- shellcheck -e "${shellcheck_exclude_list}" "${shell_files[@]}"
+# Run shellcheck on all the .sh files.
+shellcheck_tests() {
+ fetch_shellcheck
+ "${shellcheck_path}" --color -e "${shellcheck_exclude_list}" "${shell_files[@]}"
}
# Check for invalid constructions regarding read-only variables and the local