JDevlieghere created this revision.
JDevlieghere added reviewers: davide, zturner, stella.stamenova, labath.
JDevlieghere added a project: LLDB.
Herald added a reviewer: serge-sans-paille.

When running the test suite on macOS with Python 3 we noticed a difference in 
behavior between Python 2 and Python 3 for `seven.get_command_output`. The 
output contained a newline with Python 3, but not for Python 2. This resulted 
in an invalid SDK path passed to the compiler.

There were only two actual usages left of this module so I propose to remove it 
and have a simple, local implementation for `get_command_output`.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D57275

Files:
  packages/Python/lldbsuite/support/seven.py
  packages/Python/lldbsuite/test/dosep.py
  packages/Python/lldbsuite/test/dotest.py
  packages/Python/lldbsuite/test/functionalities/exec/TestExec.py
  packages/Python/lldbsuite/test/functionalities/fat_archives/TestFatArchives.py
  packages/Python/lldbsuite/test/lang/objc/ivar-IMP/TestObjCiVarIMP.py

Index: packages/Python/lldbsuite/test/lang/objc/ivar-IMP/TestObjCiVarIMP.py
===================================================================
--- packages/Python/lldbsuite/test/lang/objc/ivar-IMP/TestObjCiVarIMP.py
+++ packages/Python/lldbsuite/test/lang/objc/ivar-IMP/TestObjCiVarIMP.py
@@ -10,21 +10,11 @@
 import re
 
 import lldb
-from lldbsuite.support import seven
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
 from lldbsuite.test import lldbutil
 
 
-def execute_command(command):
-    # print('%% %s' % (command))
-    (exit_status, output) = seven.get_command_status_output(command)
-    # if output:
-    #     print(output)
-    # print('status = %u' % (exit_status))
-    return exit_status
-
-
 class ObjCiVarIMPTestCase(TestBase):
 
     mydir = TestBase.compute_mydir(__file__)
Index: packages/Python/lldbsuite/test/functionalities/fat_archives/TestFatArchives.py
===================================================================
--- packages/Python/lldbsuite/test/functionalities/fat_archives/TestFatArchives.py
+++ packages/Python/lldbsuite/test/functionalities/fat_archives/TestFatArchives.py
@@ -7,7 +7,6 @@
 import lldb
 import os
 import time
-import lldbsuite.support.seven as seven
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
 from lldbsuite.test import lldbutil
Index: packages/Python/lldbsuite/test/functionalities/exec/TestExec.py
===================================================================
--- packages/Python/lldbsuite/test/functionalities/exec/TestExec.py
+++ packages/Python/lldbsuite/test/functionalities/exec/TestExec.py
@@ -7,21 +7,11 @@
 import lldb
 import os
 import time
-from lldbsuite.support import seven
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
 from lldbsuite.test import lldbutil
 
 
-def execute_command(command):
-    #print('%% %s' % (command))
-    (exit_status, output) = seven.get_command_status_output(command)
-    # if output:
-    #    print(output)
-    #print('status = %u' % (exit_status))
-    return exit_status
-
-
 class ExecTestCase(TestBase):
 
     NO_DEBUG_INFO_TESTCASE = True
Index: packages/Python/lldbsuite/test/dotest.py
===================================================================
--- packages/Python/lldbsuite/test/dotest.py
+++ packages/Python/lldbsuite/test/dotest.py
@@ -46,9 +46,15 @@
 from lldbsuite.test_event import formatter
 from . import test_result
 from lldbsuite.test_event.event_builder import EventBuilder
-from ..support import seven
 
 
+def get_command_output(cmd):
+  try:
+    return subprocess.check_output(cmd, shell=True).rstrip()
+  except:
+    pass
+  return ''
+
 def is_exe(fpath):
     """Returns true if fpath is an executable."""
     if fpath == None:
@@ -290,7 +296,7 @@
         # Use a compiler appropriate appropriate for the Apple SDK if one was
         # specified
         if platform_system == 'Darwin' and args.apple_sdk:
-            configuration.compiler = seven.get_command_output(
+            configuration.compiler = get_command_output(
                 'xcrun -sdk "%s" -find clang 2> /dev/null' %
                 (args.apple_sdk))
         else:
@@ -304,7 +310,7 @@
     if args.dsymutil:
       os.environ['DSYMUTIL'] = args.dsymutil
     elif platform_system == 'Darwin':
-      os.environ['DSYMUTIL'] = seven.get_command_output(
+      os.environ['DSYMUTIL'] = get_command_output(
           'xcrun -find -toolchain default dsymutil')
 
     if args.filecheck:
@@ -336,7 +342,7 @@
 
     # Set SDKROOT if we are using an Apple SDK
     if platform_system == 'Darwin' and args.apple_sdk:
-        os.environ['SDKROOT'] = seven.get_command_output(
+        os.environ['SDKROOT'] = get_command_output(
             'xcrun --sdk "%s" --show-sdk-path 2> /dev/null' %
             (args.apple_sdk))
 
@@ -344,10 +350,10 @@
         configuration.arch = args.arch
         if configuration.arch.startswith(
                 'arm') and platform_system == 'Darwin' and not args.apple_sdk:
-            os.environ['SDKROOT'] = seven.get_command_output(
+            os.environ['SDKROOT'] = get_command_output(
                 'xcrun --sdk iphoneos.internal --show-sdk-path 2> /dev/null')
             if not os.path.exists(os.environ['SDKROOT']):
-                os.environ['SDKROOT'] = seven.get_command_output(
+                os.environ['SDKROOT'] = get_command_output(
                     'xcrun --sdk iphoneos --show-sdk-path 2> /dev/null')
     else:
         configuration.arch = platform_machine
@@ -637,7 +643,7 @@
 def get_llvm_bin_dirs():
     """
     Returns an array of paths that may have the llvm/clang/etc binaries
-    in them, relative to this current file.  
+    in them, relative to this current file.
     Returns an empty array if none are found.
     """
     result = []
@@ -1094,7 +1100,7 @@
 
 def getVersionForSDK(sdk):
     sdk = str.lower(sdk)
-    full_path = seven.get_command_output('xcrun -sdk %s --show-sdk-path' % sdk)
+    full_path = get_command_output('xcrun -sdk %s --show-sdk-path' % sdk)
     basename = os.path.basename(full_path)
     basename = os.path.splitext(basename)[0]
     basename = str.lower(basename)
@@ -1104,7 +1110,7 @@
 
 def getPathForSDK(sdk):
     sdk = str.lower(sdk)
-    full_path = seven.get_command_output('xcrun -sdk %s --show-sdk-path' % sdk)
+    full_path = get_command_output('xcrun -sdk %s --show-sdk-path' % sdk)
     if os.path.exists(full_path):
         return full_path
     return None
Index: packages/Python/lldbsuite/test/dosep.py
===================================================================
--- packages/Python/lldbsuite/test/dosep.py
+++ packages/Python/lldbsuite/test/dosep.py
@@ -51,7 +51,6 @@
 
 # Our packages and modules
 import lldbsuite
-import lldbsuite.support.seven as seven
 
 from . import configuration
 from . import dotest_args
@@ -1480,7 +1479,7 @@
         return False
 
     system_version = distutils.version.StrictVersion(platform.mac_ver()[0])
-    return seven.cmp_(system_version, target_version) < 0
+    return cmp(system_version, target_version) < 0
 
 
 def default_test_runner_name(num_threads):
Index: packages/Python/lldbsuite/support/seven.py
===================================================================
--- packages/Python/lldbsuite/support/seven.py
+++ /dev/null
@@ -1,25 +0,0 @@
-import six
-
-if six.PY2:
-    import commands
-    get_command_output = commands.getoutput
-    get_command_status_output = commands.getstatusoutput
-
-    cmp_ = cmp
-else:
-    def get_command_status_output(command):
-        try:
-            import subprocess
-            return (
-                0,
-                subprocess.check_output(
-                    command,
-                    shell=True,
-                    universal_newlines=True))
-        except subprocess.CalledProcessError as e:
-            return (e.returncode, e.output)
-
-    def get_command_output(command):
-        return get_command_status_output(command)[1]
-
-    cmp_ = lambda x, y: (x > y) - (x < y)
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to