chromiumやskiaのビルド環境を整えた状態でそれらと関係ないプロジェクトでclang-formatを実行すると
% clang-format
Problem while looking for clang-format in Chromium source tree:
Could not find checkout in any parent of the current path.
とか言われて死ぬことがある
解決策1: direnvを使う
direnvでchromium系のディレクトリだけdepot_toolsを有効にすれば良い
解決策2
自前でネイティブのclang-formatを探せばいいじゃない
#!/bin/sh
set -eu
if ! which clang-format > /dev/null 2>&1; then
exit 1
fi
clang_format=
for qdir in '' $(echo "$PATH" | sed -e 's|:|/" "|g' | sed -e 's|^|"|' | sed -e 's|$|/"|'); do
dir=$(echo "$qdir" | sed 's/^"//' | sed 's/"$//')
if (! which "${dir}clang-format" 2>&1 || ("${dir}clang-format" --version 2>&1 | grep "Problem while looking for clang-format")) > /dev/null; then
continue
fi
clang_format="${dir}clang-format"
break
done
if [ -z "$clang_format" ]; then
exit 1
fi
"$clang_format" "$@"