From 6dd0b9cbd67478e20361933a994ca01fc1758f43 Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Wed, 2 Jan 2019 17:48:03 -0500 Subject: [PATCH] Buildifier fixes (#87) * fix typo * Handing buildifier exit status better. buildifier started reporting an error for lint issue, update the script to not stop because of that. --- .travis.yml | 4 ++-- .travis_build.sh | 12 ++++++++---- .travis_install.sh | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8fa911e..db865dd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ matrix: - os: linux dist: trusty sudo: false - env: BUILDIFER=RELEASE + env: BUILDIFIER=RELEASE # ----------------------------------------------------------------- # macOS hosted tests @@ -21,7 +21,7 @@ matrix: - os: osx osx_image: xcode10.1 env: BAZEL=HEAD - # No need for a BUILDIFER run on mac, the results will be the same. + # No need for a BUILDIFIER run on mac, the results will be the same. # And linux boxes test faster on travis, so just use the one. before_install: diff --git a/.travis_build.sh b/.travis_build.sh index 3c4525d..706a054 100755 --- a/.travis_build.sh +++ b/.travis_build.sh @@ -24,7 +24,7 @@ fi # ------------------------------------------------------------------------------------------------- # Asked to do a buildifier run. -if [[ -n "${BUILDIFER:-}" ]]; then +if [[ -n "${BUILDIFIER:-}" ]]; then FOUND_ISSUES="no" # buildifier supports BUILD/WORKSPACE/*.bzl files, this provides the args @@ -61,14 +61,18 @@ if [[ -n "${BUILDIFER:-}" ]]; then # Check for lint issues? if [[ "${LINT:-yes}" == "yes" ]] ; then - LINT_ISSUES=$(find . "${FIND_ARGS[@]}" -print | xargs buildifier --lint=warn 2>&1) - if [[ -n "${LINT_ISSUES}" ]] ; then + # NOTE: buildifier defaults to --mode=fix, so these lint runs also + # reformat the files. But since this is on travis, that is fine. + # https://github.com/bazelbuild/buildtools/issues/453 + if ! find . "${FIND_ARGS[@]}" -print | xargs buildifier --lint=warn > /dev/null 2>&1 ; then if [[ "${FOUND_ISSUES}" != "no" ]] ; then echo "" fi echo "ERROR: BUILD/.bzl lint issue(s):" echo "" - echo "${LINT_ISSUES}" + # buildifier now exits with error if there are issues, so use `|| true` + # to keep the script running. + find . "${FIND_ARGS[@]}" -print | xargs buildifier --lint=warn || true echo "" echo "Please download the latest buildifier" echo " https://github.com/bazelbuild/buildtools/releases" diff --git a/.travis_install.sh b/.travis_install.sh index 291dd4a..bef55ea 100755 --- a/.travis_install.sh +++ b/.travis_install.sh @@ -85,7 +85,7 @@ function install_buildifier() { fi if [[ "${VERSION}" == "HEAD" ]]; then - echo "buildifer head is not supported" + echo "buildifier head is not supported" exit 1 fi @@ -104,4 +104,4 @@ function install_buildifier() { # ------------------------------------------------------------------------------------------------- # Install what is requested. [[ -z "${BAZEL:-}" ]] || install_bazel "${BAZEL}" -[[ -z "${BUILDIFER:-}" ]] || install_buildifier "${BUILDIFER}" +[[ -z "${BUILDIFIER:-}" ]] || install_buildifier "${BUILDIFIER}"