mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
[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>
This commit is contained in:
19
gn.py
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):
|
def main(args):
|
||||||
# Prune all evidence of VPython/VirtualEnv out of the environment. This
|
# Prune all evidence of VPython/VirtualEnv out of the environment. This
|
||||||
# means that we 'unwrap' vpython VirtualEnv path/env manipulation.
|
# means that we 'unwrap' vpython VirtualEnv path/env manipulation.
|
||||||
@@ -58,6 +74,9 @@ def main(args):
|
|||||||
# inside of buildtools.
|
# inside of buildtools.
|
||||||
bin_path = gclient_paths.GetBuildtoolsPlatformBinaryPath()
|
bin_path = gclient_paths.GetBuildtoolsPlatformBinaryPath()
|
||||||
if not bin_path:
|
if not bin_path:
|
||||||
|
gn_path = findGnInPath()
|
||||||
|
if gn_path:
|
||||||
|
return subprocess.call([gn_path] + args[1:])
|
||||||
print(
|
print(
|
||||||
'gn.py: Could not find checkout in any parent of the current '
|
'gn.py: Could not find checkout in any parent of the current '
|
||||||
'path.\nThis must be run inside a checkout.',
|
'path.\nThis must be run inside a checkout.',
|
||||||
|
|||||||
4
ninja.py
4
ninja.py
@@ -19,11 +19,11 @@ def findNinjaInPath():
|
|||||||
if not env_path:
|
if not env_path:
|
||||||
return
|
return
|
||||||
exe = 'ninja'
|
exe = 'ninja'
|
||||||
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'):
|
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
|
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):
|
||||||
|
|||||||
Reference in New Issue
Block a user