Skip to content

Commit 0ab4b48

Browse files
author
Zachary Turner
committedJul 10, 2014
Get the python scripting interface working on Windows.
This patch fixes a number of issues with embedded Python on Windows. In particular: 1) The script that builds the python modules was normalizing the case of python filenames during copies. The module name is the filename, and is case-sensitive, so this was breaking code. 2) Changes the build to not attempt to link against python27.lib (e.g. the release library) when linking against msvcrt debug library. Doing a debug build of LLDB with embedded python support now requires you to provide your own self-compiled debug version of python. 3) Don't import termios when initializing the interpreter. This is part of a larger effort to remove the dependency on termios since it is not available on Windows. This particular instance was unnecessary and unused. Reviewed by: Todd Fiala Differential Revision: http://reviews.llvm.org/D4441 llvm-svn: 212785
1 parent 0902a51 commit 0ab4b48

File tree

5 files changed

+27
-49
lines changed

5 files changed

+27
-49
lines changed
 

‎lldb/CMakeLists.txt

-4
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,6 @@ macro(add_lldb_definitions)
108108
endmacro(add_lldb_definitions)
109109

110110
if (NOT LLDB_DISABLE_PYTHON)
111-
if (MSVC)
112-
# this definition will stop python from auto linking python27_d.lib when Python.h is included
113-
add_definitions( -DSWIG_PYTHON_INTERPRETER_NO_DEBUG )
114-
endif()
115111
find_package(PythonLibs REQUIRED)
116112
include_directories(${PYTHON_INCLUDE_DIRS})
117113
endif()

‎lldb/include/lldb/lldb-python.h

+10-37
Original file line numberDiff line numberDiff line change
@@ -15,44 +15,17 @@
1515
#ifdef LLDB_DISABLE_PYTHON
1616
// Python is disabled in this build
1717
#else
18-
// If this is a visual studio build
19-
#if defined( _MSC_VER )
20-
// Special case for debug build since python unfortunately
21-
// adds library to the linker path through a #pragma directive
22-
#if defined( _DEBUG )
23-
// Python forces a header link to python27_d.lib when building debug.
24-
// To get around this (because most python packages for Windows
25-
// don't come with debug python libraries), we undefine _DEBUG, include
26-
// python.h and then restore _DEBUG.
27-
28-
// The problem with this is that any system level headers included from
29-
// python.h were also effectively included in 'release' mode when we undefined
30-
// _DEBUG. To work around this we include headers that python includes
31-
// before undefining _DEBUG.
32-
# include <stdlib.h>
33-
// Undefine to force python to link against the release distro
34-
# undef _DEBUG
35-
# include <Python.h>
36-
# define _DEBUG
37-
38-
#else
39-
#include <Python.h>
40-
#endif
41-
42-
#else
43-
#if defined(__linux__)
44-
// features.h will define _POSIX_C_SOURCE if _GNU_SOURCE is defined. This value
45-
// may be different from the value that Python defines it to be which results
46-
// in a warning. Undefine _POSIX_C_SOURCE before including Python.h The same
47-
// holds for _XOPEN_SOURCE.
48-
#undef _POSIX_C_SOURCE
49-
#undef _XOPEN_SOURCE
50-
#endif
51-
52-
// Include python for non windows machines
53-
#include <Python.h>
54-
18+
#if defined(__linux__)
19+
// features.h will define _POSIX_C_SOURCE if _GNU_SOURCE is defined. This value
20+
// may be different from the value that Python defines it to be which results
21+
// in a warning. Undefine _POSIX_C_SOURCE before including Python.h The same
22+
// holds for _XOPEN_SOURCE.
23+
#undef _POSIX_C_SOURCE
24+
#undef _XOPEN_SOURCE
5525
#endif
26+
27+
// Include python for non windows machines
28+
#include <Python.h>
5629
#endif // LLDB_DISABLE_PYTHON
5730

5831
#endif // LLDB_lldb_python_h_

‎lldb/scripts/Python/finishSwigPythonLLDB.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
strMsgFrameWkPyMkDir = "Python output folder '%s' will be created";
7272
strErrMsgCreateFrmWkPyDirFailed = "Unable to create directory '%s' error: %s";
7373
strMsglldbsoExists = "Symlink '%s' already exists";
74-
strMsglldbsoMk = "Creating symlink for _lldb.so";
74+
strMsglldbsoMk = "Creating symlink for _lldb.so (%s -> %s)";
7575
strErrMsgCpLldbpy = "copying lldb to lldb package directory";
7676
strErrMsgCreatePyPkgMissingSlash = "Parameter 3 fn create_py_pkg() missing slash";
7777
strErrMsgMkLinkExecute = "Command mklink failed: %s";
@@ -135,7 +135,6 @@ def create_py_pkg( vDictArgs, vstrFrameworkPythonDir, vstrPkgDir, vListPkgFiles
135135

136136
strPkgName = vstrPkgDir;
137137
strPkgName = "lldb" + strPkgName.replace( "/", "." );
138-
strPkgName = os.path.normcase( strPkgName );
139138

140139
strPkgDir = vstrFrameworkPythonDir;
141140
strPkgDir += vstrPkgDir;
@@ -148,10 +147,9 @@ def create_py_pkg( vDictArgs, vstrFrameworkPythonDir, vstrPkgDir, vListPkgFiles
148147

149148
for strPkgFile in vListPkgFiles:
150149
if os.path.exists( strPkgFile ) and os.path.isfile( strPkgFile ):
151-
strPyFile = os.path.normcase( strPkgFile );
152150
if bDbg:
153151
print(strMsgCreatePyPkgCopyPkgFile % (strPkgFile, strPkgDir));
154-
shutil.copy( strPyFile, strPkgDir );
152+
shutil.copy( strPkgFile, strPkgDir );
155153

156154
# Create a packet init files if there wasn't one
157155
strPkgIniFile = strPkgDir + "/__init__.py";
@@ -162,8 +160,7 @@ def create_py_pkg( vDictArgs, vstrFrameworkPythonDir, vstrPkgDir, vListPkgFiles
162160
strPyScript = "__all__ = [";
163161
strDelimiter = "";
164162
for strPkgFile in vListPkgFiles:
165-
strPyFile = os.path.normcase( strPkgFile );
166-
if os.path.exists( strPyFile ) and os.path.isfile( strPyFile ):
163+
if os.path.exists( strPkgFile ) and os.path.isfile( strPkgFile ):
167164
strBaseName = os.path.basename( strPkgFile );
168165
nPos = strBaseName.find( "." );
169166
if nPos != -1:
@@ -257,7 +254,7 @@ def make_symlink_windows( vDictArgs, vstrFrameworkPythonDir, vstrDllName ):
257254
return (bOk, strMsg);
258255

259256
if bDbg:
260-
print strMsglldbsoMk;
257+
print strMsglldbsoMk % (os.path.abspath(strSrc), os.path.abspath(strTarget));
261258

262259
try:
263260
csl = ctypes.windll.kernel32.CreateHardLinkW

‎lldb/source/CMakeLists.txt

+12
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,18 @@ endif ()
327327
# FIXME: implement svn/git revision and repository parsing solution on Windows. There is an SVN-only
328328
# revision parsing solution in tools/clang/lib/Basic/CMakelists.txt.
329329

330+
if ( LLDB_ENABLE_PYTHON_SCRIPTS_SWIG_API_GENERATION )
331+
# Add a Post-Build Event to copy over Python files and create the symlink to liblldb.so for the Python API(hardlink on Windows)
332+
if ( NOT LLDB_DISABLE_PYTHON )
333+
message("Adding post build step to run finishSwigWrapperClasses.py")
334+
add_custom_command( TARGET liblldb
335+
POST_BUILD
336+
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/finishSwigWrapperClasses.py
337+
COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/finishSwigWrapperClasses.py "--srcRoot=${LLDB_SOURCE_DIR}" "--targetDir=${CMAKE_CURRENT_BINARY_DIR}/../scripts" "--cfgBldDir=${CMAKE_CURRENT_BINARY_DIR}/../scripts" "--prefix=${CMAKE_BINARY_DIR}" "--cmakeBuildConfiguration=${CMAKE_CFG_INTDIR}" -m
338+
COMMENT "Python script sym-linking LLDB Python API")
339+
endif ()
340+
endif ()
341+
330342
install(TARGETS liblldb
331343
RUNTIME DESTINATION bin
332344
LIBRARY DESTINATION lib

‎lldb/source/Interpreter/ScriptInterpreterPython.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2621,7 +2621,7 @@ ScriptInterpreterPython::InitializePrivate ()
26212621
}
26222622
}
26232623

2624-
PyRun_SimpleString ("sys.dont_write_bytecode = 1; import lldb.embedded_interpreter; from lldb.embedded_interpreter import run_python_interpreter; from lldb.embedded_interpreter import run_one_line; from termios import *");
2624+
PyRun_SimpleString ("sys.dont_write_bytecode = 1; import lldb.embedded_interpreter; from lldb.embedded_interpreter import run_python_interpreter; from lldb.embedded_interpreter import run_one_line");
26252625

26262626
if (threads_already_initialized) {
26272627
if (log)

0 commit comments

Comments
 (0)
Please sign in to comment.