Skip to content

Commit

Permalink
Compute Python library suffix in CMakeLists.txt
Browse files Browse the repository at this point in the history
Introduce LLDB_PY_LIB_SUFFIX and use it in various places in the
build.  This lets the x.py-based build work properly without having to
set LLVM_LIBDIR_SUFFIX.

See https://bugs.llvm.org/show_bug.cgi?id=18957 for some discussion.
  • Loading branch information
tromey authored and cuviper committed Mar 18, 2019
1 parent 91d8cf1 commit f65a0c0
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 4 deletions.
9 changes: 8 additions & 1 deletion lldb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ if(APPLE)
add_definitions(-DLLDB_USE_OS_LOG)
endif()

if (NOT LLDB_DISABLE_PYTHON)
execute_process(
COMMAND
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/get_libdir_suffix.py
OUTPUT_VARIABLE LLDB_PY_LIB_SUFFIX)
endif ()

add_subdirectory(docs)
if (NOT LLDB_DISABLE_PYTHON)
add_subdirectory(scripts)
Expand Down Expand Up @@ -146,7 +153,7 @@ if (NOT LLDB_DISABLE_PYTHON)
--cfgBldDir=${lldb_scripts_dir}
--prefix=${CMAKE_BINARY_DIR}
--cmakeBuildConfiguration=${CMAKE_CFG_INTDIR}
--lldbLibDir=lib${LLVM_LIBDIR_SUFFIX}
--lldbLibDir=lib${LLDB_PY_LIB_SUFFIX}
${use_python_wrapper_from_src_dir}
${use_six_py_from_system}
VERBATIM
Expand Down
2 changes: 1 addition & 1 deletion lldb/docs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ if(EPYDOC_EXECUTABLE)
--url "http://lldb.llvm.org"
${EPYDOC_OPTIONS}
DEPENDS swig_wrapper liblldb
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../../../lib${LLVM_LIBDIR_SUFFIX}/python2.7/site-packages
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../../../lib${LLDB_PY_LIB_SUFFIX}/python2.7/site-packages
COMMENT "Generating LLDB Python API reference with epydoc" VERBATIM
)
endif(EPYDOC_EXECUTABLE)
2 changes: 1 addition & 1 deletion lldb/scripts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ if(NOT LLDB_BUILD_FRAMEWORK)
endif()

set(SWIG_PYTHON_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${swig_python_subdir})
set(SWIG_INSTALL_DIR lib${LLVM_LIBDIR_SUFFIX})
set(SWIG_INSTALL_DIR lib${LLDB_PY_LIB_SUFFIX})

# Install the LLDB python module
install(DIRECTORY ${SWIG_PYTHON_DIR} DESTINATION ${SWIG_INSTALL_DIR})
Expand Down
2 changes: 1 addition & 1 deletion lldb/scripts/Python/modules/readline/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ set_target_properties(readline PROPERTIES
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})
install(TARGETS readline LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib${LLDB_PY_LIB_SUFFIX}/${PYTHON_DIRECTORY})
33 changes: 33 additions & 0 deletions lldb/scripts/get_libdir_suffix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import distutils.sysconfig
import os
import platform
import re
import sys


def get_python_libdir_suffix():
"""Returns the appropropriate python libdir suffix.
@return the python libdir suffix, normally either "" or "64".
"""
if platform.system() != 'Linux':
return ""

# We currently have a bug in lldb -P that does not account for
# architecture variants in python paths for
# architecture-specific modules. Handle the lookup here.
# When that bug is fixed, we should just ask lldb for the
# right answer always.
arch_specific_libdir = distutils.sysconfig.get_python_lib(True, False)
split_libdir = arch_specific_libdir.split(os.sep)
lib_re = re.compile(r"^lib.+$")

for i in range(len(split_libdir)):
match = lib_re.match(split_libdir[i])
if match is not None:
return split_libdir[i][3:]
return ""

if __name__ == '__main__':
sys.stdout.write(get_python_libdir_suffix())
sys.exit(0)

0 comments on commit f65a0c0

Please sign in to comment.