mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 02:31:29 +00:00
Fix clang-format to work when you're not in a chromium checkout.
Bug: 40861992 Change-Id: Ic9dc3102815febc1e05795b88ed434bed66d123f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6872983 Commit-Queue: Matt Stark <msta@google.com> Reviewed-by: Gavin Mak <gavinmak@google.com>
This commit is contained in:
@@ -84,13 +84,29 @@ def FindClangFormatScriptInChromiumTree(script_name):
|
||||
raise NotFoundError('File does not exist: %s' % script_path)
|
||||
return script_path
|
||||
|
||||
def FindClangFormatInPath():
|
||||
env_path = os.environ.get('PATH')
|
||||
if not env_path:
|
||||
return
|
||||
for bin_dir in env_path.split(os.pathsep):
|
||||
if bin_dir.rstrip(os.sep).endswith('depot_tools'):
|
||||
# skip depot_tools to avoid calling gn.py infinitely.
|
||||
continue
|
||||
tool = os.path.join(
|
||||
bin_dir,
|
||||
'clang-format' + gclient_paths.GetExeSuffix(),
|
||||
)
|
||||
if os.path.isfile(tool):
|
||||
return tool
|
||||
|
||||
def main(args):
|
||||
try:
|
||||
tool = FindClangFormatToolInChromiumTree()
|
||||
except NotFoundError as e:
|
||||
sys.stderr.write("%s\n" % str(e))
|
||||
return 1
|
||||
tool = FindClangFormatInPath()
|
||||
if tool is None:
|
||||
sys.stderr.write("%s\n" % str(e))
|
||||
return 1
|
||||
|
||||
# Add some visibility to --help showing where the tool lives, since this
|
||||
# redirection can be a little opaque.
|
||||
|
||||
5
gn.py
5
gn.py
@@ -37,14 +37,11 @@ def findGnInPath():
|
||||
env_path = os.getenv('PATH')
|
||||
if not env_path:
|
||||
return
|
||||
exe = 'gn'
|
||||
if sys.platform in ('win32', 'cygwin'):
|
||||
exe += '.exe'
|
||||
for bin_dir in env_path.split(os.pathsep):
|
||||
if bin_dir.rstrip(os.sep).endswith('depot_tools'):
|
||||
# skip depot_tools to avoid calling gn.py infinitely.
|
||||
continue
|
||||
gn_path = os.path.join(bin_dir, exe)
|
||||
gn_path = os.path.join(bin_dir, 'gn' + gclient_paths.GetExeSuffix())
|
||||
if os.path.isfile(gn_path):
|
||||
return gn_path
|
||||
|
||||
|
||||
Reference in New Issue
Block a user