152 lines
3.7 KiB
Markdown
152 lines
3.7 KiB
Markdown
# AOSP 编译错误分析 Agent
|
||
|
||
基于火山方舟 Ark API(DeepSeek)的 AOSP 编译错误自动分析工具。编译失败后一键运行,Agent 自动读取日志、翻阅源码、定位根因、给出修复建议。
|
||
|
||
**分析过程纯只读**:Agent 仅使用本地实现的 read_file / glob / grep 工具,不执行命令、不修改任何文件;"验证命令"仅作为建议输出。
|
||
|
||
## 1. 前置依赖
|
||
|
||
| 依赖 | 说明 | 获取方式 |
|
||
|------|------|---------|
|
||
| ARK_API_KEY | **必需**。火山方舟 API Key | https://console.volcengine.com/ark/region:cn-beijing/apikey |
|
||
| 网络 | 能访问 ark.cn-beijing.volces.com | — |
|
||
|
||
无其他运行时依赖(单二进制自包含,不需要 Node/Bun/qoderclicn)。
|
||
|
||
环境变量(由 `install.sh` 自动写入 `~/.aosp-analyzer.env`):
|
||
|
||
```bash
|
||
export ARK_API_KEY="ark-xxxxx" # 必需
|
||
export ARK_MODEL="deepseek-v4-flash-260425" # 可选,默认值
|
||
export ARK_BASE_URL="https://ark.cn-beijing.volces.com/api/v3" # 可选,默认值
|
||
```
|
||
|
||
## 2. 安装
|
||
|
||
### 编译服务器一键安装
|
||
|
||
```bash
|
||
# 使用本地二进制 + 自动配置 API Key
|
||
./scripts/install.sh --token "ark-xxxxx" --binary ./analyze
|
||
|
||
# 或交互式安装
|
||
./scripts/install.sh
|
||
```
|
||
|
||
### 卸载
|
||
|
||
```bash
|
||
# 一键卸载(清理二进制、Token 配置、Shell 自动加载行)
|
||
curl -fsSL https://raw.githubusercontent.com/<你的用户名>/<仓库名>/main/scripts/uninstall.sh | bash -s --
|
||
|
||
# 或本地执行
|
||
./scripts/uninstall.sh
|
||
```
|
||
|
||
### 开发机构建
|
||
|
||
```bash
|
||
# 安装 Bun(如果没有)
|
||
curl -fsSL https://bun.sh/install | bash
|
||
|
||
bash scripts/build.sh
|
||
# 产物: dist/analyze(Linux x64 单二进制)
|
||
|
||
scp dist/analyze build-server:/usr/local/bin/analyze
|
||
```
|
||
|
||
## 3. 使用
|
||
|
||
```bash
|
||
# 编译并自动分析
|
||
m 2>&1 | tee build.log || analyze build.log
|
||
|
||
# 指定 AOSP 根目录(让 Agent 能访问源码上下文)
|
||
analyze build.log --cwd /path/to/aosp
|
||
|
||
# 不指定日志,自动查找当前目录(build.log / build_output.log / build_output.txt / out/.ninja_log)
|
||
analyze
|
||
|
||
# 帮助
|
||
analyze --help
|
||
```
|
||
|
||
输出报告格式(每个错误):
|
||
|
||
```text
|
||
### 错误 N: [类型] 一句话摘要
|
||
- 位置 / 错误信息 / 根因分析 / 修复方案 / 验证命令(仅建议)
|
||
最后给出总结与修复优先级。
|
||
```
|
||
|
||
## 4. CI/CD 集成
|
||
|
||
### Jenkins
|
||
|
||
```groovy
|
||
pipeline {
|
||
agent { label 'aosp-build' }
|
||
stages {
|
||
stage('Build') {
|
||
steps {
|
||
sh '''
|
||
source build/envsetup.sh
|
||
lunch ${PRODUCT}-${VARIANT}
|
||
m 2>&1 | tee build.log
|
||
'''
|
||
}
|
||
}
|
||
}
|
||
post {
|
||
failure {
|
||
sh 'analyze build.log --cwd ${WORKSPACE} > analysis_report.txt || true'
|
||
archiveArtifacts 'analysis_report.txt'
|
||
}
|
||
}
|
||
}
|
||
```
|
||
|
||
### GitLab CI
|
||
|
||
```yaml
|
||
build:
|
||
stage: build
|
||
script:
|
||
- source build/envsetup.sh
|
||
- lunch ${PRODUCT}-${VARIANT}
|
||
- m 2>&1 | tee build.log
|
||
artifacts:
|
||
paths:
|
||
- build.log
|
||
when: on_failure
|
||
|
||
analyze:
|
||
stage: analyze
|
||
script:
|
||
- analyze build.log --cwd $CI_PROJECT_DIR > analysis_report.txt
|
||
artifacts:
|
||
paths:
|
||
- analysis_report.txt
|
||
needs:
|
||
- job: build
|
||
artifacts: true
|
||
when: on_failure
|
||
```
|
||
|
||
## 5. 开发
|
||
|
||
```bash
|
||
npm install
|
||
npx tsx src/analyze.ts tests/fixtures/mock-aosp/build.log --cwd tests/fixtures/mock-aosp # 本地运行
|
||
npm run typecheck # 类型检查
|
||
npm run build # 交叉编译 Linux 二进制
|
||
```
|
||
|
||
需求与交付文档见 `docs/specs/aosp-build-analyzer/`。
|
||
|
||
## 6. 已知限制
|
||
|
||
- 二进制目标平台为 Linux x64;
|
||
- 需要能访问火山方舟 API 的网络环境;
|
||
- 分析结论由 AI 生成,属于候选内容,修复操作须由工程师确认后执行。
|