mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-02-10 19:34:29 +00:00
[libc++][NFC] Resolve Python 2 FIXME
We don't use Python 2 anymore, so let us do the recommended fix instead of using the workaround made for Python 2. Differential Revision: https://reviews.llvm.org/D107715
This commit is contained in:
parent
4a0af824ee
commit
f46f93b478
@ -46,17 +46,7 @@ endif()
|
||||
if (LIBCXX_STANDALONE_BUILD)
|
||||
find_package(Python3 COMPONENTS Interpreter)
|
||||
if(NOT Python3_Interpreter_FOUND)
|
||||
message(WARNING "Python3 not found, using python2 as a fallback")
|
||||
find_package(Python2 COMPONENTS Interpreter REQUIRED)
|
||||
if(Python2_VERSION VERSION_LESS 2.7)
|
||||
message(SEND_ERROR "Python 2.7 or newer is required")
|
||||
endif()
|
||||
|
||||
# Treat python2 as python3
|
||||
add_executable(Python3::Interpreter IMPORTED)
|
||||
set_target_properties(Python3::Interpreter PROPERTIES
|
||||
IMPORTED_LOCATION ${Python2_EXECUTABLE})
|
||||
set(Python3_EXECUTABLE ${Python2_EXECUTABLE})
|
||||
message(SEND_ERROR "Python3 not found. Python3 is required")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
@ -147,10 +147,6 @@ class StdTuplePrinter(object):
|
||||
self.count += 1
|
||||
return ("[%d]" % self.count, child)
|
||||
|
||||
# TODO Delete when we drop Python 2.
|
||||
def next(self):
|
||||
return self.__next__()
|
||||
|
||||
def __init__(self, val):
|
||||
self.val = val
|
||||
|
||||
@ -370,10 +366,6 @@ class StdVectorPrinter(object):
|
||||
self.offset = 0
|
||||
return ("[%d]" % self.count, outbit)
|
||||
|
||||
# TODO Delete when we drop Python 2.
|
||||
def next(self):
|
||||
return self.__next__()
|
||||
|
||||
class _VectorIterator(object):
|
||||
"""Class to iterate over the non-bool vector's children."""
|
||||
|
||||
@ -393,10 +385,6 @@ class StdVectorPrinter(object):
|
||||
self.item += 1
|
||||
return ("[%d]" % self.count, entry)
|
||||
|
||||
# TODO Delete when we drop Python 2.
|
||||
def next(self):
|
||||
return self.__next__()
|
||||
|
||||
def __init__(self, val):
|
||||
"""Set val, length, capacity, and iterator for bool and normal vectors."""
|
||||
self.val = val
|
||||
|
@ -102,7 +102,7 @@ def which(command, paths = None):
|
||||
(or the PATH environment variable, if unspecified)."""
|
||||
|
||||
if paths is None:
|
||||
paths = os.environ.get('PATH','')
|
||||
paths = os.environ.get('PATH', '')
|
||||
|
||||
# Check for absolute match first.
|
||||
if os.path.isfile(command):
|
||||
@ -202,23 +202,20 @@ def executeCommand(command, cwd=None, env=None, input=None, timeout=0):
|
||||
stderr=subprocess.PIPE,
|
||||
env=env, close_fds=kUseCloseFDs)
|
||||
timerObject = None
|
||||
# FIXME: Because of the way nested function scopes work in Python 2.x we
|
||||
# need to use a reference to a mutable object rather than a plain
|
||||
# bool. In Python 3 we could use the "nonlocal" keyword but we need
|
||||
# to support Python 2 as well.
|
||||
hitTimeOut = [False]
|
||||
hitTimeOut = False
|
||||
try:
|
||||
if timeout > 0:
|
||||
def killProcess():
|
||||
# We may be invoking a shell so we need to kill the
|
||||
# process and all its children.
|
||||
hitTimeOut[0] = True
|
||||
nonlocal hitTimeOut
|
||||
hitTimeOut = True
|
||||
killProcessAndChildren(p.pid)
|
||||
|
||||
timerObject = threading.Timer(timeout, killProcess)
|
||||
timerObject.start()
|
||||
|
||||
out,err = p.communicate(input=input)
|
||||
out, err = p.communicate(input=input)
|
||||
exitCode = p.wait()
|
||||
finally:
|
||||
if timerObject != None:
|
||||
@ -228,7 +225,7 @@ def executeCommand(command, cwd=None, env=None, input=None, timeout=0):
|
||||
out = convert_string(out)
|
||||
err = convert_string(err)
|
||||
|
||||
if hitTimeOut[0]:
|
||||
if hitTimeOut:
|
||||
raise ExecuteCommandTimeoutException(
|
||||
msg='Reached timeout of {} seconds'.format(timeout),
|
||||
out=out,
|
||||
|
@ -23,11 +23,7 @@ import sys
|
||||
import tarfile
|
||||
import tempfile
|
||||
|
||||
try:
|
||||
from shlex import quote as cmd_quote
|
||||
except ImportError:
|
||||
# for Python 2 compatibility
|
||||
from pipes import quote as cmd_quote
|
||||
from shlex import quote as cmd_quote
|
||||
|
||||
def ssh(args, command):
|
||||
cmd = ['ssh', '-oBatchMode=yes']
|
||||
|
Loading…
x
Reference in New Issue
Block a user