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

[question] Using dependency with override flag inside library #3970

Open
1 task done
whs31 opened this issue Jan 27, 2025 · 4 comments
Open
1 task done

[question] Using dependency with override flag inside library #3970

whs31 opened this issue Jan 27, 2025 · 4 comments
Assignees
Milestone

Comments

@whs31
Copy link

whs31 commented Jan 27, 2025

What is your question?

I'm trying to use asio-grpc library inside my conan package, which I'll be exporting. But when I'm trying to override grpc version for asio-grpc package inside my conanfile, exporting breaks.

Removing the override flag works as intended.

Environment Details

  • Operating System+version: Windows 11 22H2
  • Compiler+version: MSVC 2022
  • Conan version: 2.11.0
  • Python version: 3.12.0

Steps to reproduce

  • Create a conanfile with the following requirements:
def requirements(self):
        self.requires("grpc/1.67.1", override=True, transitive_libs=True, transitive_headers=True)
        self.requires("asio-grpc/2.9.2", transitive_libs=True, transitive_headers=True)

# ... 

def package_info(self):
        self.cpp_info.set_property("cmake_file_name", "my_package")
        self.cpp_info.set_property("cmake_target_name", "my_package::my_package")
        self.cpp_info.libs = ["my_package"]
        self.cpp_info.requires = [
            "asio-grpc::asio-grpc",
            "grpc::grpc"
        ]
        self.cpp_info.resdirs = ["share"]
  • Run conan create .
  • Get error message:
ERROR: my_package/2.0.0: required component package 'grpc::' not in dependencies

Have you read the CONTRIBUTING guide?

  • I've read the CONTRIBUTING guide
@whs31
Copy link
Author

whs31 commented Jan 28, 2025

Update: for some reason it also works with the 'override' flag if I remove it from self.cpp_info.requires:

self.cpp_info.requires = [  "asio-grpc::asio-grpc" ] # this works

# this doesn't
self.cpp_info.requires = [
  "asio-grpc::asio-grpc",
  "grpc::grpc"
]

Both packages are present in the requirements method.

I would appreciate it if you could clarify the details of this behavior.

@memsharded memsharded self-assigned this Jan 28, 2025
@memsharded
Copy link
Member

Hi @whs31

Thanks for your question:

self.requires("grpc/1.67.1", override=True, transitive_libs=True, transitive_headers=True)

This means: "if there is an existing verison of grpc up in the dependency graph, please use the 1.67.1 version instead of the required version up there. But if there is no grpc up in the dependency graph, do nothing". That is, it only "overrides" if it is existing, if it doesn't exist, it does nothing.

If you want to force the dependency to grpc/1.67.1, then use force=True instead of override=True, and that will add the dependency always, even if it doesn't exist upstream, and if it exists upstream it will enforce the 1.67.1 version.

@whs31
Copy link
Author

whs31 commented Jan 28, 2025

Thank you very much for your answer, I think the force flag is exactly what I need in my case.

@whs31 whs31 closed this as completed Jan 28, 2025
@AbrilRBS
Copy link
Member

I'm moving this to the docs repo to better clarify the difference between both traits, thanks a lot for your question :)

@AbrilRBS AbrilRBS reopened this Jan 28, 2025
@AbrilRBS AbrilRBS transferred this issue from conan-io/conan Jan 28, 2025
@AbrilRBS AbrilRBS assigned AbrilRBS and unassigned memsharded Jan 28, 2025
@memsharded memsharded added this to the 2 milestone Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants