[PATCH] D59115: gn build: Unbreak get.py and gn.py on Windows

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 7 15:38:25 PST 2019


thakis created this revision.
thakis added reviewers: pcc, hctim.
Herald added a reviewer: serge-sans-paille.
Herald added a project: LLVM.

Inspired by the recent changes here I figured I'd test these on Windows. Looks like I haven't done that in a while, they were both broken.

`os.uname()` doesn't exist on Windows, so use `platform.machine()` which returns `os.uname()[4]` on non-Win and (on 64-bit systems) "AMD64" on Windows. Also use `sys.platform` instead of `platform` to check for Windows-ness for the file extension in gn.py (get.py got this right).

Using `[gn, '--version']` works on Windows, but I think it does the wrong thing on POSIX where it passes `--version` to the shell instead of to gn, so I think after r355645 the "broken gn on PATH" case isn't working right on POSIX. I'll leave that to you to fix.


https://reviews.llvm.org/D59115

Files:
  llvm/utils/gn/get.py
  llvm/utils/gn/gn.py


Index: llvm/utils/gn/gn.py
===================================================================
--- llvm/utils/gn/gn.py
+++ llvm/utils/gn/gn.py
@@ -16,7 +16,8 @@
 
 
 def get_platform():
-    if os.uname()[4] != 'x86_64':
+    import platform
+    if platform.machine() not in ('AMD64', 'x86_64'):
         return None
     if sys.platform.startswith('linux'):
         return 'linux-amd64'
@@ -46,7 +47,7 @@
         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 '')):
+        if not os.path.exists(gn + ('.exe' if sys.platform == 'win32' else '')):
             return print_no_gn(mention_get=True)
 
     # Compute --dotfile= and --root= args to add.
Index: llvm/utils/gn/get.py
===================================================================
--- llvm/utils/gn/get.py
+++ llvm/utils/gn/get.py
@@ -33,7 +33,8 @@
 
 
 def get_platform():
-    if os.uname()[4] != 'x86_64':
+    import platform
+    if platform.machine() not in ('AMD64', 'x86_64'):
         return None
     if sys.platform.startswith('linux'):
         return 'linux-amd64'


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59115.189792.patch
Type: text/x-patch
Size: 1220 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190307/82911b4e/attachment.bin>


More information about the llvm-commits mailing list