@ -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 (
' .g clie nt file not found in any parent of the current path.' )
' .g n 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():
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 ( _FindChromium Tree( ) , ' src ' , ' third_party ' ,
script_path = os . path . join ( _FindChromium SourceRoot( ) , ' 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 ( _FindChromium Tree( ) , ' src ' , ' third_party ' ,
script_path = os . path . join ( _FindChromium SourceRoot( ) , ' 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 )