[Lldb-commits] [PATCH] D89295: [lldb] Add /Users/jonas to Python's sys.path
Jonas Devlieghere via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Mon Oct 12 21:45:45 PDT 2020
JDevlieghere created this revision.
JDevlieghere added reviewers: LLDB, labath, lawrence_danna.
JDevlieghere requested review of this revision.
Add support for importing scripts relative the current home directory.
rdar://68310384
https://reviews.llvm.org/D89295
Files:
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
lldb/test/Shell/ScriptInterpreter/Python/Inputs/zip.py
lldb/test/Shell/ScriptInterpreter/Python/relative_import.test
Index: lldb/test/Shell/ScriptInterpreter/Python/relative_import.test
===================================================================
--- /dev/null
+++ lldb/test/Shell/ScriptInterpreter/Python/relative_import.test
@@ -0,0 +1,6 @@
+# REQUIRES: python
+
+# RUN: rm -rf %t && mkdir -p %t
+# RUN: cp %S/Inputs/zip.py %t
+# RUN: env HOME=%t %lldb --script-language python -o 'command script import zip' -o 'zip' 2>&1 | FileCheck %s
+# CHECK: 95126
Index: lldb/test/Shell/ScriptInterpreter/Python/Inputs/zip.py
===================================================================
--- /dev/null
+++ lldb/test/Shell/ScriptInterpreter/Python/Inputs/zip.py
@@ -0,0 +1,7 @@
+import lldb
+
+def zip(debugger, command, result, internal_dict):
+ print("95126")
+
+def __lldb_init_module(debugger, internal_dict):
+ debugger.HandleCommand('command script add -f zip.zip zip')
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
===================================================================
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -3229,11 +3229,16 @@
LLDBSwigPyInit();
- // Update the path python uses to search for modules to include the current
- // directory.
-
+ // We need to call this before AddToSysPath as it uses the sys module.
PyRun_SimpleString("import sys");
+
+ // Update the path python uses to search for modules to include the current
+ // directory and the home directory.
AddToSysPath(AddLocation::End, ".");
+ FileSpec home_dir_spec;
+ llvm::SmallString<128> home_dir;
+ if (FileSystem::Instance().GetHomeDirectory(home_dir))
+ AddToSysPath(AddLocation::End, std::string(home_dir));
// Don't denormalize paths when calling file_spec.GetPath(). On platforms
// that use a backslash as the path separator, this will result in executing
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89295.297762.patch
Type: text/x-patch
Size: 1931 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20201013/7f73486e/attachment-0001.bin>
More information about the lldb-commits
mailing list