Recipe and sources in a different repo
In the previous section we fetched the sources of our library from an external repository. It is a typical workflow for packaging third party libraries.
There are two different ways to fetch the sources from an external repository:
Using the
source()
method as we saw in the previous section:
from conans import ConanFile, CMake, tools
class HelloConan(ConanFile):
...
def source(self):
self.run("git clone https://github.com/memsharded/hello.git")
self.run("cd hello && git checkout static_shared")
...
You can also use the tools.Git class:
from conans import ConanFile, CMake, tools
class HelloConan(ConanFile):
...
def source(self):
git = tools.Git(folder="hello")
git.clone("https://github.com/memsharded/hello.git", "static_shared")
...
Using the scm attribute of the conanfile [EXPERIMENTAL]:
from conans import ConanFile, CMake, tools
class HelloConan(ConanFile):
scm = {
"type": "git",
"subfolder": "hello",
"url": "https://github.com/memsharded/hello.git",
"revision": "static_shared"
}
...
Conan will clone the scm url
and will checkout the scm revision
.
For git
(currently the only supported scm), the revision
field can be:
A commit hash
A branch
A tag
The source()
method will be called after the checkout process, so you can still use is to patch something or
retrieve more sources, but it is not necessary in most cases.