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>
This commit is contained in:
Ben Clayton 2022-12-06 18:29:08 +00:00 committed by Dawn LUCI CQ
parent d933470b20
commit f2b8d2b1ab
3 changed files with 36 additions and 11 deletions

View File

@ -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

View File

@ -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 \

View File

@ -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
}