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

[bug] Cannot resolve conflicts in conanfile.txt #3848

Open
madebr opened this issue Sep 24, 2024 · 11 comments
Open

[bug] Cannot resolve conflicts in conanfile.txt #3848

madebr opened this issue Sep 24, 2024 · 11 comments
Milestone

Comments

@madebr
Copy link
Contributor

madebr commented Sep 24, 2024

Describe the bug

I just created the conanfile.txt at the bottom for a project.
When installing it. conan informs me there is a version conflict between stb/cci.20230920 and stb/cci.20240531.
Looking through the documentation, I don't see a way to resolve this in the txt file.

I believe overriding packages should be do-able from the txt files, and does not require a conversion to py files.

Also, the error messages contains: Run conan graph info with your recipe and add --format=html to inspect the graph errors in an easier to visualize way.
But when I add --format=html, no html files are generated.

How to reproduce it

conanfile.txt

[requires]
miniz/3.0.2
nlohmann_json/3.11.3
stb/cci.20240531
libsquish/1.15
glew/2.2.0
assimp/5.4.2
fmt/11.0.2

[generators]
CMakeDeps
CMakeToolchain
$ conan install . --output-folder=build --build=missing
@AbrilRBS
Copy link
Member

I believe overriding packages should be do-able from the txt files, and does not require a conversion to py files.

The preferred way to change dependencies versions would be to use the [replace_requires] feature of profiles, see https://docs.conan.io/2/reference/config_files/profiles.html#replace-requires, which allow you to specify replacements for your versions, so for example:

[replace_requires]
dep/*: dep/1.1               # To override all dep versions in recipes to a specific version dep/1.1

Also, the error messages contains: Run conan graph info with your recipe and add --format=html to inspect the graph errors in an easier to visualize way.
But when I add --format=html, no html files are generated.

Conan 2 does not generate output files by itself. You'll need to redirect the output manually to a file of your choosing, like:
conan graph info .... --format=html > graph.html. Said file will then have your HTML ready for viewing in a browser

Let me know if this helps, thanks!

@madebr
Copy link
Contributor Author

madebr commented Sep 24, 2024

Let me know if this helps, thanks!

It works, but I believe adding this override globally in your profile is the incorrect approach.
You might want to use another version in another prefix.

Thanks.

@memsharded
Copy link
Member

You might want to use another version in another prefix.

Not clear what you mean, could you please clarify what is another prefix?

@madebr
Copy link
Contributor Author

madebr commented Sep 24, 2024

The profile is a global configuration.
By prefix, I mean the prefixes of the dependencies of a project (CMAKE_PREFIX_PATH).

The overrides of the dependencies of projectA should not influence the dependencies of projectB.

@memsharded
Copy link
Member

memsharded commented Sep 24, 2024

The overrides of the dependencies of projectA should not influence the dependencies of projectB.

You could have 2 different profiles conanfileA_overrides and conanfileB_overrides and you use them when installing deps for the different projects:

conan install conanfileA.txt -pr=myprofile -pr=conanfileA_overrides 
# and
conan install conanfileB.txt -pr=myprofile -pr=conanfileB_overrides

Profiles doesn't need to be global and used for all projects

@madebr
Copy link
Contributor Author

madebr commented Sep 24, 2024

That looks useful, though it feels weird to mix dependency issues with profile.

conan install -h does not show a --pr= option. Is --pr= allowed?

@memsharded
Copy link
Member

That looks useful, though it feels weird to mix dependency issues with profile.

this is because an override is considered an exceptional case, kind of graph external configuration, not part of the conanfile. The conanfile is focused on the definition of its dependencies, if there are conflicts upstream, the best approach of course would be to fix them upstream, updating the dependencies recipes. If that is not possible and a quick fix is desired, then adding it in a local profile can solve it, but keeping it in a separate profile makes it more evident and explicit that this is external and temporary configuration to resolve the conflict, not a permanent definition of the dependency graphs.

This keeps the general design that a conanfile defines "what" dependencies it wants, while profiles and configuration define "how" (defining options, changing package_id_modes, etc).

Also, it is important to consider that overrides in conanfiles is possibly the most challenging thing in the graph resolution, build-orders, CI-flows, etc, because they are graph-local information that is defined only in downstream nodes and as such not always available to resolve when processing some upstream nodes, this is why putting them in profiles makes things way more robust.

conan install -h does not show a --pr= option. Is --pr= allowed?

No, sorry, my mistake, it is just -pr always

@madebr
Copy link
Contributor Author

madebr commented Sep 24, 2024

Thanks for the background.

I felt it was a missing feature in conanfile.txt, because it is possible to do in conanfile.py through self.requires(... , force=True).
The docs only explain how to fix it in py files, not through txt files.

@memsharded
Copy link
Member

Yes, that is true, but in conanfile.py is possible also because of historical reasons, the [replace_requires] is very modern in Conan2.X, while the requires(dep, force=True / override=True) has been there for a very long time, so not really possible to remove it. But as the recommendation is to avoid overrides as much as possible, it was not worth to invent a new custom text-based syntax in conanfile.txt for something that we know it is not great.

@madebr
Copy link
Contributor Author

madebr commented Sep 24, 2024

Feel free to close this issue.
I'd suggest to document this somehow to avoid explaining this to every person.

@memsharded
Copy link
Member

Moving to the docs repo then, thanks for your feedback!

@memsharded memsharded transferred this issue from conan-io/conan Sep 25, 2024
@memsharded memsharded added this to the 2 milestone Sep 25, 2024
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

No branches or pull requests

3 participants