# ani
**Repository Path**: qinzxx/ani
## Basic Information
- **Project Name**: ani
- **Description**: A tool writen in Rust, for stoneOS development.
- **Primary Language**: Unknown
- **License**: GPL-3.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2024-12-13
- **Last Updated**: 2026-07-14
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# 1. 简介
用Rust写的一个小工具,初期参考了[rua](https://gitee.com/bzhaoland/rua)。支持对一个或多个子目录生成`compile_commands.json`文件,用于给clangd或微软的C/C++插件做编译数据库使用。
在一个子目录下生成`compile_commands.json`,直接执行ani a即可。
想要为多个子目录生成`compile_commands.json`,则执行`ani a ...`。
`/ˈæni/`
| 文档 | 说明 |
|--------------------------------------|----------------|
|[1-usage.md](doc/01-usage.md) | 用法说明 |
|[2-build.md](doc/02-build.md) | 构建说明 |
|[3-principle.md](doc/03-principle.md) | 实现原理 |
|[4-mis.md](doc/04-misc.md) | 其他杂项 |
# 2. 生成compdb主要用法简介
compdb这里特指 `compile_commands.json`文件,此文件为clangd language-server-protocol 提供编译目录和命令等信息。
```text
$ ani
A StoneOS compdb toolsets
Usage: ani
Commands:
hack hack `script/common-rule.mk` [aliases: h]
unhack unhack `script/common-rule.mk` [aliases: u]
gen execute `hsdocket7 make ani_compdb` to generate compdb after `ani hack` [aliases: g]
all do all steps to generate compdb for StoneOS code: hack, gen compdb, unhack [aliases: a]
show show make info for specified product in any svn dir, such as `A3000` [aliases: s]
workspace show build workspace according to `build-id` [aliases: w]
coreparse analyze coredump according to an `archived coredump file` [aliases: c]
vscode generate a simple vscode workspace template file for multi directories [aliases: vs]
tui start ani terminal UI [aliases: t]
update update ani to the lastest version from ftp server 10.200.6.10 [aliases: up]
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
-V, --version Print version
Ani Compile TimeStamp: 2025-09-30
Version 1.0.4, Random ID 166
Contact who@hillstonenet.com if encountered bugs
Project home page: https://gitlab.hillstonenet.com/zxqin/ani
```
`ani all`的内部执行逻辑:
1. hack:先临时修改下`scripts/common-rules.mk`文件(如果该文件已有unstaged修改则退出报错)
2. gen:再make自定义目标`ani_compdb`以生成`compile_commands.json`文件
3. unhack:最后`svn revert`或`git checkout`以恢复`scripts/common-rules.mk`文件
支持R12以后和R12之前的分支,不过二者hack的结果有点差异。如感兴趣可以通过`ani hack`查看下具体修改内容。
注:因此需要注意下你自己如果本地修改了`scripts/common-rules.mk`文件,需要先自行stash一下修改内容再操作。
`ani all`子命令用法:
```bash
$ ani all -h
do all steps to generate compdb for StoneOS code: hack, gen compdb, unhack
Usage: ani all [OPTIONS] [sub_dirs]...
Arguments:
[sub_dirs]... Sub dirs which need to generate compdb
Options:
-q, --quiet Suppress the output when make ani_compdb
-h, --help Print help
```
### 2. `ani all` 子命令 生成`compile_commands.json`
#### 2.1 支持为多个子目录生成一个合并的`compile_commands.json`文件:
0. `cd HAWAII_REL_R11/src`
1. `ani a mgmt/cli dhcpd smspd/ netd`,这会为`mgmt/cli, dhcpd, smspd and netd`这几个子目录生成一个合并的`compile_commands.json`文件。
生成的compdb给clangd lsp提供编译目录和命令等信息,也可以用于`clang-tidy`来做快速静态检查。这两个场景可以更方便点。
如果想快速结合clangd看单个目录代理,compdb+helix编辑器的组合也很方便。
目前个人工作流是使用`ani vs`命令新建vscode/lingma工作区,将常用目录加入工作区,然后结合`ani all命`令生成compdb文件来查看代码。
好处是clangd内存占用少些,并且也不会将不关心的目录加入vscode工作区。
### 2.2 也可以为单个子目录生成`compile_commands.json`文件,比如`src/mgmt/cli`:
`ani all src/mgmt/cli`
或:
`cd src/mgmt/cli && ani all`
这个方式简单快速。
注:
1. `ani all`不指定目录时,为当前目录生成compdb。
2. `ani all`后可以指定一个或多个子目录,当多个子目录生成compdb。
### 1.3 添加其他编译选项的用法
如果想在compdb里指定其他编译选项,比如 `ISBUILDRELEASE=1 HS_LICENSE_CHECK=0`,可以使用如下方式:
1. `ani h`: 临时修改下`$(TOP_DIR)/scripts/common-rules.mk`文件,添加自定义`ani_compdb`目标。
2. `hsdocker7 make ani_compdb -j16 ISBUILDRELEASE=1 HS_LICENSE_CHECK=0 -C mgmt/cli`: 指定自定义编译参数,在mgmt/cli目录下生成 compdb 文件。
3. `ani unhack`: revert掉对 `$(TOP_DIR)/scripts/common-rules.mk`文件的修改(内部调用`svn revert xxx` or `git checkout xxx`回退文件)。
>**注**
>`all all`命令生成compdb只适用于stone OS自己的代码,三方库/开源代码的话,可以另行使用`intercept-build make ...`或`bear make ...`。
## 2. 安装
### 方式1: 直接拷贝sz ftp目录下的二进制文件:
```bash
wget ftp://10.200.6.10/zxqin/tools/ani && chmod +x ani && mv ani ~/.local/bin/
# if ~/.local/bin dose not exist, create it and add it into path env var
```
### or, 自行编译构建然后导入二进制文件到研发域使用:
```bash
# cargo build
cargo b -r --target x86_64-unknown-linux-musl
# copy binary
cp target/x86_64-unknown-linux-musl/release/ani ./
# copy to ftp server
...
# execute on build server
# wget ftp://x.x.x.x/user/ani ~/.local/bin/
# if ~/.local/bin dose not exist, create it and add it into path env var
```
### or,
```bash
# build and copy binary to current directory
make bin
# copy to ftp server
...
# execute on build server
# wget ftp://x.x.x.x/user/ani ~/.local/bin/
# if ~/.local/bin dose not exist, create it and add it into path env var
```
# 3. 参考
- https://gitlab.hillstonenet.com/bzhao/rua
- stoneos compdb