question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[question] how to specify `requires`/`tool_requires` for same dependency.

See original GitHub issue

How does one add a requirement for both build and runtime?

I would like to build autoconf so have the following:

    def requirements(self) -> None:
        self.requires(f"perl/5.34.1@{self._channel}")
        self.requires(f"m4/1.4.19@{self._channel}")

    def build_requirements(self) -> None:
        self.tool_requires(f"make/4.3@{self._channel}")
        self.tool_requires(f"m4/1.4.19@{self._channel}")
        self.tool_requires(f"perl/5.34.1@{self._channel}")

As perl/m4 is needed for both building and runtime of autoconf. However, doing conan info $PWD/package/autoconf results in the following:

Requires:
    perl/5.34.1@mychannel/testing
    m4/1.4.19@mychannel/testing
Build Requires:
    make/4.3@mychannel/testing

This means that the build fails beacause perl and the m4 binaries are not exposed on the PATH for the build.

How do I get both: expose the requirement to the build and use the requirement at runtime.

I’m using host/build contexts with 1.47 and trying to make my recipes as Conan v2 compatible as possible.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:21 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
mattyclarksoncommented, May 11, 2022

OK, found it and figured it out 🎉

In the test_package we have:

def build_requirements(self):
    self.tool_requires(self.tested_reference_str)

That was a misunderstanding when reading the docs

What that does is adds the top level package (autoconf) in the build context.

When the dependencies in autoconf are resolved, they all ge put in the build context. This means that when the dependencies are updated they overwrite each other due to the ID for the node being calculated with the reference name and the context.

I think the correct way to do this is:

def requirements(self):
    self.tool_requires(self.tested_reference_str)

That’ll put autoconf into the host context. I’m not 100% sure if that’s the correct thing because the example in here:

    def build_requirements(self):
        self.test_requires(self.tested_reference_str)

I assume that test_requires put the reference string in the host context.

I’ll have to look around at the best practices here for testing binaries within Conan.

@memsharded thanks for all the help, certainly learnt a lot here and it was totally on us.

It would be pretty cool if we could deny calling the tool_requires in build_requirements in the test package somehow (unless that is a valid use case…)

1reaction
memshardedcommented, May 11, 2022

I think I am a bit confused again 😅

In Conan 1.X the self.tool_requires() inside requirements() wouldn’t be valid.

It sounds like there still could be some failure mode that I am missing, do you think it would be possible to reproduce what you are commenting in the test in your PR in https://github.com/conan-io/conan/pull/11213?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Maven: how to override the dependency added by a library
Simply specify the version in your current pom. The version specified here will override other. Forcing a version. A version will always be ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found