memsharded / conan-protobuf

Google protocol buffers conan package
MIT License
1 stars 17 forks source link

env_info for other packages depends on this pacakge #11

Open gasuketsu opened 7 years ago

gasuketsu commented 7 years ago

Currently I am trying coming conan 0.20.0 (0.20.0dev1) to create packages that depends on this protobuf package with new "virturlbuildenv" generator.

In Linux environment, library package (let's name it A here) depends on this protobuf may want perform "protoc" to generate pb.cc/h in its make phase. I have tried describe imports() in recipe for package A and found files listed in imports() are missing when building package under package build directory (i.e. ~/.conan/data/A/version/user/channel/build/package). I am not sure if this is expected behavior in conan, but I think adding env_info like following snipet would be helpful for this scenario and users will be able to run "protoc" without importing.

Or, is there other good way ?

diff --git a/conanfile.py b/conanfile.py
index d23e28b..57ab8ab 100644
--- a/conanfile.py
+++ b/conanfile.py
@@ -103,3 +103,6 @@ class ProtobufConan(ConanFile):
             self.cpp_info.libs = ["libprotobuf.a"] if not self.options.shared else ["libprotobuf.9.dylib"]
         else:
             self.cpp_info.libs = ["protobuf"]
+        if self.settings.os == "Linux":
+            self.env_info.path.append(os.path.join(self.package_folder, "bin"))
+            self.env_info.LD_LIBRARY_PATH.append(os.path.join(self.package_folder, "lib"))
memsharded commented 7 years ago

Hi @gasuketsu ! This is quite right. New conan version will have huge improvements with the environment variables management, so it could be a good approach to define env-vars for making tools available via PATHs, instead of relying on consumers importing files. Actually, the protobuf package protoc app might have some issues when using shared libraries due to relocation, so the LD_LIBRARY_PATH might be quite good. Especially because now the environment variables are set per package, so this reduce the risks of trouble of excessive polluting the environment.

The behavior you describe with the imports when the package is being built by conan (in the conan local cache), could be that the imported files are removed after build(). We had the issue of packages doing imports (like protoc), they were re-packaging those artifacts, which was not intended by the users. So the default is that they are removed after the build command. If someone wants to re-package them for any reason, it is simple: just copy them in the build step to a different folder.

lasote commented 7 years ago

@gasuketsu Nice to see that you are trying development versions. Be little careful with that version, it has some known bugs. We hope to publish a release candidate today, I'll write you then.

lasote commented 7 years ago

Hi! We have the release candidate ready, please help us to try it! :)

pip install conan==0.20.0rc1

gasuketsu commented 7 years ago

@lasote @memsharded Thank you for your information.

Now I am trying 0.20.0rc1 and it gets easier to apply existing autotools based projects. Thanks! One thing I found is, as I have commented on conan.io's issue 1015 env val PATH definition in activate.sh generated in consumer package gets increased like below by performing conan install for consumer package. (in this example, package_info() in recipe for Protobuf/2.6.1@gasuketsu/testing appends path to package bin directory)

PATH="/home/tharada/.conan/data/Protobuf/2.6.1/gasuketsu/testing/package/81a2fd4ff2b1309c415a72710e1b7fcb494ee7e6/bin":"/home/tharada/.conan/data/Protobuf/2.6.1/gasuketsu/testing/package/81a2fd4ff2b1309c415a72710e1b7fcb494ee7e6/bin":"/home/tharada/.conan/data/Protobuf/2.6.1/gasuketsu/testing/package/81a2fd4ff2b1309c415a72710e1b7fcb494ee7e6/bin":"/home/tharada/.conan/data/Protobuf/2.6.1/gasuketsu/testing/package/81a2fd4ff2b1309c415a72710e1b7fcb494ee7e6/bin":"/home/tharada/.conan/data/Protobuf/2.6.1/gasuketsu/testing/package/81a2fd4ff2b1309c415a72710e1b7fcb494ee7e6/bin":"/home/tharada/.conan/data/Protobuf/2.6.1/gasuketsu/testing/package/81a2fd4ff2b1309c415a72710e1b7fcb494ee7e6/bin":"/home/tharada/.conan/data/Protobuf/2.6.1/gasuketsu/testing/package/81a2fd4ff2b1309c415a72710e1b7fcb494ee7e6/bin":"/home/tharada/.conan/data/Protobuf/2.6.1/gasuketsu/testing/package/81a2fd4ff2b1309c415a72710e1b7fcb494ee7e6/bin":"/home/tharada/.conan/data/Protobuf/2.6.1/gasuketsu/testing/package/81a2fd4ff2b1309c415a72710e1b7fcb494ee7e6/bin":"/home/tharada/.conan/data/Protobuf/2.6.1/gasuketsu/testing/package/81a2fd4ff2b1309c415a72710e1b7fcb494ee7e6/bin":$PATH
export PATH