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] Conan 2.0 export -pkg - Exported the binary pacakge but package reference is not found in the environment #14257

Closed
1 task done
AroshikaFernando opened this issue Jul 10, 2023 · 10 comments
Assignees

Comments

@AroshikaFernando
Copy link

AroshikaFernando commented Jul 10, 2023

What is your question?

I am new to conan and trying to export package.
I have written sample recipe file and try to execute export-pkg command.

Environment Details:

  • OS Version: Red Hat Enterprise Linux 8.5 (Ootpa)
  • Conan Version: 2.0.7
  • Python Version: 3.6.8

My Sample recipe file as follows,

import os, yaml
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMake
from conan.tools.files import save, load, copy

class sampleRecipe(ConanFile):
    name = "sample"
    version = "0.1"
    settings = "os", "compiler", "build_type", "arch"
    generators = "CMakeToolchain", "CMakeDeps"
    options = {"shared": [True, False]}
    default_options = {"shared": False}

    def build(self):
        cmake = CMake(self)
        cmake.configure()
        cmake.build()

    def package(self):
        copy(self, "bin/CCQueryServer", src="test_make/mtech_1/build/bin", dst="sampleRecipe/bin")

NOTE: bin/CCQueryServer is in this test_make/mtech_1/build/bin directory and want to copy sampleRecipe/bin.

I have execute conan install cmd and then execute conan export-pkg ~/sampleRecipe/ . My conanfile.py is in ~/sampleRecipe/.

Received log as follows,

======== Exporting recipe to the cache ========
sample/0.1: Exporting package recipe: /home/ec2-user/sampleRecipe/conanfile.py
sample/0.1: Copied 1 '.py' file: conanfile.py
sample/0.1: Exported to cache folder: /home/ec2-user/.conan2/p/sampldf96ecb674796/e
sample/0.1: Exported: sample/0.1#8751dffed570bcd7ba03c01d4ce073ec (2023-07-10 06:14:37 UTC)

======== Computing dependency graph ========
Graph root
    conanfile.py (sample/0.1): /home/ec2-user/sampleRecipe/conanfile.py

======== Computing necessary packages ========

======== Installing packages ========
conanfile.py (sample/0.1): Writing generators to /home/ec2-user/sampleRecipe
conanfile.py (sample/0.1): Generator 'CMakeToolchain' calling 'generate()'
conanfile.py (sample/0.1): CMakeToolchain generated: conan_toolchain.cmake
conanfile.py (sample/0.1): Preset 'conan-debug' added to CMakePresets.json. Invoke it manually using 'cmake --preset conan-debug' if using CMake>=3.23
conanfile.py (sample/0.1): If your CMake version is not compatible with CMakePresets (<3.23) call cmake like: 'cmake <path> -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=/home/ec2-user/sampleRecipe/conan_toolchain.cmake -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_BUILD_TYPE=debug'
conanfile.py (sample/0.1): CMakeToolchain generated: CMakePresets.json
conanfile.py (sample/0.1): Generator 'CMakeDeps' calling 'generate()'
conanfile.py (sample/0.1): Generating aggregated env files
conanfile.py (sample/0.1): Generated aggregated env files: ['conanbuild.sh', 'conanrun.sh']

======== Exporting recipe and package to the cache ========
conanfile.py (sample/0.1): Exporting binary from user folder to Conan cache
conanfile.py (sample/0.1): Packaging to f4eea5ae5cc643670c079a6b210a9e6d35b061b3
conanfile.py (sample/0.1): Generating the package
conanfile.py (sample/0.1): Temporary package folder /home/ec2-user/.conan2/p/b/sampl20a4bf7f08d11/p
conanfile.py (sample/0.1): Calling package()
conanfile.py (sample/0.1): package(): WARN: No files in this package!
conanfile.py (sample/0.1): Created package revision c447120b91cf9d8113c6a397917062f2
conanfile.py (sample/0.1): Package 'f4eea5ae5cc643670c079a6b210a9e6d35b061b3' created
conanfile.py (sample/0.1): Full package reference: sample/0.1#8751dffed570bcd7ba03c01d4ce073ec:f4eea5ae5cc643670c079a6b210a9e6d35b061b3#c447120b91cf9d8113c6a397917062f2
conanfile.py (sample/0.1): Package folder /home/ec2-user/.conan2/p/b/sampl20a4bf7f08d11/p
conanfile.py (sample/0.1): Exported package binary

Output:

  • conan will just warn WARN: No files in this package!
  • this package Package 'f4eea5ae5cc643670c079a6b210a9e6d35b061b3' is not in my environment.
  • Copy Doesn't happen also

Why is that happen? Could someone please explain?

Have you read the CONTRIBUTING guide?

  • I've read the CONTRIBUTING guide
@memsharded
Copy link
Member

Hi @AroshikaFernando

Thanks for your question.

I think you are duplicating the bin folder path:

copy(self, "bin/CCQueryServer", src="test_make/mtech_1/build/bin", dst="sampleRecipe/bin")

That would mean that files are in test_make/mtech_1/build/bin/bin/CCQueryServer, with a double bin.
I'd encourage you to try copy(self, "*", ) and then run conan cache path sample/0.1:f4eea5ae5cc643670c079a6b210a9e6d35b061b3``, which gives you the folder and you can inspect the files there.

this package Package 'f4eea5ae5cc643670c079a6b210a9e6d35b061b3' is not in my environment.

Not sure what you mean. If you do conan list sample/0.1:* you should see your package listed there, with the configuration you used to build it.

Other side hints (probably you know them, and you just simplified the recipe for reporting, but just in case):

  • Defining a layout() method that describes what are the folders where libs, bins, and includes are is the recommended way specify it, instead of hardcoding "bin". Not fully necessary, but take it into account if you write other recipes, recipes building from source, etc.
  • The conan new cmake_lib -d name=sample -d version=0.1 is a good starting point to try things. With that recipe you should be able to do: conan build . to build locally the binaries, then conan export-pkg .
  • generators generators = "CMakeToolchain", "CMakeDeps" not necessary if you don't have dependencies and you are not building from source.
  • If you have the shared option, it means you are building static and shared variants of a library, and it is typical that you could be doing if self.options.shared: copy(self, "*.dll", ... (just the idea, not real code)

@AroshikaFernando
Copy link
Author

AroshikaFernando commented Jul 10, 2023

Hi @memsharded

Thank you for the response and the hints.

Yes, given recipe file is not my actual recipe file. I have simplified the recipe file for the reporting.

I have update the recipe file as copy(self, "*", src="test_make/mtech_1/build/bin", dst="sampleRecipe/bin")

but that file is not copying to the given destination folder.

this package Package 'f4eea5ae5cc643670c079a6b210a9e6d35b061b3' is not in my environment.

I mean, Can't we find our package in our local directory path like,
/home/ec2-user/.conan2/<some directory>/f4eea5ae5cc643670c079a6b210a9e6d35b061b3

And could you please explain little bit more about what conan cache path is?

then run conan cache path sample/0.1:f4eea5ae5cc643670c079a6b210a9e6d35b061b3``, which gives you the folder and you can inspect the files there.

@memsharded
Copy link
Member

but that file is not copying to the given destination folder.

Oh, I am sorry, my bad, I didn't realize that you are missing something there: the current directory is the build directory when package() executes. The new copy() method needs the explicit path, so something like this is needed:

copy(self, "*", src=os.path.join(self.build_folder, "test_make..."), dst=os.path.join(self.package_folder, "sampleRecipe/bin"))

Some more notes:

  • In general you want to package the binaries in just dst=os.path.join(self.package_folder, "bin"), and avoid the extra sampleRecipe folder. The "standard" layout of a final package is better "include", "bin", lib" folders. Otherwise you might need to define in your recipe package_info() self.cpp_info.bindirs = ["sampleRecipe/bin"] and things like that. As the binaries are already inside the "sample" package, adding that extra folder doesn't add much.

  • Also, the src=os.path.join(self.build_folder, .. could be strictly not necessary, as the package() method is running in the build_folder already, but it is better in most cases, it helps disambiguate some cases.

  • Note that things like headers are typically not in the build_folder, but in the source_folder, so something like this: copy(self, "*.h", self.source_folder, os.path.join(self.package_folder, "include"))

/home/ec2-user/.conan2//f4eea5ae5cc643670c079a6b210a9e6d35b061b3

You won't find a f4eea5ae5cc643670c079a6b210a9e6d35b061b3 folder in your cache. The folder in the cache containing your package is exactly what the conan cache path sample/0.1:f4eea5ae5cc643670c079a6b210a9e6d35b061b3 will give you, the folder in the cache containing your package (conan cache path sample/0.1 will give you the folder in the cache containing your exported recipe)

@AroshikaFernando
Copy link
Author

AroshikaFernando commented Jul 10, 2023

Thank you very much for your explanation.

I'll update copy() in my recipe file and check.

@AroshikaFernando
Copy link
Author

Hi @memsharded,

Thank you very much for the help. My issue was sorted.

I am doing conan migration from 1.X to 2.0.X

My conan 1.X recipe file has following copy () statement.
self.copy("lib/libmbase.od.so*", symlinks=True)

How do we migrate that symlinks=true in conan 2.0?

@memsharded
Copy link
Member

In the copy() function, less "magic" is done to symlinks, compared with the previous self.copy implementation.
They will still be copied, but without that much processing. If some processing is necessary, like making them relative, removing the ones that would be broken, etc, then there are a few new helpers to "preprocess" the symlinks, so copy() will handle them without problems, check https://docs.conan.io/2/reference/tools/files/symlinks.html

But in many cases, the normal copy() will already copy symlinks by default

@AroshikaFernando
Copy link
Author

Thank you very much @memsharded.

@AroshikaFernando
Copy link
Author

Hi @memsharded,

Could you please look into following query?

[https://github.com/conan-io/examples2/issues/109]

@memsharded
Copy link
Member

Yes, responded there. It seems that the question in this ticket is solved, can we close this ticket then? Thanks!

@AroshikaFernando
Copy link
Author

Thank you very much @memsharded . I'll close this ticket.

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

2 participants