-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Push down the swig module to avoid an import cycle #129135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Push down the swig module to avoid an import cycle #129135
Conversation
@llvm/pr-subscribers-lldb Author: wieDasDing (dingxiangfei2009) ChangesFix #92603 This replaces #113066. I finally came back to this issue and it seems that this approach is still very promising. As requested, I have added a short explanation as to why CPython module should be moved into a submodule. cc @JDevlieghere who reviewed on the previous PR earlier. Full diff: https://github.com/llvm/llvm-project/pull/129135.diff 2 Files Affected:
diff --git a/lldb/bindings/python/CMakeLists.txt b/lldb/bindings/python/CMakeLists.txt
index 69306a384e0b1..c4bf74e094f00 100644
--- a/lldb/bindings/python/CMakeLists.txt
+++ b/lldb/bindings/python/CMakeLists.txt
@@ -59,8 +59,10 @@ endfunction()
function(finish_swig_python swig_target lldb_python_bindings_dir lldb_python_target_dir)
# Add a Post-Build Event to copy over Python files and create the symlink to
# liblldb.so for the Python API(hardlink on Windows).
+ # Note that Swig-generated code is located one level deeper in the `native`
+ # module, in order to avoid cyclic importing.
add_custom_target(${swig_target} ALL VERBATIM
- COMMAND ${CMAKE_COMMAND} -E make_directory ${lldb_python_target_dir}
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${lldb_python_target_dir}/native/
DEPENDS ${lldb_python_bindings_dir}/lldb.py
COMMENT "Python script sym-linking LLDB Python API")
@@ -74,6 +76,8 @@ function(finish_swig_python swig_target lldb_python_bindings_dir lldb_python_tar
"${LLDB_SOURCE_DIR}/source/Interpreter/embedded_interpreter.py"
"${lldb_python_target_dir}")
+ create_python_package(${swig_target} ${lldb_python_target_dir} "native" FILES)
+
# Distribute the examples as python packages.
create_python_package(
${swig_target}
@@ -141,7 +145,7 @@ function(finish_swig_python swig_target lldb_python_bindings_dir lldb_python_tar
endif()
set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb${LLDB_PYTHON_EXT_SUFFIX}")
create_relative_symlink(${swig_target} ${LIBLLDB_SYMLINK_DEST}
- ${lldb_python_target_dir} ${LIBLLDB_SYMLINK_OUTPUT_FILE})
+ ${lldb_python_target_dir}/native/ ${LIBLLDB_SYMLINK_OUTPUT_FILE})
if (NOT WIN32)
diff --git a/lldb/bindings/python/python.swig b/lldb/bindings/python/python.swig
index 278c0eed2bab2..f1b156624e8d8 100644
--- a/lldb/bindings/python/python.swig
+++ b/lldb/bindings/python/python.swig
@@ -50,7 +50,12 @@ Older swig versions will simply ignore this setting.
import $module
except ImportError:
# Relative import should work if we are being loaded by Python.
- from . import $module"
+ # The cpython module built by swig is pushed one level down into
+ # the native submodule, because at this point the interpreter
+ # is still constructing the lldb module itself.
+ # Simply importing anything using `from . import` constitutes
+ # a cyclic importing.
+ from .native import $module"
%enddef
// The name of the module to be created.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for adding the comment with the motivation!
@dingxiangfei2009 please let me know if you need me to press the merge button for you.
Thank you so much, @JDevlieghere!
Yes, you may hit the merge button. 🙏
Jonas Devlieghere ***@***.***> schrieb am Fr. 28. Feb. 2025
um 16:35:
… ***@***.**** approved this pull request.
LGTM. Thanks for adding the comment with the motivation!
@dingxiangfei2009 <https://github.com/dingxiangfei2009> please let me
know if you need me to press the merge button for you.
—
Reply to this email directly, view it on GitHub
<#129135 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABUQYWAI3OOBDBR467AQLAD2SB63TAVCNFSM6AAAAABYA6D5JCVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDMNJRGEYDENRWGQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
these changes break the lldb-remote-linux-win buildbot with the following error:
https://lab.llvm.org/buildbot/#/builders/197/builds/2712 Could you take a look at this? |
It seems this patch have broken a lot of test on the buildbot lldb-remote-linux-win |
Could be a coincidence, but we also have more failures on Windows on Arm - https://lab.llvm.org/buildbot/#/builders/141/builds/6744 that came in with this change. Might be failing too build the inferior and reporting that badly. |
This reverts commit 396139a.
Reverts #129135 due to buildbot test failures. Definitely caused remote Linux to Windows failures (https://lab.llvm.org/buildbot/#/builders/197/builds/2712), may be the cause of Windows on Arm failures https://lab.llvm.org/buildbot/#/builders/141/builds/6744.
I've reverted this since we have at least 1 confirmed problem. Also next time please set a valid email address for the contribution so that you get notifications via email as well. |
…" (#129714) Reverts llvm/llvm-project#129135 due to buildbot test failures. Definitely caused remote Linux to Windows failures (https://lab.llvm.org/buildbot/#/builders/197/builds/2712), may be the cause of Windows on Arm failures https://lab.llvm.org/buildbot/#/builders/141/builds/6744.
Okay! Thank you for reverting! I will run more test and find a solution. |
It seems that This should help:
|
Fix llvm#92603 This replaces llvm#113066. I finally came back to this issue and it seems that this approach is still very promising. As requested, I have added a short explanation as to why CPython module should be moved into a submodule. cc @JDevlieghere who reviewed on the previous PR earlier.
) Reverts llvm#129135 due to buildbot test failures. Definitely caused remote Linux to Windows failures (https://lab.llvm.org/buildbot/#/builders/197/builds/2712), may be the cause of Windows on Arm failures https://lab.llvm.org/buildbot/#/builders/141/builds/6744.
Fix #92603
This replaces #113066. I finally came back to this issue and it seems that this approach is still very promising.
As requested, I have added a short explanation as to why CPython module should be moved into a submodule.
cc @JDevlieghere who reviewed on the previous PR earlier.