west init 命令详解与工程配置优化
引言
在Zephyr开发中,west init是项目初始化的第一个命令,它负责设置工作区并克隆必要的代码仓库。然而,对于网络条件受限或磁盘空间有限的开发者来说,如何优化这个过程、只下载必要的内容,是一个非常实际的问题。本文将详细介绍west init命令的执行过程,以及如何配置工程以实现按需下载。
一、west init 命令概述
1.1 命令功能
west init命令执行以下核心任务:
| 任务 | 说明 |
|---|---|
| 创建工作区 | 在指定目录创建West工作区 |
| 克隆Manifest仓库 | 克隆包含仓库清单的Git仓库 |
| 生成配置文件 | 创建.west/config配置文件 |
| 初始化Git子模块 | 设置Git子模块关联 |
1.2 命令格式
bash
# 基本用法
west init <project_dir>
# 指定Manifest仓库
west init -m <manifest_url> <project_dir>
# 指定分支或标签
west init -m <manifest_url> --mr <revision> <project_dir>
# 本地Manifest
west init -l <local_manifest_dir>
1.3 执行示例
bash
$ west init ~/zephyrproject
=== Initializing workspace ~/zephyrproject
-- Cloning manifest repository from https://github.com/zephyrproject-rtos/zephyr
-- Using revision main
Cloning into '/home/user/zephyrproject/zephyr'...
remote: Enumerating objects: 125432, done.
receiving objects: 100% (125432/125432), 45.2 MiB | 2.1 MiB/s
-- initializing manifest repository
=== West initialized. Run 'west update' to clone repositories.
二、west init 执行过程详解
2.1 整体流程图
#mermaid-svg-UwffLWGCgG5h84fo{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-UwffLWGCgG5h84fo .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-UwffLWGCgG5h84fo .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-UwffLWGCgG5h84fo .error-icon{fill:#552222;}#mermaid-svg-UwffLWGCgG5h84fo .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-UwffLWGCgG5h84fo .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-UwffLWGCgG5h84fo .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-UwffLWGCgG5h84fo .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-UwffLWGCgG5h84fo .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-UwffLWGCgG5h84fo .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-UwffLWGCgG5h84fo .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-UwffLWGCgG5h84fo .marker{fill:#333333;stroke:#333333;}#mermaid-svg-UwffLWGCgG5h84fo .marker.cross{stroke:#333333;}#mermaid-svg-UwffLWGCgG5h84fo svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-UwffLWGCgG5h84fo p{margin:0;}#mermaid-svg-UwffLWGCgG5h84fo .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-UwffLWGCgG5h84fo .cluster-label text{fill:#333;}#mermaid-svg-UwffLWGCgG5h84fo .cluster-label span{color:#333;}#mermaid-svg-UwffLWGCgG5h84fo .cluster-label span p{background-color:transparent;}#mermaid-svg-UwffLWGCgG5h84fo .label text,#mermaid-svg-UwffLWGCgG5h84fo span{fill:#333;color:#333;}#mermaid-svg-UwffLWGCgG5h84fo .node rect,#mermaid-svg-UwffLWGCgG5h84fo .node circle,#mermaid-svg-UwffLWGCgG5h84fo .node ellipse,#mermaid-svg-UwffLWGCgG5h84fo .node polygon,#mermaid-svg-UwffLWGCgG5h84fo .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-UwffLWGCgG5h84fo .rough-node .label text,#mermaid-svg-UwffLWGCgG5h84fo .node .label text,#mermaid-svg-UwffLWGCgG5h84fo .image-shape .label,#mermaid-svg-UwffLWGCgG5h84fo .icon-shape .label{text-anchor:middle;}#mermaid-svg-UwffLWGCgG5h84fo .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-UwffLWGCgG5h84fo .rough-node .label,#mermaid-svg-UwffLWGCgG5h84fo .node .label,#mermaid-svg-UwffLWGCgG5h84fo .image-shape .label,#mermaid-svg-UwffLWGCgG5h84fo .icon-shape .label{text-align:center;}#mermaid-svg-UwffLWGCgG5h84fo .node.clickable{cursor:pointer;}#mermaid-svg-UwffLWGCgG5h84fo .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-UwffLWGCgG5h84fo .arrowheadPath{fill:#333333;}#mermaid-svg-UwffLWGCgG5h84fo .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-UwffLWGCgG5h84fo .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-UwffLWGCgG5h84fo .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-UwffLWGCgG5h84fo .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-UwffLWGCgG5h84fo .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-UwffLWGCgG5h84fo .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-UwffLWGCgG5h84fo .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-UwffLWGCgG5h84fo .cluster text{fill:#333;}#mermaid-svg-UwffLWGCgG5h84fo .cluster span{color:#333;}#mermaid-svg-UwffLWGCgG5h84fo div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-UwffLWGCgG5h84fo .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-UwffLWGCgG5h84fo rect.text{fill:none;stroke-width:0;}#mermaid-svg-UwffLWGCgG5h84fo .icon-shape,#mermaid-svg-UwffLWGCgG5h84fo .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-UwffLWGCgG5h84fo .icon-shape p,#mermaid-svg-UwffLWGCgG5h84fo .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-UwffLWGCgG5h84fo .icon-shape .label rect,#mermaid-svg-UwffLWGCgG5h84fo .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-UwffLWGCgG5h84fo .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-UwffLWGCgG5h84fo .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-UwffLWGCgG5h84fo :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 参数解析
west init ~/zephyrproject
参数解析
创建工作区目录
克隆Manifest仓库
创建.west目录
生成配置文件
设置Git钩子
初始化完成
解析Manifest URL
解析Revision
解析本地配置
2.2 详细时序图
文件系统 Git West工具 用户 文件系统 Git West工具 用户 #mermaid-svg-pWlKd3k8C0WPbnwG{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-pWlKd3k8C0WPbnwG .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-pWlKd3k8C0WPbnwG .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-pWlKd3k8C0WPbnwG .error-icon{fill:#552222;}#mermaid-svg-pWlKd3k8C0WPbnwG .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-pWlKd3k8C0WPbnwG .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-pWlKd3k8C0WPbnwG .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-pWlKd3k8C0WPbnwG .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-pWlKd3k8C0WPbnwG .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-pWlKd3k8C0WPbnwG .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-pWlKd3k8C0WPbnwG .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-pWlKd3k8C0WPbnwG .marker{fill:#333333;stroke:#333333;}#mermaid-svg-pWlKd3k8C0WPbnwG .marker.cross{stroke:#333333;}#mermaid-svg-pWlKd3k8C0WPbnwG svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-pWlKd3k8C0WPbnwG p{margin:0;}#mermaid-svg-pWlKd3k8C0WPbnwG .actor{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-pWlKd3k8C0WPbnwG text.actor>tspan{fill:black;stroke:none;}#mermaid-svg-pWlKd3k8C0WPbnwG .actor-line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-pWlKd3k8C0WPbnwG .innerArc{stroke-width:1.5;stroke-dasharray:none;}#mermaid-svg-pWlKd3k8C0WPbnwG .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333;}#mermaid-svg-pWlKd3k8C0WPbnwG .messageLine1{stroke-width:1.5;stroke-dasharray:2,2;stroke:#333;}#mermaid-svg-pWlKd3k8C0WPbnwG #arrowhead path{fill:#333;stroke:#333;}#mermaid-svg-pWlKd3k8C0WPbnwG .sequenceNumber{fill:white;}#mermaid-svg-pWlKd3k8C0WPbnwG #sequencenumber{fill:#333;}#mermaid-svg-pWlKd3k8C0WPbnwG #crosshead path{fill:#333;stroke:#333;}#mermaid-svg-pWlKd3k8C0WPbnwG .messageText{fill:#333;stroke:none;}#mermaid-svg-pWlKd3k8C0WPbnwG .labelBox{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-pWlKd3k8C0WPbnwG .labelText,#mermaid-svg-pWlKd3k8C0WPbnwG .labelText>tspan{fill:black;stroke:none;}#mermaid-svg-pWlKd3k8C0WPbnwG .loopText,#mermaid-svg-pWlKd3k8C0WPbnwG .loopText>tspan{fill:black;stroke:none;}#mermaid-svg-pWlKd3k8C0WPbnwG .loopLine{stroke-width:2px;stroke-dasharray:2,2;stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-pWlKd3k8C0WPbnwG .note{stroke:#aaaa33;fill:#fff5ad;}#mermaid-svg-pWlKd3k8C0WPbnwG .noteText,#mermaid-svg-pWlKd3k8C0WPbnwG .noteText>tspan{fill:black;stroke:none;}#mermaid-svg-pWlKd3k8C0WPbnwG .activation0{fill:#f4f4f4;stroke:#666;}#mermaid-svg-pWlKd3k8C0WPbnwG .activation1{fill:#f4f4f4;stroke:#666;}#mermaid-svg-pWlKd3k8C0WPbnwG .activation2{fill:#f4f4f4;stroke:#666;}#mermaid-svg-pWlKd3k8C0WPbnwG .actorPopupMenu{position:absolute;}#mermaid-svg-pWlKd3k8C0WPbnwG .actorPopupMenuPanel{position:absolute;fill:#ECECFF;box-shadow:0px 8px 16px 0px rgba(0,0,0,0.2);filter:drop-shadow(3px 5px 2px rgb(0 0 0 / 0.4));}#mermaid-svg-pWlKd3k8C0WPbnwG .actor-man line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-pWlKd3k8C0WPbnwG .actor-man circle,#mermaid-svg-pWlKd3k8C0WPbnwG line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;stroke-width:2px;}#mermaid-svg-pWlKd3k8C0WPbnwG :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} west init ~/zephyrproject 创建工作区目录 git clone zephyr仓库 克隆完成 创建.west目录 写入.west/config 创建.west/manifest文件 设置remote 初始化完成
2.3 West源码解析
west/commands/init.py 核心逻辑:
python
# west init 命令实现
class Init(WestCommand):
def do_run(self, args, unknown_args):
# 1. 解析Manifest URL
if args.manifest_url:
manifest_url = args.manifest_url
else:
# 使用默认Zephyr仓库
manifest_url = DEFAULT_ZEPHYR_URL
# 2. 解析Revision
revision = args.manifest_revision or 'main'
# 3. 创建工作区目录
project_dir = Path(args.project_dir)
project_dir.mkdir(parents=True, exist_ok=True)
# 4. 克隆Manifest仓库
manifest_path = project_dir / args.manifest_path
self.git_clone(manifest_url, manifest_path, revision)
# 5. 初始化Git子模块
self.git_submodule_init(manifest_path)
# 6. 创建West配置文件
self.create_config(project_dir, manifest_path)
# 7. 写入Manifest缓存
self.write_manifest_cache(manifest_path)
三、生成的目录结构
3.1 工作区目录结构
~/zephyrproject/
├── .west/
│ ├── config # West配置文件
│ └── manifest.xml # Manifest缓存(自动生成)
├── zephyr/ # Manifest仓库(主仓库)
│ ├── .git/
│ ├── .gitmodules # 子模块配置
│ ├── CMakeLists.txt
│ ├── Kconfig
│ ├── boards/
│ ├── drivers/
│ ├── dts/
│ ├── include/
│ ├── kernel/
│ ├── modules/
│ ├── scripts/
│ └── samples/
└── (其他克隆的仓库)
3.2 配置文件详解
.west/config 文件内容:
ini
[manifest]
file = west.yml
path = zephyr
[build]
board = qemu_x86
build-dir = build
3.3 Manifest文件结构
west.yml 文件结构:
yaml
# Zephyr Manifest文件结构
manifest:
defaults:
remote: origin
revision: main
remotes:
- name: origin
url-base: https://github.com/zephyrproject-rtos
projects:
- name: zephyr
revision: main
url: https://github.com/zephyrproject-rtos/zephyr
path: zephyr
clone-depth: 1
- name: hal_nordic
revision: v3.0.0
url: https://github.com/nrfconnect/sdk-hal_nordic
path: modules/hal/nordic
- name: hal_st
revision: zephyr-v1.0
url: https://github.com/zephyrproject-rtos/sdk-hal_st
path: modules/hal/st
四、west update 命令详解
4.1 命令功能
west update根据Manifest文件克隆或更新所有项目仓库:
bash
# 更新所有仓库
west update
# 更新指定项目
west update zephyr
# 强制更新(忽略本地修改)
west update --force
# 只获取指定分支
west update --fetch-opt=--depth=1
4.2 更新流程图
#mermaid-svg-wmT2lSti3BWUGxPL{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-wmT2lSti3BWUGxPL .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-wmT2lSti3BWUGxPL .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-wmT2lSti3BWUGxPL .error-icon{fill:#552222;}#mermaid-svg-wmT2lSti3BWUGxPL .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-wmT2lSti3BWUGxPL .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-wmT2lSti3BWUGxPL .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-wmT2lSti3BWUGxPL .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-wmT2lSti3BWUGxPL .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-wmT2lSti3BWUGxPL .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-wmT2lSti3BWUGxPL .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-wmT2lSti3BWUGxPL .marker{fill:#333333;stroke:#333333;}#mermaid-svg-wmT2lSti3BWUGxPL .marker.cross{stroke:#333333;}#mermaid-svg-wmT2lSti3BWUGxPL svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-wmT2lSti3BWUGxPL p{margin:0;}#mermaid-svg-wmT2lSti3BWUGxPL .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-wmT2lSti3BWUGxPL .cluster-label text{fill:#333;}#mermaid-svg-wmT2lSti3BWUGxPL .cluster-label span{color:#333;}#mermaid-svg-wmT2lSti3BWUGxPL .cluster-label span p{background-color:transparent;}#mermaid-svg-wmT2lSti3BWUGxPL .label text,#mermaid-svg-wmT2lSti3BWUGxPL span{fill:#333;color:#333;}#mermaid-svg-wmT2lSti3BWUGxPL .node rect,#mermaid-svg-wmT2lSti3BWUGxPL .node circle,#mermaid-svg-wmT2lSti3BWUGxPL .node ellipse,#mermaid-svg-wmT2lSti3BWUGxPL .node polygon,#mermaid-svg-wmT2lSti3BWUGxPL .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-wmT2lSti3BWUGxPL .rough-node .label text,#mermaid-svg-wmT2lSti3BWUGxPL .node .label text,#mermaid-svg-wmT2lSti3BWUGxPL .image-shape .label,#mermaid-svg-wmT2lSti3BWUGxPL .icon-shape .label{text-anchor:middle;}#mermaid-svg-wmT2lSti3BWUGxPL .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-wmT2lSti3BWUGxPL .rough-node .label,#mermaid-svg-wmT2lSti3BWUGxPL .node .label,#mermaid-svg-wmT2lSti3BWUGxPL .image-shape .label,#mermaid-svg-wmT2lSti3BWUGxPL .icon-shape .label{text-align:center;}#mermaid-svg-wmT2lSti3BWUGxPL .node.clickable{cursor:pointer;}#mermaid-svg-wmT2lSti3BWUGxPL .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-wmT2lSti3BWUGxPL .arrowheadPath{fill:#333333;}#mermaid-svg-wmT2lSti3BWUGxPL .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-wmT2lSti3BWUGxPL .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-wmT2lSti3BWUGxPL .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-wmT2lSti3BWUGxPL .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-wmT2lSti3BWUGxPL .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-wmT2lSti3BWUGxPL .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-wmT2lSti3BWUGxPL .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-wmT2lSti3BWUGxPL .cluster text{fill:#333;}#mermaid-svg-wmT2lSti3BWUGxPL .cluster span{color:#333;}#mermaid-svg-wmT2lSti3BWUGxPL div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-wmT2lSti3BWUGxPL .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-wmT2lSti3BWUGxPL rect.text{fill:none;stroke-width:0;}#mermaid-svg-wmT2lSti3BWUGxPL .icon-shape,#mermaid-svg-wmT2lSti3BWUGxPL .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-wmT2lSti3BWUGxPL .icon-shape p,#mermaid-svg-wmT2lSti3BWUGxPL .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-wmT2lSti3BWUGxPL .icon-shape .label rect,#mermaid-svg-wmT2lSti3BWUGxPL .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-wmT2lSti3BWUGxPL .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-wmT2lSti3BWUGxPL .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-wmT2lSti3BWUGxPL :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 不存在
存在
有修改
无修改
west update
读取Manifest
解析项目列表
仓库存在?
克隆仓库
本地修改?
保留本地
更新到最新
设置remote
克隆代码
切换分支
跳过更新
git fetch
git checkout
初始化子模块
更新完成
4.3 项目克隆过程
Manifest Git West工具 Manifest Git West工具 #mermaid-svg-sLcCVdmoKguExpcb{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-sLcCVdmoKguExpcb .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-sLcCVdmoKguExpcb .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-sLcCVdmoKguExpcb .error-icon{fill:#552222;}#mermaid-svg-sLcCVdmoKguExpcb .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-sLcCVdmoKguExpcb .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-sLcCVdmoKguExpcb .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-sLcCVdmoKguExpcb .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-sLcCVdmoKguExpcb .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-sLcCVdmoKguExpcb .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-sLcCVdmoKguExpcb .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-sLcCVdmoKguExpcb .marker{fill:#333333;stroke:#333333;}#mermaid-svg-sLcCVdmoKguExpcb .marker.cross{stroke:#333333;}#mermaid-svg-sLcCVdmoKguExpcb svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-sLcCVdmoKguExpcb p{margin:0;}#mermaid-svg-sLcCVdmoKguExpcb .actor{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-sLcCVdmoKguExpcb text.actor>tspan{fill:black;stroke:none;}#mermaid-svg-sLcCVdmoKguExpcb .actor-line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-sLcCVdmoKguExpcb .innerArc{stroke-width:1.5;stroke-dasharray:none;}#mermaid-svg-sLcCVdmoKguExpcb .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333;}#mermaid-svg-sLcCVdmoKguExpcb .messageLine1{stroke-width:1.5;stroke-dasharray:2,2;stroke:#333;}#mermaid-svg-sLcCVdmoKguExpcb #arrowhead path{fill:#333;stroke:#333;}#mermaid-svg-sLcCVdmoKguExpcb .sequenceNumber{fill:white;}#mermaid-svg-sLcCVdmoKguExpcb #sequencenumber{fill:#333;}#mermaid-svg-sLcCVdmoKguExpcb #crosshead path{fill:#333;stroke:#333;}#mermaid-svg-sLcCVdmoKguExpcb .messageText{fill:#333;stroke:none;}#mermaid-svg-sLcCVdmoKguExpcb .labelBox{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-sLcCVdmoKguExpcb .labelText,#mermaid-svg-sLcCVdmoKguExpcb .labelText>tspan{fill:black;stroke:none;}#mermaid-svg-sLcCVdmoKguExpcb .loopText,#mermaid-svg-sLcCVdmoKguExpcb .loopText>tspan{fill:black;stroke:none;}#mermaid-svg-sLcCVdmoKguExpcb .loopLine{stroke-width:2px;stroke-dasharray:2,2;stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-sLcCVdmoKguExpcb .note{stroke:#aaaa33;fill:#fff5ad;}#mermaid-svg-sLcCVdmoKguExpcb .noteText,#mermaid-svg-sLcCVdmoKguExpcb .noteText>tspan{fill:black;stroke:none;}#mermaid-svg-sLcCVdmoKguExpcb .activation0{fill:#f4f4f4;stroke:#666;}#mermaid-svg-sLcCVdmoKguExpcb .activation1{fill:#f4f4f4;stroke:#666;}#mermaid-svg-sLcCVdmoKguExpcb .activation2{fill:#f4f4f4;stroke:#666;}#mermaid-svg-sLcCVdmoKguExpcb .actorPopupMenu{position:absolute;}#mermaid-svg-sLcCVdmoKguExpcb .actorPopupMenuPanel{position:absolute;fill:#ECECFF;box-shadow:0px 8px 16px 0px rgba(0,0,0,0.2);filter:drop-shadow(3px 5px 2px rgb(0 0 0 / 0.4));}#mermaid-svg-sLcCVdmoKguExpcb .actor-man line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-sLcCVdmoKguExpcb .actor-man circle,#mermaid-svg-sLcCVdmoKguExpcb line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;stroke-width:2px;}#mermaid-svg-sLcCVdmoKguExpcb :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} alt 仓库不存在 仓库存在 loop 每个项目 读取west.yml 返回项目列表 检查仓库是否存在 仓库状态 git clone --depth 1 克隆完成 git fetch origin git checkout revision 设置remote 初始化子模块 更新完成
五、按需下载配置方法
5.1 理解Zephyr模块结构
Zephyr项目包含大量可选模块,合理配置可以大幅减少下载量:
#mermaid-svg-i9uTaIU0yQ0WeBEp{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-i9uTaIU0yQ0WeBEp .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-i9uTaIU0yQ0WeBEp .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-i9uTaIU0yQ0WeBEp .error-icon{fill:#552222;}#mermaid-svg-i9uTaIU0yQ0WeBEp .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-i9uTaIU0yQ0WeBEp .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-i9uTaIU0yQ0WeBEp .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-i9uTaIU0yQ0WeBEp .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-i9uTaIU0yQ0WeBEp .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-i9uTaIU0yQ0WeBEp .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-i9uTaIU0yQ0WeBEp .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-i9uTaIU0yQ0WeBEp .marker{fill:#333333;stroke:#333333;}#mermaid-svg-i9uTaIU0yQ0WeBEp .marker.cross{stroke:#333333;}#mermaid-svg-i9uTaIU0yQ0WeBEp svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-i9uTaIU0yQ0WeBEp p{margin:0;}#mermaid-svg-i9uTaIU0yQ0WeBEp .pieCircle{stroke:#000000;stroke-width:2px;opacity:0.7;}#mermaid-svg-i9uTaIU0yQ0WeBEp .pieOuterCircle{stroke:#000000;stroke-width:1px;fill:none;}#mermaid-svg-i9uTaIU0yQ0WeBEp .pieTitleText{text-anchor:middle;font-size:25px;fill:#000000;font-family:"trebuchet ms",verdana,arial,sans-serif;}#mermaid-svg-i9uTaIU0yQ0WeBEp .slice{font-family:"trebuchet ms",verdana,arial,sans-serif;fill:#000000;font-size:17px;}#mermaid-svg-i9uTaIU0yQ0WeBEp .legend text{fill:#000000;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:17px;}#mermaid-svg-i9uTaIU0yQ0WeBEp :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 30% 25% 20% 15% 10% Zephyr仓库大小分布(估计) zephyr核心 驱动模块 协议栈模块 HAL模块 其他模块
5.2 方法一:使用子模块初始化
只克隆主仓库:
bash
# 1. 只克隆zephyr主仓库
west init -m https://github.com/zephyrproject-rtos/zephyr --mr v3.5.0 ~/zephyrproject
# 2. 进入工作区
cd ~/zephyrproject
# 3. 只更新必要的模块(根据需要添加)
west update zephyr
5.3 方法二:自定义Manifest文件
创建精简的Manifest:
yaml
# my-manifest.yml
manifest:
remotes:
- name: zephyr
url-base: https://github.com/zephyrproject-rtos
projects:
# 只包含核心仓库
- name: zephyr
revision: main
url: https://github.com/zephyrproject-rtos/zephyr
path: zephyr
clone-depth: 1
使用自定义Manifest:
bash
# 克隆项目
west init -m https://your.repo/my-manifest.yml ~/myproject
# 更新
west update
5.4 方法三:使用浅克隆
配置浅克隆以减少下载量:
bash
# 全局设置浅克隆
west config --global update.clone-depth 1
# 或者在Manifest中配置
manifest:
self:
clone-depth: 1
projects:
- name: zephyr
clone-depth: 1
5.5 方法四:使用--fetch-opt参数
bash
# 使用浅克隆选项
west update --fetch-opt="--depth=1"
# 只获取最新提交
west update --fetch-opt="--filter=blob:none"
5.6 方法五:选择性更新模块
在Manifest中使用path-exclude排除不需要的模块:
yaml
manifest:
defaults:
clone-depth: 1
projects:
- name: zephyr
path: zephyr
# 只包含需要的HAL
- name: hal_nordic
path: modules/hal/nordic
# 排除不需要的模块
- name: hal_espressif
path: modules/hal/espressif
clone-depth: 0 # 不克隆
六、深度优化策略
6.1 分层Manifest设计
#mermaid-svg-TSoKFYOpQX319K7o{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-TSoKFYOpQX319K7o .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-TSoKFYOpQX319K7o .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-TSoKFYOpQX319K7o .error-icon{fill:#552222;}#mermaid-svg-TSoKFYOpQX319K7o .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-TSoKFYOpQX319K7o .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-TSoKFYOpQX319K7o .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-TSoKFYOpQX319K7o .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-TSoKFYOpQX319K7o .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-TSoKFYOpQX319K7o .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-TSoKFYOpQX319K7o .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-TSoKFYOpQX319K7o .marker{fill:#333333;stroke:#333333;}#mermaid-svg-TSoKFYOpQX319K7o .marker.cross{stroke:#333333;}#mermaid-svg-TSoKFYOpQX319K7o svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-TSoKFYOpQX319K7o p{margin:0;}#mermaid-svg-TSoKFYOpQX319K7o .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-TSoKFYOpQX319K7o .cluster-label text{fill:#333;}#mermaid-svg-TSoKFYOpQX319K7o .cluster-label span{color:#333;}#mermaid-svg-TSoKFYOpQX319K7o .cluster-label span p{background-color:transparent;}#mermaid-svg-TSoKFYOpQX319K7o .label text,#mermaid-svg-TSoKFYOpQX319K7o span{fill:#333;color:#333;}#mermaid-svg-TSoKFYOpQX319K7o .node rect,#mermaid-svg-TSoKFYOpQX319K7o .node circle,#mermaid-svg-TSoKFYOpQX319K7o .node ellipse,#mermaid-svg-TSoKFYOpQX319K7o .node polygon,#mermaid-svg-TSoKFYOpQX319K7o .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-TSoKFYOpQX319K7o .rough-node .label text,#mermaid-svg-TSoKFYOpQX319K7o .node .label text,#mermaid-svg-TSoKFYOpQX319K7o .image-shape .label,#mermaid-svg-TSoKFYOpQX319K7o .icon-shape .label{text-anchor:middle;}#mermaid-svg-TSoKFYOpQX319K7o .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-TSoKFYOpQX319K7o .rough-node .label,#mermaid-svg-TSoKFYOpQX319K7o .node .label,#mermaid-svg-TSoKFYOpQX319K7o .image-shape .label,#mermaid-svg-TSoKFYOpQX319K7o .icon-shape .label{text-align:center;}#mermaid-svg-TSoKFYOpQX319K7o .node.clickable{cursor:pointer;}#mermaid-svg-TSoKFYOpQX319K7o .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-TSoKFYOpQX319K7o .arrowheadPath{fill:#333333;}#mermaid-svg-TSoKFYOpQX319K7o .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-TSoKFYOpQX319K7o .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-TSoKFYOpQX319K7o .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-TSoKFYOpQX319K7o .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-TSoKFYOpQX319K7o .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-TSoKFYOpQX319K7o .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-TSoKFYOpQX319K7o .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-TSoKFYOpQX319K7o .cluster text{fill:#333;}#mermaid-svg-TSoKFYOpQX319K7o .cluster span{color:#333;}#mermaid-svg-TSoKFYOpQX319K7o div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-TSoKFYOpQX319K7o .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-TSoKFYOpQX319K7o rect.text{fill:none;stroke-width:0;}#mermaid-svg-TSoKFYOpQX319K7o .icon-shape,#mermaid-svg-TSoKFYOpQX319K7o .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-TSoKFYOpQX319K7o .icon-shape p,#mermaid-svg-TSoKFYOpQX319K7o .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-TSoKFYOpQX319K7o .icon-shape .label rect,#mermaid-svg-TSoKFYOpQX319K7o .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-TSoKFYOpQX319K7o .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-TSoKFYOpQX319K7o .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-TSoKFYOpQX319K7o :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 分层配置
主Manifest
基础层
驱动层
协议栈层
zephyr核心
需要的驱动
需要的协议栈
主Manifest示例:
yaml
# west-base.yml
manifest:
remotes:
- name: zephyr
url-base: https://github.com/zephyrproject-rtos
projects:
- name: zephyr
url: https://github.com/zephyrproject-rtos/zephyr
path: zephyr
clone-depth: 1
扩展Manifest示例:
yaml
# west-ext.yml
extends:
file: west-base.yml
manifest:
projects:
- name: hal_nordic
url: https://github.com/nrfconnect/sdk-hal_nordic
path: modules/hal/nordic
- name: mcuboot
url: https://github.com/mcu-tools/mcuboot
path: bootloader/mcuboot
6.2 使用本地Manifest
创建本地Manifest目录:
bash
mkdir -p ~/zephyrproject/.west/local
在local目录添加项目配置:
yaml
# .west/local/my-projects.yml
manifest:
projects:
# 只添加需要的模块
- name: hal_nordic
url: https://github.com/nrfconnect/sdk-hal_nordic
path: modules/hal/nordic
revision: v2.0.0
6.3 条件化模块加载
使用west config条件配置:
bash
# 只克隆指定路径下的模块
west update --paged
# 查看可用的模块路径
west list
6.4 Git LFS配置
bash
# 安装Git LFS
git lfs install
# 只克隆LFS指针
git lfs clone --skip-smudge https://github.com/zephyrproject-rtos/zephyr
# 按需拉取大文件
git lfs pull --include="*.bin"
七、实用配置示例
7.1 最小化配置(仅QEMU测试)
bash
# 创建工作区
west init -m https://github.com/zephyrproject-rtos/zephyr --mr v3.5.0 ~/zephyr-minimal
# 只更新zephyr核心
cd ~/zephyr-minimal
west update --exclude=modules/*/hal_*
Manifest配置:
yaml
# minimal.yml
manifest:
remotes:
- name: zephyr
url-base: https://github.com/zephyrproject-rtos
projects:
- name: zephyr
url: https://github.com/zephyrproject-rtos/zephyr
path: zephyr
clone-depth: 1
7.2 Nordic芯片配置
bash
# 创建Nordic专用工作区
west init -m https://github.com/nrfconnect/sdk-nrf --mr v2.5.0 ~/nrf-project
cd ~/nrf-project
west update
7.3 STM32芯片配置
yaml
# stm32.yml
manifest:
remotes:
- name: zephyr
url-base: https://github.com/zephyrproject-rtos
projects:
- name: zephyr
url: https://github.com/zephyrproject-rtos/zephyr
path: zephyr
clone-depth: 1
- name: hal_stm32
url: https://github.com/zephyrproject-rtos/sdk-hal_stm32
path: modules/hal/stm32
clone-depth: 1
- name: openocd
url: https://github.com/zephyrproject-rtos/openocd
path: tools/openocd
clone-depth: 1
7.4 ESP32芯片配置
yaml
# esp32.yml
manifest:
remotes:
- name: espressif
url-base: https://github.com/espressif
- name: zephyr
url-base: https://github.com/zephyrproject-rtos
projects:
- name: zephyr
url: https://github.com/zephyrproject-rtos/zephyr
path: zephyr
clone-depth: 1
- name: esp-idf
url: https://github.com/espressif/esp-idf
path: tools/esp-idf
clone-depth: 1
- name: hal_espressif
url: https://github.com/zephyrproject-rtos/sdk-hal_espressif
path: modules/hal/espressif
clone-depth: 1
八、管理和维护
8.1 查看当前配置
bash
# 查看West配置
west config --list
# 查看Manifest内容
west manifest --freeze
# 列出所有项目
west list
8.2 更新策略
| 策略 | 命令 | 适用场景 |
|---|---|---|
| 完整更新 | west update |
首次克隆 |
| 浅更新 | west update --fetch-opt="--depth=1" |
日常开发 |
| 选择性更新 | west update <project> |
节省时间 |
| 强制更新 | west update --force |
修复损坏 |
8.3 清理工作区
bash
# 查看工作区大小
du -sh ~/zephyrproject
# 清理构建缓存
west build --clean
# 删除未跟踪的文件
cd ~/zephyrproject/zephyr
git clean -fd
# 清理Git对象
git gc --aggressive
8.4 备份和恢复
bash
# 备份Manifest配置
cp ~/.west/config ~/.west/config.bak
# 备份所有remote配置
west config --list > west-config.txt
# 恢复配置
west init -l ~/.west ~/zephyrproject
九、常见问题与解决
9.1 克隆失败
问题:网络超时或速度慢
解决方案:
bash
# 使用SSH代替HTTPS
west init -m git@github.com:zephyrproject-rtos/zephyr.git ~/project
# 或使用代理
export https_proxy=http://proxy:8080
west init ~/zephyrproject
9.2 磁盘空间不足
问题:仓库过大
解决方案:
bash
# 1. 使用浅克隆
west init -m https://github.com/zephyrproject-rtos/zephyr --mr v3.5.0 ~/zephyrproject
# 2. 之后只选择性更新
west update --fetch-opt="--depth=1"
# 3. 清理不必要的模块
rm -rf modules/hal/* # 删除不需要的HAL
9.3 子模块更新失败
问题:子模块引用无效
解决方案:
bash
# 重新同步子模块
cd ~/zephyrproject/zephyr
git submodule sync
git submodule update --init --recursive
9.4 Manifest版本冲突
问题:多个Manifest版本不兼容
解决方案:
bash
# 使用固定版本
west init -m https://github.com/zephyrproject-rtos/zephyr --mr v3.5.0 ~/project
# 锁定所有子模块版本
west update --fetch-opt="--depth=1"
十、最佳实践总结
10.1 开发环境配置推荐
| 场景 | 推荐配置 |
|---|---|
| 初学者 | 默认完整安装,使用最新稳定版 |
| QEMU测试 | 仅安装zephyr核心,跳过HAL模块 |
| 单芯片开发 | 只安装对应HAL和必要工具 |
| CI/CD环境 | 使用固定版本,完全可重现 |
10.2 快速启动模板
创建最小化QEMU开发环境:
bash
#!/bin/bash
# setup-minimal.sh
set -e
PROJECT_DIR=~/zephyr-minimal
ZEPHYR_VERSION=v3.5.0
# 1. 创建工作区
west init -m https://github.com/zephyrproject-rtos/zephyr \
--mr $ZEPHYR_VERSION $PROJECT_DIR
cd $PROJECT_DIR
# 2. 只更新核心
west update zephyr
# 3. 设置环境变量
source zephyr/zephyr-env.sh
echo "Minimal Zephyr environment ready!"
echo "Try: west build -b qemu_x86 samples/hello_world -t run"
10.3 CI/CD优化配置
yaml
# .github/workflows/build.yml
name: Build
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install West
run: pip install west
- name: Initialize
run: |
west init -m https://github.com/zephyrproject-rtos/zephyr \
--mr ${{ github.event.release.tag_name }}
west update --fetch-opt="--depth=1"
- name: Build
run: |
source zephyr/zephyr-env.sh
west build -b qemu_x86 samples/hello_world
结束语
通过本文的详细介绍,相信您对west init和west update命令的执行过程有了深入理解,并掌握了多种按需下载的配置方法。
核心要点回顾:
| 优化方法 | 效果 | 适用场景 |
|---|---|---|
| 浅克隆 | 减少90%下载量 | 日常开发 |
| 自定义Manifest | 按需加载 | 特定芯片开发 |
| 分层Manifest | 模块化管理 | 复杂项目 |
| 选择性更新 | 节省时间 | 快速迭代 |
合理的配置不仅能节省网络带宽和磁盘空间,还能加快CI/CD流程,提高开发效率。建议根据实际项目需求,选择最适合的配置方案。
参考资料: