Reputation: 1223
I have C/C++ project configuring with cmake and building with conan create
, using conanfile.py
.
I do not need to export my sources in packages that I will upload. I need only put the generated library in the package. So, I do not need to use export_sources
in conanfile.py
. Also, export()
method (or its equivalent export
attribute), I do not know why, but takes too much time to copy my source files from its original folder into conan cache folders, although there is only one 1KB small .txt file.
First, I want to describe what I mean with each type of folder:
Original folder: The path conanfile.py
as well as CMakeLists.txt
and my sources(.cpp), in src directory. Also note that I execute conan create
within this path.
Conan cache folders: Conan creates its own temporary folders to work: build, source, export, etc. In source()
, build()
, etc. methods of conanfile.py
, attributes like source_folder
of ConanFile
already refers to these cache folders, and not to original folder. Also note that conan copies conanfile.py
also in these cache folders and the path of __file__
also gives these cache folders.
So, in build()
method, when I do "self.run('cmake
" I need to refer to the original folder but ConanFile
does not have it, as far as I know. It seemed to strange to me because I do not believe that my case is so strange. I would expect that Conan already has a solution for this.
So, is this a bad practice or is there a solution of Conan that I do not know?
Note that no_copy_source
attribute does not make a difference, because it is about only no copying between Conan cache folders.
If anyway I need to copy my sources from the original path into the Conan cache folders, why export
, or copy
takes too much time even for a single 1kb file of same machine? (With too much time I mean, for copying that small file, it got stuck 1 minute. What does it wait for?)
Either case, how should I do?
conanfile.py
from conans import ConanFile, CMake, tools
import shutil, os, inspect
class MyConan(ConanFile):
name = "MyLib"
version = "0.0.1"
generators = "cmake"
no_copy_source = True
exports = "CMakeLists.txt" # Takes too much time to copy it
def source(self):
current_dir = os.getcwd() # This already points to cache folders
def source(self):
# self.source_folder is pointing to cache folders. I have already lost path of original folder
def build(self):
cmake = CMake(self)
#self.run('cmake %s --preset="my-preset"') HOW TO REFER TO my original source folder? Or HOW TO copy my sources to Conan cache folders without taking too much time
#cmake.build()
command:
cd /path/of/conanfile/and/sources
conan create . 0.0.1/whatever/hotfix
Upvotes: 1
Views: 1750
Reputation: 6007
The build in the Conan cache via conan create
will always do a copy somehow of the sources. The goal is to make sure the package creation is fully reproducible from source, and also guaranteeing a clean build.
If you don't want to upload a copy of the sources, you can use the scm
approach, which captures the coordinates (url, commit), instead of doing a copy. Still, it will do a new clone/checkout in the Conan cache. The goal is to make things fully
If you only want to package the final binaries, that you build locally, you can use the conan export-pkg
functionality (see this link). But this won't allow building the package later, for example to automatically add a new configuration, and will not allow the --build=missing
, for example.
Upvotes: 0