Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply final set of Shellcheck fixes and turn on in CI #7832

Merged
merged 16 commits into from
Jun 3, 2019
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ base_linux_config: &base_linux_config
- libssl-dev
- jq
- unzip
- shellcheck
language: python
before_install:
- ./build-support/bin/install_aws_cli_for_ci.sh
Expand Down
1 change: 1 addition & 0 deletions build-support/bin/check_rust_formatting.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ if [[ "${check}" == "true" ]]; then
cmd=("${cmd[@]}" "--check")
fi

# shellcheck disable=SC2207
Eric-Arellano marked this conversation as resolved.
Show resolved Hide resolved
bad_files=(
$(
cd "${NATIVE_ROOT}" || exit "${PIPESTATUS[0]}"
Expand Down
2 changes: 1 addition & 1 deletion build-support/bin/get_added_files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
# Check for copies (-C) and moves (-M), so we don't get false positives when people do
# refactorings. -l50 bounds the time git takes to search for these non-additions.
# See git-diff(1) and https://stackoverflow.com/a/2299672/2518889 for discussion of these options.
exec git diff --cached --name-only --diff-filter=A -C -M -l50
exec git --no-pager diff --cached --name-only --diff-filter=A -C -M -l50
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on how the user has their git set up, this script would sometimes fail. For example, my git for some reason defaults to opening git diff through less.

Now, the script will work no matter what.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know about this argument! Note that many programs (including git) will respect the PAGER env var, and I've usually done this by running the command with PAGER=cat -- but this is definitely better!

1 change: 1 addition & 0 deletions build-support/bin/get_failing_travis_targets_for_pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ for job in ${jobs}; do
;;
"failed")
"${curl[@]}" "https://api.travis-ci.org/job/${job}/log.txt" > "logs/jobs/${job}/txt"
# shellcheck disable=SC2207
targets=("${targets[@]}" $(cat -v "logs/jobs/${job}/txt" | awk '$2 == "....." && $3 ~ /^FAILURE/ {print $1}'))
;;
*)
Expand Down
2 changes: 1 addition & 1 deletion build-support/bin/native/bootstrap_rust.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function bootstrap_rust() {
fi
done

ln -fs "$(dirname "${cargo_bin_dir}")/lib/rustlib/src/rust/src"
ln -fs "$(dirname "${cargo_bin_dir}")/lib/rustlib/src/rust/src" .
Eric-Arellano marked this conversation as resolved.
Show resolved Hide resolved
ln -fs cargo.sh cargo
ln -fs cargo.sh ".${cargo_versioned}"
)
Expand Down
2 changes: 2 additions & 0 deletions build-support/bin/release-changelog-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ do
echo "* ${subject}"

urls=()
# shellcheck disable=SC2207
urls=(
"${urls[@]}"
$(
Expand All @@ -82,6 +83,7 @@ do
sed -Ee "s|^\(#([0-9]+)\)$|https://github.com/pantsbuild/pants/pull/\1|"
)
)
# shellcheck disable=SC2207
urls=(
"${urls[@]}"
$(
Expand Down
11 changes: 7 additions & 4 deletions build-support/bin/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ function build_pants_packages() {
pants_version_set "${version}"

start_travis_section "${NAME}" "Building packages"
# shellcheck disable=SC2207
packages=(
$(run_packages_script build_and_print "${version}")
) || die "Failed to build packages at ${version}!"
Expand Down Expand Up @@ -315,6 +316,7 @@ function install_and_test_packages() {
export PANTS_PLUGIN_CACHE_DIR
trap 'rm -rf "${PANTS_PLUGIN_CACHE_DIR}"' EXIT

# shellcheck disable=SC2207
packages=(
$(run_packages_script list | grep '.' | awk '{print $1}')
) || die "Failed to list packages!"
Expand Down Expand Up @@ -515,11 +517,12 @@ function fetch_and_check_prebuilt_wheels() {
fetch_prebuilt_wheels "${check_dir}"

local missing=()
# shellcheck disable=SC2207
RELEASE_PACKAGES=(
$(run_packages_script list | grep '.' | awk '{print $1}')
) || die "Failed to get a list of packages to release!"
for PACKAGE in "${RELEASE_PACKAGES[@]}"
do
for PACKAGE in "${RELEASE_PACKAGES[@]}"; do
# shellcheck disable=SC2207
packages=($(find_pkg "${PACKAGE}" "${PANTS_UNSTABLE_VERSION}" "${check_dir}"))
if [ ${#packages[@]} -eq 0 ]; then
missing+=("${PACKAGE}")
Expand All @@ -528,8 +531,7 @@ function fetch_and_check_prebuilt_wheels() {

# Confirm that if the package is not cross platform that we have whls for two platforms.
local cross_platform=""
for package in "${packages[@]}"
do
for package in "${packages[@]}"; do
if [[ "${package}" =~ -none-any.whl ]]
then
cross_platform="true"
Expand Down Expand Up @@ -559,6 +561,7 @@ function adjust_wheel_platform() {
local src_plat="$1"
local dst_plat="$2"
local dir="$3"
# shellcheck disable=SC2044
Eric-Arellano marked this conversation as resolved.
Show resolved Hide resolved
for src_whl in $(find "${dir}" -name '*'"${src_plat}.whl"); do
local dst_whl=${src_whl/$src_plat/$dst_plat}
mv -f "${src_whl}" "${dst_whl}"
Expand Down
4 changes: 1 addition & 3 deletions build-support/bin/shellcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import subprocess
from glob import glob

from common import die, green
from common import die


def main() -> None:
Expand Down Expand Up @@ -37,8 +37,6 @@ def run_shellcheck() -> None:
subprocess.run(command, check=True)
except subprocess.CalledProcessError:
die("Please fix the above errors and run again.")
else:
green("./pants passed the shellcheck!")


if __name__ == "__main__":
Expand Down
15 changes: 8 additions & 7 deletions build-support/githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,23 @@ DIRS_TO_CHECK=(
# integration test!
set -e

# You can use ("$()") with double quotes in zsh, I assume this splits by IFS...
# shellcheck disable=SC2207
ADDED_FILES=($(./build-support/bin/get_added_files.sh))
MERGE_BASE="$(git_merge_base)"

echo "* Checking packages"
# TODO: Determine the most *hygienic* way to split an array on the command line in portable bash,
# and stick to it.
./build-support/bin/check_packages.sh "${DIRS_TO_CHECK[@]}"
./build-support/bin/check_packages.sh "${DIRS_TO_CHECK[@]}" || exit 1

echo "* Checking headers"
./build-support/bin/check_header.py "${DIRS_TO_CHECK[@]}" --files-added "${ADDED_FILES[@]}"
./build-support/bin/check_header.py "${DIRS_TO_CHECK[@]}" --files-added "${ADDED_FILES[@]}" || exit 1

echo "* Checking for banned imports"
./build-support/bin/check_banned_imports.py
./build-support/bin/check_banned_imports.py || exit 1

echo "* Checking for bad shell patterns"
echo "* Checking shell scripts via shellcheck"
./build-support/bin/shellcheck.py || exit 1

echo "* Checking shell scripts via our custom linter"
./build-support/bin/check_shell.sh || exit 1

# When travis builds a tag, it does so in a shallow clone without master fetched, which
Expand Down
1 change: 1 addition & 0 deletions build-support/travis/travis.yml.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ base_linux_config: &base_linux_config
- libssl-dev
- jq
- unzip
- shellcheck
language: python
before_install:
- ./build-support/bin/install_aws_cli_for_ci.sh
Expand Down
4 changes: 2 additions & 2 deletions contrib/release_packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ function pkg_scrooge_install_test() {
function pkg_buildgen_install_test() {
local version=$1
shift
local PIP_ARGS="$@"
pip install ${PIP_ARGS} "pantsbuild.pants.contrib.buildgen==${version}" && \
local PIP_ARGS=("$@")
pip install "${PIP_ARGS[@]}" "pantsbuild.pants.contrib.buildgen==${version}" && \
python -c "from pants.contrib.buildgen.build_file_manipulator import *"
}

Expand Down
6 changes: 4 additions & 2 deletions pants
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export PANTS_PYTHON_SETUP_INTERPRETER_CONSTRAINTS="${PANTS_PYTHON_SETUP_INTERPRE
PANTS_EXE="${HERE}/src/python/pants/bin/pants_loader.py"

if [[ -n "${WRAPPER_REQUIREMENTS}" ]]; then
# shellcheck disable=SC2207
REQUIREMENTS=(
$(echo "${WRAPPER_REQUIREMENTS}" | tr : ' ')
"${REQUIREMENTS[@]}"
Expand All @@ -83,18 +84,19 @@ PANTS_SRCPATH=(
"${HERE}/src/python"
)
if [[ -n "${WRAPPER_SRCPATH}" ]]; then
# shellcheck disable=SC2207
PANTS_SRCPATH=(
$(echo "${WRAPPER_SRCPATH}" | tr : ' ')
"${PANTS_SRCPATH[@]}"
)
fi
PANTS_SRCPATH="$(echo "${PANTS_SRCPATH[@]}" | tr ' ' :)"
PANTS_SRCPATH_STR="$(echo "${PANTS_SRCPATH[@]}" | tr ' ' :)"
Eric-Arellano marked this conversation as resolved.
Show resolved Hide resolved

function exec_pants_bare() {
# Redirect activation and native bootstrap to ensure that they don't interfere with stdout.
activate_pants_venv 1>&2
bootstrap_native_code 1>&2
PYTHONPATH="${PANTS_SRCPATH}:${PYTHONPATH}" \
PYTHONPATH="${PANTS_SRCPATH_STR}:${PYTHONPATH}" \
exec python "${PANTS_EXE}" "$@"
}

Expand Down
4 changes: 2 additions & 2 deletions src/docs/publish_via_git.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ set -eo pipefail
# If a file "went away", this won't remove it.

root=$(
cd "$(dirname $0)"
cd "$(dirname "$0")"
/bin/pwd
)

Expand All @@ -32,7 +32,7 @@ path_within_url=$2
out=/tmp/pantsdoc.$$

# When done, clean up tmp dir:
trap "rm -fr $out" 0 1 2
trap 'rm -fr $out' 0 1 2
Eric-Arellano marked this conversation as resolved.
Show resolved Hide resolved

mkdir -p $out
cd $out
Expand Down