aboutsummaryrefslogtreecommitdiff
path: root/presubmit.sh
diff options
context:
space:
mode:
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