summaryrefslogtreecommitdiffstats
path: root/llvm/utils/gn/gn.py
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2019-01-28 19:54:41 +0000
committerNico Weber <nicolasweber@gmx.de>2019-01-28 19:54:41 +0000
commit285becfa4c25e803e809ded615ea5981d1d0dbcf (patch)
treec7883dc9ce17a97c6faa1a7e4d97ecfca89e0c2a /llvm/utils/gn/gn.py
parent3d4f49fa78aefef333fff8bf0c49bc0fd184b197 (diff)
downloadbcm5719-llvm-285becfa4c25e803e809ded615ea5981d1d0dbcf.tar.gz
bcm5719-llvm-285becfa4c25e803e809ded615ea5981d1d0dbcf.zip
gn build: Add get.py script to download prebuilt gn, make gn.py run downloaded gn if gn is not on PATH
Prebuilts are available for x86_64 Linux, macOS, Windows. The script always pulls the latest GN version. Differential Revision: https://reviews.llvm.org/D57256 llvm-svn: 352420
Diffstat (limited to 'llvm/utils/gn/gn.py')
-rwxr-xr-xllvm/utils/gn/gn.py32
1 files changed, 30 insertions, 2 deletions
diff --git a/llvm/utils/gn/gn.py b/llvm/utils/gn/gn.py
index f80873b3be8..f523e6443ea 100755
--- a/llvm/utils/gn/gn.py
+++ b/llvm/utils/gn/gn.py
@@ -15,10 +15,38 @@ THIS_DIR = os.path.dirname(__file__)
ROOT_DIR = os.path.join(THIS_DIR, '..', '..', '..')
+def get_platform():
+ if os.uname()[4] != 'x86_64':
+ return None
+ if sys.platform.startswith('linux'):
+ return 'linux-amd64'
+ if sys.platform == 'darwin':
+ return 'mac-amd64'
+ if sys.platform == 'win32':
+ return 'windows-amd64'
+
+
+def print_no_gn(mention_get):
+ print('gn binary not found in PATH')
+ if mention_get:
+ print('run llvm/utils/gn/get.py to download a binary and try again, or')
+ print('follow https://gn.googlesource.com/gn/#getting-started')
+ return 1
+
+
def main():
- # Find real gn executable. For now, just assume it's on PATH.
- # FIXME: Probably need to append '.exe' on Windows.
+ # Find real gn executable.
gn = 'gn'
+ if subprocess.call([gn, '--version'], stdout=open(os.devnull, 'w'),
+ stderr=subprocess.STDOUT) != 0:
+ # Not on path. See if get.py downloaded a prebuilt binary and run that
+ # if it's there, or suggest to run get.py if it isn't.
+ platform = get_platform()
+ if not platform:
+ return print_no_gn(mention_get=False)
+ gn = os.path.join(os.path.dirname(__file__), 'bin', platform, 'gn')
+ if not os.path.exists(gn + ('.exe' if platform == 'windows' else '')):
+ return print_no_gn(mention_get=True)
# Compute --dotfile= and --root= args to add.
extra_args = []
OpenPOWER on IntegriCloud