conan-io / conan-center-index

Recipes for the ConanCenter repository
https://conan.io/center
MIT License
929 stars 1.67k forks source link

[package] capnproto/0.10.3: PATH is not propagated to dependents #17392

Open kaveish opened 1 year ago

kaveish commented 1 year ago

Description

The path to the capnproto binaries is not available to dependents calling self.run().

I believe this line:

https://github.com/conan-io/conan-center-index/blob/f5add38230cd2d8b77ed949730e1a14fd7873ce3/recipes/capnproto/all/conanfile.py#L233

Should be changed to:

self.buildenv_info.append_path("PATH", bin_path)
self.runenv_info.append_path("PATH", bin_path)

Using this in my conanfile.py:

def generate(self):
    self.run("capnp compile -oc++ myschema.capnp")
    ...

Gives this error:

capnproto/0.10.3: Already installed!
capnproto/0.10.3: Appending PATH env var with: C:\Users\myuser\.conan\data\capnproto\0.10.3\_\_\package\7760cd27822f09aa10e25330b02e7c1b1d0d9b53\bin   
conanfile.py (mypackage/6b34f77081d216c846a5376a6ce160f25ee1a51c): Generator 'CMakeDeps' calling 'generate()'
conanfile.py (mypackage/6b34f77081d216c846a5376a6ce160f25ee1a51c): Generator txt created conanbuildinfo.txt
conanfile.py (mypackage/6b34f77081d216c846a5376a6ce160f25ee1a51c): Calling generate()
'capnp.exe' is not recognized as an internal or external command,
operable program or batch file.
ERROR: conanfile.py (mypackage/6b34f77081d216c846a5376a6ce160f25ee1a51c): Error in generate() method, line 68
        self.run("capnp compile -oc++ myschema.capnp")
        ConanException: Error 1 while executing capnp.exe compile -oc++ src/detector.capnp

Package and Environment Details

Conan profile

[settings] os=Macos os_build=Macos arch=armv8 arch_build=armv8 compiler=apple-clang compiler.version=14 compiler.libcxx=libc++ build_type=Release [options] [conf] [build_requires] [env]

Steps to reproduce

conan install . conan build .

Logs

Click to expand log ``` capnproto/0.10.3: Already installed! capnproto/0.10.3: Appending PATH env var with: C:\Users\myuser\.conan\data\capnproto\0.10.3\_\_\package\7760cd27822f09aa10e25330b02e7c1b1d0d9b53\bin conanfile.py (mypackage/6b34f77081d216c846a5376a6ce160f25ee1a51c): Generator 'CMakeDeps' calling 'generate()' conanfile.py (mypackage/6b34f77081d216c846a5376a6ce160f25ee1a51c): Generator txt created conanbuildinfo.txt conanfile.py (mypackage/6b34f77081d216c846a5376a6ce160f25ee1a51c): Calling generate() 'capnp.exe' is not recognized as an internal or external command, operable program or batch file. ERROR: conanfile.py (mypackage/6b34f77081d216c846a5376a6ce160f25ee1a51c): Error in generate() method, line 68 self.run("capnp compile -oc++ myschema.capnp") ConanException: Error 1 while executing capnp.exe compile -oc++ src/detector.capnp ```
SpaceIm commented 1 year ago

generate() is not the appropriate place to run anything coming from requirements or build requirements.

kaveish commented 1 year ago

generate() is not the appropriate place to run anything coming from requirements or build requirements.

Thanks, I'm new to conan. The requirement is capnproto, which includes capnp.exe which is used to generate a .h and .cxx file from a .capnp file. I want my CMakeLists.txt file to pick up those generated files, so I thought it was appropriate to call this in generate() before calling CMakeToolchain.generate(). Do I have that wrong?

SpaceIm commented 1 year ago

It should be called in build() before calling CMake, or better your CMakeLists should be written such that it calls capnp through a custom command & custom target. If capnproto is only in your requirements, you may have to add run=True in self.requires("capnproto/x.y.z") (and eventually inject VirtualRunEnv in build scope), because conan assumes that executables come from build requirements by default.

kaveish commented 1 year ago

That makes sense, I'll give that a try. I wasn't aware of the run parameter in self.requires, that's useful.