[depot_tools] Support both gn paths in gn.py

Build in support for both buildtools/<platform>/gn and
buildtools/<platform>/gn/gn preemptively.
This will allow the libfuzzer builders in https://chromium-review.googlesource.com/c/chromium/src/+/5474162 to succeed.

Bug: b/328065301
Change-Id: I97b401cb1b3339cfa7962f60b891be05baac75d5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5479888
Reviewed-by: Joanna Wang <jojwang@chromium.org>
Commit-Queue: Stephanie Kim <kimstephanie@google.com>
changes/88/5479888/6
Stephanie Kim 10 months ago committed by LUCI CQ
parent 3d170cb6ce
commit df8c52a549

51
gn.py

@ -33,22 +33,33 @@ def PruneVirtualEnv():
])
def findGnInPath():
# TODO(b/328065301): Once chromium/src CL has landed to migrate
# buildtools/<platform>/gn to buildtools/<platform>/gn/gn, only return
# gn/gn path.
def findGnOptionsInPath():
env_path = os.getenv('PATH')
if not env_path:
return
exe = 'gn'
if sys.platform in ('win32', 'cygwin'):
exe += '.exe'
path_options = []
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
for path in [
os.path.join(bin_dir, 'gn', exe),
os.path.join(bin_dir, exe),
]:
if os.path.isfile(path):
path_options.append(path)
return path_options
# TODO(b/328065301): Once chromium/src CL has landed to migrate
# buildtools/<platform>/gn to buildtools/<platform>/gn/gn, only return
# gn/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.
@ -63,29 +74,35 @@ def main(args):
# downloaded by cipd in the projects DEPS.
primary_solution_path = gclient_paths.GetPrimarySolutionPath()
if primary_solution_path:
gn_path = os.path.join(primary_solution_path, 'third_party', 'gn',
'gn' + gclient_paths.GetExeSuffix())
if os.path.exists(gn_path):
return subprocess.call([gn_path] + args[1:])
old_gn_path = os.path.join(primary_solution_path, 'third_party',
'gn' + gclient_paths.GetExeSuffix())
new_gn_path = os.path.join(primary_solution_path, 'third_party', 'gn',
'gn' + gclient_paths.GetExeSuffix())
for path in [new_gn_path, old_gn_path]:
if os.path.exists(path):
return subprocess.call([path] + args[1:])
# Otherwise try the old .sha1 and download_from_google_storage locations
# 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:])
gn_path_options = findGnOptionsInPath()
for path in gn_path_options:
if os.path.exists(path):
return subprocess.call([path] + args[1:])
print(
'gn.py: Could not find checkout in any parent of the current '
'path.\nThis must be run inside a checkout.',
file=sys.stderr)
return 1
gn_path = os.path.join(bin_path, 'gn' + gclient_paths.GetExeSuffix())
if not os.path.exists(gn_path):
print('gn.py: Could not find gn executable at: %s' % gn_path,
file=sys.stderr)
return 2
return subprocess.call([gn_path] + args[1:])
old_gn_path = os.path.join(bin_path, gclient_paths.GetExeSuffix())
new_gn_path = os.path.join(bin_path, 'gn', gclient_paths.GetExeSuffix())
paths = [new_gn_path, old_gn_path]
for path in paths:
if os.path.exists(path):
return subprocess.call([path] + args[1:])
print('gn.py: Could not find gn executable at: %s' % paths, file=sys.stderr)
return 2
if __name__ == '__main__':

Loading…
Cancel
Save