Allow customized relative PYTHONHOME
Summary: This change allows a hard coded relative PYTHONHOME setting. So that python can easily be packaged together with lldb. The change includes: 1. Extend LLDB_RELOCATABLE_PYTHON to all platforms. It defaults to ON for platforms other than Windows, to keep the behavior compatible. 2. Allows to customize LLDB_PYTHON_HOME. But still defaults to PYTHON_HOME. 3. LLDB_PYTHON_HOME can be a path relative to liblldb. If it is relative, we will resolve it before send it to Py_DecodeLocale. Subscribers: mgorny, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D74727
This commit is contained in:
@@ -277,14 +277,36 @@ public:
|
||||
|
||||
private:
|
||||
void InitializePythonHome() {
|
||||
#if defined(LLDB_PYTHON_HOME)
|
||||
#if LLDB_EMBED_PYTHON_HOME
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
size_t size = 0;
|
||||
static wchar_t *g_python_home = Py_DecodeLocale(LLDB_PYTHON_HOME, &size);
|
||||
typedef const wchar_t* str_type;
|
||||
#else
|
||||
static char g_python_home[] = LLDB_PYTHON_HOME;
|
||||
typedef char* str_type;
|
||||
#endif
|
||||
Py_SetPythonHome(g_python_home);
|
||||
static str_type g_python_home = []() -> str_type {
|
||||
const char *lldb_python_home = LLDB_PYTHON_HOME;
|
||||
const char *absolute_python_home = nullptr;
|
||||
llvm::SmallString<64> path;
|
||||
if (llvm::sys::path::is_absolute(lldb_python_home)) {
|
||||
absolute_python_home = lldb_python_home;
|
||||
} else {
|
||||
FileSpec spec = HostInfo::GetShlibDir();
|
||||
if (!spec)
|
||||
return nullptr;
|
||||
spec.GetPath(path);
|
||||
llvm::sys::path::append(path, lldb_python_home);
|
||||
absolute_python_home = path.c_str();
|
||||
}
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
size_t size = 0;
|
||||
return Py_DecodeLocale(absolute_python_home, &size);
|
||||
#else
|
||||
return strdup(absolute_python_home);
|
||||
#endif
|
||||
}();
|
||||
if (g_python_home != nullptr) {
|
||||
Py_SetPythonHome(g_python_home);
|
||||
}
|
||||
#else
|
||||
#if defined(__APPLE__) && PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION == 7
|
||||
// For Darwin, the only Python version supported is the one shipped in the
|
||||
|
||||
Reference in New Issue
Block a user