conan cache¶
执行本地缓存(配方和/或包)中的文件操作。
conan cache path¶
$ conan cache path -h
usage: conan cache path [-h] [-f FORMAT] [--out-file OUT_FILE]
[-v [{quiet,error,warning,notice,status,verbose,debug,v,trace,vv}]]
[-cc CORE_CONF]
[--folder {export_source,source,build,metadata}]
reference
Show the path to the Conan cache for a given reference.
positional arguments:
reference Recipe reference or Package reference
options:
-h, --help show this help message and exit
-f FORMAT, --format FORMAT
Select the output format: json
--out-file OUT_FILE Write the output of the command to the specified file
instead of stdout.
-v [{quiet,error,warning,notice,status,verbose,debug,v,trace,vv}]
Level of detail of the output. Valid options from less
verbose to more verbose: -vquiet, -verror, -vwarning,
-vnotice, -vstatus, -v or -vverbose, -vv or -vdebug,
-vvv or -vtrace
-cc CORE_CONF, --core-conf CORE_CONF
Define core configuration, overwriting global.conf
values. E.g.: -cc core:non_interactive=True
--folder {export_source,source,build,metadata}
Path to show. The 'build' requires a package
reference. If the argument is not passed, it shows
'exports' path for recipe references and 'package'
folder for package references.
该 conan cache path 返回给定引用在缓存中的路径。根据引用,它可以返回配方路径,或指向包二进制文件的路径。
假设我们在当前缓存中创建了一个包:
$ conan new cmake_lib -d name=pkg -d version=0.1
$ conan create .
...
Requirements
pkg/0.1#cdc0d9d0e8f554d3df2388c535137d77 - Cache
Requirements
pkg/0.1#cdc0d9d0e8f554d3df2388c535137d77:2401fa1d188d289bb25c37cfa3317e13e377a351 - Build
现在我们想获取我们的 pkg/0.1 配方 conanfile.py 被导出到的路径
$ conan cache path pkg/0.1
<path to conan cache>/p/5cb229164ec1d245/e
$ ls <path to conan cache>/p/5cb229164ec1d245/e
conanfile.py conanmanifest.txt
默认情况下,如果未指定配方修订版,则表示缓存中的“最新”修订版。这也可以通过字面量 #latest 显式说明,并且可以显式定义任何配方修订版,这些命令等效于上述命令
$ conan cache path pkg/0.1#latest
<path to conan cache>/p/5cb229164ec1d245/e
# The recipe revision might be different in your case.
# Check the "conan create" output to get yours
$ conan cache path pkg/0.1#cdc0d9d0e8f554d3df2388c535137d77
<path to conan cache>/p/5cb229164ec1d245/e
与配方文件夹一起,还有另外两个文件夹对于使用此配方生成的所有二进制文件都是通用的: “export_source” 文件夹和 “source” 文件夹。都可以通过以下方式获取:
$ conan cache path pkg/0.1 --folder=export_source
<path to conan cache>/p/5cb229164ec1d245/es
$ ls <path to conan cache>/p/5cb229164ec1d245/es
CMakeLists.txt include/ src/
$ conan cache path pkg/0.1 --folder=source
<path to conan cache>/p/5cb229164ec1d245/s
$ ls <path to conan cache>/p/5cb229164ec1d245/s
CMakeLists.txt include/ src/
在这种情况下,“source” 文件夹的内容与 “export_source” 文件夹的内容相同,因为该配方未实现任何 source() 方法,该方法可以检索代码或对代码执行任何其他操作,例如应用补丁。
默认情况下,配方修订版将为 #latest,这遵循上述相同规则。
请注意,如果包未从源代码构建,例如从服务器检索预编译二进制文件,则这两个文件夹将不存在。
也可以通过提供 package_id 来获取二进制包的文件夹
# Your package_id might be different, it depends on the platform
# Check the "conan create" output to obtain yours
$ conan cache path pkg/0.1:2401fa1d188d289bb25c37cfa3317e13e377a351
<path to conan cache>/p/1cae77d6250c23b7/p
$ ls <path to conan cache>/p/1cae77d6250c23b7/p
conaninfo.txt conanmanifest.txt include/ lib/
如上所述,默认情况下它将解析为“最新”配方修订版和包修订版。上述命令等效于显式定义 #latest 或确切的修订版。以下所有命令都等效于上述命令
$ conan cache path pkg/0.1#latest:2401fa1d188d289bb25c37cfa3317e13e377a351
<path to conan cache>/p/1cae77d6250c23b7/p
$ conan cache path pkg/0.1#latest:2401fa1d188d289bb25c37cfa3317e13e377a351#latest
<path to conan cache>/p/1cae77d6250c23b7/p
$ conan cache path pkg/0.1#cdc0d9d0e8f554d3df2388c535137d77:2401fa1d188d289bb25c37cfa3317e13e377a351
<path to conan cache>/p/1cae77d6250c23b7/p
可以访问包含所有临时构建工件的“build”文件夹
$ conan cache path pkg/0.1:2401fa1d188d289bb25c37cfa3317e13e377a351 --folder=build
<path to conan cache>/p/1cae77d6250c23b7/b
ls -al <path to conan cache>/p/1cae77d6250c23b7/b
build/ CMakeLists.txt CMakeUserPresets.json conaninfo.txt include/ src/
同样,“build”文件夹仅在从源代码构建包时才存在。
注意
最佳实践
此
conan cache path命令用于最终检查缓存,但应将缓存包存储视为**只读**。请勿修改、更改、删除或从缓存中添加文件。如果您使用此命令获取工件的路径然后复制它们,请考虑使用
deployer代替。通常,手动从缓存中提取工件是不鼓励的。开发人员可以使用
conan list ... --format=compact以紧凑的方式获取完整的引用,可以将其复制并粘贴到conan cache path命令中
conan cache clean¶
$ conan cache clean -h
usage: conan cache clean [-h] [--out-file OUT_FILE]
[-v [{quiet,error,warning,notice,status,verbose,debug,v,trace,vv}]]
[-cc CORE_CONF] [-l LIST] [-s] [-b] [-d] [-t] [-bs]
[-p PACKAGE_QUERY]
[pattern]
Remove non-critical folders from the cache, like source, build and/or download
(.tgz store) ones.
positional arguments:
pattern Selection pattern for references to clean
options:
-h, --help show this help message and exit
--out-file OUT_FILE Write the output of the command to the specified file
instead of stdout.
-v [{quiet,error,warning,notice,status,verbose,debug,v,trace,vv}]
Level of detail of the output. Valid options from less
verbose to more verbose: -vquiet, -verror, -vwarning,
-vnotice, -vstatus, -v or -vverbose, -vv or -vdebug,
-vvv or -vtrace
-cc CORE_CONF, --core-conf CORE_CONF
Define core configuration, overwriting global.conf
values. E.g.: -cc core:non_interactive=True
-l LIST, --list LIST Package list of packages to clean
-s, --source Clean source folders
-b, --build Clean build folders
-d, --download Clean download and metadata folders
-t, --temp Clean temporary folders
-bs, --backup-sources
Clean backup sources
-p PACKAGE_QUERY, --package-query PACKAGE_QUERY
Remove only the packages matching a specific query,
e.g., os=Windows AND (arch=x86 OR compiler=gcc)
此命令将删除所有临时文件夹,以及 Conan 在其执行过程中生成的所有源、构建和下载文件夹。它将对传递给 pattern 中的每个匹配引用执行此操作,或者如果使用了 --list 选项,则执行 pkglist 文件中的内容。可以使用不同的标志将清理限制为某些类型的文件夹。
示例:
删除所有非关键文件
$ conan cache clean "*"
删除所有临时文件
$ conan cache clean "*" --temp
删除
zlib配方的下载文件夹$ conan cache clean "zlib/*" --download
删除
zlib配方的所有内容,但下载文件夹$ conan cache clean "zlib/*" --source --build --temp
获取要从中删除临时文件的包列表,然后删除它们
$ conan list "zlib/*" -f=json > pkglist.json $ conan cache clean --list pkglist.json
conan cache check-integrity¶
$ conan cache check-integrity -h
usage: conan cache check-integrity [-h] [-f FORMAT] [--out-file OUT_FILE]
[-v [{quiet,error,warning,notice,status,verbose,debug,v,trace,vv}]]
[-cc CORE_CONF] [-l LIST]
[-p PACKAGE_QUERY]
[pattern]
Check the integrity of the local cache for the given references
positional arguments:
pattern Selection pattern for references to check integrity
for
options:
-h, --help show this help message and exit
-f FORMAT, --format FORMAT
Select the output format: json
--out-file OUT_FILE Write the output of the command to the specified file
instead of stdout.
-v [{quiet,error,warning,notice,status,verbose,debug,v,trace,vv}]
Level of detail of the output. Valid options from less
verbose to more verbose: -vquiet, -verror, -vwarning,
-vnotice, -vstatus, -v or -vverbose, -vv or -vdebug,
-vvv or -vtrace
-cc CORE_CONF, --core-conf CORE_CONF
Define core configuration, overwriting global.conf
values. E.g.: -cc core:non_interactive=True
-l LIST, --list LIST Package list of packages to check integrity for
-p PACKAGE_QUERY, --package-query PACKAGE_QUERY
Only the packages matching a specific query, e.g.,
os=Windows AND (arch=x86 OR compiler=gcc)
该 conan cache check-integrity 命令检查本地缓存中与给定 pattern 匹配的 Conan 包的完整性,或者如果使用了 --list 选项,则检查 pkglist 文件中的内容。这意味着,如果 conanmanifest.txt 中包含的任何文件丢失或与该文件中声明的校验和不匹配,它将引发错误。
例如,要验证整个 Conan 本地缓存的完整性,请执行
$ conan cache check-integrity "*"
mypkg/1.0: Integrity checked: ok
mypkg/1.0:454923cd42d0da27b9b1294ebc3e4ecc84020747: Integrity checked: ok
mypkg/1.0:454923cd42d0da27b9b1294ebc3e4ecc84020747: Integrity checked: ok
zlib/1.3.1: Integrity checked: ok
zlib/1.3.1:6fe7fa69f760aee504e0be85c12b2327c716f9e7: Integrity checked: ok
当使用 --format=json 选项时,此命令还可以返回 pkglist。这会返回损坏的包,这对于生成可用于一次删除所有潜在损坏包的包列表非常有用
$ conan cache check-integrity "*" --format=json --out-file pkglist.json
$ conan remove --list pkglist.json
conan cache backup-upload¶
$ conan cache backup-upload -h
usage: conan cache backup-upload [-h] [--out-file OUT_FILE]
[-v [{quiet,error,warning,notice,status,verbose,debug,v,trace,vv}]]
[-cc CORE_CONF]
Upload all the source backups present in the cache
options:
-h, --help show this help message and exit
--out-file OUT_FILE Write the output of the command to the specified file
instead of stdout.
-v [{quiet,error,warning,notice,status,verbose,debug,v,trace,vv}]
Level of detail of the output. Valid options from less
verbose to more verbose: -vquiet, -verror, -vwarning,
-vnotice, -vstatus, -v or -vverbose, -vv or -vdebug,
-vvv or -vtrace
-cc CORE_CONF, --core-conf CORE_CONF
Define core configuration, overwriting global.conf
values. E.g.: -cc core:non_interactive=True
该 conan cache backup-upload 将上传本地缓存中存在的所有源备份到备份服务器(不包括在 core.sources:exclude_urls 配置中列出的排除 URL 中获取的那些),无论它们属于哪个包,如果有的话。
conan cache save¶
$ conan cache save -h
usage: conan cache save [-h] [-f FORMAT] [--out-file OUT_FILE]
[-v [{quiet,error,warning,notice,status,verbose,debug,v,trace,vv}]]
[-cc CORE_CONF] [-l LIST] [--file FILE] [--no-source]
[pattern]
Get the artifacts from a package list and archive them
positional arguments:
pattern A pattern in the form
'pkg/version#revision:package_id#revision', e.g:
zlib/1.2.13:* means all binaries for zlib/1.2.13. If
revision is not specified, it is assumed latest one.
options:
-h, --help show this help message and exit
-f FORMAT, --format FORMAT
Select the output format: json
--out-file OUT_FILE Write the output of the command to the specified file
instead of stdout.
-v [{quiet,error,warning,notice,status,verbose,debug,v,trace,vv}]
Level of detail of the output. Valid options from less
verbose to more verbose: -vquiet, -verror, -vwarning,
-vnotice, -vstatus, -v or -vverbose, -vv or -vdebug,
-vvv or -vtrace
-cc CORE_CONF, --core-conf CORE_CONF
Define core configuration, overwriting global.conf
values. E.g.: -cc core:non_interactive=True
-l LIST, --list LIST Package list of packages to save
--file FILE Save to this tgz file
--no-source Exclude the sources
请参阅 从/向缓存保存和还原包 以了解更多信息。
conan cache restore¶
$ conan cache restore -h
usage: conan cache restore [-h] [-f FORMAT] [--out-file OUT_FILE]
[-v [{quiet,error,warning,notice,status,verbose,debug,v,trace,vv}]]
[-cc CORE_CONF]
file
Put the artifacts from an archive into the cache
positional arguments:
file Path to archive to restore
options:
-h, --help show this help message and exit
-f FORMAT, --format FORMAT
Select the output format: json
--out-file OUT_FILE Write the output of the command to the specified file
instead of stdout.
-v [{quiet,error,warning,notice,status,verbose,debug,v,trace,vv}]
Level of detail of the output. Valid options from less
verbose to more verbose: -vquiet, -verror, -vwarning,
-vnotice, -vstatus, -v or -vverbose, -vv or -vdebug,
-vvv or -vtrace
-cc CORE_CONF, --core-conf CORE_CONF
Define core configuration, overwriting global.conf
values. E.g.: -cc core:non_interactive=True
请参阅 从/向缓存保存和还原包 以了解更多信息。
conan cache ref¶
$ conan cache ref -h
usage: conan cache ref [-h] [--out-file OUT_FILE]
[-v [{quiet,error,warning,notice,status,verbose,debug,v,trace,vv}]]
[-cc CORE_CONF]
path
Show the reference for a given Conan cache folder
positional arguments:
path Path to a Conan cache folder
options:
-h, --help show this help message and exit
--out-file OUT_FILE Write the output of the command to the specified file
instead of stdout.
-v [{quiet,error,warning,notice,status,verbose,debug,v,trace,vv}]
Level of detail of the output. Valid options from less
verbose to more verbose: -vquiet, -verror, -vwarning,
-vnotice, -vstatus, -v or -vverbose, -vv or -vdebug,
-vvv or -vtrace
-cc CORE_CONF, --core-conf CORE_CONF
Define core configuration, overwriting global.conf
values. E.g.: -cc core:non_interactive=True
对于给定的缓存文件夹,返回 Conan 引用,即采用 name/version#recipe_revision 形式的配方引用,或采用 name/version#recipe_revision:package_id#package_revision 形式的包引用(两者也可能具有 user/channel),具体取决于文件夹的内容。
这是一个开发人员和调试命令,旨在供开发人员偶尔使用,用于调试潜在问题,但不建议用于任何其他用途。
注意
最佳实践
导航 Conan 缓存不是预期或受支持的用途。强烈建议不要在任何自动化、CI 或脚本中使用 conan cache ref 命令。conan cache ref 仅旨在成为开发人员在调试时使用的辅助命令。