[PATCH] D59003: [GN] Locate prebuilt binaries correctly.

Mitch Phillips via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 5 15:34:00 PST 2019


hctim created this revision.
hctim added a reviewer: thakis.
Herald added a reviewer: serge-sans-paille.
Herald added subscribers: llvm-commits, jdoerfert.
Herald added a project: LLVM.

Currently downloading a prebuilt binary and not having it on $PATH fails ungracefully, as subprocess.call doesn't like being called to a binary that doesn't exist. This should hopefully solve this problem for Linux, OSX and Windows, but I can only test the Linux component.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D59003

Files:
  llvm/utils/gn/gn.py


Index: llvm/utils/gn/gn.py
===================================================================
--- llvm/utils/gn/gn.py
+++ llvm/utils/gn/gn.py
@@ -33,12 +33,23 @@
     print('follow https://gn.googlesource.com/gn/#getting-started')
     return 1
 
+def system_binary_available(binary_name):
+    if sys.platform == 'win32':
+        if subprocess.call(['WHERE', '/q', binary_name],
+                           stdout=open(os.devnull, 'w'),
+                           stderr=subprocess.STDOUT) == 0:
+            return True
+    elif os.name == 'posix':
+        if subprocess.call(['which', binary_name],
+                           stdout=open(os.devnull, 'w'),
+                           stderr=subprocess.STDOUT) == 0:
+            return True
+    return False
 
 def main():
     # Find real gn executable.
     gn = 'gn'
-    if subprocess.call([gn, '--version'], stdout=open(os.devnull, 'w'),
-                                          stderr=subprocess.STDOUT) != 0:
+    if not system_binary_available(gn):
         # 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()


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59003.189409.patch
Type: text/x-patch
Size: 1198 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190305/cab35d34/attachment.bin>


More information about the llvm-commits mailing list