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

[conan v2] Migrate expat recipe #11696

Merged
merged 11 commits into from
Jul 26, 2022
Merged

Conversation

danimtb
Copy link
Member

@danimtb danimtb commented Jul 14, 2022

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.

_cmake = None

@property
def _source_subfolder(self):
Copy link
Member Author

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):
Copy link
Member Author

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")
Copy link
Member Author

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

Comment on lines -51 to +39
if tools.Version(self.version) < "2.2.8":
if Version(self.version) < "2.2.8":
Copy link
Member Author

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

Comment on lines +45 to +46
if not is_msvc(self):
del self.settings.compiler.libcxx
Copy link
Member Author

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"
Copy link
Member Author

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

@conan-center-bot

This comment has been minimized.

recipes/expat/all/conanfile.py Outdated Show resolved Hide resolved
recipes/expat/all/test_package/CMakeUserPresets.json Outdated Show resolved Hide resolved
recipes/expat/all/test_package/conanfile.py Outdated Show resolved Hide resolved
def layout(self):
cmake_layout(self)

def requirements(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

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!

jwillikers
jwillikers previously approved these changes Jul 14, 2022
@conan-center-bot

This comment has been minimized.

@conan-center-bot

This comment has been minimized.

@conan-center-bot

This comment has been minimized.

@conan-center-bot

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)
Copy link
Contributor

@SpaceIm SpaceIm Jul 15, 2022

Choose a reason for hiding this comment

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

Suggested change
target_link_libraries(${PROJECT_NAME} expat::expat)
target_link_libraries(${PROJECT_NAME} expat::expat)

Perfect example of misleading behavior: conan-io/conan#10387 (comment)

Copy link
Member Author

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?

Copy link
Contributor

@SpaceIm SpaceIm Jul 26, 2022

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"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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?

Copy link
Member Author

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.

@SpaceIm
Copy link
Contributor

SpaceIm commented Jul 15, 2022

CMake Error at conan_toolchain.cmake:27 (message):
  The CMake policy CMP0091 must be NEW, but is ''

Looks like a conan bug coming from conan-io/conan#11098. I see -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" in cmake command line, so what's wrong? It passes for expat >= 2.2.8, the only difference is that cmake_minimum_required is less than 3.1 before 2.2.8.
Probably a different way to manage policies when you set min CMake < 3.0, so that CMP0091 final value is not available at toolchain evaluation time?

/cc @memsharded @lasote @czoido

danimtb and others added 2 commits July 18, 2022 07:57
Co-authored-by: SpaceIm <30052553+SpaceIm@users.noreply.github.com>
Co-authored-by: SpaceIm <30052553+SpaceIm@users.noreply.github.com>
@conan-center-bot

This comment has been minimized.

@github-actions
Copy link
Contributor

Hooks produced the following warnings for commit 1b0ba28
expat/2.4.5
post_package(): WARN: [MISSING SYSTEM LIBS (KB-H043)] Library './lib/libexpat.so' links to system library 'm' but it is not in cpp_info.system_libs.
expat/2.4.6
post_package(): WARN: [MISSING SYSTEM LIBS (KB-H043)] Library './lib/libexpat.so' links to system library 'm' but it is not in cpp_info.system_libs.
expat/2.4.7
post_package(): WARN: [MISSING SYSTEM LIBS (KB-H043)] Library './lib/libexpat.so' links to system library 'm' but it is not in cpp_info.system_libs.
expat/2.4.8
post_package(): WARN: [MISSING SYSTEM LIBS (KB-H043)] Library './lib/libexpat.so' links to system library 'm' but it is not in cpp_info.system_libs.
expat/2.4.4
post_package(): WARN: [MISSING SYSTEM LIBS (KB-H043)] Library './lib/libexpat.so' links to system library 'm' but it is not in cpp_info.system_libs.
expat/2.4.3
post_package(): WARN: [MISSING SYSTEM LIBS (KB-H043)] Library './lib/libexpat.so' links to system library 'm' but it is not in cpp_info.system_libs.
expat/2.4.2
post_package(): WARN: [MISSING SYSTEM LIBS (KB-H043)] Library './lib/libexpat.so' links to system library 'm' but it is not in cpp_info.system_libs.

@danimtb
Copy link
Member Author

danimtb commented Jul 20, 2022

CMake Error at conan_toolchain.cmake:27 (message):
  The CMake policy CMP0091 must be NEW, but is ''

Looks like a conan bug coming from conan-io/conan#11098. I see -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" in cmake command line, so what's wrong? It passes for expat >= 2.2.8, the only difference is that cmake_minimum_required is less than 3.1 before 2.2.8. Probably a different way to manage policies when you set min CMake < 3.0, so that CMP0091 final value is not available at toolchain evaluation time?

/cc @memsharded @lasote @czoido

See latest commit here 79462cc for the fix 🤯

@prince-chrismc
Copy link
Contributor

See latest commit here

Well be patching lots of CMake

@conan-center-bot
Copy link
Collaborator

All green in build 9 (426be9017268c577e80e4926ebdafa8e10bbb0da):

  • expat/2.4.6@:
    All packages built successfully! (All logs)

  • expat/2.4.7@:
    All packages built successfully! (All logs)

  • expat/2.4.5@:
    All packages built successfully! (All logs)

  • expat/2.4.8@:
    All packages built successfully! (All logs)

  • expat/2.4.1@:
    All packages built successfully! (All logs)

  • expat/2.4.4@:
    All packages built successfully! (All logs)

  • expat/2.2.7@:
    All packages built successfully! (All logs)

  • expat/2.4.3@:
    All packages built successfully! (All logs)

  • expat/2.4.2@:
    All packages built successfully! (All logs)

  • expat/2.2.8@:
    All packages built successfully! (All logs)

  • expat/2.2.10@:
    All packages built successfully! (All logs)

  • expat/2.3.0@:
    All packages built successfully! (All logs)

  • expat/2.2.9@:
    All packages built successfully! (All logs)

@github-actions
Copy link
Contributor

Hooks produced the following warnings for commit 426be90
expat/2.4.6
post_package(): WARN: [MISSING SYSTEM LIBS (KB-H043)] Library './lib/libexpat.so' links to system library 'm' but it is not in cpp_info.system_libs.
expat/2.4.7
post_package(): WARN: [MISSING SYSTEM LIBS (KB-H043)] Library './lib/libexpat.so' links to system library 'm' but it is not in cpp_info.system_libs.
expat/2.4.5
post_package(): WARN: [MISSING SYSTEM LIBS (KB-H043)] Library './lib/libexpat.so' links to system library 'm' but it is not in cpp_info.system_libs.
expat/2.4.8
post_package(): WARN: [MISSING SYSTEM LIBS (KB-H043)] Library './lib/libexpat.so' links to system library 'm' but it is not in cpp_info.system_libs.
expat/2.4.4
post_package(): WARN: [MISSING SYSTEM LIBS (KB-H043)] Library './lib/libexpat.so' links to system library 'm' but it is not in cpp_info.system_libs.
expat/2.4.3
post_package(): WARN: [MISSING SYSTEM LIBS (KB-H043)] Library './lib/libexpat.so' links to system library 'm' but it is not in cpp_info.system_libs.
expat/2.4.2
post_package(): WARN: [MISSING SYSTEM LIBS (KB-H043)] Library './lib/libexpat.so' links to system library 'm' but it is not in cpp_info.system_libs.

@SpaceIm
Copy link
Contributor

SpaceIm commented Jul 20, 2022

CMake Error at conan_toolchain.cmake:27 (message):
  The CMake policy CMP0091 must be NEW, but is ''

Looks like a conan bug coming from conan-io/conan#11098. I see -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" in cmake command line, so what's wrong? It passes for expat >= 2.2.8, the only difference is that cmake_minimum_required is less than 3.1 before 2.2.8. Probably a different way to manage policies when you set min CMake < 3.0, so that CMP0091 final value is not available at toolchain evaluation time?
/cc @memsharded @lasote @czoido

See latest commit here 79462cc for the fix 🤯

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")
Copy link
Member

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 🤔

Copy link
Member

@uilianries uilianries left a comment

Choose a reason for hiding this comment

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

Conan 2.0

@conan-center-bot conan-center-bot merged commit f27bcd7 into conan-io:master Jul 26, 2022
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.

None yet

7 participants