ninja: Improve depot_tools directory detection

Tweak the code in ninja.py so it would only skip directories in $PATH
that are named "depot_tools". The existing detection logic skips
"foo_depot_tools". Also rename functions in the file to follow Python
Style and auto-format the file.

Change-Id: I631958768168f0d673b824c8e14783d2c6f65563
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6259139
Reviewed-by: Junji Watanabe <jwata@google.com>
Commit-Queue: Lei Zhang <thestig@chromium.org>
changes/39/6259139/2
Lei Zhang 2 weeks ago committed by LUCI CQ
parent 2451ee476d
commit 664154a905

@ -15,7 +15,7 @@ import gclient_paths
import gn_helper
def findNinjaInPath():
def find_ninja_in_path():
env_path = os.getenv("PATH")
if not env_path:
return
@ -23,14 +23,16 @@ def findNinjaInPath():
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"):
bin_dir = bin_dir.rstrip(os.sep)
if os.path.basename(bin_dir) == "depot_tools":
# skip depot_tools to avoid calling ninja.py infinitely.
continue
ninja_path = os.path.join(bin_dir, exe)
if os.path.isfile(ninja_path):
return ninja_path
def checkOutdir(ninja_args):
def check_out_dir(ninja_args):
out_dir = "."
tool = ""
for i, arg in enumerate(ninja_args):
@ -65,11 +67,12 @@ def checkOutdir(ninja_args):
file=sys.stderr)
sys.exit(1)
def fallback(ninja_args):
# Try to find ninja in PATH.
ninja_path = findNinjaInPath()
ninja_path = find_ninja_in_path()
if ninja_path:
checkOutdir(ninja_args)
check_out_dir(ninja_args)
return subprocess.call([ninja_path] + ninja_args)
print(
@ -120,7 +123,7 @@ def main(args):
"ninja" + gclient_paths.GetExeSuffix(),
)
if os.path.isfile(ninja_path):
checkOutdir(args[1:])
check_out_dir(args[1:])
return subprocess.call([ninja_path] + args[1:])
return fallback(args[1:])

Loading…
Cancel
Save