[Lldb-commits] [PATCH] D77661: [lldb/Python] Add lldbconfig Python module to make the lldb module configurable.

2020-04-07 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere created this revision.
JDevlieghere added a reviewer: labath.
Herald added a subscriber: mgorny.
JDevlieghere marked an inline comment as done.
JDevlieghere added inline comments.



Comment at: lldb/packages/Python/lldbsuite/test/dotest.py:957
 
+import lldbconfig
 import lldb

This is a NO-OP for now, but just shows that we can load the lldbconfig module. 


Using the approach described in [1] and suggested by Pavel D77588 
 , this patch introduces a new `lldbconfig` 
module that lives next to the `lldb` module. It makes it possible to make the 
`lldb` module configurable. More specifically it makes it possible to delay 
initializing the debugger, which is needed for testing the reproducer.

I chose to name the module lldbconfig rather than `lldb.config` because I 
thought it would be weird to import a "submodule" before the main module, but 
if anyone feels the other approach is more desirable I'd be happy to change it.

[1] 
https://stackoverflow.com/questions/3720740/pass-variable-on-import/39360070#39360070


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D77661

Files:
  lldb/CMakeLists.txt
  lldb/bindings/python.swig
  lldb/bindings/python/lldbconfig.py
  lldb/packages/Python/lldbsuite/test/dotest.py


Index: lldb/packages/Python/lldbsuite/test/dotest.py
===
--- lldb/packages/Python/lldbsuite/test/dotest.py
+++ lldb/packages/Python/lldbsuite/test/dotest.py
@@ -954,7 +954,9 @@
 
 setupSysPath()
 
+import lldbconfig
 import lldb
+
 # Use host platform by default.
 lldb.selected_platform = lldb.SBPlatform.GetHostPlatform()
 
Index: lldb/bindings/python/lldbconfig.py
===
--- /dev/null
+++ lldb/bindings/python/lldbconfig.py
@@ -0,0 +1 @@
+INITIALIZE = True
Index: lldb/bindings/python.swig
===
--- lldb/bindings/python.swig
+++ lldb/bindings/python.swig
@@ -128,8 +128,15 @@
 %include "./python/python-wrapper.swig"
 
 %pythoncode%{
+INITIALIZE = True
+try:
+   import lldbconfig
+   INITIALIZE = lldbconfig.INITIALIZE
+except ImportError:
+   pass
 debugger_unique_id = 0
-SBDebugger.Initialize()
+if INITIALIZE:
+   SBDebugger.Initialize()
 debugger = None
 target = None
 process = None
Index: lldb/CMakeLists.txt
===
--- lldb/CMakeLists.txt
+++ lldb/CMakeLists.txt
@@ -99,11 +99,13 @@
   get_target_property(lldb_bindings_dir swig_wrapper BINARY_DIR)
 
   if(LLDB_BUILD_FRAMEWORK)
-set(lldb_python_build_path 
"${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Resources/Python/lldb")
+set(python_build_path 
"${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Resources/Python")
   else()
-set(lldb_python_build_path 
"${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${LLDB_PYTHON_RELATIVE_PATH}/lldb")
+set(python_build_path 
"${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${LLDB_PYTHON_RELATIVE_PATH}")
   endif()
 
+  set(lldb_python_build_path "${python_build_path}/lldb")
+
   # Add a Post-Build Event to copy over Python files and create the symlink
   # to liblldb.so for the Python API(hardlink on Windows).
   add_custom_target(finish_swig ALL VERBATIM
@@ -115,14 +117,24 @@
 add_custom_command(TARGET finish_swig POST_BUILD VERBATIM
   COMMAND ${CMAKE_COMMAND} -E copy
 "${LLDB_SOURCE_DIR}/third_party/Python/module/six/six.py"
-"${lldb_python_build_path}/../six.py")
+"${python_build_path}/six.py")
   endif()
 
+  add_custom_command(TARGET finish_swig POST_BUILD VERBATIM
+COMMAND ${CMAKE_COMMAND} -E make_directory
+  "${python_build_path}/lldbconfig")
+
+  add_custom_command(TARGET finish_swig POST_BUILD VERBATIM
+COMMAND ${CMAKE_COMMAND} -E copy
+  "${LLDB_SOURCE_DIR}/bindings/python/lldbconfig.py"
+  "${python_build_path}/lldbconfig/__init__.py")
+
   add_custom_command(TARGET finish_swig POST_BUILD VERBATIM
 COMMAND ${CMAKE_COMMAND} -E copy
   "${lldb_bindings_dir}/lldb.py"
   "${lldb_python_build_path}/__init__.py")
 
+
   function(create_python_package pkg_dir)
 cmake_parse_arguments(ARG "NOINIT" "" "FILES" ${ARGN})
 if(ARG_FILES)


Index: lldb/packages/Python/lldbsuite/test/dotest.py
===
--- lldb/packages/Python/lldbsuite/test/dotest.py
+++ lldb/packages/Python/lldbsuite/test/dotest.py
@@ -954,7 +954,9 @@
 
 setupSysPath()
 
+import lldbconfig
 import lldb
+
 # Use host platform by default.
 lldb.selected_platform = lldb.SBPlatform.GetHostPlatform()
 
Index: lldb/bindings/python/lldbconfig.py
===
--- /dev/null
+++ lldb/bindings/python/lldbconfig.py
@@ -0,0 +1 @@
+INITIALIZE = True
Index: lldb/bindings/python.swig
===

[Lldb-commits] [PATCH] D77661: [lldb/Python] Add lldbconfig Python module to make the lldb module configurable.

2020-04-07 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere marked an inline comment as done.
JDevlieghere added inline comments.



Comment at: lldb/packages/Python/lldbsuite/test/dotest.py:957
 
+import lldbconfig
 import lldb

This is a NO-OP for now, but just shows that we can load the lldbconfig module. 


Repository:
  rLLDB LLDB

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77661/new/

https://reviews.llvm.org/D77661



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D77661: [lldb/Python] Add lldbconfig Python module to make the lldb module configurable.

2020-04-07 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

Thanks. This looks fine, just a question about the placement of the lldbconfig 
module.




Comment at: lldb/CMakeLists.txt:130
+  "${LLDB_SOURCE_DIR}/bindings/python/lldbconfig.py"
+  "${python_build_path}/lldbconfig/__init__.py")
+

If we're not going to ship this file, should we place it under 
`packages/Python/...` (I'm sure there is some place we could put it where it 
would already be in `sys.path` ? That way it would not be accessible from 
regular lldb runs, only for those from dotest, which would decrease the 
likelyhood of lldb suddenly stopping to work after being installed.



Comment at: lldb/bindings/python.swig:131
 %pythoncode%{
+INITIALIZE = True
+try:

Maybe `_initialize` (the convention for "private" variables in python)?


Repository:
  rLLDB LLDB

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77661/new/

https://reviews.llvm.org/D77661



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D77661: [lldb/Python] Add lldbconfig Python module to make the lldb module configurable.

2020-04-07 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere updated this revision to Diff 255792.
JDevlieghere marked 2 inline comments as done.
JDevlieghere added a comment.

Address code review feedback


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77661/new/

https://reviews.llvm.org/D77661

Files:
  lldb/bindings/python.swig
  lldb/packages/Python/lldbconfig/__init__.py
  lldb/packages/Python/lldbsuite/test/dotest.py


Index: lldb/packages/Python/lldbsuite/test/dotest.py
===
--- lldb/packages/Python/lldbsuite/test/dotest.py
+++ lldb/packages/Python/lldbsuite/test/dotest.py
@@ -954,7 +954,9 @@
 
 setupSysPath()
 
+import lldbconfig
 import lldb
+
 # Use host platform by default.
 lldb.selected_platform = lldb.SBPlatform.GetHostPlatform()
 
Index: lldb/packages/Python/lldbconfig/__init__.py
===
--- /dev/null
+++ lldb/packages/Python/lldbconfig/__init__.py
@@ -0,0 +1 @@
+_initialize = True
Index: lldb/bindings/python.swig
===
--- lldb/bindings/python.swig
+++ lldb/bindings/python.swig
@@ -128,8 +128,15 @@
 %include "./python/python-wrapper.swig"
 
 %pythoncode%{
+_initialize = True
+try:
+   import lldbconfig
+   _initialize = lldbconfig.INITIALIZE
+except ImportError:
+   pass
 debugger_unique_id = 0
-SBDebugger.Initialize()
+if _initialize:
+   SBDebugger.Initialize()
 debugger = None
 target = None
 process = None


Index: lldb/packages/Python/lldbsuite/test/dotest.py
===
--- lldb/packages/Python/lldbsuite/test/dotest.py
+++ lldb/packages/Python/lldbsuite/test/dotest.py
@@ -954,7 +954,9 @@
 
 setupSysPath()
 
+import lldbconfig
 import lldb
+
 # Use host platform by default.
 lldb.selected_platform = lldb.SBPlatform.GetHostPlatform()
 
Index: lldb/packages/Python/lldbconfig/__init__.py
===
--- /dev/null
+++ lldb/packages/Python/lldbconfig/__init__.py
@@ -0,0 +1 @@
+_initialize = True
Index: lldb/bindings/python.swig
===
--- lldb/bindings/python.swig
+++ lldb/bindings/python.swig
@@ -128,8 +128,15 @@
 %include "./python/python-wrapper.swig"
 
 %pythoncode%{
+_initialize = True
+try:
+   import lldbconfig
+   _initialize = lldbconfig.INITIALIZE
+except ImportError:
+   pass
 debugger_unique_id = 0
-SBDebugger.Initialize()
+if _initialize:
+   SBDebugger.Initialize()
 debugger = None
 target = None
 process = None
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D77661: [lldb/Python] Add lldbconfig Python module to make the lldb module configurable.

2020-04-07 Thread Pavel Labath via Phabricator via lldb-commits
labath accepted this revision.
labath added a comment.
This revision is now accepted and ready to land.

Let's see how this goes.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77661/new/

https://reviews.llvm.org/D77661



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D77661: [lldb/Python] Add lldbconfig Python module to make the lldb module configurable.

2020-04-08 Thread Jonas Devlieghere via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb0bdaf9ba2bf: [lldb/Python] Add lldbconfig module to make 
the lldb module configurable (authored by JDevlieghere).
Herald added a project: LLDB.

Changed prior to commit:
  https://reviews.llvm.org/D77661?vs=255792&id=256140#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77661/new/

https://reviews.llvm.org/D77661

Files:
  lldb/bindings/python.swig
  lldb/packages/Python/lldbconfig/__init__.py
  lldb/packages/Python/lldbsuite/test/dotest.py


Index: lldb/packages/Python/lldbsuite/test/dotest.py
===
--- lldb/packages/Python/lldbsuite/test/dotest.py
+++ lldb/packages/Python/lldbsuite/test/dotest.py
@@ -954,7 +954,9 @@
 
 setupSysPath()
 
+import lldbconfig
 import lldb
+
 # Use host platform by default.
 lldb.selected_platform = lldb.SBPlatform.GetHostPlatform()
 
Index: lldb/packages/Python/lldbconfig/__init__.py
===
--- /dev/null
+++ lldb/packages/Python/lldbconfig/__init__.py
@@ -0,0 +1 @@
+INITIALIZE = True
Index: lldb/bindings/python.swig
===
--- lldb/bindings/python.swig
+++ lldb/bindings/python.swig
@@ -128,8 +128,15 @@
 %include "./python/python-wrapper.swig"
 
 %pythoncode%{
+_initialize = True
+try:
+   import lldbconfig
+   _initialize = lldbconfig.INITIALIZE
+except ImportError:
+   pass
 debugger_unique_id = 0
-SBDebugger.Initialize()
+if _initialize:
+   SBDebugger.Initialize()
 debugger = None
 target = None
 process = None


Index: lldb/packages/Python/lldbsuite/test/dotest.py
===
--- lldb/packages/Python/lldbsuite/test/dotest.py
+++ lldb/packages/Python/lldbsuite/test/dotest.py
@@ -954,7 +954,9 @@
 
 setupSysPath()
 
+import lldbconfig
 import lldb
+
 # Use host platform by default.
 lldb.selected_platform = lldb.SBPlatform.GetHostPlatform()
 
Index: lldb/packages/Python/lldbconfig/__init__.py
===
--- /dev/null
+++ lldb/packages/Python/lldbconfig/__init__.py
@@ -0,0 +1 @@
+INITIALIZE = True
Index: lldb/bindings/python.swig
===
--- lldb/bindings/python.swig
+++ lldb/bindings/python.swig
@@ -128,8 +128,15 @@
 %include "./python/python-wrapper.swig"
 
 %pythoncode%{
+_initialize = True
+try:
+   import lldbconfig
+   _initialize = lldbconfig.INITIALIZE
+except ImportError:
+   pass
 debugger_unique_id = 0
-SBDebugger.Initialize()
+if _initialize:
+   SBDebugger.Initialize()
 debugger = None
 target = None
 process = None
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits