11.2 工作区(Workspaces)
A workspace is a collection of one or more packages, namely workspace members, that are managed together.
workspace 是一个或多个包的集合,即一起进行管理的 workspace 成员。
The key points for workspaces are: 工作区的要点是:
Common
forc
commands available for a single package can also be used for a workspace, likeforc build
orforc deploy
. 适用于单个包的常见forc
命令也可用于工作区,例如forc build
或forc deploy
。All packages share a common
Forc.lock
file which resides in the root directory of the workspace. 所有包共享一个通用的Forc.lock
文件,该文件位于工作区的根目录中。
Workspace manifests are declared within Forc.toml
files and support the following fields:
工作区清单在Forc.toml
文件中声明并支持以下字段:
members
- Packages to include in the workspace.members
- 要包含在工作区中的包。[patch]
- Defines the patches.[patch]
- 定义补丁。
An empty workspace can be created with forc new --workspace
or forc init --workspace
.
可以使用forc new --workspace
或forc init --workspace
创建空工作区。
成员 members
字段(The members
field)
成员 members
字段(The members
field)The members
field defines which packages are members of the workspace:
members
字段定义哪些包是工作区的成员:
The members
field accepts entries to be given in relative path with respect to the workspace root. Packages that are located within a workspace directory but are not contained within the members
set are ignored.
members
字段接受,相对于工作区根的相对路径而给出的条目。位于工作区目录中但 不 包含在members 成员
集中的包将被忽略。
[patch 补丁]
部分 (The [patch]
section)
[patch 补丁]
部分 (The [patch]
section)The [patch]
section can be used to override any dependency in the workspace dependency graph. The usage is the same with package level [patch]
section and details can be seen here.
[patch]
部分可用于覆盖工作区依赖关系图中的任何依赖。用法与包级别的[patch]
部分相同,详细信息可以参见此处。
It is not allowed to declare patch table in member of a workspace if the workspace manifest file contains a patch table.
如果工作区清单文件包含补丁表,则不允许在工作区成员中声明补丁表。
Example 举例:
In the above example each occurance of std
as a dependency in the workspace will be changed with std
from test
branch of sway repo.
在上面的示例中,工作区中作为依赖项出现的每次std
都将被 sway 存储库的test
分支中的std
更改。
一些支持工作区的forc
命令 (Some forc
commands that support workspaces)
forc
命令 (Some forc
commands that support workspaces)forc build
- Builds an entire workspace.forc build
- 构建整个工作区。forc deploy
- Builds and deploys all deployable members (i.e, contracts) of the workspace in the correct order.forc deploy
- 按正确的顺序构建和部署工作区的所有可部署成员(即合约)forc run
- Builds and runs all scripts of the workspace.forc run
- 构建并运行工作区的所有脚本。forc check
- Checks all members of the workspace.forc check
- 检查工作区的所有成员。forc update
- Checks and updates workspace levelForc.lock
file that is shared between workspace members.forc update
- 检查并更新在工作区成员之间,共享的工作区级别Forc.lock
文件。forc clean
- Cleans all output artifacts for each member of the workspace.forc clean
- 清除工作区每个成员的所有输出工件。forc fmt
- Formats all members of a workspace.forc fmt
- 格式化工作区的所有成员。
Last updated