Skip to content

Commit 7056eaf

Browse files
tromeynikic
authored andcommitted
Compute Python library suffix in CMakeLists.txt
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.
1 parent 0a2514c commit 7056eaf

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

lldb/CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ if (WIN32)
3030
add_definitions(-D_ENABLE_EXTENDED_ALIGNED_STORAGE)
3131
endif()
3232

33+
if (NOT LLDB_DISABLE_PYTHON)
34+
execute_process(
35+
COMMAND
36+
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/get_libdir_suffix.py
37+
OUTPUT_VARIABLE LLDB_PY_LIB_SUFFIX)
38+
endif ()
39+
40+
add_subdirectory(docs)
3341
if (NOT LLDB_DISABLE_PYTHON)
3442
add_subdirectory(scripts)
3543
endif ()
@@ -186,7 +194,7 @@ if (NOT LLDB_DISABLE_PYTHON)
186194
--cfgBldDir=${lldb_scripts_dir}
187195
--prefix=${CMAKE_BINARY_DIR}
188196
--cmakeBuildConfiguration=${CMAKE_CFG_INTDIR}
189-
--lldbLibDir=lib${LLVM_LIBDIR_SUFFIX}
197+
--lldbLibDir=lib${LLDB_PY_LIB_SUFFIX}
190198
${use_python_wrapper_from_src_dir}
191199
${use_six_py_from_system}
192200
VERBATIM

lldb/scripts/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ if(NOT LLDB_BUILD_FRAMEWORK)
4444
endif()
4545

4646
set(SWIG_PYTHON_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${swig_python_subdir})
47-
set(SWIG_INSTALL_DIR lib${LLVM_LIBDIR_SUFFIX})
47+
set(SWIG_INSTALL_DIR lib${LLDB_PY_LIB_SUFFIX})
4848

4949
# Install the LLDB python module
5050
install(DIRECTORY ${SWIG_PYTHON_DIR} DESTINATION ${SWIG_INSTALL_DIR})

lldb/scripts/get_libdir_suffix.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import distutils.sysconfig
2+
import os
3+
import platform
4+
import re
5+
import sys
6+
7+
8+
def get_python_libdir_suffix():
9+
"""Returns the appropropriate python libdir suffix.
10+
11+
@return the python libdir suffix, normally either "" or "64".
12+
"""
13+
if platform.system() != 'Linux':
14+
return ""
15+
16+
# We currently have a bug in lldb -P that does not account for
17+
# architecture variants in python paths for
18+
# architecture-specific modules. Handle the lookup here.
19+
# When that bug is fixed, we should just ask lldb for the
20+
# right answer always.
21+
arch_specific_libdir = distutils.sysconfig.get_python_lib(True, False)
22+
split_libdir = arch_specific_libdir.split(os.sep)
23+
lib_re = re.compile(r"^lib.+$")
24+
25+
for i in range(len(split_libdir)):
26+
match = lib_re.match(split_libdir[i])
27+
if match is not None:
28+
return split_libdir[i][3:]
29+
return ""
30+
31+
if __name__ == '__main__':
32+
sys.stdout.write(get_python_libdir_suffix())
33+
sys.exit(0)

0 commit comments

Comments
 (0)