LoginSignup
0
0

More than 5 years have passed since last update.

clang-formatがProblem while looking for clang-format in Chromium source treeとか吐いて死ぬ場合の対処法

Posted at

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" "$@"
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0