目录
1 介绍
- 类似Git子模块,West的内置命令提供了一个多仓库管理系统,其开发仓库在:zephyrproject-rtos/west: West, Zephyr's meta-tool (github.com)
- 同时该工具也支持插件化,允许用户自己编写west的扩展功能
- 在使用west命令之前,需要先了解几个关联的内容:manifest,config
1)manifest
- west作为一种多仓库模式,肯定需要一个清单表管理。使用YAML格式的文件manifest就作为这个清单表。
- 典型的manifest内容如下,主要包括几个子节:remotes,projects,self
manifest:
remotes:
# 指定url-base,用于工程从该url fetch
projects:
# 各个子仓库清单
self:
# configuration related to the manifest repository itself,
# i.e. the repository containing west.yml
- remotes
指定一个base-url,用于工程从该url fetch
remotes:
- name: upstream
url-base: https://github.com/zephyrproject-rtos
- projects
记录了子仓库的信息,指明了有哪些子仓库,各子仓库需要的版本,以及下载到项目的哪个路径
projects:
# 子仓库名称,即url-base/name
- name: canopennode
# 版本
revision: 1052dae561497bef901f931ef75e117c9224aecd
# 保存至project/path
path: modules/lib/canopennode
- name: civetweb
revision: 094aeb41bb93e9199d24d665ee43e9e05d6d7b1c
path: modules/lib/civetweb
- self
管理west的扩展命令,当执行west扩展命令时,会通过该子段的内容,关联到zephyr/scripts/west-commnad.yml
self:
path: zephyr
west-commands: scripts/west-commands.yml
import: submanifests
接着看zephyr/scripts/west-commnad.yml的内容,显然
执行west completion时,最终会执行python脚本scripts/west_commnads/completion.py
west-commands:
- file: scripts/west_commands/completion.py
commands:
- name: completion
class: Completion
help: display shell completion scripts
- file: scripts/west_commands/boards.py
commands:
- name: boards
class: Boards
help: display information about supported boards
2)config file
- west的配置,我们需要知道配置文件(编写语法,配置项),以及如何配置
- 有三种类型配置文件,各自作用范围不同,其优先级按下面顺序依次提高:
System:该配置下的修改作用于所有登录用户
对于Linux平台,配置文件在 /etc/westconfig
Global(per user):该配置下的修改作用于具体的一个登录用户
所有平台路径在~/.westconfig
Local:作用于当前workspace
该配置文件在workspace/.west/config(west init命令执行时自动生成的)
2.1)配置文件语法
- 语法类似ini文件,一个简单示例如下:
PS:如果使用命令表示即manifest.path,zephyr.base等
[manifest]
path = zephyr
file = west.yml
[zephyr]
base = zephyr
2.2)哪些配置项
2.3)如何修改
使用west config命令,具体见后续命令介绍
2 安装
- Linux下安装
pip3 install --user -U west
- Windows和macOS下安装
pip3 install -U west
3 west init
1)用法
west init [-m URL] [--mr REVISION] [--mf FILE] [directory]
- -m 指定manifest URL,未指定时是https://github.com/zephyrproject-rtos/zephyr
- --mr check out初始版本,未指定时是默认分支
- --mf 指定manifest文件,未指定时是west.yml
- directory 指定工程名称
2)执行结果
- 一般典型用法如下
west init -m https://github.com/zephyrproject-rtos/zephyr --mr v2.5.0 zephyrproject
- 该命令自动完成如下操作:
- 创建工程路径zephyrproject,同时在该文件夹下生成.west和.west/config
- 从https://github.com/zephyrproject-rtos/zephyr clone仓库至zephyrproject/zephyr
- Check out 版本v2.5.0
- 在.west/config中设置manifest.path和manifest.file(关于manifest的使用后面会提到)
- 这样一个基本的workspace就准备就绪了,后面就可以使用west update更新其他子仓库代码
4 west update
- 进入workspace后,直接输入该命令
- 该命令自动完成如下操作:
- 通过.west/config文件中的manifest配置,获取到manifest文件,即workspace/zephyr/下的west.yml文件
- 依据west.yml内容来决定,获取哪些子仓库,从哪个URL获取,获取什么版本,保持至workspace下的哪个路径
PS:以下图wets.yml红色标记的projects/canopennode为例,即从https://github.com/zephyrproject-rtos/canopennode获取对应版本的子仓库,并保存至workspace/path
- 默认url-base是从github访问,子仓库代码比较庞大,执行west update容易失败,可以修改此处的url-bae为国内的镜像。
5 west list
- 输出manifest中每个项目的信息
6 west manifest
- 用于管理manifest文件,命令后需加上具体的动作和参数
1)--resolve
输出详细的manifest的项目信息,类似west list命令,相比输出的信息更为详细
2)--validate
验证manifest是否有效,无效会输出错误信息
3)--path
输出manifest的绝对路径
7 west config
- 在前面已经了解west配置的相关信息,这里介绍如果通过命令修改
1)选择配置文件
--system/global/local
- 通过该选项,选择具体操作的配置文件。
- 如果未设置该选项,默认写是local,默认读是从3个配置文件按优先级读取
2)列出选项
-l && --list
- 列出所有配置选项
conor@Conor:/mnt/c/00-conor/02-study/07-zephyr/zephyrproject$ west config --list
manifest.path=zephyr
manifest.file=west.yml
zephyr.base=zephyr
3)删除
- west config -d --global
删除global配置文件中的指定项
- west config -D
删除所有配置文件中的指定项
4)修改配置项
- west config --global
修改global配置文件中指定项的值
8 west topdir
- 输出workspace顶层路径
9 扩展命令
- 前面有提到,west是插件化的命令工具,除了上述几个内置命令,同时扩展命令当然也支持用户新增自己需要的命令
1)west-commands.yml
- 在前面章节"介绍/manifest"中已经提到"self"子段,其子段关联到/zephyr/scripts/west-commands.yml文件,该文件管理着所有的扩展命令
截取一部分该文件中的内容,如下执行west boards命令时,最终会执行scripts/west_commands/boards.py
west-commands:
- file: scripts/west_commands/completion.py
commands:
- name: completion
class: Completion
help: display shell completion scripts
- file: scripts/west_commands/boards.py
commands:
- name: boards
class: Boards
help: display information about supported boards