diff options
Diffstat (limited to 'scripts/Python/modules')
-rw-r--r-- | scripts/Python/modules/CMakeLists.txt | 11 | ||||
-rw-r--r-- | scripts/Python/modules/Makefile | 20 | ||||
-rw-r--r-- | scripts/Python/modules/readline/CMakeLists.txt | 25 | ||||
-rw-r--r-- | scripts/Python/modules/readline/Makefile | 100 | ||||
-rw-r--r-- | scripts/Python/modules/readline/readline.cpp | 76 |
5 files changed, 232 insertions, 0 deletions
diff --git a/scripts/Python/modules/CMakeLists.txt b/scripts/Python/modules/CMakeLists.txt new file mode 100644 index 0000000..396d447 --- /dev/null +++ b/scripts/Python/modules/CMakeLists.txt @@ -0,0 +1,11 @@ +# Disable some warnings triggered by Python's headers. +check_cxx_compiler_flag("-Wno-macro-redefined" + CXX_SUPPORTS_NO_MACRO_REDEFINED) +if (CXX_SUPPORTS_NO_MACRO_REDEFINED) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-macro-redefined") +endif () + +# build the Python readline suppression module only on Linux +if (CMAKE_SYSTEM_NAME MATCHES "Linux" AND NOT __ANDROID_NDK__) + add_subdirectory(readline) +endif() diff --git a/scripts/Python/modules/Makefile b/scripts/Python/modules/Makefile new file mode 100644 index 0000000..b698988 --- /dev/null +++ b/scripts/Python/modules/Makefile @@ -0,0 +1,20 @@ +##===- scripts/Python/modules/Makefile ---------------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## + +LLDB_LEVEL := ../../.. +include $(LLDB_LEVEL)/../../Makefile.config + +DIRS:= + +# only build the readline suppression module on Linux, Kfreebsd & Hurd +ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux GNU GNU/kFreeBSD)) +DIRS += readline +endif + +include $(LLDB_LEVEL)/Makefile diff --git a/scripts/Python/modules/readline/CMakeLists.txt b/scripts/Python/modules/readline/CMakeLists.txt new file mode 100644 index 0000000..0a4376c --- /dev/null +++ b/scripts/Python/modules/readline/CMakeLists.txt @@ -0,0 +1,25 @@ +# FIXME: if a non-standard version of python is requested, the cmake macro +# below will need Python_ADDITIONAL_VERSIONS set in order to find it. +include(FindPythonInterp) +SET(PYTHON_DIRECTORY python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages) + +# Build the readline python module +include_directories(${PYTHON_INCLUDE_DIR}) +add_library(readline SHARED readline.cpp) + +if (NOT LLDB_DISABLE_LIBEDIT) + target_link_libraries(readline ${PYTHON_LIBRARY} edit) +else() + target_link_libraries(readline ${PYTHON_LIBRARY}) +endif() + +# FIXME: the LIBRARY_OUTPUT_PATH seems to be ignored - this is not a +# functional issue for the build dir, though, since the shared lib dir +# for the build is in the python shared library load path, and thus +# python finds it when loading the python readline module. +set_target_properties(readline PROPERTIES + PREFIX "" + LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/${PYTHON_DIRECTORY}) + +# Install the readline module. +install(TARGETS readline LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}/${PYTHON_DIRECTORY}) diff --git a/scripts/Python/modules/readline/Makefile b/scripts/Python/modules/readline/Makefile new file mode 100644 index 0000000..dc0d757 --- /dev/null +++ b/scripts/Python/modules/readline/Makefile @@ -0,0 +1,100 @@ +##===- scripts/Python/modules/readline/Makefile ------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## + +# Skip this entire Makefile if python is disabled. +ifeq (,$(findstring -DLLDB_DISABLE_PYTHON,$(CXXFLAGS))) + +LEVEL := ../../../../../.. +LLDB_LEVEL := ../../../.. + +LIBRARYNAME = readline + +NO_BUILD_ARCHIVE = 1 +LINK_LIBS_IN_SHARED = 1 +SHARED_LIBRARY = 1 +LOADABLE_MODULE = 1 + +PYTHON_CONFIG?= python-config +PYTHON_INC_DIR = $(shell $(PYTHON_CONFIG) --includes) + +# Include all archives in the shared lib +USEDLIBS := + +include $(LLDB_LEVEL)/../../Makefile.config + +LINK_COMPONENTS := + +include $(LEVEL)/Makefile.common + +# include python headers +CPP.Flags += $(PYTHON_INC_DIR) + +ifeq ($(HOST_OS),Darwin) + LLVMLibsOptions += -Wl,-all_load + # set dylib internal version number to llvmCore submission number + ifdef LLDB_SUBMIT_VERSION + LLVMLibsOptions += -Wl,-current_version \ + -Wl,$(LLDB_SUBMIT_VERSION).$(LLDB_SUBMIT_SUBVERSION) \ + -Wl,-compatibility_version -Wl,1 + endif + # extra options to override libtool defaults + LVMLibsOptions += -F/System/Library/Frameworks -F/System/Library/PrivateFrameworks + LLVMLibsOptions += -framework Foundation -framework CoreFoundation + LLVMLibsOptions += -framework CoreServices -framework Carbon -framework Security + LLVMLibsOptions += -framework DebugSymbols $(PYTHON_BUILD_FLAGS) -lobjc + # Mac OS X 10.4 and earlier tools do not allow a second -install_name on command line + DARWIN_VERS := $(shell echo $(TARGET_TRIPLE) | sed 's/.*darwin\([0-9]*\).*/\1/') + ifneq ($(DARWIN_VERS),8) + LLVMLibsOptions += -Wl,-install_name \ + -Wl,"@executable_path/../lib/$(LIBRARYNAME)$(SHLIBEXT)" + endif +endif + +ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux GNU GNU/kFreeBSD)) + # Include everything from the .a's into the shared library. + ProjLibsOptions := -Wl,--whole-archive $(ProjLibsOptions) \ + -Wl,--no-whole-archive + # Link in libedit + # LLVMLibsOptions += -ledit + LLVMLibsOptions += -Wl,--soname,$(LIBRARYNAME)$(SHLIBEXT) +endif + +ifeq ($(HOST_OS),FreeBSD) + # Include everything from the .a's into the shared library. + ProjLibsOptions := -Wl,--whole-archive $(ProjLibsOptions) \ + -Wl,--no-whole-archive + # Allow unresolved symbols. + LLVMLibsOptions += -Wl,--allow-shlib-undefined + # Link in libedit + # LLVMLibsOptions += -L/usr/local/lib -ledit +endif + +# FIXME: dynamically construct the version from `python -V` +PYTHON_VERSION:=2.7 +LLDB_PYTHON_MODULE_REL_DIR:=python$(PYTHON_VERSION)/site-packages +LLDB_PYTHON_MODULE_DIR:=$(LibDir)/$(LLDB_PYTHON_MODULE_REL_DIR) + +# Target to move readline module from shared lib build location to +# local python module directory. +all-local:: $(LLDB_PYTHON_MODULE_DIR)/$(LIBRARYNAME)$(SHLIBEXT) + +$(LLDB_PYTHON_MODULE_DIR)/$(LIBRARYNAME)$(SHLIBEXT): $(SharedLibDir)/$(LIBRARYNAME)$(SHLIBEXT) + $(Echo) Staging $(BuildMode) $(LIBRARYNAME)$(SHLIBEXT) to $(LLDB_PYTHON_MODULE_DIR) + $(Verb) $(MKDIR) "$(LLDB_PYTHON_MODULE_DIR)" + $(Verb) $(ProgInstall) $(SharedLibDir)/$(LIBRARYNAME)$(SHLIBEXT) $(LLDB_PYTHON_MODULE_DIR) + +# Target to move the shared library from the build python lib dir to +# the install python lib dir. +install-local:: $(LLDB_PYTHON_MODULE_DIR)/$(LIBRARYNAME)$(SHLIBEXT) + $(Echo) Installing $(BuildMode) $(LLDB_PYTHON_MODULE_DIR)/$(LIBRARYNAME)$(SHLIBEXT) to $(DESTDIR)$(prefix)/lib/$(LLDB_PYTHON_MODULE_REL_DIR) + $(Verb) $(MKDIR) "$(DESTDIR)$(prefix)/lib/$(LLDB_PYTHON_MODULE_REL_DIR)" + $(Verb) $(ProgInstall) "$(LLDB_PYTHON_MODULE_DIR)/$(LIBRARYNAME)$(SHLIBEXT)" "$(DESTDIR)$(prefix)/lib/$(LLDB_PYTHON_MODULE_REL_DIR)" + $(Verb) $(RM) "$(DESTDIR)$(prefix)/lib/$(LIBRARYNAME)$(SHLIBEXT)" + +endif # if !defined(LLDB_DISABLE_PYTHON) diff --git a/scripts/Python/modules/readline/readline.cpp b/scripts/Python/modules/readline/readline.cpp new file mode 100644 index 0000000..d66ccf4 --- /dev/null +++ b/scripts/Python/modules/readline/readline.cpp @@ -0,0 +1,76 @@ +// NOTE: Since Python may define some pre-processor definitions which affect the +// standard headers on some systems, you must include Python.h before any +// standard headers are included. +#include "Python.h" + +#include <stdio.h> + +#ifndef LLDB_DISABLE_LIBEDIT +#include <editline/readline.h> +#endif + +// Simple implementation of the Python readline module using libedit. +// In the event that libedit is excluded from the build, this turns +// back into a null implementation that blocks the module from pulling +// in the GNU readline shared lib, which causes linkage confusion when +// both readline and libedit's readline compatibility symbols collide. +// +// Currently it only installs a PyOS_ReadlineFunctionPointer, without +// implementing any of the readline module methods. This is meant to +// work around LLVM pr18841 to avoid seg faults in the stock Python +// readline.so linked against GNU readline. + +static struct PyMethodDef moduleMethods[] = +{ + {nullptr, nullptr, 0, nullptr} +}; + +#ifndef LLDB_DISABLE_LIBEDIT +PyDoc_STRVAR( + moduleDocumentation, + "Simple readline module implementation based on libedit."); +#else +PyDoc_STRVAR( + moduleDocumentation, + "Stub module meant to avoid linking GNU readline."); +#endif + +#ifndef LLDB_DISABLE_LIBEDIT +static char* +simple_readline(FILE *stdin, FILE *stdout, char *prompt) +{ + rl_instream = stdin; + rl_outstream = stdout; + char* line = readline(prompt); + if (!line) + { + char* ret = (char*)PyMem_Malloc(1); + if (ret != NULL) + *ret = '\0'; + return ret; + } + if (*line) + add_history(line); + int n = strlen(line); + char* ret = (char*)PyMem_Malloc(n + 2); + strncpy(ret, line, n); + free(line); + ret[n] = '\n'; + ret[n+1] = '\0'; + return ret; +} +#endif + +PyMODINIT_FUNC +initreadline(void) +{ +#ifndef LLDB_DISABLE_LIBEDIT + PyOS_ReadlineFunctionPointer = simple_readline; +#endif + Py_InitModule4( + "readline", + moduleMethods, + moduleDocumentation, + static_cast<PyObject *>(NULL), + PYTHON_API_VERSION); +} |