diff --git a/gclient_utils.py b/gclient_utils.py index e8d916e78d..a21e65a5fc 100644 --- a/gclient_utils.py +++ b/gclient_utils.py @@ -681,7 +681,10 @@ def GetBuildtoolsPath(): if os.path.exists(os.path.join(top_dir, 'buildtools')): return os.path.join(top_dir, 'buildtools') return None - return os.path.join(gclient_root, 'src', 'buildtools') + + # Some projects' top directory is not named 'src'. + source_dir_name = GetGClientPrimarySolutionName(gclient_root) or 'src' + return os.path.join(gclient_root, source_dir_name, 'buildtools') def GetBuildtoolsPlatformBinaryPath(): @@ -713,6 +716,17 @@ def GetExeSuffix(): return '' +def GetGClientPrimarySolutionName(gclient_root_dir_path): + """Returns the name of the primary solution in the .gclient file specified.""" + gclient_config_file = os.path.join(gclient_root_dir_path, '.gclient') + env = {} + execfile(gclient_config_file, env) + solutions = env.get('solutions', []) + if solutions: + return solutions[0].get('name') + return None + + def GetGClientRootAndEntries(path=None): """Returns the gclient root and the dict of entries.""" config_file = '.gclient_entries' diff --git a/gn.py b/gn.py index e3bcc97835..325e685d77 100755 --- a/gn.py +++ b/gn.py @@ -24,9 +24,13 @@ def main(args): print >> sys.stderr, ('gn.py: Could not find checkout in any parent of ' 'the current path.\nThis must be run inside a ' 'checkout.') - sys.exit(1) + return 1 gn_path = os.path.join(bin_path, 'gn' + gclient_utils.GetExeSuffix()) - return subprocess.call([gn_path] + sys.argv[1:]) + if not os.path.exists(gn_path): + print >> sys.stderr, 'gn.py: Could not find gn executable at: %s' % gn_path + return 2 + else: + return subprocess.call([gn_path] + sys.argv[1:]) if __name__ == '__main__':