conan lock remove

$ conan lock remove -h
usage: conan lock remove [-h] [--out-file OUT_FILE] [-v [V]] [-cc CORE_CONF]
                         [--requires REQUIRES]
                         [--build-requires BUILD_REQUIRES]
                         [--python-requires PYTHON_REQUIRES]
                         [--config-requires CONFIG_REQUIRES]
                         [--lockfile-out LOCKFILE_OUT] [--lockfile LOCKFILE]

Remove requires, build-requires or python-requires from an existing lockfile.
References can be supplied with and without revisions like "--
requires=pkg/version",

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 [V]                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   Remove references to lockfile.
  --build-requires BUILD_REQUIRES
                        Remove build-requires from lockfile
  --python-requires PYTHON_REQUIRES
                        Remove python-requires from lockfile
  --config-requires CONFIG_REQUIRES
                        Remove config-requires from lockfile
  --lockfile-out LOCKFILE_OUT
                        Filename of the created lockfile
  --lockfile LOCKFILE   Filename of the input lockfile

conan lock remove 命令能够从现有的锁定文件(lockfile)中移除 requiresbuild_requirespython_requiresconfig_requires 项。

例如,如果我们有以下 conan.lock

$ cat conan.lock
{
    "version": "0.5",
    "requires": [
        "math/1.0#85d927a4a067a531b1a9c7619522c015%1702683583.3411012",
        "engine/1.0#fd2b006646a54397c16a1478ac4111ac%1702683583.3544693"
    ],
    "build_requires": [
        "cmake/1.0#85d927a4a067a531b1a9c7619522c015%1702683583.3411012",
        "ninja/1.0#fd2b006646a54397c16a1478ac4111ac%1702683583.3544693"
    ],
    "python_requires": [
        "mytool/1.0#85d927a4a067a531b1a9c7619522c015%1702683583.3411012",
        "othertool/1.0#fd2b006646a54397c16a1478ac4111ac%1702683583.3544693"
    ]
}

conan lock remove 命令

$ conan lock remove --requires="math/*" --build-requires=cmake/1.0 --python-requires="*tool/*"

将产生以下 conan.lock

$ cat conan.lock
{
    "version": "0.5",
    "requires": [
        "engine/1.0#fd2b006646a54397c16a1478ac4111ac%1702683583.3544693"
    ],
    "build_requires": [
        "ninja/1.0#fd2b006646a54397c16a1478ac4111ac%1702683583.3544693"
    ],
    "python_requires": [
    ]
}

可以指定不同的模式

  • 按版本范围移除,使用 `--requires="math/[>=1.0 <2]"` 等表达式,此外

  • 移除特定修订版:--requires=math/1.0#revision

  • 移除给定“team”用户的锁定依赖项:--requires=*/*@team*

conan lock remove 可用于

  • conan lock add 结合使用时,它可用于强制将锁定版本降级到旧版本。因为 conan lock add 总是添加并排序,导致新版本具有高优先级,所以仅使用 add 无法强制回退到旧版本。但如果先使用 conan lock remove,然后使用 conan lock add,就可以实现这一点。

  • conan lock remove 可以解锁某些依赖项,从而生成一个不完整的锁定文件(lockfile),该文件可以与 --lockfile-partial 一起使用,以解析未锁定依赖项的最新可用版本,同时保持其余依赖项锁定。