[gn] Fallback GN in PATH

This allows us to call GN outside of gclient checkout.
e.g PATH=$PATH:~/chromium/src/buildtools/linux64 gn

Change-Id: Ib4b6d09fbd4d3a12ea1407fcea0eb5494c808fb5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4886535
Auto-Submit: Junji Watanabe <jwata@google.com>
Commit-Queue: Junji Watanabe <jwata@google.com>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
changes/35/4886535/7
Junji Watanabe 1 year ago committed by LUCI CQ
parent 4af2818c5b
commit c5505889cf

19
gn.py

@ -35,6 +35,22 @@ def PruneVirtualEnv():
])
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)
if os.path.isfile(gn_path):
return gn_path
def main(args):
# Prune all evidence of VPython/VirtualEnv out of the environment. This
# means that we 'unwrap' vpython VirtualEnv path/env manipulation.
@ -58,6 +74,9 @@ def main(args):
# inside of buildtools.
bin_path = gclient_paths.GetBuildtoolsPlatformBinaryPath()
if not bin_path:
gn_path = findGnInPath()
if gn_path:
return subprocess.call([gn_path] + args[1:])
print(
'gn.py: Could not find checkout in any parent of the current '
'path.\nThis must be run inside a checkout.',

@ -19,11 +19,11 @@ def findNinjaInPath():
if not env_path:
return
exe = 'ninja'
if sys.platform in ['win32', 'cygwin']:
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 ninja.py infitely.
# skip depot_tools to avoid calling ninja.py infinitely.
continue
ninja_path = os.path.join(bin_dir, exe)
if os.path.isfile(ninja_path):

Loading…
Cancel
Save