conan workspace

警告

此功能是新的孵化中功能的一部分。这意味着它正在开发中,并正在寻求用户测试和反馈。有关更多信息,请参阅孵化中部分

命令 conan workspace 允许从当前工作区打开、添加和移除包。请查看 conan workspace -h 帮助以及子命令的帮助以了解其用法。

$ conan workspace -h
Error executing: conan workspace -h
ERROR: Workspace command disabled without CONAN_WORKSPACE_ENABLE env var,please read the docs about this 'incubating' feature

conan workspace init

$ conan workspace init -h
Error executing: conan workspace init -h
ERROR: Workspace command disabled without CONAN_WORKSPACE_ENABLE env var,please read the docs about this 'incubating' feature

命令 conan workspace init [path] 会在该路径中创建一个空的 conanws.yml 文件和一个最简的 conanws.py,如果它们尚不存在。该路径可以是相对于当前工作目录的相对路径。

$ conan workspace init myfolder
Created empty conanws.yml in myfolder
Created minimal conanws.py in myfolder

conan workspace [add | remove]

$ conan workspace add -h
Error executing: conan workspace add -h
ERROR: Workspace command disabled without CONAN_WORKSPACE_ENABLE env var,please read the docs about this 'incubating' feature
$ conan workspace remove -h
Error executing: conan workspace remove -h
ERROR: Workspace command disabled without CONAN_WORKSPACE_ENABLE env var,please read the docs about this 'incubating' feature

使用这些命令向当前工作区添加或移除可编辑包。 conan workspace add <path> 文件夹必须包含一个 conanfile.py。该路径可以是相对于当前工作区的相对路径。

conanws.py 有一个默认实现,但可以重写默认行为

conanws.py
import os
from conan import Workspace

class MyWorkspace(Workspace):
   def name(self):
      return "myws"

   def add(self, ref, path, *args, **kwargs):
      self.output.info(f"Adding {ref} at {path}")
      super().add(ref, path, *args, **kwargs)

   def remove(self, path, *args, **kwargs):
      self.output.info(f"Removing {path}")
      return super().remove(path, *args, **kwargs)

conan workspace info

$ conan workspace info -h
Error executing: conan workspace info -h
ERROR: Workspace command disabled without CONAN_WORKSPACE_ENABLE env var,please read the docs about this 'incubating' feature

使用此命令显示当前工作区的信息

$ cd myfolder
$ conan new workspace
$ conan workspace info
WARN: Workspace found
WARN: Workspace is a dev-only feature, exclusively for testing
name: myfolder
folder: /path/to/myfolder
products
   app1
packages
   liba/0.1
      path: liba
   libb/0.1
      path: libb
   app1/0.1
      path: app1

conan workspace clean

$ conan workspace clean -h
Error executing: conan workspace clean -h
ERROR: Workspace command disabled without CONAN_WORKSPACE_ENABLE env var,please read the docs about this 'incubating' feature

新的 conan workspace clean 命令默认会移除工作区中每个包的 output-folder(如果已定义)。如果未定义,默认不会移除任何东西,因为移除用户空间的文件很危险,可能会破坏用户更改或文件。建议用户使用 git clean -xdf 或类似策略来管理清理。也可以通过实现 clean() 方法来定义自定义清理逻辑。

class Ws(Workspace):
   def name(self):
      return "my_workspace"
   def clean(self):
      self.output.info("MY CLEAN!!!!")

conan workspace open

$ conan workspace open -h
Error executing: conan workspace open -h
ERROR: Workspace command disabled without CONAN_WORKSPACE_ENABLE env var,please read the docs about this 'incubating' feature

新的 conan workspace open 命令实现了一个新概念。包含 conandata.ymlscm 信息(使用 git.coordinates_to_conandata())的包可以根据其 Conan 配方引用(包括配方修订版)自动克隆并检出到当前工作区内。

conan workspace build

$ conan workspace build -h
Error executing: conan workspace build -h
ERROR: Workspace command disabled without CONAN_WORKSPACE_ENABLE env var,please read the docs about this 'incubating' feature

命令 conan workspace build 对于工作区中定义的每个 product,执行的操作等同于 conan build <product-path> --build=editable

产品是“下游”消费者,是依赖图的“根”和起始节点。可以使用 conan workspace add <folder> --product 新的 --product 参数来定义它们。

命令 conan workspace build 仅遍历所有产品,因此它可能会重复构建产品的可编辑依赖项。在大多数情况下,由于项目已经构建,这将是一个空操作 (no-op),但仍可能需要一些时间。这有待优化,但这将在稍后完成,现在重要的是专注于工具、用户体验、流程和定义(例如 products 等事物)。

conan workspace install

$ conan workspace install -h
Error executing: conan workspace install -h
ERROR: Workspace command disabled without CONAN_WORKSPACE_ENABLE env var,please read the docs about this 'incubating' feature

命令 conan workspace install 对于将当前工作区作为一个可编辑项的整体超级项目来安装和构建非常有用。

默认情况下,它使用工作区中的所有 editable 包。可以使用 conan workspace install <folder1> .. <folderN> 可选参数仅选择其中的一部分。只会安装这些包的子图,包括它们的依赖项和传递性依赖项。

另请参阅

阅读 工作区教程 部分。阅读 conan new workspace 命令部分。