Make gn wrapper use the one in buildtools rather than tools/gn/bin.
This updates some infrastructure to make it easy to get at the platform-specific build tools directories.
Review URL: https://codereview.chromium.org/341533006
git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@279132 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/gclient_utils.py b/gclient_utils.py
index 1777cfd..655e5aa 100644
--- a/gclient_utils.py
+++ b/gclient_utils.py
@@ -650,6 +650,37 @@
raise Error('Unknown platform: ' + sys.platform)
+def GetBuildtoolsPath():
+ """Returns the full path to the buildtools directory.
+ This is based on the root of the checkout containing the current directory."""
+ gclient_root = FindGclientRoot(os.getcwd())
+ if not gclient_root:
+ return None
+ return os.path.join(gclient_root, 'src', 'buildtools')
+
+
+def GetBuildtoolsPlatformBinaryPath():
+ """Returns the full path to the binary directory for the current platform."""
+ # Mac and Windows just have one directory, Linux has two according to whether
+ # it's 32 or 64 bits.
+ buildtools_path = GetBuildtoolsPath()
+ if not buildtools_path:
+ return None
+
+ if sys.platform.startswith(('cygwin', 'win')):
+ subdir = 'win'
+ elif sys.platform == 'darwin':
+ subdir = 'mac'
+ elif sys.platform.startswith('linux'):
+ if sys.maxsize > 2**32:
+ subdir = 'linux64'
+ else:
+ subdir = 'linux32'
+ else:
+ raise Error('Unknown platform: ' + sys.platform)
+ return os.path.join(buildtools_path, subdir)
+
+
def GetExeSuffix():
"""Returns '' or '.exe' depending on how executables work on this platform."""
if sys.platform.startswith(('cygwin', 'win')):
diff --git a/gn.py b/gn.py
index ab08b52..e3bcc97 100755
--- a/gn.py
+++ b/gn.py
@@ -18,32 +18,15 @@
import sys
-def RunGN(sourceroot):
- # The binaries in platform-specific subdirectories in src/tools/gn/bin.
- gnpath = os.path.join(sourceroot,
- 'tools', 'gn', 'bin', gclient_utils.GetMacWinOrLinux(),
- 'gn' + gclient_utils.GetExeSuffix())
- return subprocess.call([gnpath] + sys.argv[1:])
-
-
def main(args):
- for arg in sys.argv:
- if arg.startswith('--root='):
- sourceroot = arg.replace('--root=', '')
- dotfile_path = os.path.join(sourceroot, '.gn')
- if not os.path.exists(dotfile_path):
- print >> sys.stderr, 'gn.py: "%s" not found, exiting.' % dotfile_path
- sys.exit(1)
- return RunGN(sourceroot)
-
- sourceroot = gclient_utils.FindFileUpwards('.gn')
- if not sourceroot:
- print >> sys.stderr, ('gn.py: No .gn file found in any parent of '
- 'the current path.')
- print >> sys.stderr, ('\nYou need to either be inside a checkout, '
- 'or use --root to specify the checkout root.')
+ bin_path = gclient_utils.GetBuildtoolsPlatformBinaryPath()
+ if not bin_path:
+ 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 RunGN(sourceroot)
+ gn_path = os.path.join(bin_path, 'gn' + gclient_utils.GetExeSuffix())
+ return subprocess.call([gn_path] + sys.argv[1:])
if __name__ == '__main__':