Skip to content

Commit

Permalink
Make gn.py support root directories other than 'src'.
Browse files Browse the repository at this point in the history
In https://codereview.chromium.org/341533006/ a change
was made so that gn.py is not looking for the .gn file
to identify the root of the checkout. This breaks
GN functionality for projects that uses gclient but
have a top directory named something else than 'src'.

This change adds support for arbitrarily named primary (the first)
solutions in the .gclient file.
It also adds a check for the generated GN path so a friendly
error message can be printed if the GN executable cannot be found.


BUG=389883
TESTED=Various cases of Chromium, WebRTC and custom checkouts
with .gclient containing empty solution list, solution missing the
'name' key and so on.

Review URL: https://codereview.chromium.org/538393002

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@291819 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
[email protected] committed Sep 5, 2014
1 parent 42f9adf commit f7facfa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
16 changes: 15 additions & 1 deletion gclient_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,10 @@ def filter_fn(line):
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():
Expand Down Expand Up @@ -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'
Expand Down
8 changes: 6 additions & 2 deletions gn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__':
Expand Down

0 comments on commit f7facfa

Please sign in to comment.