-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[conan v2] Migrate expat recipe #11696
Conversation
_cmake = None | ||
|
||
@property | ||
def _source_subfolder(self): |
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.
layout seems to be not strictly neeeded
return "build_subfolder" | ||
|
||
@property | ||
def _is_msvc(self): |
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.
this was added as a built in tool conan.tools.microsoft.is_msvc
def export_sources(self): | ||
self.copy("CMakeLists.txt") |
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.
CMakelists wrapper is no longer needed
if tools.Version(self.version) < "2.2.8": | ||
if Version(self.version) < "2.2.8": |
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.
conans.tools.Version
--> conan.tools.scm.Version
if not is_msvc(self): | ||
del self.settings.compiler.libcxx |
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.
deleting a non existent compiler setting (tested with msvc
) raises in Conan v2
def generate(self): | ||
tc = CMakeToolchain(self) | ||
if Version(self.version) < "2.2.8": | ||
tc.variables["BUILD_doc"] = "Off" |
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.
cmake.definitions
can be changed directly to CMakeToolchain::variables
This comment has been minimized.
This comment has been minimized.
def layout(self): | ||
cmake_layout(self) | ||
|
||
def requirements(self): |
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.
Is this necessary?
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.
will be required in conan 2.0 https://docs.conan.io/en/latest/migrating_to_2.0/recipes.html#changes-in-the-test-package-recipe
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.
I definitely need to start doing that then. Much appreciated!
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
find_package(EXPAT REQUIRED) | ||
|
||
add_executable(${PROJECT_NAME} test_package.c) | ||
target_link_libraries(${PROJECT_NAME} EXPAT::EXPAT) | ||
target_link_libraries(${PROJECT_NAME} expat::expat) |
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.
target_link_libraries(${PROJECT_NAME} expat::expat) | |
target_link_libraries(${PROJECT_NAME} expat::expat) |
Perfect example of misleading behavior: conan-io/conan#10387 (comment)
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.
Why do you think it is misleading? New CMakeDeps
generators follows the value set at cmake_target_name
, so it makes sense. Should we change it to EXPAT::EXPAT
instead?
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.
It's misleading because you call find_package(EXPAT REQUIRED)
, so you should expect the target from https://cmake.org/cmake/help/latest/module/FindEXPAT.html. But since CMakeDeps forces CMAKE_FIND_PACKAGE_PREFER_CONFIG
to ON (not the default value), it breaks. This is why in test_package, you have to use expat::expat
(the target defined in CMake config file) instead of EXPAT::EXPAT
(target defined by CMake module file).
expat, as well as freetype, are corner case: target in module file is different than target of config file.
import os | ||
|
||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "compiler", "build_type", "arch" | ||
generators = "cmake", "cmake_find_package" | ||
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" |
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.
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" | |
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" |
For my own education, I don't see any explicit call to scripts generated by VirtualRunEnv
, where are they implicitly called in this conanfile?
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.
For CMake, here is the deal https://docs.conan.io/en/2.0/reference/tools/cmake/cmake.html
For VirtualRunEnv, here you see the file names that it generates: https://docs.conan.io/en/2.0/reference/tools/env/virtualrunenv.html and here you can see the run()
part https://docs.conan.io/en/2.0/reference/tools/env/envvars.html#running-with-environment-files
I agree we have to document it better and crosslink both sections. Thanks for the feedback.
Looks like a conan bug coming from conan-io/conan#11098. I see |
Co-authored-by: SpaceIm <30052553+SpaceIm@users.noreply.github.com>
Co-authored-by: SpaceIm <30052553+SpaceIm@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
Hooks produced the following warnings for commit 1b0ba28expat/2.4.5
expat/2.4.6
expat/2.4.7
expat/2.4.8
expat/2.4.4
expat/2.4.3
expat/2.4.2
|
See latest commit here 79462cc for the fix 🤯 |
Well be patching lots of CMake |
All green in build 9 (
|
Hooks produced the following warnings for commit 426be90expat/2.4.6
expat/2.4.7
expat/2.4.5
expat/2.4.8
expat/2.4.4
expat/2.4.3
expat/2.4.2
|
good catch |
bin_path = os.path.join("bin", "test_package") | ||
self.run(bin_path, run_environment=True) | ||
if not cross_building(self): | ||
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") |
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.
Maybe, we could suggest to Conan client to create an alias for it, like self.cpp.build.bindir
. 99% of cases we will use the index 0 🤔
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.
Effort to migrate recipe syntax no new one in conan v2
The aim of this PR is to make the recipe work for both conan v1 and conan v1 without braking consumers of conan v1 as well.