Commit 09812233 authored by ajm@chromium.org's avatar ajm@chromium.org

Search for the source root rather than checkout root in clang_format.py.

Use the source root (src/ in Chromium) rather than the checkout root as
the path from which to locate the clang-format binaries.

webrtc uses the Chromium build/tools infrastructure but doesn't have
src/ as a source root path. This change allows us to continue to use
'git cl format' in a standalone webrtc checkout (which would be nice.)

BUG=240309
TESTED='git cl format' works on a trivial test change in both a
Chromium and webrtc checkout.

Review URL: https://codereview.chromium.org/135653014

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@248651 0039d316-1c4b-4281-b951-d872f2087c98
parent 26cb836b
...@@ -23,19 +23,20 @@ class NotFoundError(Exception): ...@@ -23,19 +23,20 @@ class NotFoundError(Exception):
' %s' % e) ' %s' % e)
def _FindChromiumTree(): def _FindChromiumSourceRoot():
"""Return the root of the current chromium checkout, or die trying.""" """Return the source root of the current chromium checkout, or die trying."""
source_root = gclient_utils.FindFileUpwards('.gclient') # The use of .gn is somewhat incongruous here, but we need a file uniquely
# existing at src/. GN does the same thing at least.
source_root = gclient_utils.FindFileUpwards('.gn')
if not source_root: if not source_root:
raise NotFoundError( raise NotFoundError(
'.gclient file not found in any parent of the current path.') '.gn file not found in any parent of the current path.')
return source_root return source_root
def FindClangFormatToolInChromiumTree(): def FindClangFormatToolInChromiumTree():
"""Return a path to the clang-format executable, or die trying.""" """Return a path to the clang-format executable, or die trying."""
# The binaries in platform-specific subdirectories in src/tools/gn/bin. tool_path = os.path.join(_FindChromiumSourceRoot(), 'third_party',
tool_path = os.path.join(_FindChromiumTree(), 'src', 'third_party',
'clang_format', 'bin', 'clang_format', 'bin',
gclient_utils.GetMacWinOrLinux(), gclient_utils.GetMacWinOrLinux(),
'clang-format' + gclient_utils.GetExeSuffix()) 'clang-format' + gclient_utils.GetExeSuffix())
...@@ -62,11 +63,11 @@ def FindClangFormatToolInChromiumTree(): ...@@ -62,11 +63,11 @@ def FindClangFormatToolInChromiumTree():
def FindClangFormatScriptInChromiumTree(script_name): def FindClangFormatScriptInChromiumTree(script_name):
"""Return a path to a clang-format helper script, or die trying.""" """Return a path to a clang-format helper script, or die trying."""
script_path = os.path.join(_FindChromiumTree(), 'src', 'third_party', script_path = os.path.join(_FindChromiumSourceRoot(), 'third_party',
'clang_format', 'script', script_name) 'clang_format', 'script', script_name)
if not os.path.exists(script_path): if not os.path.exists(script_path):
# TODO(thakis): Remove the fallback to the old location after a few weeks. # TODO(thakis): Remove the fallback to the old location after a few weeks.
script_path = os.path.join(_FindChromiumTree(), 'src', 'third_party', script_path = os.path.join(_FindChromiumSourceRoot(), 'third_party',
'clang_format', 'scripts', script_name) 'clang_format', 'scripts', script_name)
if not os.path.exists(script_path): if not os.path.exists(script_path):
raise NotFoundError('File does not exist: %s' % script_path) raise NotFoundError('File does not exist: %s' % script_path)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment