From 7dbf5caa5f25551658aee614247aed10012166e2 Mon Sep 17 00:00:00 2001 From: Gil Date: Wed, 6 Jun 2018 12:31:37 -0700 Subject: Fix support scripts on Linux (#1385) * Make it possible to run style.sh on Linux Needs clang-format in a nonstandard location, but can be made to work. * Fix lint.sh on Linux * Fix multiline comment error --- scripts/lint.sh | 18 ++++++++++++++++-- scripts/style.sh | 34 ++++++++++++++++++++++++++-------- 2 files changed, 42 insertions(+), 10 deletions(-) (limited to 'scripts') diff --git a/scripts/lint.sh b/scripts/lint.sh index d474129..3d4f453 100755 --- a/scripts/lint.sh +++ b/scripts/lint.sh @@ -68,10 +68,21 @@ else command=(git ls-files) fi +# POSIX xargs is required to run commands at least once, but cpplint.py fails +# (with huge help text) if no files are supplied. Apple xargs avoids invocation +# if there are no arguments. Use a temporary file to avoid depending on/testing +# for this feature. +TEMP=$(mktemp -t lint-files-$$.XXXXXXXXXX) +trap "rm '$TEMP'" EXIT + # Straight C++ files get regular cpplint "${command[@]}" "${git_options[@]}" \ -- 'Firestore/core/**/*.'{h,cc} \ - | xargs -0 python scripts/cpplint.py --quiet 2>&1 + > "$TEMP" + +if [[ -s "$TEMP" ]]; then + xargs -0 python scripts/cpplint.py --quiet 2>&1 < "$TEMP" +fi CPP_STATUS=$? # Objective-C++ files get a looser cpplint @@ -79,7 +90,10 @@ CPP_STATUS=$? -- 'Firestore/Source/**/*.'{h,m,mm} \ 'Firestore/Example/Tests/**/*.'{h,m,mm} \ 'Firestore/core/**/*.mm' \ - | xargs -0 python scripts/cpplint.py "${objc_lint_options[@]}" --quiet 2>&1 + > "$TEMP" +if [[ -s "$TEMP" ]]; then + xargs -0 python scripts/cpplint.py "${objc_lint_options[@]}" --quiet 2>&1 < "$TEMP" +fi OBJC_STATUS=$? if [[ $CPP_STATUS != 0 || $OBJC_STATUS != 0 ]]; then diff --git a/scripts/style.sh b/scripts/style.sh index 8eff1e8..f82af77 100755 --- a/scripts/style.sh +++ b/scripts/style.sh @@ -21,18 +21,36 @@ # Commonly # ./scripts/style.sh master -system=$(uname -s) - +# Strip the clang-format version output down to the major version. Examples: +# clang-format version 7.0.0 (tags/google/stable/2018-01-11) +# clang-format version google3-trunk (trunk r333779) version=$(clang-format --version) + +# Remove leading "clang-format version" version="${version/*version /}" +# Remove trailing parenthetical version details +version="${version/ (*)/}" +# Remove everything after the first dot (note this is a glob, not a regex) version="${version/.*/}" -if [[ "$version" != 6 && "$version" != 7 ]]; then - # Allow an older clang-format to accommodate Travis version skew. - echo "Please upgrade to clang-format version 7." - echo "If it's installed via homebrew you can run: brew upgrade clang-format" - exit 1 -fi +case "$version" in + 6 | 7) + # Allow an older clang-format to accommodate Travis version skew. + ;; + google3-trunk) + echo "Please use a publicly released clang-format; a recent LLVM release" + echo "from http://releases.llvm.org/download.html will work." + echo "Prepend to PATH when running style.sh." + exit 1 + ;; + *) + echo "Please upgrade to clang-format version 7." + echo "If it's installed via homebrew you can run: brew upgrade clang-format" + exit 1 + ;; +esac + +system=$(uname -s) if [[ "$system" == "Darwin" ]]; then version=$(swiftformat --version) version="${version/*version /}" -- cgit v1.2.3