conan lock add

$ conan lock add -h
usage: conan lock add [-h] [--out-file OUT_FILE]
                      [-v [{quiet,error,warning,notice,status,verbose,debug,v,trace,vv}]]
                      [-cc CORE_CONF] [--requires REQUIRES]
                      [--build-requires BUILD_REQUIRES]
                      [--python-requires PYTHON_REQUIRES]
                      [--config-requires CONFIG_REQUIRES]
                      [--lockfile-out LOCKFILE_OUT] [--lockfile LOCKFILE]

Add requires, build-requires or python-requires to an existing or new
lockfile. The resulting lockfile will be ordered, newer versions/revisions
first. References can be supplied with and without revisions like "--
requires=pkg/version", but they must be package references, including at least
the version, and they cannot contain a version range.

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
  --requires REQUIRES   Add references to lockfile.
  --build-requires BUILD_REQUIRES
                        Add build-requires to lockfile
  --python-requires PYTHON_REQUIRES
                        Add python-requires to lockfile
  --config-requires CONFIG_REQUIRES
                        Add config-requires to lockfile
  --lockfile-out LOCKFILE_OUT
                        Filename of the created lockfile
  --lockfile LOCKFILE   Filename of the input lockfile

conan lock add 命令能够将一个包版本添加到现有的或新的 lockfile 的 requiresbuild_requirespython_requiresconfig_requires 中。

例如,以下命令可以创建一个 lockfile(默认情况下,命名为 conan.lock

$ conan lock add --requires=pkg/1.1 --build-requires=tool/2.2 --python-requires=mypytool/3.3
Generated lockfile: ...conan.lock

$cat conan.lock
{
    "version": "0.5",
    "requires": [
        "pkg/1.1"
    ],
    "build_requires": [
        "tool/2.2"
    ],
    "python_requires": [
        "mypytool/3.3"
    ]
}

conan lock add 命令也允许提供一个现有的 lockfile 作为输入,并将参数添加到现有的 lockfile 中,保持包版本排序。

$ conan lock add --build-requires=tool/2.3 --lockfile=conan.lock
Using lockfile: '.../conan.lock'
Generated lockfile: .../conan.lock

$ cat conan.lock
{
    "version": "0.5",
    "requires": [
        "pkg/1.1"
    ],
    "build_requires": [
        "tool/2.3",
        "tool/2.2"
    ],
    "python_requires": [
        "mypytool/3.3"
    ]
}

conan lock add 命令不会对 lockfile、包、包的存在性、包版本的存在性或这些包在给定依赖图中的存在性进行任何检查,它只是对 json 信息的基本操作。当该 lockfile 被应用于解析依赖图时,有可能添加的版本不存在,或者无法解析 conanfile.py 脚本中定义的版本范围。

此外,版本列表仍然排序。将一个较旧的版本(例如 tool/2.1)添加到之前的 lockfile 中,不会自动使用该版本,如果脚本包含版本范围 tool/[>=2.0 <3],因为 tool/2.2 版本已列出,并且范围将解析到它,而不是较旧的 tool/2.1

请注意,使用 conan lock add 创建的 lockfile 可能是不完整的,并且不包含完整的依赖图所需的所有锁定的版本。对于这些情况,请记住可以使用 --lockfile-partial 参数。 另外请注意,如果在当前文件夹中存在 conan.lock 文件,Conan 命令(例如 conan install)将自动使用它。请参阅 lockfiles 教程

如果显式添加修订版本,请记住修订版本是按时间戳排序的。如果 lockfile 中存在多个修订版本,则必须提供这些修订版本的时间戳,以便排序有意义,这可以通过以下方式完成:

$ conan lock add --requires=pkg/1.1#revision%timestamp

警告

  • 禁止手动操作 Conan lockfile,更改引用的严格排序,这可能会导致任何任意未定义行为。

  • 请记住,无法使用 conan lock add 添加版本范围。版本可能不完整(例如,未提供修订版本),但必须是确切的版本。

注意

最佳实践

在许多情况下,此命令是不必要的。现有的 conan installconan createconan lockconan exportconan graph 命令可以直接更新或生成包含包新信息的新的 lockfile,并且可以使用这些新的或更新的 lockfile 继续处理。