本文档翻译自:https://docs.conan.io/en/latest/creating_packages/external_repo.html
在上一节中,我们从外部存储库中获取了库的源代码。通常打包第三方库就是采用此流程。
从外部存储库中获取源代码有两种不同的方式:
1、使用我们在上一节中显示的source()
方法:
from conans import ConanFile, CMake, tools
class HelloConan(ConanFile):
...
def source(self):
self.run("git clone https://github.com/conan-io/hello.git")
...
您还可以使用tools.Git类:
from conans import ConanFile, CMake, tools
class HelloConan(ConanFile):
...
def source(self):
git = tools.Git(folder="hello")
git.clone("https://github.com/conan-io/hello.git", "master")
...
2、使用ConanFile的scm属性:
:::success
Waring
这是一项实验性功能,可能会在将来的版本中发生重大更改。
:::
from conans import ConanFile, CMake, tools
class HelloConan(ConanFile):
scm = {
"type": "git",
"subfolder": "hello",
"url": "https://github.com/conan-io/hello.git",
"revision": "master"
}
...
Conan 将 clone scm url
并检查scm revision
。前往创建包文档,了解更多有关捕获远程服务器并提交:scm详细信息。
source()
方法将在签出过程之后调用,因此您仍然可以使用它来修补某些内容或检索更多源,但在大多数情况下这不是必需的。
下一篇:配方与源代码在相同的位置