tools: Parallelize ./tools/format
10x speed improvement on my 3990x machine
Change-Id: Ie4b2377719e9a25860ec05bb7649aa652d26ccf0
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/113022
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Ben Clayton <bclayton@google.com>
diff --git a/tools/format b/tools/format
index d6de133..dc1545d 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 94a96b6..23aabc0 100755
--- a/tools/lint
+++ b/tools/lint
@@ -24,8 +24,12 @@
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 @@
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 bab82a2..1588dce 100644
--- a/tools/src/cmd/run-parallel/main.go
+++ b/tools/src/cmd/run-parallel/main.go
@@ -75,6 +75,7 @@
taskIndices := make(chan int, 64)
type result struct {
+ cmd string
msg string
failed bool
}
@@ -93,7 +94,7 @@
}
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 @@
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
}