diff options
author | Lawrence D'Anna <larry@elder-gods.org> | 2021-11-16 13:50:18 -0800 |
---|---|---|
committer | Lawrence D'Anna <lawrence_danna@apple.com> | 2021-11-16 13:50:20 -0800 |
commit | 4c2cf3a314d9131b1b288e7c8ab0c75ac1b2be1d (patch) | |
tree | 204b684bb3e3adb769b447893bb130c21e5b5012 /lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp | |
parent | 913d78c40c37c9c3428285d868ce454b058e40f3 (diff) | |
download | llvm-4c2cf3a314d9131b1b288e7c8ab0c75ac1b2be1d.zip llvm-4c2cf3a314d9131b1b288e7c8ab0c75ac1b2be1d.tar.gz llvm-4c2cf3a314d9131b1b288e7c8ab0c75ac1b2be1d.tar.bz2 |
[lldb] fix -print-script-interpreter-info on windows
Apparently "{sys.prefix}/bin/python3" isn't where you find the
python interpreter on windows, so the test I wrote for
-print-script-interpreter-info is failing.
We can't rely on sys.executable at runtime, because that will point
to lldb.exe not python.exe.
We can't just record sys.executable from build time, because python
could have been moved to a different location.
But it should be OK to apply relative path from sys.prefix to sys.executable
from build-time to the sys.prefix at runtime.
Reviewed By: JDevlieghere
Differential Revision: https://reviews.llvm.org/D113650
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp')
-rw-r--r-- | lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp index 418e223..c1f4c2d 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -410,30 +410,31 @@ FileSpec ScriptInterpreterPython::GetPythonDir() { return g_spec; } +static const char GetInterpreterInfoScript[] = R"( +import os +import sys + +def main(lldb_python_dir, python_exe_relative_path): + info = { + "lldb-pythonpath": lldb_python_dir, + "language": "python", + "prefix": sys.prefix, + "executable": os.path.join(sys.prefix, python_exe_relative_path) + } + return info +)"; + +static const char python_exe_relative_path[] = LLDB_PYTHON_EXE_RELATIVE_PATH; + StructuredData::DictionarySP ScriptInterpreterPython::GetInterpreterInfo() { GIL gil; FileSpec python_dir_spec = GetPythonDir(); if (!python_dir_spec) return nullptr; - PythonString python_dir(python_dir_spec.GetPath()); - PythonDictionary info(PyInitialValue::Empty); - llvm::Error error = info.SetItem("lldb-pythonpath", python_dir); - if (error) - return nullptr; - static const char script[] = R"( -def main(info): - import sys - import os - name = 'python' + str(sys.version_info.major) - info.update({ - "language": "python", - "prefix": sys.prefix, - "executable": os.path.join(sys.prefix, "bin", name), - }) - return info -)"; - PythonScript get_info(script); - auto info_json = unwrapIgnoringErrors(As<PythonDictionary>(get_info(info))); + PythonScript get_info(GetInterpreterInfoScript); + auto info_json = unwrapIgnoringErrors( + As<PythonDictionary>(get_info(PythonString(python_dir_spec.GetPath()), + PythonString(python_exe_relative_path)))); if (!info_json) return nullptr; return info_json.CreateStructuredDictionary(); |