Skip to content

[clang][python] Add CLANG_DISABLE_RUN_PYTHON_TESTS CMake option to disable clang python bindings tests #111367

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

Conversation

asb
Copy link
Contributor

@asb asb commented Oct 7, 2024

We already have hard-coded logic to disable adding these tests to the check-all target in various cases. It's handy to have a CMake option to disable if in an environment where the tests don't work and you want check-all to work as expected.


By my understanding there's no ability to treat CMake options as tri-state, where I'd be able to tell if it was explicitly st to ON, explicitly set to OFF, or left to the default. So the new option is just "force disable" rather than allowing a force enable/

CC also @linux4life798 as another contributor I can see from the commit logs.


Closed in favour of #111657

…sable clang python bindings tests

We already have hard-coded logic to disable adding these tests to the
`check-all` target in various cases. It's handy to have a CMake option
to disable if in an environment where the tests don't work and you want
`check-all` to work as expected.
@asb asb requested a review from DeinAlptraum as a code owner October 7, 2024 12:24
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:as-a-library libclang and C++ API labels Oct 7, 2024
@llvmbot
Copy link
Member

llvmbot commented Oct 7, 2024

@llvm/pr-subscribers-clang

Author: Alex Bradbury (asb)

Changes

We already have hard-coded logic to disable adding these tests to the check-all target in various cases. It's handy to have a CMake option to disable if in an environment where the tests don't work and you want check-all to work as expected.


By my understanding there's no ability to treat CMake options as tri-state, where I'd be able to tell if it was explicitly st to ON, explicitly set to OFF, or left to the default. So the new option is just "force disable" rather than allowing a force enable/

CC also @linux4life798 as another contributor I can see from the commit logs.


Full diff: https://github.com/llvm/llvm-project/pull/111367.diff

1 Files Affected:

  • (modified) clang/bindings/python/tests/CMakeLists.txt (+6)
diff --git a/clang/bindings/python/tests/CMakeLists.txt b/clang/bindings/python/tests/CMakeLists.txt
index 2543cf739463d9..b97195c24d62b1 100644
--- a/clang/bindings/python/tests/CMakeLists.txt
+++ b/clang/bindings/python/tests/CMakeLists.txt
@@ -47,6 +47,12 @@ if(${LLVM_NATIVE_ARCH} MATCHES "^(AArch64|Hexagon|Sparc|SystemZ)$")
   set(RUN_PYTHON_TESTS FALSE)
 endif()
 
+# Allow user to explicitly disable these tests.
+option(CLANG_DISABLE_RUN_PYTHON_TESTS "Do not run Clang Python bindings tests" OFF)
+if(CLANG_DISABLE_RUN_PYTHON_TESTS)
+  set(RUN_PYTHON_TESTS FALSE)
+endif()
+
 if(RUN_PYTHON_TESTS)
     set_property(GLOBAL APPEND PROPERTY
                  LLVM_ALL_ADDITIONAL_TEST_TARGETS check-clang-python)

Copy link
Contributor

@DeinAlptraum DeinAlptraum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I'd like @Endilll to take a look as well, since I'm not that familiar with our build infrastructure & cmake

@Endilll
Copy link
Contributor

Endilll commented Oct 8, 2024

We already have hard-coded logic to disable adding these tests to the check-all target in various cases.

Why do you have to do that?

@asb
Copy link
Contributor Author

asb commented Oct 9, 2024

We already have hard-coded logic to disable adding these tests to the check-all target in various cases.

Why do you have to do that?

I've never worked with the clang python bindings before, but you can basically see the reasoning in https://github.com/llvm/llvm-project/blob/bf7022f71a95313e8ebdd34e5ea7cb7bca90a24d/clang/bindings/python/tests/CMakeLists.txt - there are various targets and configurations where they are expected or known to fail.

@Endilll
Copy link
Contributor

Endilll commented Oct 9, 2024

We already have hard-coded logic to disable adding these tests to the check-all target in various cases.

Why do you have to do that?

I've never worked with the clang python bindings before, but you can basically see the reasoning in https://github.com/llvm/llvm-project/blob/bf7022f71a95313e8ebdd34e5ea7cb7bca90a24d/clang/bindings/python/tests/CMakeLists.txt - there are various targets and configurations where they are expected or known to fail.

Sorry, I'm asking for the use case for the particular CMake knob you're adding. If there are more platforms that those tests are not working on, we should simply expand the pre-existing list

if(${LLVM_NATIVE_ARCH} MATCHES "^(AArch64|Hexagon|Sparc|SystemZ)$")

Or, better, disable tests individually based on the triple, like we do elsewhere.

@asb
Copy link
Contributor Author

asb commented Oct 9, 2024

Sorry, I'm asking for the use case for the particular CMake knob you're adding. If there are more platforms that those tests are not working on, we should simply expand the pre-existing list

Ah sorry for misunderstanding you - good question. In my case it's a cross setup. The host Python3_EXECUTABLE will never successfully run these tests, even if a target python3 (run via qemu-user and binfmt_misc) could. Though now I write this, I'm thinking it would make more sense to set RUN_PYTHON_TESTS to FALSE if CMAKE_CROSSCOMPILING is set. What do you think?

@Endilll
Copy link
Contributor

Endilll commented Oct 9, 2024

Though now I write this, I'm thinking it would make more sense to set RUN_PYTHON_TESTS to FALSE if CMAKE_CROSSCOMPILING is set. What do you think?

Yes, I like this direction much more. Probably you should also print a message during configuration saying that those tests are excluded because of cross setup.

Do you know what the state of support for cross environments is in general? If they are generally well-maintained, we're more incentivized to do a proper support for them in Python bindings tests.

asb added a commit to asb/llvm-project that referenced this pull request Oct 9, 2024
…mpiling

Consistent with other cases for these tests, we opt not to add the
target to check-all if they're known to fail. The tests fail when cross
compiling for a different architecture because the host
Python3_EXECUTABLE is used to run them, and FFI calls will of course
fail against the libraries compiled for the target.

This is an alternate take on
<llvm#111367>.
@asb
Copy link
Contributor Author

asb commented Oct 9, 2024

Though now I write this, I'm thinking it would make more sense to set RUN_PYTHON_TESTS to FALSE if CMAKE_CROSSCOMPILING is set. What do you think?

Yes, I like this direction much more. Probably you should also print a message during configuration saying that those tests are excluded because of cross setup.

Thanks for the review and feedback, definitely a better solution. I've posted it as a separate PR rather than reworking this one because it's a fundamentally different approach and editing this one would be confusing when coming back later. #111657

Do you know what the state of support for cross environments is in general? If they are generally well-maintained, we're more incentivized to do a proper support for them in Python bindings tests.

Now I've landed #111373 a cross-build and then check-all actually works surprisingly well. I'm not sure to what degree I'd consider it officially supported, but I'm working to clean it up a bit as I think there's scope for taking more advantage of this setup for local development, litmus testing for releases, and at least some CI (on the staging buildmaster if not the main one).

@asb asb closed this Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:as-a-library libclang and C++ API clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants