Skip to content
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

Fixes #570: Do not remove CMAKE_MODULE_PATH if already set on find_package() #571

Merged
merged 7 commits into from
Nov 14, 2023

Conversation

curlybeast
Copy link
Contributor

@curlybeast curlybeast commented Oct 4, 2023

This fixes the issue for me.

Close #570

@CLAassistant
Copy link

CLAassistant commented Oct 4, 2023

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@memsharded memsharded left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution @curlybeast

I don't fully get what is the difference, looks similar behavior to me.
Maybe having a unit test that would fail without the change would clarify it (and a test seems necessary anyway). Do you think you could try to contribute a test too? If not, don't worry, just tell us, and we will try to help with that.

UPDATE: Sorry I hadn't seen #570, I have added a reference in this PR message.

I know understand the reasons. Still, that further reveals the importance of adding a test to cover this test for now and to avoid future breakage.

@curlybeast
Copy link
Contributor Author

I don't fully get what is the difference, looks similar behavior to me.
The CMAKE_MODULE_PATH is a list. All this patch does is:

  • Only add the provider path once.
  • Only remove the provider path if it's in the list.

Using strings as before means that subsequent runs of that function may change the originally saved string irrevocably, which I believe is what is happening.

Do you think you could try to contribute a test too? If not, don't worry, just tell us, and we will try to help with that.
If I find time. But I've also not used the test framework you're using. Would appreciate some help with that if possible.
I agree a test should be added.

@curlybeast
Copy link
Contributor Author

I've added the beginnings of a test (to the same branch / PR) which replicate the find_package() calls I'm using in my project.
I am using REQUIRED though and we can't really do this. I also can not reproduce the problem (if I revert the fix) using this test, which is odd. I wonder if one of the modules (my hunch is the OpenSSL module) is doing another find_package() that triggers this?

If that is the problem, the question is how to test this effectively without requiring a bunch of pre-installed libraries. Thoughts?

@memsharded
Copy link
Member

I've added the beginnings of a test (to the same branch / PR) which replicate the find_package() calls I'm using in my project.
I am using REQUIRED though and we can't really do this. I also can not reproduce the problem (if I revert the fix) using this test, which is odd. I wonder if one of the modules (my hunch is the OpenSSL module) is doing another find_package() that triggers this?

This is good, exactly the reason why adding the tests are important :)

Indeed do not depend on external packages if possible

It is possible to create simple packages locally, that simulate the openssl package behavior, with an internal find_package or whatever (when using CMakeDeps, this will not happen, not sure about your setup, if you were using openssl in a different way, not via CMakeDeps).

Comment on lines 14 to 15
add_executable(app main.cpp)
target_link_libraries(app hello::hello bye::bye)
Copy link
Member

Choose a reason for hiding this comment

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

The executable build can be removed for the test

run("cmake .. -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=conan_provider.cmake -DCMAKE_BUILD_TYPE=Release Module -DCMAKE_C_COMPILER=/usr/bin/cc", check=False)
out, _ = capfd.readouterr()
assert "We should be seeing this warning, if we do the test works" in out
run("cmake --build .")
Copy link
Member

Choose a reason for hiding this comment

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

This line an be removed

Comment on lines 6 to 9
find_program(CCACHE ccache)
find_package(OpenSSL)
find_package(ZLIB)
find_package(prometheus-cpp)
Copy link
Member

Choose a reason for hiding this comment

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

This would be the thing to simplify, maybe adding a fake openssl-config.cmake in another folder and adding it to the CMAKE_PREFIX_PATH?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, these are the find_package() calls before the problem occurs.
I'll do some digging in my environment to pinpoint exactly what it is.

@jcar87
Copy link
Contributor

jcar87 commented Nov 13, 2023

Hi @curlybeast - I've sync'ed up the changes with the develop2 branch, and rebased accordingly. I'll take care of the tests as well, as there are a few more things ! Keep this in mind, if you work on this branch locally you'll have to do git fetch followed by git reset --hard origin/develop, otherwise you'll may get merge errors.

Copy link
Contributor

@jcar87 jcar87 left a comment

Choose a reason for hiding this comment

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

LGTM

Thanks @curlybeast - the issue happened in a very specific case where two nested find_package calls were satisfied by a CMake FIND module, rather than a config. Only in that scenario was CMAKE_MODULE_PATH incorrectly restored. Your solution fixes this.

We discovered a second issue - some recipes can define cpp_info.builddirs, which result in paths being prepended to CMAKE_MODULE_PATH - those were being lost too. Happy to report your proposed solution also fixes that bug :)

I've added tests for both situations.

@jcar87 jcar87 merged commit c35579a into conan-io:develop2 Nov 14, 2023
4 checks passed
@curlybeast
Copy link
Contributor Author

Thank you for the help on this @jcar87, glad to hear I could help the project and that we found / fixed other related issues too! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants