嵌入式系统与单片机|技术阅读
登录|注册

您现在的位置是:嵌入式系统与单片机 > 技术阅读 > C/C++包管理Conan教程【17】版本管理

C/C++包管理Conan教程【17】版本管理

Versioning:

废话不多说,我们先从练习入手:

进入到version_ranges中,

conan create hello hello/0.1@user/testing
conan create chat user/testing

在hello/src/hello.cpp中做一个改动(我这里加了一个v0.2)

再次执行:

conan create hello hello/0.2@user/testing
conan create chat user/testing

你能看到输出有所不同。

现在,我们看一下chat的recipe:

你会注意到这里的requires,hello包的版本在0.0到1.0范围内。

这里还可以写成这种形式,如上图。


Revisions

要使用revisions需要先使能这个功能:

conan config set general.revisions_enabled=True

然后设置远程仓库(参考C/C++包管理Conan教程【8】上传到远程仓库 - 知乎 (zhihu.com))

conan remote add artifactory http://jfrog-artifactory-training:8081/artifactory/api/conan/conan-tmp

最后删除已创建的包):

conan remove "hello*" -f

准备工作就完成了。

现在,进入到revisions工程中:

cd revisions

然后创建hello包:

conan create hello user/testing
conan upload "hello*" --all -r=artifactory --confirm

修改hello.cpp然后再次create并上传:

conan create hello user/testing
conan upload "hello*" --all -r=artifactory --confirm

然后检索远程仓库的hello包:

conan search hello/0.1@user/testing --revision -r=artifactory

如果想使用某个特定的版本,可以通过以下命令完成:

conan install hello/0.1@user/testing#<revision>

如果不加revision,则默认安装最新版本。


Lockfiles

cd lockfiles
conan remove "hello*" -f
conan create hello hello/0.1@user/testing
conan lock create chat/conanfile.py --user=user --channel=testing

现在,在hello/src/hello.cpp中随便改点什么,然后执行:

conan create hello hello/0.2@user/testing

会生成0.2的hello包。

现在尝试执行:

conan create chat user/testing

你会发现依赖的是0.2版本的hello包。

如果使用刚才生成的lockfile:

conan create chat user/testing --lockfile conan.lock

则使用的是lockfile里设置的0.1版本的hello包