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

CppInfo Components internal requirements #6871

Merged
merged 16 commits into from Apr 29, 2020

Conversation

danimtb
Copy link
Member

@danimtb danimtb commented Apr 16, 2020

Changelog: Feature: Implements cpp_info.components dependencies.
Docs: conan-io/docs#1682

#tags: slow

  • Refer to the issue that supports this Pull Request: closes #6716
  • If the issue has missing info, explain the purpose/use case/pain/need that covers this Pull Request.
  • I've read the Contributing guide.
  • I've followed the PEP8 style guides for Python code.
  • I've opened another PR in the Conan docs repo to the develop branch, documenting this one.

Note: By default this PR will skip the slower tests and will use a limited set of python versions. Check here how to increase the testing level by writing some tags in the current PR body text.

@danimtb danimtb added this to the 1.25 milestone Apr 16, 2020
@danimtb danimtb self-assigned this Apr 16, 2020
conans/model/build_info.py Outdated Show resolved Hide resolved
conans/model/build_info.py Outdated Show resolved Hide resolved
conans/model/build_info.py Outdated Show resolved Hide resolved
conans/model/build_info.py Outdated Show resolved Hide resolved
conans/model/build_info.py Outdated Show resolved Hide resolved
Copy link
Member

@jgsogo jgsogo left a comment

Some comments over the tests, I've been having a look mostly to the functionality, not the implementation

conans/test/integration/package_info_test.py Outdated Show resolved Hide resolved
conans/test/integration/package_info_test.py Show resolved Hide resolved
conans/test/integration/package_info_test.py Show resolved Hide resolved
conans/test/integration/package_info_test.py Show resolved Hide resolved
conans/test/integration/package_info_test.py Show resolved Hide resolved
conans/model/build_info.py Show resolved Hide resolved
conans/model/build_info.py Outdated Show resolved Hide resolved
conans/model/build_info.py Show resolved Hide resolved
conans/test/integration/package_info_test.py Show resolved Hide resolved
conans/model/build_info.py Outdated Show resolved Hide resolved
conans/model/build_info.py Outdated Show resolved Hide resolved
conans/model/build_info.py Outdated Show resolved Hide resolved
if not all([dep in components for dep in comp.requires]):
raise ConanException("Component '%s' declares a missing dependency" % comp_name)
# check if component is not required and can be added to ordered
if comp_name not in [require for dep in components.values() for require in
Copy link
Member

@memsharded memsharded Apr 26, 2020

Choose a reason for hiding this comment

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

Probably way simpler and faster to sort in the opposite order: check that the current components requires are None or all in ordered.

Copy link
Member Author

@danimtb danimtb Apr 28, 2020

Choose a reason for hiding this comment

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

I implemented that logic before and it was a mess calculating the link order later. I'd like to keep it as is for now and improve the speed in the future if needed

@danimtb danimtb changed the title Feature/components deps CppInfo Components internal requirements Apr 27, 2020
@danimtb danimtb marked this pull request as ready for review Apr 27, 2020
@danimtb danimtb requested a review from jgsogo Apr 27, 2020
conans/test/unittests/model/build_info_test.py Outdated Show resolved Hide resolved
conans/test/unittests/model/build_info/components_test.py Outdated Show resolved Hide resolved
conans/model/build_info.py Outdated Show resolved Hide resolved
conans/client/installer.py Outdated Show resolved Hide resolved
@danimtb danimtb requested a review from memsharded Apr 28, 2020
Sort Components from most dependent one first to the less dependent one last
:return: List of sorted components
"""
if not self._sorted_components:
Copy link
Member

@memsharded memsharded Apr 28, 2020

Choose a reason for hiding this comment

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

When lazy/caching, this is better checked against None if self._sorted_components is None, to avoid firing again computations when result is an empty dict, list or set.

@@ -206,6 +218,12 @@ def _raise_if_mixing_components(self):
raise ConanException("self.cpp_info.components cannot be used with self.cpp_info configs"
" (release/debug/...) at the same time")

# Raise on component name
for comp_name in self.components:
Copy link
Member

@memsharded memsharded Apr 28, 2020

Choose a reason for hiding this comment

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

Also as a oneliner: if any(comp_name == name for comp_name in self.components)

Copy link
Member

@jgsogo jgsogo left a comment

I'm missing a test here, but I don't know how to make it. Maybe you have an idea:

I need a package llvm using components that require another package openssl. I want to see that components from llvm need to require openssl explicitly in order to work (because it has to be explicit, right?):

OpenSSL recipe: any recipe not using components

LLVM recipe

class LLVM(ConanFile):
    name = 'llvm'
    requires = "openssl/1.1.1z"

    def package_info(self):
        self.cpp_info.components["tooling"].requires["openssl::openssl"]

        # What happens with this line in this PR? By now it should work the same as the previous one? raise? ignore?
        self.cpp_info.components["unwind"].requires["openssl::crypto"]

People will start to use components and we want them to add the .requires["openssl::openssl"] so it will work in the next Conan iteration with the "enhanced-generators". Otherwise people will need to change their recipes again with the next version.

I really don't know if it is worth to check it in the sources (at least for CMake I imagine a weird if clause in the CMake file) or just write it big and clear in the docs.

@memsharded
Copy link
Member

@memsharded memsharded commented Apr 28, 2020

People will start to use components and we want them to add the .requires["openssl::openssl"] so it will work in the next Conan iteration with the "enhanced-generators". Otherwise people will need to change their recipes again with the next version.

You mean to force the definition of at least one components["some_comp"].requires to each one of the current direct package requires definition, and otherwise it will be an error, right? Yes, this would be a nice addition if not too complex, to avoid badly-defined recipes.

It should be clearly documented that when defining components, it is not assumed a dependency to the required packages, and it should be explicit.

jgsogo
jgsogo approved these changes Apr 28, 2020
Copy link
Member

@jgsogo jgsogo left a comment

Easier than expected. Thanks for this extra effort \o/

Copy link
Member

@memsharded memsharded left a comment

It seems that you were hit by your own check in another test: package_info_components_test()

@danimtb
Copy link
Member Author

@danimtb danimtb commented Apr 29, 2020

Added docs!

@danimtb danimtb assigned jgsogo and unassigned danimtb Apr 29, 2020
jgsogo
jgsogo approved these changes Apr 29, 2020
Copy link
Member

@jgsogo jgsogo left a comment

🎁 Ready to go!

@jgsogo jgsogo merged commit f6fbe52 into conan-io:develop Apr 29, 2020
2 checks passed
@jgsogo jgsogo added this to Closed in Components via automation Apr 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Components
  
Closed
Development

Successfully merging this pull request may close these issues.

3 participants