diff options
Diffstat (limited to 'gnu/llvm/lldb/packages/Python/lldbsuite/support')
5 files changed, 162 insertions, 0 deletions
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/support/__init__.py b/gnu/llvm/lldb/packages/Python/lldbsuite/support/__init__.py new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/support/__init__.py diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/support/encoded_file.py b/gnu/llvm/lldb/packages/Python/lldbsuite/support/encoded_file.py new file mode 100644 index 00000000000..c233e046ba7 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/support/encoded_file.py @@ -0,0 +1,67 @@ +""" +Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +See https://llvm.org/LICENSE.txt for license information. +SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +Prepares language bindings for LLDB build process. Run with --help +to see a description of the supported command line arguments. +""" + +# Python modules: +import io + +# Third party modules +import six + + +def _encoded_read(old_read, encoding): + def impl(size): + result = old_read(size) + # If this is Python 2 then we need to convert the resulting `unicode` back + # into a `str` before returning + if six.PY2: + result = result.encode(encoding) + return result + return impl + + +def _encoded_write(old_write, encoding): + def impl(s): + # If we were asked to write a `str` (in Py2) or a `bytes` (in Py3) decode it + # as unicode before attempting to write. + if isinstance(s, six.binary_type): + s = s.decode(encoding, "replace") + # Filter unreadable characters, Python 3 is stricter than python 2 about them. + import re + s = re.sub(r'[^\x00-\x7f]',r' ',s) + return old_write(s) + return impl + +''' +Create a Text I/O file object that can be written to with either unicode strings or byte strings +under Python 2 and Python 3, and automatically encodes and decodes as necessary to return the +native string type for the current Python version +''' + + +def open( + file, + encoding, + mode='r', + buffering=-1, + errors=None, + newline=None, + closefd=True): + wrapped_file = io.open( + file, + mode=mode, + buffering=buffering, + encoding=encoding, + errors=errors, + newline=newline, + closefd=closefd) + new_read = _encoded_read(getattr(wrapped_file, 'read'), encoding) + new_write = _encoded_write(getattr(wrapped_file, 'write'), encoding) + setattr(wrapped_file, 'read', new_read) + setattr(wrapped_file, 'write', new_write) + return wrapped_file diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/support/funcutils.py b/gnu/llvm/lldb/packages/Python/lldbsuite/support/funcutils.py new file mode 100644 index 00000000000..648d95d23d9 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/support/funcutils.py @@ -0,0 +1,15 @@ +import inspect + +def requires_self(func): + func_argc = len(inspect.getargspec(func).args) + if func_argc == 0 or ( + getattr( + func, + 'im_self', + None) is not None) or ( + hasattr( + func, + '__self__')): + return False + else: + return True diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/support/gmodules.py b/gnu/llvm/lldb/packages/Python/lldbsuite/support/gmodules.py new file mode 100644 index 00000000000..5d66bd14896 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/support/gmodules.py @@ -0,0 +1,29 @@ +from __future__ import absolute_import +from __future__ import print_function + +# System modules +import os +import re + + +GMODULES_SUPPORT_MAP = {} +GMODULES_HELP_REGEX = re.compile(r"\s-gmodules\s") + + +def is_compiler_clang_with_gmodules(compiler_path): + # Before computing the result, check if we already have it cached. + if compiler_path in GMODULES_SUPPORT_MAP: + return GMODULES_SUPPORT_MAP[compiler_path] + + def _gmodules_supported_internal(): + compiler = os.path.basename(compiler_path) + if "clang" not in compiler: + return False + else: + # Check the compiler help for the -gmodules option. + clang_help = os.popen("%s --help" % compiler_path).read() + return GMODULES_HELP_REGEX.search( + clang_help, re.DOTALL) is not None + + GMODULES_SUPPORT_MAP[compiler_path] = _gmodules_supported_internal() + return GMODULES_SUPPORT_MAP[compiler_path] diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/support/seven.py b/gnu/llvm/lldb/packages/Python/lldbsuite/support/seven.py new file mode 100644 index 00000000000..9b23d94b021 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/support/seven.py @@ -0,0 +1,51 @@ +import binascii +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).rstrip()) + 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) + +def bitcast_to_string(b): + """ + Take a string(PY2) or a bytes(PY3) object and return a string. The returned + string contains the exact same bytes as the input object (latin1 <-> unicode + transformation is an identity operation for the first 256 code points). + """ + return b if six.PY2 else b.decode("latin1") + +def bitcast_to_bytes(s): + """ + Take a string and return a string(PY2) or a bytes(PY3) object. The returned + object contains the exact same bytes as the input string. (latin1 <-> + unicode transformation is an identity operation for the first 256 code + points). + """ + return s if six.PY2 else s.encode("latin1") + +def unhexlify(hexstr): + """Hex-decode a string. The result is always a string.""" + return bitcast_to_string(binascii.unhexlify(hexstr)) + +def hexlify(data): + """Hex-encode string data. The result if always a string.""" + return bitcast_to_string(binascii.hexlify(bitcast_to_bytes(data))) |