diff --git a/tools/format b/tools/format index d6de1335f9..dc1545d523 100755 --- a/tools/format +++ b/tools/format @@ -13,9 +13,29 @@ # See the License for the specific language governing permissions and # limitations under the License. -find src -name "*.h" -exec clang_format.py -i {} \; -find src -name "*.cc" -exec clang_format.py -i {} \; -find src -name "*.cpp" -exec clang_format.py -i {} \; -find src -name "*.m" -exec clang_format.py -i {} \; -find src -name "*.mm" -exec clang_format.py -i {} \; -find include -name "*.h" -exec clang_format.py -i {} \; +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )" +ROOT_DIR="$( cd "${SCRIPT_DIR}/.." >/dev/null 2>&1 && pwd )" + +set -e # fail on error + +if ! command -v clang_format.py &> /dev/null; then + echo "clang_format.py not found on PATH" + exit 1 +fi + +FILES="" +FILES+="`find src -name "*.h"` " +FILES+="`find src -name "*.cc"` " +FILES+="`find src -name "*.cpp"` " +FILES+="`find src -name "*.m"` " +FILES+="`find src -name "*.mm"` " +FILES+="`find include -name "*.h"` " + +if command -v go &> /dev/null; then + # Go is installed. Run cpplint in parallel for speed wins + ${SCRIPT_DIR}/run run-parallel \ + clang_format.py -i \ + $ -- $FILES +else + clang_format.py -i $FILES +fi diff --git a/tools/lint b/tools/lint index 94a96b646b..23aabc019f 100755 --- a/tools/lint +++ b/tools/lint @@ -24,8 +24,12 @@ if ! command -v cpplint.py &> /dev/null; then fi FILTER="-runtime/references" -FILES="`find src/tint -type f` `find src/tint/cmd -type f`" -FILES+="`find tools/src -type f` `find src/tint/cmd -type f`" + +FILES="" +FILES+="`find src/tint -type f` " +FILES+="`find src/tint/cmd -type f` " +FILES+="`find tools/src -type f` " +FILES+="`find src/tint/cmd -type f` " # Note, there is currently no verbosity level set for cpplint.py which means # it will use the default level of 1. This level needs to match what is in the @@ -33,7 +37,7 @@ FILES+="`find tools/src -type f` `find src/tint/cmd -type f`" if command -v go &> /dev/null; then # Go is installed. Run cpplint in parallel for speed wins - go run $SCRIPT_DIR/src/cmd/run-parallel/main.go \ + ${SCRIPT_DIR}/run run-parallel \ --only-print-failures \ cpplint.py \ --root=$ROOT_DIR \ diff --git a/tools/src/cmd/run-parallel/main.go b/tools/src/cmd/run-parallel/main.go index bab82a2408..1588dcec36 100644 --- a/tools/src/cmd/run-parallel/main.go +++ b/tools/src/cmd/run-parallel/main.go @@ -75,6 +75,7 @@ func run() error { taskIndices := make(chan int, 64) type result struct { + cmd string msg string failed bool } @@ -93,7 +94,7 @@ func run() error { } success, out := invoke(exe, taskArgs) if !success || !*onlyPrintFailures { - results[idx] = result{out, !success} + results[idx] = result{fmt.Sprint(append([]string{exe}, taskArgs...)), out, !success} } } }() @@ -109,7 +110,7 @@ func run() error { failed := false for _, result := range results { if result.msg != "" { - fmt.Println(result.msg) + fmt.Printf("'%v' returned %v\n", result.cmd, result.msg) } failed = failed || result.failed }