Skip to content

Commit

Permalink
Create _lldb python symlink correctly when LLVM_LIBDIR_SUFFIX is used
Browse files Browse the repository at this point in the history
Summary:
Do not assume that liblldb.so is located in $(lldb -P)/../../../lib
when creating the _lldb python symlink. Instead, use the path passed
to LLVM_LIBDIR_SUFFIX, defaulting to $(lldb -P)/../../../lib when this
variable is not set.

Reviewers: vharron, emaste, zturner

Subscribers: zturner, labath, lldb-commits, sas

Differential Revision: http://reviews.llvm.org/D19067

This is a cherry-pick of r267462

llvm-svn: 270130
  • Loading branch information
fjricci committed May 19, 2016
1 parent 3619fcb commit bec7731
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lldb/CMakeLists.txt
Expand Up @@ -31,7 +31,7 @@ add_subdirectory(lit)
if (NOT LLDB_DISABLE_PYTHON)
# Add a Post-Build Event to copy over Python files and create the symlink to liblldb.so for the Python API(hardlink on Windows)
add_custom_target( finish_swig ALL
COMMAND ${PYTHON_EXECUTABLE} ${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
COMMAND ${PYTHON_EXECUTABLE} ${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}" "--lldbLibDir=lib${LLVM_LIBDIR_SUFFIX}" -m
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/scripts/finishSwigWrapperClasses.py
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/scripts/lldb.py
COMMENT "Python script sym-linking LLDB Python API")
Expand Down
42 changes: 36 additions & 6 deletions lldb/scripts/Python/finishSwigPythonLLDB.py
Expand Up @@ -345,11 +345,12 @@ def make_symlink(vDictArgs, vstrFrameworkPythonDir, vstrSrcFile, vstrTargetFile)
# Args: vDictArgs - (R) Program input parameters.
# vstrFrameworkPythonDir - (R) Python framework directory.
# vstrLiblldbName - (R) File name for _lldb library.
# vstrLiblldbDir - (R) liblldb directory.
# Returns: Bool - True = function success, False = failure.
# Str - Error description on task failure.
# Throws: None.
#--
def make_symlink_liblldb(vDictArgs, vstrFrameworkPythonDir, vstrLiblldbFileName):
def make_symlink_liblldb(vDictArgs, vstrFrameworkPythonDir, vstrLiblldbFileName, vstrLldbLibDir):
dbg = utilsDebug.CDebugFnVerbose("Python script make_symlink_liblldb()")
bOk = True
strErrMsg = ""
Expand All @@ -369,7 +370,7 @@ def make_symlink_liblldb(vDictArgs, vstrFrameworkPythonDir, vstrLiblldbFileName)

bMakeFileCalled = "-m" in vDictArgs
if not bMakeFileCalled:
strSrc = os.path.join("lib", "LLDB")
strSrc = os.path.join(vstrLldbLibDir, "LLDB")
else:
strLibFileExtn = ""
if eOSType == utilsOsType.EnumOsType.Windows:
Expand All @@ -379,7 +380,7 @@ def make_symlink_liblldb(vDictArgs, vstrFrameworkPythonDir, vstrLiblldbFileName)
strLibFileExtn = ".dylib"
else:
strLibFileExtn = ".so"
strSrc = os.path.join("lib", "liblldb" + strLibFileExtn)
strSrc = os.path.join(vstrLldbLibDir, "liblldb" + strLibFileExtn)

bOk, strErrMsg = make_symlink(vDictArgs, vstrFrameworkPythonDir, strSrc, strTarget)

Expand Down Expand Up @@ -449,11 +450,12 @@ def make_symlink_lldb_argdumper(vDictArgs, vstrFrameworkPythonDir, vstrArgdumper
# the Python framework directory.
# Args: vDictArgs - (R) Program input parameters.
# vstrFrameworkPythonDir - (R) Python framework directory.
# vstrLldbLibDir - (R) liblldb directory.
# Returns: Bool - True = function success, False = failure.
# strErrMsg - Error description on task failure.
# Throws: None.
#--
def create_symlinks(vDictArgs, vstrFrameworkPythonDir):
def create_symlinks(vDictArgs, vstrFrameworkPythonDir, vstrLldbLibDir):
dbg = utilsDebug.CDebugFnVerbose("Python script create_symlinks()")
bOk = True
strErrMsg = ""
Expand All @@ -464,7 +466,8 @@ def create_symlinks(vDictArgs, vstrFrameworkPythonDir):
if bOk:
bOk, strErrMsg = make_symlink_liblldb(vDictArgs,
vstrFrameworkPythonDir,
strLibLldbFileName)
strLibLldbFileName,
vstrLldbLibDir)

# Make symlink for darwin-debug on Darwin
strDarwinDebugFileName = "darwin-debug"
Expand Down Expand Up @@ -659,6 +662,28 @@ def get_framework_python_dir(vDictArgs):

return (bOk, strWkDir, strErrMsg)

#++---------------------------------------------------------------------------
# Details: Retrieve the liblldb directory path, if it exists and is valid.
# Args: vDictArgs - (R) Program input parameters.
# Returns: Bool - True = function success, False = failure.
# Str - liblldb directory path.
# strErrMsg - Error description on task failure.
# Throws: None.
#--
def get_liblldb_dir(vDictArgs):
dbg = utilsDebug.CDebugFnVerbose("Python script get_liblldb_dir()")
bOk = True
strErrMsg = ""

strLldbLibDir = ""
bHaveLldbLibDir = "--lldbLibDir" in vDictArgs
if bHaveLldbLibDir:
strLldbLibDir = vDictArgs["--lldbLibDir"]
if (bHaveLldbLibDir == False) or (strLldbLibDir.__len__() == 0):
strLldbLibDir = "lib"

return (bOk, strLldbLibDir, strErrMsg)

#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
Expand All @@ -684,6 +709,8 @@ def get_framework_python_dir(vDictArgs):
be installed. Where non-Darwin systems want to put
the .py and .so files so that Python can find them
automatically. Python install directory.
--lldbLibDir The name of the directory containing liblldb.so.
(optional) "lib" by default.
Results: 0 Success
-100+ Error from this script to the caller script.
-100 Error program failure with optional message.
Expand Down Expand Up @@ -713,11 +740,14 @@ def main(vDictArgs):
print((strMsgPyFileLocatedHere % strFrameworkPythonDir))
print((strMsgConfigBuildDir % strCfgBldDir))

if bOk:
bOk, strLldbLibDir, strMsg = get_liblldb_dir(vDictArgs)

if bOk:
bOk, strMsg = find_or_create_python_dir(vDictArgs, strFrameworkPythonDir)

if bOk:
bOk, strMsg = create_symlinks(vDictArgs, strFrameworkPythonDir)
bOk, strMsg = create_symlinks(vDictArgs, strFrameworkPythonDir, strLldbLibDir)

if bOk:
bOk, strMsg = copy_six(vDictArgs, strFrameworkPythonDir)
Expand Down
11 changes: 8 additions & 3 deletions lldb/scripts/finishSwigWrapperClasses.py
Expand Up @@ -72,6 +72,8 @@
be installed. Where non-Darwin systems want to put\n\
the .py and .so files so that Python can find them\n\
automatically. Python install directory.\n\
--lldbLibDir (optional) The name of the directory containing liblldb.so.\n\
\"lib\" by default.\n\
--cmakeBuildConfiguration= (optional) Is the build configuration(Debug, Release, RelWithDebugInfo)\n\
used to determine where the bin and lib directories are \n\
created for a Windows build.\n\
Expand All @@ -80,7 +82,7 @@
\n\
Usage:\n\
finishSwigWrapperClasses.py --srcRoot=ADirPath --targetDir=ADirPath\n\
--cfgBldDir=ADirPath --prefix=ADirPath -m -d\n\
--cfgBldDir=ADirPath --prefix=ADirPath --lldbLibDir=ADirPath -m -d\n\
\n\
" #TAG_PROGRAM_HELP_INFO

Expand Down Expand Up @@ -158,7 +160,7 @@ def validate_arguments(vArgv):
nResult = 0
strListArgs = "hdm" # Format "hiox:" = -h -i -o -x <arg>
listLongArgs = ["srcRoot=", "targetDir=", "cfgBldDir=", "prefix=", "cmakeBuildConfiguration=",
"argsFile"]
"lldbLibDir=", "argsFile"]
dictArgReq = { "-h": "o", # o = optional, m = mandatory
"-d": "o",
"-m": "o",
Expand All @@ -167,6 +169,7 @@ def validate_arguments(vArgv):
"--cfgBldDir": "o",
"--prefix": "o",
"--cmakeBuildConfiguration": "o",
"--lldbLibDir": "o",
"--argsFile": "o" }

# Check for mandatory parameters
Expand Down Expand Up @@ -337,11 +340,13 @@ def main(vArgv):
--cmakeBuildConfiguration= (optional) Is the build configuration(Debug, Release, RelWithDebugInfo)\n\
used to determine where the bin and lib directories are \n\
created for a Windows build.\n\
--lldbLibDir= The name of the directory containing liblldb.so.
(optional) "lib" by default.
--argsFile= The args are read from a file instead of the
command line. Other command line args are ignored.
Usage:
finishSwigWrapperClasses.py --srcRoot=ADirPath --targetDir=ADirPath
--cfgBldDir=ADirPath --prefix=ADirPath -m -d
--cfgBldDir=ADirPath --prefix=ADirPath --lldbLibDir=ADirPath -m -d
Results: 0 Success
-1 Error - invalid parameters passed.
Expand Down

0 comments on commit bec7731

Please sign in to comment.