其他重要的 Conan 功能

python_requires

可以通过 python_requires 功能 来重用其他 recipe 中的代码。

如果您为不同的包维护了许多共享一些通用逻辑的 recipe,并且您不想在每个 recipe 中重复代码,您可以将该通用代码放入 Conan 的 conanfile.py 中,将其上传到您的服务器,然后让其他 recipe 的 conanfiles 进行 python_requires = "mypythoncode/version" 来依赖它并重用它。

包列表

可以通过“packages-list”功能管理包、recipe 和二进制文件的列表。几个命令,如 uploaddownloadremove,允许接收包文件列表作为输入,并且它们可以对该列表执行操作。一个典型的用例是“将 last conan create 中构建的包上传到服务器”,这可以通过以下方式完成:

$ conan create . --format=json > build.json
$ conan list --graph=build.json --graph-binaries=build --format=json > pkglist.json
$ conan upload --list=pkglist.json -r=myremote -c

请参阅 本节中的示例

从缓存中删除未使用的包

警告

(lru) 最近最少使用功能处于 **预览** 状态。有关更多信息,请参阅 Conan 稳定性 部分。

Conan 缓存不实现任何自动过期策略,因此除非删除包或不时删除缓存,否则其大小将持续增加。可以删除最近未使用的 recipe 和包,同时保留在给定时间段内使用的包(最近最少使用 LRU 策略)。这可以通过 conan removeconan list 命令的 --lru 参数来完成。

# remove all binaries (but not recipes) not used in the last 4 weeks
$ conan remove "*:*" --lru=4w -c
# remove all recipes that have not been used in the last 4 weeks (with their binaries)
$ conan remove "*" --lru=4w -c

请注意,LRU 时间遵循 remove 命令的规则。如果我们使用“*”模式删除 recipe,则只检查 recipe 的 LRU 时间。如果 recipe 最近被使用过,它将保留所有二进制文件;如果 recipe 最近未被使用过,它将自行删除及其所有二进制文件。如果我们使用“*:*”模式,它将只检查二进制文件,并删除未使用的二进制文件,但始终保留 recipe。

首先使用 conan list (请注意,与 remove 不同,conan list 默认不列出所有修订版本,因此如果需要选择所有修订版本,则有必要明确指定 #*),可以创建最近最少使用的包列表。

# List all unused (last 4 weeks) recipe revisions
$ conan list "*#*" --lru=4w --format=json > old.json
# Remove those recipe revisions (and their binaries)
$ conan remove --list=old.json -c

请参阅命令帮助 conan removeconan list