oxide-sloc/oxide-sloc

GitHub: oxide-sloc/oxide-sloc

基于 Rust 的跨平台源代码行统计工具,符合 IEEE 1045-1992 标准,提供 CLI、Web UI、Git 历史浏览、多格式报告及 CI/CD 集成。

Stars: 0 | Forks: 0

# oxide-sloc [![CI](https://static.pigsec.cn/wp-content/uploads/repos/2026/05/8112e5b403051805.svg)](https://github.com/oxide-sloc/oxide-sloc/actions/workflows/ci.yml) [![发布](https://static.pigsec.cn/wp-content/uploads/repos/2026/05/ff79d6cca5051806.svg)](https://github.com/oxide-sloc/oxide-sloc/actions/workflows/release.yml) [![Docker](https://static.pigsec.cn/wp-content/uploads/repos/2026/05/f48ff94a91051807.svg)](https://github.com/oxide-sloc/oxide-sloc/actions/workflows/docker.yml) [![最新发布](https://img.shields.io/github/v/release/oxide-sloc/oxide-sloc?include_prereleases&label=release)](https://github.com/oxide-sloc/oxide-sloc/releases/latest) [![crates.io](https://img.shields.io/crates/v/oxide-sloc.svg)](https://crates.io/crates/oxide-sloc) [![许可证:AGPL-3.0-or-later](https://img.shields.io/badge/license-AGPL--3.0--or--later-blue.svg)](./LICENSE) **oxide-sloc** 是一个基于 Rust 的源代码行分析工具 —— 符合 IEEE 1045-1992 标准,远不止是一个行数计数器。 ## 快速开始 ``` bash scripts/install.sh # detects bundled binary or builds from vendor sources bash scripts/run.sh # web UI at http://127.0.0.1:4317 ``` | 平台 | 安装 | 启动 | LAN 服务器 | |---|---|---|---| | **Windows 10/11** (Git Bash) | `bash scripts/install.sh` | `bash scripts/run.sh` | `bash scripts/serve-server.sh` | | **Linux — RHEL 8/9, Ubuntu, Debian** | `bash scripts/install.sh` | `bash scripts/run.sh` | `bash scripts/serve-server.sh` | **网络要求:** - **Windows** —— 不需要网络;`oxide-sloc.exe` 已包含在仓库根目录中。 - **安装了 Rust 的 Linux** —— 不需要网络;`vendor.tar.xz` 包含了所有 crate 源码,可实现完全离线构建。 - **未安装 Rust 的 Linux** —— 将 `dist/oxide-sloc-linux-x86_64.tar.gz` 放置在仓库旁边(不需要网络),或者在有 `curl` 的情况下运行 `bash scripts/install.sh --online` 从 GitHub 下载。 有关所有部署方式,请参阅 [`docs/airgap.md`](./docs/airgap.md)。 ## 在局域网中托管 使 oxide-sloc 可以从同一网络上的任何设备访问。 **最快方式:** ``` bash scripts/serve-server.sh ``` 自动生成 API 密钥,打印服务器可访问的每个 LAN 地址,并提供一个现成的 `curl` 测试命令。如果其他设备连接超时,说明你的防火墙拦截了端口 4317 —— 脚本会准确告诉你该运行什么命令,或者传递 `--open-firewall` 让它自动开放端口(在 Linux 上需要 `sudo`)。 **或者直接运行二进制文件:** ``` export SLOC_API_KEY=$(openssl rand -hex 32) oxide-sloc serve --server # binds to 0.0.0.0:4317 ``` 然后在同一网络上的任何设备上打开 `http://<你的IP>:4317`(Linux 上使用 `hostname -I`,Windows 上使用 `ipconfig`)。 设置 API 密钥后,CLI/curl 调用方必须包含该密钥: ``` curl -H "Authorization: Bearer $SLOC_API_KEY" http://:4317/healthz ``` **防火墙(Linux):** ``` sudo ufw allow 4317/tcp # UFW sudo firewall-cmd --add-port=4317/tcp --permanent # firewalld ``` 在 Windows 上,出现提示时请允许 oxide-sloc 通过 Windows Defender 防火墙。 ## 功能特性 - **CLI + Web UI** —— `analyze / report / diff / serve / send / init / git-scan / git-compare` 命令;引导式的 4 步 Web 流程,支持明暗主题和一键快速扫描 - **符合 IEEE 1045-1992 的物理 SLOC** —— 可配置的混合行策略、续行、编译器指令和块注释中的空行分类;符号计数(函数、类、变量、导入) - **灵活的输出** —— 包含逐文件细分和语言图表的 HTML 报告;PDF、CSV 和 4 个工作表的 Excel 导出;重新渲染任何已保存的 JSON 结果 - **Git 集成** —— 用于分支/标签/提交的浏览器 UI,GitHub/GitLab/Bitbucket webhook 和轮询自动化,通过 git worktree 进行时间点比较,子模块细分 - **CI/CD 和集成** —— Jenkinsfile、GitHub Actions、GitLab CI;JSON 指标 API、SVG 徽章端点、可嵌入的 ` ``` ## CI/CD ### Web UI → CLI 对照 | Web UI | 等效的 CLI 命令 | |---|---| | 步骤 1:选择项目 | `oxide-sloc analyze ./my-repo` | | 步骤 1:包含 / 排除模式 | `--include-glob` / `--exclude-glob` | | 步骤 1:子模块细分 | `--submodule-breakdown` | | 快速扫描 | `oxide-sloc analyze ./my-repo --plain` | | 步骤 2:混合行策略 | `--mixed-line-policy code-only` | | 步骤 2:将 Python docstrings 视为代码 | `--python-docstrings-as-code` | | *(仅限配置 / CLI)* | `--continuation-line-policy collapse-to-logical` | | *(仅限配置 / CLI)* | `--blank-in-block-comment-policy count-as-blank` | | *(仅限配置 / CLI)* | `--no-count-compiler-directives` | | 步骤 3:输出 | `-j` `-H` `--pdf-out` `-c` `-x` `--open` | | 步骤 3:自定义标题 | `--report-title "My Report"` | | 从保存的 JSON 重新渲染 | `oxide-sloc report result.json -H report.html` | | 比较两次扫描 | `oxide-sloc diff baseline.json current.json` | | 生成入门配置 | `oxide-sloc init` | | 静默 / 失败保护 | `--quiet` `--fail-on-warnings` `--fail-below N` | ### CI 配置预设 | 文件 | 用例 | |---|---| | `ci/sloc-ci-default.toml` | 均衡的默认设置 | | `ci/sloc-ci-strict.toml` | 遇到二进制文件时快速失败 | | `ci/sloc-ci-full-scope.toml` | 审计模式 —— 也计算 vendor/lockfiles | ### GitHub Actions | 工作流 | 触发条件 | 功能 | |---|---|---| | `ci.yml` | 推送到 `main`,所有 PR | fmt → clippy → build → 测试 → CLI 冒烟测试 → Web 健康检查 | | `release.yml` | `v*` 标签 | 为 5 个平台交叉编译 → 签名 Windows 二进制文件 → GitHub Release | | `docker.yml` | 推送到 `main`,`v*` 标签 | 构建并将 Docker 镜像推送到 GHCR | | `update-dist.yml` | `v*` 标签,手动 | 构建平台捆绑包并提交到 `dist/` | 所有工作流均在 Node 24 上运行。 发起一个发布: ``` git tag v1.1.0 git push origin v1.1.0 ``` ### Jenkins / GitLab CI 仓库根目录中包含了 `Jenkinsfile` 和 `.gitlab-ci.yml`。在自托管或离线 Runner 上,`vendor.tar.xz` 已提交至仓库 —— 只需一次 `git clone` 即可。流水线会在运行之间自动解压并缓存 `vendor/`。 有关包含 Confluence 发布在内的详细设置,请参阅 [`docs/ci-integrations.md`](./docs/ci-integrations.md)。 ## 本地开发 ``` # 在推送前运行所有 CI 门禁 cargo fmt --all -- --check cargo clippy --workspace --all-targets -- -D warnings cargo build --workspace cargo test --workspace # 在开发期间运行 Web UI cargo run -p oxide-sloc -- serve # 快速重建(保留 vendored 依赖缓存,约 1 分钟) cargo clean -p oxide-sloc -p sloc-config -p sloc-core -p sloc-languages -p sloc-report -p sloc-web \ && cargo run -p oxide-sloc -- serve ``` **Make 目标(Linux/macOS):** ``` make check # fmt + lint + test make dev # fmt + lint + test + serve make build # release binary → target/release/oxide-sloc make docker-build # build Docker image locally ``` ## 仓库布局 ``` crates/ sloc-cli/ # CLI entry point and commands sloc-config/ # Config schema and TOML parsing sloc-core/ # File discovery, decoding, aggregation, delta engine sloc-languages/ # Language detection, lexical analyzers, symbol counting sloc-report/ # HTML rendering, PDF export, CSV/Excel export sloc-web/ # Axum web server, scan registry, metrics API, badge endpoint ci/ # CI shell scripts (lint.sh, build.sh, test.sh, release.sh) + config presets deploy/ # systemd unit + server config template dist/ # Release bundles — generated by CI, not tracked in git docs/ assets/ # Icons, logos (served at /images/* by the web UI) airgap.md # Offline and air-gapped deployment guide ci-integrations.md server-deployment.md examples/ # Runnable examples + sloc.example.toml config template scripts/ # install.sh, run.sh, serve-server.sh (user-facing entry points) scripts/internal/ # airgap-build.sh, make-airgap-kit.sh, update-vendor.sh, install-hooks.sh tests/ fixtures/basic/ # Sample source files used by smoke tests ``` ## 许可证 **oxide-sloc** 采用 [AGPL-3.0-or-later](./LICENSE) 授权。 版权所有 (C) 2026 Nima Shafie。所有知识产权仅归作者所有。 商业支持、托管服务和专有附加组件可通过单独的安排提供。请参阅 [`docs/licensing-commercial.md`](./docs/licensing-commercial.md)。 **Nima Shafie** —— [github.com/NimaShafie](https://github.com/NimaShafie)
标签:crates.io, Docker, GitHub Actions, Git历史, HTML报告, IEEE 1045-1992, PDF报告, Python安全, Rust, SLOC计数器, TCP SYN 扫描, Web UI, 云安全监控, 代码分析工具, 代码度量, 代码统计, 可视化界面, 安全防御评估, 源码行分析, 研发效能, 离线安装, 网络流量审计, 自动笔记, 请求拦截, 通知系统, 静态分析