@ -15,7 +15,7 @@ import gclient_paths
import gn_helper
import gn_helper
def find NinjaInP ath( ) :
def find _ninja_in_p ath( ) :
env_path = os . getenv ( " PATH " )
env_path = os . getenv ( " PATH " )
if not env_path :
if not env_path :
return
return
@ -23,14 +23,16 @@ def findNinjaInPath():
if sys . platform in ( " win32 " , " cygwin " ) :
if sys . platform in ( " win32 " , " cygwin " ) :
exe + = " .exe "
exe + = " .exe "
for bin_dir in env_path . split ( os . pathsep ) :
for bin_dir in env_path . split ( os . pathsep ) :
if bin_dir . rstrip ( os . sep ) . endswith ( " depot_tools " ) :
bin_dir = bin_dir . rstrip ( os . sep )
if os . path . basename ( bin_dir ) == " depot_tools " :
# skip depot_tools to avoid calling ninja.py infinitely.
# skip depot_tools to avoid calling ninja.py infinitely.
continue
continue
ninja_path = os . path . join ( bin_dir , exe )
ninja_path = os . path . join ( bin_dir , exe )
if os . path . isfile ( ninja_path ) :
if os . path . isfile ( ninja_path ) :
return ninja_path
return ninja_path
def checkOutdir ( ninja_args ) :
def check_out_dir ( ninja_args ) :
out_dir = " . "
out_dir = " . "
tool = " "
tool = " "
for i , arg in enumerate ( ninja_args ) :
for i , arg in enumerate ( ninja_args ) :
@ -65,11 +67,12 @@ def checkOutdir(ninja_args):
file = sys . stderr )
file = sys . stderr )
sys . exit ( 1 )
sys . exit ( 1 )
def fallback ( ninja_args ) :
def fallback ( ninja_args ) :
# Try to find ninja in PATH.
# Try to find ninja in PATH.
ninja_path = find NinjaInP ath( )
ninja_path = find _ninja_in_p ath( )
if ninja_path :
if ninja_path :
check Out dir( ninja_args )
check _out_ dir( ninja_args )
return subprocess . call ( [ ninja_path ] + ninja_args )
return subprocess . call ( [ ninja_path ] + ninja_args )
print (
print (
@ -120,7 +123,7 @@ def main(args):
" ninja " + gclient_paths . GetExeSuffix ( ) ,
" ninja " + gclient_paths . GetExeSuffix ( ) ,
)
)
if os . path . isfile ( ninja_path ) :
if os . path . isfile ( ninja_path ) :
check Out dir( args [ 1 : ] )
check _out_ dir( args [ 1 : ] )
return subprocess . call ( [ ninja_path ] + args [ 1 : ] )
return subprocess . call ( [ ninja_path ] + args [ 1 : ] )
return fallback ( args [ 1 : ] )
return fallback ( args [ 1 : ] )