Hello,
We are using Conan 1.3.1 (currently under OS X 10.12, but this is hopefully not relevant)
We are following Gitflow (so, branches), and to ease the development process, we defined the gitbranch
option, defaulting to develop, and use it in source()
as follows:
def source(self):
self.run("git clone [email protected]:ourepo.git")
self.run("cd ourrepo && git checkout {branch} && git submodule update --init"
.format(branch=self.options.gitbranch))
A complication we observe at the moment is that, when calling conan create
with a different option value, a new package_id is generated (as expected), the build()
is re-run, but not the source()
: the sources cloned during the first run of conan create
聽are reused.
Thus our option is never actually taken into account, and the same artifacts are packaged under a different package_id.
Is this the expected behaviour? Is it possible to override it?
Thank you for reading,
Hi @Adnn !
yes, this is totally intended. The source()
method is designed to do the tasks that are common for all binaries. Typically, getting the source code. So the execution of this task is just done once, and not re-run for every different configuration. If you want to do something that is specific for different configurations/binaries, then you can do it in the build()
method. It is totally fine to download source code or other things in the build()
method, it doesn't need to be read as "compile code", but as to "build the package". So you should be able to move those lines safely to the build()
method.
Please tell me if you have any further doubt. Thanks!
Hi @memsharded !
Once again thank you for the very helpful answer. Following your recommendation of moving some logic to build()
, my recipe now looks like this:
def source(self):
self.run("git clone [email protected]:agdevs/handy.git")
def build(self):
self.run("cd myrepo && git checkout {branch} && git pull && git submodule update --init"
.format(branch=self.options.gitbranch))
#compilation logic here
And it switches branch as expected.
On a note less related to this question, thank you for both the extremely useful project and the awesome attitude you have toward helping your users. I am very enthusiastic about Conan since I started using it, and it is only getting better!
Hi @Adnn
Sure, your approach is better than mine, indeed, only need to clone once :)
I think this issue can be closed now, then, but please re-open or comment if necessary.
Thanks to you for your kind words and your support! Just in case you don't know it, there is also a very helpful #conan channel in the CppLang slack team, with many friendly and supportive community. We also hang around there often, so it is also possible to chat with us.
Most helpful comment
Hi @Adnn !
yes, this is totally intended. The
source()
method is designed to do the tasks that are common for all binaries. Typically, getting the source code. So the execution of this task is just done once, and not re-run for every different configuration. If you want to do something that is specific for different configurations/binaries, then you can do it in thebuild()
method. It is totally fine to download source code or other things in thebuild()
method, it doesn't need to be read as "compile code", but as to "build the package". So you should be able to move those lines safely to thebuild()
method.Please tell me if you have any further doubt. Thanks!