@chengzhao-dev/dsh-cpp-workflow 0.6.19 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +11 -26
- package/README.md +13 -28
- package/cordis.patch.yml +1 -1
- package/lib/client.js +33 -21
- package/lib/comment-policy.js +15 -6
- package/lib/index.js +1 -1
- package/lib/workspace.js +0 -15
- package/package.json +7 -7
- package/skills/building-cpp/SKILL.md +34 -21
- package/skills/building-cpp/assets/templates/projects/common/running-build.sh +5 -1
- package/skills/building-cpp/project/vscode/01-extensions.md +28 -0
- package/skills/building-cpp/project/vscode/02-settings.md +39 -0
- package/skills/building-cpp/references/build-script.md +14 -7
- package/skills/building-cpp/references/environment.md +8 -1
- package/skills/building-cpp/steps/01-build.md +8 -8
- package/skills/building-cpp/steps/02-tooling.md +17 -9
- package/skills/building-cpp/steps/03-check.md +16 -14
- package/skills/developing-cpp/SKILL.md +37 -25
- package/skills/developing-cpp/references/comments/comment-rules.md +181 -0
- package/skills/developing-cpp/references/comments/comment-style.md +80 -0
- package/skills/developing-cpp/references/comments/examples/declaration-class.md +66 -0
- package/skills/developing-cpp/references/comments/examples/declaration-constructor.md +22 -0
- package/skills/developing-cpp/references/comments/examples/declaration-enum.md +48 -0
- package/skills/developing-cpp/references/comments/examples/declaration-file.md +66 -0
- package/skills/developing-cpp/references/comments/examples/declaration-function.md +127 -0
- package/skills/developing-cpp/references/comments/examples/declaration-member.md +23 -0
- package/skills/developing-cpp/references/comments/examples/declaration-predicate.md +14 -0
- package/skills/developing-cpp/references/comments/examples/declaration-struct.md +18 -0
- package/skills/developing-cpp/references/comments/examples/implementation-body.md +64 -0
- package/skills/developing-cpp/references/comments/examples/implementation-todo.md +16 -0
- package/skills/developing-cpp/references/comments/glossary/comment-terms.md +93 -0
- package/skills/developing-cpp/references/design/examples/behavior-sentence.md +14 -0
- package/skills/developing-cpp/references/design/examples/coordinate-table.md +31 -0
- package/skills/developing-cpp/references/design/examples/header-place.md +26 -0
- package/skills/developing-cpp/references/design/examples/library-boundary.md +30 -0
- package/skills/developing-cpp/references/design/examples/library-split.md +7 -0
- package/skills/developing-cpp/references/design/examples/move-result.md +39 -0
- package/skills/developing-cpp/references/design/examples/preview-read.md +40 -0
- package/skills/developing-cpp/references/{project-design.md → design/project-design.md} +57 -5
- package/skills/developing-cpp/references/{change-model.md → editing/01-edit-operations.md} +5 -3
- package/skills/developing-cpp/references/{priority.md → editing/02-rule-priority.md} +2 -2
- package/skills/developing-cpp/references/exceptions/examples/throw-boundary.md +28 -0
- package/skills/developing-cpp/references/exceptions/examples/throw-build-mode.md +38 -0
- package/skills/developing-cpp/references/exceptions/examples/throw-catch.md +21 -0
- package/skills/developing-cpp/references/exceptions/examples/throw-destructor.md +21 -0
- package/skills/developing-cpp/references/exceptions/examples/throw-format.md +13 -0
- package/skills/developing-cpp/references/exceptions/examples/throw-message.md +16 -0
- package/skills/developing-cpp/references/exceptions/examples/throw-when.md +27 -0
- package/skills/developing-cpp/references/{exceptions.md → exceptions/throw-rules.md} +78 -23
- package/skills/developing-cpp/references/{glossary.md → language/glossary/language-terms.md} +2 -2
- package/skills/developing-cpp/references/language/language-basics/01-objects.md +15 -0
- package/skills/developing-cpp/references/language/language-basics/02-initialization.md +26 -0
- package/skills/developing-cpp/references/language/language-basics/03-deduction.md +12 -0
- package/skills/developing-cpp/references/language/language-basics/04-const.md +25 -0
- package/skills/developing-cpp/references/language/language-basics/05-expressions.md +23 -0
- package/skills/developing-cpp/references/language/language-basics/06-functions.md +15 -0
- package/skills/developing-cpp/references/language/language-basics/07-classes.md +15 -0
- package/skills/developing-cpp/references/language/language-basics/08-raii.md +15 -0
- package/skills/developing-cpp/references/language/language-basics/09-templates.md +26 -0
- package/skills/developing-cpp/references/language/language-basics/10-checklist.md +10 -0
- package/skills/developing-cpp/references/language/performance/01-measure.md +22 -0
- package/skills/developing-cpp/references/language/performance/02-complexity.md +13 -0
- package/skills/developing-cpp/references/language/performance/03-memory.md +14 -0
- package/skills/developing-cpp/references/language/performance/04-undefined-behavior.md +28 -0
- package/skills/developing-cpp/references/language/performance/05-pitfalls.md +17 -0
- package/skills/developing-cpp/references/language/performance/06-false-optimizations.md +13 -0
- package/skills/developing-cpp/references/language/performance/07-checklist.md +8 -0
- package/skills/developing-cpp/references/language/standard-library/01-containers.md +29 -0
- package/skills/developing-cpp/references/language/standard-library/02-access.md +14 -0
- package/skills/developing-cpp/references/language/standard-library/03-iteration.md +18 -0
- package/skills/developing-cpp/references/language/standard-library/04-algorithms.md +26 -0
- package/skills/developing-cpp/references/language/standard-library/05-string.md +13 -0
- package/skills/developing-cpp/references/language/standard-library/06-format.md +106 -0
- package/skills/developing-cpp/references/language/standard-library/07-time.md +13 -0
- package/skills/developing-cpp/references/language/standard-library/08-random.md +13 -0
- package/skills/developing-cpp/references/language/standard-library/09-files.md +14 -0
- package/skills/developing-cpp/references/language/standard-library/10-checklist.md +9 -0
- package/skills/developing-cpp/references/language/value-types/01-width.md +17 -0
- package/skills/developing-cpp/references/language/value-types/02-signed.md +26 -0
- package/skills/developing-cpp/references/language/value-types/03-integer-roles.md +38 -0
- package/skills/developing-cpp/references/language/value-types/04-enum.md +24 -0
- package/skills/developing-cpp/references/language/value-types/05-strong-type.md +17 -0
- package/skills/developing-cpp/references/language/value-types/06-const-method.md +22 -0
- package/skills/developing-cpp/references/language/value-types/07-nodiscard.md +15 -0
- package/skills/developing-cpp/references/language/value-types/08-comparison.md +10 -0
- package/skills/developing-cpp/references/language/value-types/09-subscript.md +15 -0
- package/skills/developing-cpp/references/language/value-types/10-float-bool.md +13 -0
- package/skills/developing-cpp/references/language/value-types/11-checklist.md +8 -0
- package/skills/developing-cpp/references/{layout.md → layout/01-source-layout.md} +10 -4
- package/skills/developing-cpp/references/{file-template.md → layout/02-file-template.md} +10 -4
- package/skills/developing-cpp/references/layout/03-declaration-order.md +138 -0
- package/skills/developing-cpp/references/naming/examples/naming-accessor.md +17 -0
- package/skills/developing-cpp/references/naming/examples/naming-basic.md +3 -0
- package/skills/developing-cpp/references/naming/examples/naming-current-prefix.md +19 -0
- package/skills/developing-cpp/references/naming/examples/naming-lookup.md +18 -0
- package/skills/developing-cpp/references/naming/examples/naming-lower-layer.md +39 -0
- package/skills/developing-cpp/references/naming/examples/naming-multiple-return.md +20 -0
- package/skills/developing-cpp/references/naming/examples/naming-player-value.md +16 -0
- package/skills/developing-cpp/references/naming/examples/naming-predicate.md +18 -0
- package/skills/developing-cpp/references/naming/examples/naming-rename.md +5 -0
- package/skills/developing-cpp/references/naming/examples/naming-responsibility.md +19 -0
- package/skills/developing-cpp/references/naming/examples/naming-role.md +21 -0
- package/skills/developing-cpp/references/naming/examples/naming-state-change.md +57 -0
- package/skills/developing-cpp/references/{naming.md → naming/identifier-names.md} +37 -9
- package/skills/developing-cpp/references/{google-cpp-style.md → style/google-cpp-style.md} +11 -10
- package/skills/developing-cpp/scripts/checking-comments.mjs +71 -14
- package/skills/developing-cpp/scripts/checking-declaration-order.mjs +357 -0
- package/skills/developing-cpp/steps/01-behavior.md +5 -5
- package/skills/developing-cpp/steps/02-boundary.md +10 -10
- package/skills/developing-cpp/steps/03-declaration.md +16 -14
- package/skills/developing-cpp/steps/04-implementation.md +21 -17
- package/skills/engineering/SKILL.md +87 -0
- package/skills/{configuring-cmake/assets/cmake → engineering/references/cmake/assets}/CompileSettings.cmake +2 -0
- package/skills/{building-cpp/references/linking.md → engineering/references/cmake/linking/01-libraries.md} +7 -48
- package/skills/engineering/references/cmake/linking/02-rpath.md +25 -0
- package/skills/engineering/references/cmake/linking/03-undefined-reference.md +20 -0
- package/skills/engineering/references/cmake/linking/04-inspect.md +21 -0
- package/skills/{configuring-cmake/references/modules.md → engineering/references/cmake/modules/functions.md} +8 -5
- package/skills/{configuring-cmake/references → engineering/references/cmake/standard}/cxx-standard.md +5 -4
- package/skills/engineering/references/cmake/standard/examples/standard.md +19 -0
- package/skills/{building-cpp/references → engineering/references/cmake/standard}/standards/README.md +9 -9
- package/skills/{building-cpp/references → engineering/references/cmake/standard}/standards/c++20/README.md +1 -1
- package/skills/engineering/references/cmake/targets/examples/glob.md +22 -0
- package/skills/engineering/references/cmake/targets/examples/rpath.md +24 -0
- package/skills/{configuring-cmake/examples/cmake.md → engineering/references/cmake/targets/examples/target.md} +2 -70
- package/skills/{configuring-cmake/references/cmake.md → engineering/references/cmake/targets/rules.md} +18 -11
- package/skills/{building-cpp/references/testing.md → engineering/references/cmake/testing/ctest.md} +11 -4
- package/skills/{building-cpp/references/encoding.md → engineering/references/formatting/01-encoding.md} +1 -1
- package/skills/engineering/references/formatting/02-clang-format.md +20 -0
- package/skills/engineering/references/formatting/03-clang-tidy.md +58 -0
- package/skills/engineering/references/formatting/04-clangd.md +90 -0
- package/skills/engineering/references/formatting/examples/clang-format.md +38 -0
- package/skills/engineering/references/formatting/examples/clang-tidy.md +43 -0
- package/skills/{building-cpp/examples/tooling.md → engineering/references/formatting/examples/clangd.md} +1 -80
- package/skills/{configuring-cmake → engineering}/steps/01-targets.md +6 -6
- package/skills/{configuring-cmake → engineering}/steps/02-modules.md +4 -4
- package/skills/{configuring-cmake → engineering}/steps/03-check.md +3 -2
- package/templates/cpp-workflow-project/SKILL.md +1 -1
- package/skills/building-cpp/references/static-analysis.md +0 -148
- package/skills/configuring-cmake/SKILL.md +0 -68
- package/skills/developing-cpp/examples/comments-declaration.md +0 -313
- package/skills/developing-cpp/examples/comments-implementation.md +0 -66
- package/skills/developing-cpp/examples/exceptions.md +0 -173
- package/skills/developing-cpp/examples/naming.md +0 -168
- package/skills/developing-cpp/examples/structure.md +0 -194
- package/skills/developing-cpp/references/comment-terms.md +0 -75
- package/skills/developing-cpp/references/comments.md +0 -223
- package/skills/developing-cpp/references/declaration-order.md +0 -118
- package/skills/developing-cpp/references/language.md +0 -123
- package/skills/developing-cpp/references/performance.md +0 -83
- package/skills/developing-cpp/references/standard-library.md +0 -138
- package/skills/developing-cpp/references/types.md +0 -154
- /package/skills/{configuring-cmake/assets/cmake → engineering/references/cmake/assets}/LinkSettings.cmake +0 -0
- /package/skills/{building-cpp/references → engineering/references/cmake/standard}/standards/c++11/README.md +0 -0
- /package/skills/{building-cpp/references → engineering/references/cmake/standard}/standards/c++11/cmake-snippet.cmake +0 -0
- /package/skills/{building-cpp/references → engineering/references/cmake/standard}/standards/c++14/README.md +0 -0
- /package/skills/{building-cpp/references → engineering/references/cmake/standard}/standards/c++14/cmake-snippet.cmake +0 -0
- /package/skills/{building-cpp/references → engineering/references/cmake/standard}/standards/c++17/README.md +0 -0
- /package/skills/{building-cpp/references → engineering/references/cmake/standard}/standards/c++17/cmake-snippet.cmake +0 -0
- /package/skills/{building-cpp/references → engineering/references/cmake/standard}/standards/c++20/cmake-snippet.cmake +0 -0
- /package/skills/{building-cpp/references → engineering/references/cmake/standard}/standards/c++23/README.md +0 -0
- /package/skills/{building-cpp/references → engineering/references/cmake/standard}/standards/c++23/cmake-snippet.cmake +0 -0
- /package/skills/{building-cpp → engineering/references/formatting}/scripts/checking-encoding.mjs +0 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# 推荐扩展
|
|
2
|
+
|
|
3
|
+
只在工程已经有 `.vscode/` 时读本页;从当前目录向上到 git 根都没有 `.vscode/` 时,不打开本页,也不新建目录。新工程从 `../../assets/config/.vscode/extensions.json` 复制时除外。
|
|
4
|
+
|
|
5
|
+
## 三个角色
|
|
6
|
+
|
|
7
|
+
| 扩展 | 负责 | 不负责 |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| `llvm-vs-code-extensions.vscode-clangd` | 补全、跳转、诊断、格式化 | 配置与构建 |
|
|
10
|
+
| `ms-vscode.cmake-tools` | 配置、构建、运行、调试入口 | 语言服务 |
|
|
11
|
+
| `ms-vscode.cpptools` | 只作为 `CMake: Debug` 的调试后端 | IntelliSense 与格式化(关闭) |
|
|
12
|
+
|
|
13
|
+
不要同时开两套语言服务;C/C++ 扩展的 IntelliSense 必须关闭,否则会和 clangd 抢编译数据库。
|
|
14
|
+
|
|
15
|
+
## 对照现有文件
|
|
16
|
+
|
|
17
|
+
1. 读工程根 `.vscode/extensions.json`;已有推荐只补缺,不重排、不删除。
|
|
18
|
+
2. 旧工程只写了 C/C++ 扩展时,加 clangd 与 CMake Tools,并在设置里关掉 IntelliSense,理由写在提交说明里。
|
|
19
|
+
3. 不写 `tasks.json` 或 `launch.json`;配置、构建、运行和调试都从 CMake Tools 进入,构建命令仍以 `running-build.sh` 为准。
|
|
20
|
+
4. 模板在 `../../assets/config/.vscode/extensions.json`,只作为新工程的起点;工程已有文件时不复制整份覆盖。
|
|
21
|
+
|
|
22
|
+
下一步:扩展对齐后,读 [02-settings.md](02-settings.md) 接线设置。
|
|
23
|
+
|
|
24
|
+
## 依据
|
|
25
|
+
|
|
26
|
+
- [clangd: Editor Plugins](https://clangd.llvm.org/installation#editor-plugins):VS Code 的 clangd 扩展与语言服务。
|
|
27
|
+
- [CMake Tools for VS Code](https://github.com/microsoft/vscode-cmake-tools/blob/main/docs/README.md):配置、构建、调试入口。
|
|
28
|
+
- [VS Code: Extension Recommendations](https://code.visualstudio.com/docs/editor/extension-marketplace#_workspace-recommended-extensions):`extensions.json` 的 `recommendations`。
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# 设置接线
|
|
2
|
+
|
|
3
|
+
## 什么时候打开
|
|
4
|
+
|
|
5
|
+
工程已经有 `.vscode/` 时,格式、静态检查与 clangd 的选择落定后再读本页;没有 `.vscode/` 时不打开,也不新建。模板在 `../../assets/config/.vscode/settings.json`。
|
|
6
|
+
|
|
7
|
+
## 复制后改三处
|
|
8
|
+
|
|
9
|
+
| 键 | clang 模式 | gcc 模式 |
|
|
10
|
+
| --- | --- | --- |
|
|
11
|
+
| `cmake.buildDirectory` | `${workspaceFolder}/build/clang` | `${workspaceFolder}/build/gcc` |
|
|
12
|
+
| `clangd.arguments` 的 `--query-driver` | `/usr/bin/clang++` | `/usr/bin/g++` |
|
|
13
|
+
| `cmake.debugConfig` | `MIMode: lldb`、`miDebuggerPath: /usr/bin/lldb` | `MIMode: gdb`、`miDebuggerPath: /usr/bin/gdb` |
|
|
14
|
+
|
|
15
|
+
只改与 `environment.json` 冲突的键;其余保持工程原值。`.clangd` 的 `CompilationDatabase` 也随编译器改,见 `../../../engineering/references/formatting/04-clangd.md`。
|
|
16
|
+
|
|
17
|
+
## 各键分工
|
|
18
|
+
|
|
19
|
+
- `cmake.buildDirectory`:与定构建的 `build/<compiler>` 一致;不要在 CMake Tools 里再选第二个构建目录。
|
|
20
|
+
- `cmake.generator: Ninja`、`cmake.configureOnOpen: false`、`cmake.buildBeforeRun: true`、`cmake.exportCompileCommandsFile: true`:构建仍由入口脚本和 CMake 决定,编辑器只消费同一份数据库。
|
|
21
|
+
- `clangd.arguments`:`--query-driver` 写绝对路径且只列一个驱动,不用 `*`;`--header-insertion=never` 与 `--background-index` 沿用模板。
|
|
22
|
+
- `cmake.debugConfig`:只改调试后端;`type` 仍是 `cppdbg`。
|
|
23
|
+
- `C_Cpp.intelliSenseEngine: "disabled"`:把语言服务让给 clangd;不要把 C/C++ 扩展再配一套 include 路径。
|
|
24
|
+
- `editor.formatOnSave` 与 `[cpp]` / `[c]` 的默认格式化器:都指向 clangd;是否开启保存即格式化由工程决定,不在构建脚本里跑 `clang-format -i`。
|
|
25
|
+
|
|
26
|
+
## 不写什么
|
|
27
|
+
|
|
28
|
+
- 不写 `tasks.json`、`launch.json`,不另起构建或启动路径。
|
|
29
|
+
- 不把标准写死在设置里,也不靠 `.clangd` 的 `-std` 覆盖编译数据库。
|
|
30
|
+
- 不在设置里堆 `-I` / `-D` 或系统头路径;这些从 `compile_commands.json` 来。
|
|
31
|
+
- 注释用 JSONC 的 `//`,只写为什么这样设。
|
|
32
|
+
|
|
33
|
+
下一步:设置与扩展对齐后,回到 [定工具配置](../../steps/02-tooling.md) 收尾,再进 [通过检查](../../steps/03-check.md)。
|
|
34
|
+
|
|
35
|
+
## 依据
|
|
36
|
+
|
|
37
|
+
- [clangd: Configuration](https://clangd.llvm.org/config):`.clangd` 与 `clangd.arguments`。
|
|
38
|
+
- [CMake Tools: Settings](https://github.com/microsoft/vscode-cmake-tools/blob/main/docs/cmake-settings.md):`cmake.buildDirectory`、`cmake.generator`、`cmake.exportCompileCommandsFile`。
|
|
39
|
+
- [VS Code: Debugging](https://code.visualstudio.com/docs/debugtest/debugging):`cppdbg` 调试配置与 `miDebuggerPath`。
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
clang-format --dry-run --Werror src/*.cpp include/*.h
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
需要修复时单独运行 `clang-format -i`,再回看 diff。`clang-format` 只排版,不会把行尾注释搬到上一行;数据成员注释位置按 `developing-cpp/references/comments.md` 的规则和 `checking-comments.mjs` 检查。
|
|
15
|
+
需要修复时单独运行 `clang-format -i`,再回看 diff。`clang-format` 只排版,不会把行尾注释搬到上一行;数据成员注释位置按 `developing-cpp/references/comments/comment-rules.md` 的规则和 `checking-comments.mjs` 检查。
|
|
16
16
|
|
|
17
17
|
## 用法
|
|
18
18
|
|
|
@@ -34,7 +34,7 @@ clang-format --dry-run --Werror src/*.cpp include/*.h
|
|
|
34
34
|
4. **configure**:每次运行都重新 configure,不复用缓存;传 `-G Ninja`、`-DCMAKE_BUILD_TYPE=Debug`、`-DCMAKE_C_COMPILER`、`-DCMAKE_CXX_COMPILER`、`-DCMAKE_EXPORT_COMPILE_COMMANDS=ON`。C 与 C++ 使用同一套编译器;没有 C 语言的工程会忽略 C 编译器设置。
|
|
35
35
|
5. **build**:`cmake --build "$BUILD_DIR"`。
|
|
36
36
|
6. **编译数据库链接**:先 `rm -f build/compile_commands.json`,再 `ln -s "${COMPILER}/compile_commands.json" build/compile_commands.json`;不用 `ln -n`,它在 BSD/macOS 上不可移植。
|
|
37
|
-
7. **test
|
|
37
|
+
7. **test**:有 `tests/` 目录时 `ctest --test-dir "$BUILD_DIR" --output-on-failure --no-tests=error`,防止测试 discovery 失败后 0 条也算通过;没有测试目录时 `ctest --test-dir "$BUILD_DIR" --output-on-failure`,0 条不算失败。
|
|
38
38
|
8. **run**:`(cd "$BUILD_DIR/bin" && "./$APP_NAME")`;共享库的运行时路径由定构建的 CMake RPATH 负责,不在脚本里设全局 `LD_LIBRARY_PATH`。
|
|
39
39
|
|
|
40
40
|
最后一行是 `main "$@"`;函数定义在 `main()` 之前,`set` / `readonly` 在最前。
|
|
@@ -58,18 +58,18 @@ clang-format --dry-run --Werror src/*.cpp include/*.h
|
|
|
58
58
|
- `Check`:两种模式都在条件不成立时打印诊断并终止。
|
|
59
59
|
- `DebugCheck`:只在 Debug 生效,`NDEBUG` 后展开为空,参数不能带副作用。
|
|
60
60
|
|
|
61
|
-
不要写成 Debug 抛异常、Release 返回 false 的模式分支;这会把调用方逼成两套逻辑。规则详见 `developing-cpp/references/exceptions.md`。
|
|
61
|
+
不要写成 Debug 抛异常、Release 返回 false 的模式分支;这会把调用方逼成两套逻辑。规则详见 `developing-cpp/references/exceptions/throw-rules.md`。
|
|
62
62
|
|
|
63
63
|
## 失败分诊
|
|
64
64
|
|
|
65
65
|
| 输出 | 先看 | 回到 |
|
|
66
66
|
| --- | --- | --- |
|
|
67
67
|
| `CMake Error ... CXX compiler` | `environment.json`、`--live` | `building-cpp` 的定构建 / 通过检查 |
|
|
68
|
-
| `ninja: error: ... missing and no known rule` | 源文件是否在 CMake 中列出 | `
|
|
69
|
-
| `fatal error: ... No such file` | `target_include_directories` | `
|
|
70
|
-
| `undefined reference` | `target_link_libraries`、库 target 名 | `
|
|
68
|
+
| `ninja: error: ... missing and no known rule` | 源文件是否在 CMake 中列出 | `engineering` 的 target 源文件清单 |
|
|
69
|
+
| `fatal error: ... No such file` | `target_include_directories` | `engineering` 的包含边界 |
|
|
70
|
+
| `undefined reference` | `target_link_libraries`、库 target 名 | `engineering` 的链接边界 |
|
|
71
71
|
| `CTest` 失败 | 测试断言、行为句 | `developing-cpp` 的定行为 / 定实现 |
|
|
72
|
-
| 运行时报找不到 `.so` | RPATH / `LD_LIBRARY_PATH` | `
|
|
72
|
+
| 运行时报找不到 `.so` | RPATH / `LD_LIBRARY_PATH` | `engineering` 的链接边界与 RPATH |
|
|
73
73
|
|
|
74
74
|
## 验收
|
|
75
75
|
|
|
@@ -79,3 +79,10 @@ clang-format --dry-run --Werror src/*.cpp include/*.h
|
|
|
79
79
|
- 切换编译器后 `build/compile_commands.json` 指向新数据库。
|
|
80
80
|
- 调用者的 `LD_LIBRARY_PATH` 在脚本结束后不变。
|
|
81
81
|
- Windows 原生:声明校验已拒绝该组合;不要伪造 PowerShell 脚本,也不要绕过声明。
|
|
82
|
+
|
|
83
|
+
## 依据
|
|
84
|
+
|
|
85
|
+
- [CMake: `cmake(1)`](https://cmake.org/cmake/help/latest/manual/cmake.1.html):`-S`、`-B`、`--build` 与 `-G Ninja`。
|
|
86
|
+
- [CMake: `ctest(1)`](https://cmake.org/cmake/help/latest/manual/ctest.1.html):`--test-dir`、`--output-on-failure`、`--no-tests=error`。
|
|
87
|
+
- [Ninja Manual](https://ninja-build.org/manual.html):构建目录与增量构建。
|
|
88
|
+
- [GNU Bash Reference: `set -euo pipefail`](https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html):脚本的失败即停与未定义变量检查。
|
|
@@ -105,4 +105,11 @@ node "<skill-dir>/scripts/checking-environment.mjs" --project . --live
|
|
|
105
105
|
| 3 | 活动校验失败:不在声明的 build host、角色缺失、版本不符 |
|
|
106
106
|
| 1 | 脚本自身错误:参数错误或内部异常 |
|
|
107
107
|
|
|
108
|
-
各标准对应的编译器、库设施和工具档位见 [standards/README.md](standards/README.md)。
|
|
108
|
+
各标准对应的编译器、库设施和工具档位见 [../../engineering/references/cmake/standard/standards/README.md](../../engineering/references/cmake/standard/standards/README.md)。
|
|
109
|
+
|
|
110
|
+
## 依据
|
|
111
|
+
|
|
112
|
+
- [CMake: Compilers](https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER.html):编译器探测与 `CMAKE_<LANG>_COMPILER`。
|
|
113
|
+
- [CMake: `CMakePresets.json`](https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html):preset 的继承、生成器与构建目录。
|
|
114
|
+
- [GCC: `--version`](https://gcc.gnu.org/onlinedocs/gcc/Invoking-GCC.html):版本输出与 `-dumpfullversion`。
|
|
115
|
+
- [Clang: Command Line](https://clang.llvm.org/docs/CommandGuide/clang.html):`--version` 与目标平台输出。
|
|
@@ -15,7 +15,7 @@ build/
|
|
|
15
15
|
|
|
16
16
|
## 前置
|
|
17
17
|
|
|
18
|
-
先读项目技能与 `environment.json`,再确认 `
|
|
18
|
+
先读项目技能与 `environment.json`,再确认 `engineering` 已经把 target 图、公共 include、语言标准和输出目录写进 CMake。target 缺失、标准不对、include 或链接边界没写时,停止本步,转 `engineering` 的定 target 与标准;不要在这里用全局变量或临时 `-std` 绕过。 只在需要核对时打开 `../../engineering/references/cmake/targets/rules.md` 或 `../../engineering/references/cmake/standard/cxx-standard.md` 被点名的一份;CMake 的写改仍由 `engineering` 落笔。
|
|
19
19
|
|
|
20
20
|
## 环境
|
|
21
21
|
|
|
@@ -26,16 +26,16 @@ build/
|
|
|
26
26
|
| `compiler` | `clang` / `gcc` | 用哪个编译器;一次只配一个 |
|
|
27
27
|
| `standard` | `c++11`–`c++23` | 一个工程一个语言标准;新工程默认 `c++23`,已有工程按原声明 |
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
三个环境轴为空、`standard` 取值不在 `c++11`–`c++23` 内或组合非法时,停在定构建,先让用户把 `environment.json` 填对。`standard` 缺失或为空时按默认 `c++23` 继续并提示声明升级,不按非法声明停下。不要替用户选 WSL、Clang 或构建目录。`windows` + `native` 只给一句「本版本不能在 Windows 原生壳里构建」。
|
|
30
30
|
|
|
31
31
|
## 规则
|
|
32
32
|
|
|
33
33
|
- 生成器固定单配置 Ninja,不用 Ninja Multi-Config:同一源文件会写多条命令,clangd 默认只取第一条,容易读错数据库;构建目录固定 `build/clang` 或 `build/gcc`。
|
|
34
34
|
- 一个 configure 只用一个编译器:`-DCMAKE_CXX_COMPILER=clang++` 或 `g++`;确有 C 源时 C 编译器与 C++ 编译器同属一套。
|
|
35
|
-
- `set(CMAKE_EXPORT_COMPILE_COMMANDS ON)` 由 `
|
|
36
|
-
- 输出目录由 `
|
|
35
|
+
- `set(CMAKE_EXPORT_COMPILE_COMMANDS ON)` 由 `engineering` 写在顶层;Ninja 下产出 `compile_commands.json`。
|
|
36
|
+
- 输出目录由 `engineering` 统一设到 `build/<compiler>/bin` 与 `build/<compiler>/lib`;本步只核对,不重复设。
|
|
37
37
|
- 配置后把 `build/<compiler>/compile_commands.json` 符号链接到 `build/compile_commands.json`,让 clangd 默认能找到当前数据库;换编译器时重建链接。
|
|
38
|
-
- 不写全局 `CMAKE_CXX_FLAGS`、`include_directories()` 或 `add_definitions()`;这些属于 target 契约,发现就转 `
|
|
38
|
+
- 不写全局 `CMAKE_CXX_FLAGS`、`include_directories()` 或 `add_definitions()`;这些属于 target 契约,发现就转 `engineering`。
|
|
39
39
|
- 配置阶段不隐式下载依赖;测试框架由项目显式选择固定版本、带哈希的 `FetchContent`,或使用项目自带模块。
|
|
40
40
|
|
|
41
41
|
## 命令
|
|
@@ -50,15 +50,15 @@ rm -f build/compile_commands.json
|
|
|
50
50
|
ln -s clang/compile_commands.json build/compile_commands.json
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
-
GCC 模式把目录和编译器换成 `build/gcc`、`g++`。每次构建都重新 configure
|
|
53
|
+
GCC 模式把目录和编译器换成 `build/gcc`、`g++`。每次构建都重新 configure;不要依赖上一次缓存。确有 C 源时,再补 `-DCMAKE_C_COMPILER=clang`(GCC 模式 `gcc`),不要只换 C++ 驱动。
|
|
54
54
|
|
|
55
55
|
## 情况
|
|
56
56
|
|
|
57
|
-
**新工程**:从 `../assets/templates/projects/`
|
|
57
|
+
**新工程**:从 `../assets/templates/projects/` 选形态;把 `../assets/templates/projects/common/running-build.sh` 复制到工程根,`chmod +x` 并用 `bash -n` 验证语法。模板缺 target 时先转 `engineering`,target 齐了再 configure。
|
|
58
58
|
|
|
59
59
|
**已有工程**:先读现有 `CMakeLists.txt`,只核对 target、标准与输出目录;不改与当前任务无关的 target,大改前先让现有构建跑通。
|
|
60
60
|
|
|
61
|
-
**测试**:`enable_testing()` 与 `add_subdirectory(tests)` 的顺序由 `
|
|
61
|
+
**测试**:`enable_testing()` 与 `add_subdirectory(tests)` 的顺序由 `engineering` 定;本步只跑 CTest,不在没有测试时加空测试。
|
|
62
62
|
|
|
63
63
|
**CMakePresets**:如果项目使用 preset,名称固定 `clang` / `gcc`,与构建目录一致;没有 preset 时直接用上面的命令。
|
|
64
64
|
|
|
@@ -9,23 +9,30 @@
|
|
|
9
9
|
- 工程拥有配置:`.clang-format`、`.clang-tidy`、`.clangd`、`.vscode/` 放在工程根;不要依赖用户主目录或插件目录里的同名文件。
|
|
10
10
|
- 只复制缺失的文件。已有配置先读再改,不覆盖;需要合并时逐项说明理由。
|
|
11
11
|
- 工具角色固定:`clang-format` 管排版,`clang-tidy` 管静态诊断,`clangd` 管补全/跳转/诊断;无论 `compiler` 是 clang 还是 gcc,这三件都用 Clang 工具链。
|
|
12
|
-
- 版本要求见
|
|
12
|
+
- 版本要求见 `../references/environment.md`:Clang 模式要求 `clang++`、`clang-format`、`clang-tidy`、`clangd` 同一 LLVM 主版本;GCC 模式要求 `clang-format` / `clang-tidy` ≥ 16,`clangd` 只要求可用。
|
|
13
13
|
- `.clangd` 的 `CompilationDatabase` 指向 `build/<compiler>`;切换编译器时同步改,不能留旧目录。**不要写 `-std`**:它会覆盖 `compile_commands.json`,把 C++23 工程降成旧标准;标准只由构建声明和编译数据库决定。
|
|
14
14
|
- `--query-driver` 是 clangd 的命令行参数,写在 `.vscode/settings.json` 的 `clangd.arguments` 里,不是 `.clangd` 的 YAML 键。它告诉 clangd 允许执行哪个编译器驱动来取系统头路径;路径写绝对路径,并与 `environment.json` 的编译器一致。
|
|
15
15
|
- 首次复制时按轴替换三处:`compiler=clang` 用 `CompilationDatabase: build/clang`、`--query-driver=/usr/bin/clang++` 和 `cmake.debugConfig` 的 `MIMode: lldb` / `miDebuggerPath: /usr/bin/lldb`;`compiler=gcc` 用 `build/gcc`、`/usr/bin/g++` 和 `MIMode: gdb` / `/usr/bin/gdb`。只复制模板而不改这三处,GCC 模式会指向错误的数据库、驱动或调试器。原工程已有的 `.clangd` 不覆盖;要改先征得同意。
|
|
16
|
-
- `.clang-format` 保留 `Language: Cpp`、`BasedOnStyle: Google` 和 `
|
|
16
|
+
- `.clang-format` 保留 `Language: Cpp`、`BasedOnStyle: Google`、`Standard` 和 `LineEnding: LF`:模板资产写 `Latest`;工程按 `environment.json` 声明 C++11–C++20 时,把 `Standard` 改成 `c++NN`(映射见 `../../engineering/references/cmake/standard/standards/README.md`)。clang-format 21/22 的 `Standard` 不接受 `c++23`,所以 C++23 工程仍写 `Latest`。列宽、缩进与包含顺序以工程根 `.clang-format` 为准;工程显式写 `ColumnLimit` 时按工程值执行,模板资产不写 `ColumnLimit`。需要新规则时先改 `../../developing-cpp/references/style/google-cpp-style.md` 并说明理由。
|
|
17
17
|
- `.clang-tidy` 用 `Checks: '-*, google-*, portability-avoid-pragma-once, readability-identifier-naming'`,保留 `WarningsAsErrors: '*'` 和 `FormatStyle: file`。`google-*` 覆盖 Google 风格能静态检查的部分;`readability-identifier-naming` 只配项目确实统一的命名项:类型/枚举/别名/模板参数 PascalCase,变量/参数/成员 snake_case,类成员尾随 `_`,结构体成员不尾随,常量 `k` + PascalCase。不要设 `FunctionCase`,Google 允许 `count()` / `set_count()` 这类访问器;`portability-avoid-pragma-once` 要打开,因为工程统一用路径式守卫;不要重新打开 `cppcoreguidelines-*` 整包。
|
|
18
18
|
- `.clang-tidy` 关闭项和例外必须写理由;不要借 `-*` 之后再打开 `cppcoreguidelines-*` 这类非 Google 整族检查。
|
|
19
19
|
- `.vscode/extensions.json` 推荐 clangd、CMake Tools 与 C/C++ 扩展;`.vscode/settings.json` 固定 clangd 参数、CMake 构建目录和 `cmake.debugConfig`。配置、构建、运行和调试只从 CMake Tools 进入,不写 `tasks.json` 或 `launch.json`;C/C++ 扩展只作为 CMake 快速调试的后端,IntelliSense 关闭,避免和 clangd 并行。配置注释用 JSONC 的 `//`,贴在被解释的键上方。
|
|
20
20
|
- 配置注释写「为什么这样设」,不写「这一项是什么」;不写策略头、不指向文档路径。
|
|
21
21
|
- 格式化与静态检查只扫描项目源码:`src/`、`include/`、`apps/`、`tests/` 等实际存在的源码根;不扫描 `build/`、第三方目录、生成文件。
|
|
22
22
|
- `clang-tidy` 用 `-p build/<compiler>` 读取编译数据库,`--header-filter` 只列项目根下的顶层目录,避免把第三方头纳入;不要加 `--system-headers`,也不要用 clang-tidy 19 才加入、16 没有的 `--exclude-header-filter`。
|
|
23
|
-
- 格式化用 `--dry-run --Werror` 做检查;需要自动修复时单独运行 `-i`,不要让构建脚本悄悄改源码。`clang-format` 只排版,不会把行尾注释搬到上一行;数据成员注释位置按
|
|
23
|
+
- 格式化用 `--dry-run --Werror` 做检查;需要自动修复时单独运行 `-i`,不要让构建脚本悄悄改源码。`clang-format` 只排版,不会把行尾注释搬到上一行;数据成员注释位置按 `../../developing-cpp/references/comments/comment-rules.md` 检查。
|
|
24
24
|
- 工程模板里不预置 `compile_commands.json`;它由定构建的 configure 生成,是构建产物。
|
|
25
25
|
|
|
26
|
+
## 编辑器接线
|
|
27
|
+
|
|
28
|
+
- 只在工程根(当前目录到 git 根)已经有 `.vscode/` 时读 `../project/vscode/01-extensions.md` 或 `../project/vscode/02-settings.md`;没有 `.vscode/` 时不打开,也不新建目录。
|
|
29
|
+
- 顺序:先定 `.clang-format`、`.clang-tidy`、`.clangd`,再对照现有 `.vscode/extensions.json` 与 `settings.json` 只补缺、只改与 `environment.json` 冲突的项。
|
|
30
|
+
- 一次只读 `../project/vscode/` 里被点名的一页;扩展与设置不要同时展开。工具条文一次只开 `../../engineering/references/formatting/` 里被点名的一份,其余留到下一次激活。
|
|
31
|
+
- 不写 `tasks.json` 或 `launch.json`,构建与运行仍走 `running-build.sh`。
|
|
32
|
+
|
|
26
33
|
## 情况
|
|
27
34
|
|
|
28
|
-
**新工程**:从
|
|
35
|
+
**新工程**:从 `../assets/config/` 复制 `.clang-format`、`.clang-tidy`、`.clangd` 和 `.vscode/` 下的 `extensions.json`、`settings.json`,按编译器的映射改 `.clangd` 的编译数据库目录、`.vscode/settings.json` 的 `--query-driver` 路径和 `cmake.debugConfig` 的调试后端。新工程模板自带 `.vscode/` 时按 `../project/vscode/` 两页接线;已有工程没有 `.vscode/` 时不新建。不要复制 `build/`。
|
|
29
36
|
|
|
30
37
|
**已有工程**:新工程默认 C++23;已有工程按 `environment.json` 的 `standard` 对齐 CMake target 与 `.clang-format`,不要只改一处。先跑一次 `clang-format --dry-run --Werror` 和 `clang-tidy`,看现有配置实际报什么;只改导致当前失败或与声明环境冲突的项。不要借机重排全工程格式。
|
|
31
38
|
|
|
@@ -33,11 +40,12 @@
|
|
|
33
40
|
|
|
34
41
|
**GCC 模式**:`clangd` 仍可工作,但系统头来自 GCC;`--query-driver` 指向 `g++`。`clang-format` / `clang-tidy` 仍是 Clang 工具,版本要求不因编译器是 GCC 而降低。
|
|
35
42
|
|
|
36
|
-
**共享库**:静态检查不因链接方式改变;运行时库路径由 `
|
|
43
|
+
**共享库**:静态检查不因链接方式改变;运行时库路径由 `engineering` 的 target 设置负责,见 `../../engineering/references/cmake/targets/rules.md` 的「共享库运行时路径」,不写进 clang 配置。
|
|
37
44
|
|
|
38
45
|
## 正反例指针
|
|
39
46
|
|
|
40
|
-
- `.clangd` 指错编译数据库、`query-driver` 写进 YAML
|
|
41
|
-
-
|
|
42
|
-
-
|
|
43
|
-
- 每个标准对应的 clang-format 档位与 `.clangd`
|
|
47
|
+
- `.clangd` 指错编译数据库、`query-driver` 写进 YAML:`../../engineering/references/formatting/examples/clangd.md`。
|
|
48
|
+
- 配置文件堆策略头、关闭检查不写理由:`../../engineering/references/formatting/examples/clang-tidy.md`「配置注释」。
|
|
49
|
+
- 工具调用与头文件过滤:`../../engineering/references/formatting/03-clang-tidy.md`。
|
|
50
|
+
- 每个标准对应的 clang-format 档位与 `.clangd` 读库规则:`../../engineering/references/cmake/standard/standards/README.md`。
|
|
51
|
+
- 编辑器扩展与设置:`../project/vscode/01-extensions.md`、`../project/vscode/02-settings.md`。
|
|
@@ -8,34 +8,34 @@
|
|
|
8
8
|
|
|
9
9
|
按固定顺序跑,前一步失败就停,不要带着失败继续:
|
|
10
10
|
|
|
11
|
-
1. **校验编码与行尾**:在仓库根跑编码检查。默认 UTF-8 无 BOM、LF;MSVC 原生工程加 `--profile msvc`。有问题先按
|
|
12
|
-
2. **校验环境声明(不带 `--live`)**:读 `environment.json`,检查三个环境轴、`standard`
|
|
11
|
+
1. **校验编码与行尾**:在仓库根跑编码检查。默认 UTF-8 无 BOM、LF;MSVC 原生工程加 `--profile msvc`。有问题先按 `../../engineering/references/formatting/01-encoding.md` 修正,不带着 BOM 或混用行尾继续;脚本退出码为 0 后再跑 `git diff --check`,有空白错误同样停在这里。
|
|
12
|
+
2. **校验环境声明(不带 `--live`)**:读 `environment.json`,检查三个环境轴、`standard` 和组合是否合法。三个环境轴为空、`standard` 取值不在 `c++11`–`c++23` 内或组合非法时,停在这里,不找可执行文件;`standard` 缺失或为空时按默认 `c++23` 继续并提示声明升级。
|
|
13
13
|
3. **活动校验**:在声明的 build host 上跑 `--live`,核对 PATH 中的角色和版本。`windows` + `native` 在声明校验阶段就返回失败,不会进入这一步。
|
|
14
|
-
4. **跑项目入口命令**:项目技能里写的入口命令(如 `./running-build.sh clang`)。入口命令仍是 `<entry-command>` 或空白时,停在这里,不要猜命令;是真实命令才跑。入口内部依次 configure → build → ctest → run
|
|
15
|
-
5. **核对产物**:`build/<compiler>/compile_commands.json` 存在;`build/compile_commands.json` 指向当前编译器;`app` 可执行文件在 `build/<compiler>/bin`。
|
|
14
|
+
4. **跑项目入口命令**:项目技能里写的入口命令(如 `./running-build.sh clang`)。入口命令仍是 `<entry-command>` 或空白时,停在这里,不要猜命令;是真实命令才跑。入口内部依次 configure → build → ctest → run;每一步失败都保留原始输出。有 `tests/` 目录时,脚本里的 ctest 必须带 `--output-on-failure --no-tests=error`;缺参数时按 `ctest --test-dir build/<compiler> --output-on-failure --no-tests=error` 补跑,并以补跑的退出码为准;没有测试目录时按「没有测试」情形处理,不补 `--no-tests=error`。入口通过后,再对项目源码跑 `clang-format --dry-run --Werror` 与 `clang-tidy -p build/<compiler> --header-filter="^$(pwd -P)/(include|src|apps|tests)/" --warnings-as-errors='*'`;任一非零即失败,命令细节见 `../../engineering/references/formatting/02-clang-format.md` 与 `03-clang-tidy.md`。
|
|
15
|
+
5. **核对产物**:`build/<compiler>/compile_commands.json` 存在;`build/compile_commands.json` 指向当前编译器;`app` 可执行文件在 `build/<compiler>/bin`。对 `app` 跑 `file` 与 `ldd`(macOS 用 `otool -L`),`ldd` 不得出现 `not found`,并做一次最小启动;见 `../../engineering/references/cmake/linking/04-inspect.md`。
|
|
16
16
|
6. **记录结果**:通过时记录编译器版本、构建目录、测试数量;失败时记录命令、退出码、第一条根因诊断。
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
编码检查与环境校验脚本(`<skill-dir>` 换成插件里 `building-cpp` 的实际目录):
|
|
19
19
|
|
|
20
20
|
```bash
|
|
21
|
-
node "<skill-dir
|
|
21
|
+
node "<skill-dir>/../engineering/references/formatting/scripts/checking-encoding.mjs" --profile portable # UTF-8 无 BOM、LF
|
|
22
22
|
node "<skill-dir>/scripts/checking-environment.mjs" --project . # 声明校验
|
|
23
23
|
node "<skill-dir>/scripts/checking-environment.mjs" --project . --live # 活动校验
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
脚本只读,不安装、不下载、不改 PATH;不要复制到项目里再改。
|
|
27
27
|
|
|
28
28
|
## 失败分诊
|
|
29
29
|
|
|
30
30
|
| 现象 | 先看 | 回到 |
|
|
31
31
|
| --- | --- | --- |
|
|
32
32
|
| 轴为空、组合非法、版本不匹配 | `environment.json`、`--live` 输出 | 定构建,先修声明 |
|
|
33
|
-
| 找不到头文件、链接失败、target 不存在 | `CMakeLists.txt`、`target_include_directories`、`target_link_libraries` | `
|
|
34
|
-
| 没有 `compile_commands.json` | 顶层 `CMAKE_EXPORT_COMPILE_COMMANDS` 是否由 target 图声明 | `
|
|
33
|
+
| 找不到头文件、链接失败、target 不存在 | `CMakeLists.txt`、`target_include_directories`、`target_link_libraries` | `engineering` 的定 target;修完回定构建 |
|
|
34
|
+
| 没有 `compile_commands.json` | 顶层 `CMAKE_EXPORT_COMPILE_COMMANDS` 是否由 target 图声明 | `engineering` 的定 target;生成器与目录回定构建 |
|
|
35
35
|
| clangd 跳转失败、数据库指向旧编译器 | `.clangd` 的 `CompilationDatabase`、`build/compile_commands.json` 链接 | 定工具配置 |
|
|
36
36
|
| 编译错误指向函数体 | 实现 | `developing-cpp` 的定实现;先修语义,再重跑 |
|
|
37
37
|
| CTest 失败 | 测试断言、行为句 | `developing-cpp` 的定行为 / 定实现 |
|
|
38
|
-
| `app` 启动失败、找不到共享库 | 输出目录、RPATH / 运行时库路径 | `
|
|
38
|
+
| `app` 启动失败、找不到共享库 | 输出目录、RPATH / 运行时库路径 | `engineering` 的定 target(输出目录与 RPATH) |
|
|
39
39
|
|
|
40
40
|
分诊只定位,不自动改。一次只改一类问题;改完从失败的那一步重跑,只有行为或边界也变了才回到定行为。
|
|
41
41
|
|
|
@@ -45,9 +45,11 @@ node "<skill-dir>/scripts/checking-environment.mjs" --project . --live # 活
|
|
|
45
45
|
|
|
46
46
|
**只改源码**:仍跑完整入口命令;CTest 可能暴露声明层问题,不要只看编译通过。
|
|
47
47
|
|
|
48
|
+
**改过 C++ 源码**:再按 `../../engineering/references/cmake/testing/ctest.md` 的运行顺序第 4 条,用 `-fsanitize=address,undefined -fno-omit-frame-pointer` 重新 configure 并跑一轮 CTest;报告按第一条栈帧定位,不靠猜。
|
|
49
|
+
|
|
48
50
|
**只改配置**:至少跑一次完整构建 + CTest;配置错误常常在链接或测试阶段才暴露。
|
|
49
51
|
|
|
50
|
-
**没有测试**:项目确实还没有测试时,CTest 显示 0 条不算构建失败;不要为了「全绿」造空测试。已有公开行为却没有任何用例时,按
|
|
52
|
+
**没有测试**:项目确实还没有测试时,CTest 显示 0 条不算构建失败;不要为了「全绿」造空测试。已有公开行为却没有任何用例时,按 `../../engineering/references/cmake/testing/ctest.md` 的「先决定测什么」补成功与拒绝各一条,再跑 `--no-tests=error` 确认它真的被注册。
|
|
51
53
|
|
|
52
54
|
**Windows 原生**:本版本不支持 `host=windows` + `build_host=native`。声明校验会返回 `ok: false`,`issues` 只有一句「本版本不能在 Windows 原生壳里构建」。停在这里,不要伪造 PowerShell 脚本,不要建议改 WSL 来绕过,也不要让代理改 `environment.json` 过关。
|
|
53
55
|
|
|
@@ -55,6 +57,6 @@ node "<skill-dir>/scripts/checking-environment.mjs" --project . --live # 活
|
|
|
55
57
|
|
|
56
58
|
## 正反例指针
|
|
57
59
|
|
|
58
|
-
- 环境组合与 `--live`
|
|
59
|
-
-
|
|
60
|
-
-
|
|
60
|
+
- 环境组合与 `--live` 输出:`../examples/environment.md`。
|
|
61
|
+
- 失败分诊的具体命令:`../references/build-script.md`「失败分诊」。
|
|
62
|
+
- 工具调用细节:`../../engineering/references/formatting/03-clang-tidy.md`。
|
|
@@ -7,25 +7,19 @@ metadata:
|
|
|
7
7
|
|
|
8
8
|
# developing-cpp
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
下面这些文件不归本技能:
|
|
13
|
-
|
|
14
|
-
- `CMakeLists.txt` 与 `cmake/`:开 `configuring-cmake`。
|
|
15
|
-
- `running-build.sh`、`.clang-*`、`.vscode/` 和 `environment.json`:开 `building-cpp`,本技能只读其中的 `standard`。
|
|
16
|
-
- `.qmd`、仓库 README、Python 和非 C++ 文档:不打开本技能。
|
|
17
|
-
|
|
18
|
-
只改函数体、命名、异常或注释且入口命令可运行时,定实现后只开 `building-cpp` 的「通过检查」;新增或移动源文件、改库与程序的边界、补测试 target 时,声明和实现可以先写,但完成前必须开 `configuring-cmake` 把文件写进 CMake,再开 `building-cpp` 定工具配置并通过检查。
|
|
10
|
+
本技能处理换一台机器也不会改的源码内容:可观察行为、库与程序的边界、声明、命名、异常与源码注释。文件槽位以 `references/layout/02-file-template.md` 为准,排版以 `references/style/google-cpp-style.md` 的 Google 基线为准,命名以 `references/naming/identifier-names.md` 为准。
|
|
19
11
|
|
|
20
12
|
## 适用场景
|
|
21
13
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
14
|
+
- **负责**:类型、函数与文件的行为和契约;声明与实现;命名;异常;源码注释。
|
|
15
|
+
- **不负责**:`CMakeLists.txt` 与 `cmake/` 开 `engineering`;`running-build.sh`、`.clang-*`、`.vscode/`、`environment.json` 开 `building-cpp`,本技能只读其中的 `standard`;`.qmd`、仓库 README、Python 与其他文档不打开本技能。
|
|
16
|
+
- **交接**:一次改动跨域时按「源码 → engineering → building-cpp」逐段进入,前一段结论落下再开下一段。只改函数体、命名、异常或注释且入口命令可运行时,第 4 步后只开 `building-cpp` 的通过检查;新增或移动源文件、改库与程序的边界、补测试 target 时,完成前必须开 `engineering` 把文件写进 CMake。
|
|
17
|
+
- **前置**:存在项目技能 `cpp-workflow-project` 时先读它的 `SKILL.md`:工程名、库与程序的边界、阶段表、术语增补、入口命令与语言档位。项目技能没写档位才读 `environment.json` 的 `standard`,两者都没有时才用新工程默认 C++23;声明 C++20 的工程里不写 C++23 才有的设施。没有项目技能时门禁不会放出本技能,不猜项目约定。
|
|
18
|
+
- **编码**:源码与构建文件的编码以 `engineering` 的 `references/formatting/01-encoding.md` 为准;行尾与 `.clang-format` 的 `LineEnding` 跟仓库根 `.gitattributes` 与 `.editorconfig`。
|
|
25
19
|
|
|
26
20
|
## 三种操作
|
|
27
21
|
|
|
28
|
-
|
|
22
|
+
一次只选一种,范围(单点、整段)是任务属性;判据、边界与交接见 `references/editing/01-edit-operations.md`。四类改动是域,不是操作。
|
|
29
23
|
|
|
30
24
|
| 操作 | 什么时候用 | 从哪步进 |
|
|
31
25
|
| --- | --- | --- |
|
|
@@ -33,7 +27,10 @@ metadata:
|
|
|
33
27
|
| 改写 | 行为与契约不变,文件位置、声明顺序或函数体组织不对 | 从被打破的步重走,可到第 4 步 |
|
|
34
28
|
| 润色 | 只改命名或注释措辞 | 第 3 步 |
|
|
35
29
|
|
|
36
|
-
|
|
30
|
+
- 不发明阶段表和用户请求里没有的行为、类型与命令;选类型与写法时以项目声明的语言标准为上限。
|
|
31
|
+
- 只改注释或格式时不改可观察行为;不覆盖已有源码;不安装工具链;代理侧不写 `wsl` 或 `bash -lc`。
|
|
32
|
+
- 计划、命名方案或注释措辞与条文、项目技能或用户明确要求冲突时,先列冲突位置、原文与出处,由用户选一条;不自行取舍,也不默认采用计划。
|
|
33
|
+
- 后一步发现前一步没做完,退回那一步,不在当前步补结构;拿不准先用单点修正,边界被打破则退回整段重构。
|
|
37
34
|
|
|
38
35
|
## 步骤
|
|
39
36
|
|
|
@@ -44,19 +41,35 @@ metadata:
|
|
|
44
41
|
| 3 | 定声明 | `steps/03-declaration.md` | 写命名、声明顺序、头文件契约和声明注释 |
|
|
45
42
|
| 4 | 定实现 | `steps/04-implementation.md` | 写 `.cpp` 函数体的操作顺序、分组和实现注释 |
|
|
46
43
|
|
|
47
|
-
|
|
44
|
+
每步只打开同号的一个步骤文件;判不准才打开与该步对应的案例,完整条文只在排错、整目录重构,或步骤里明确指向某一条时打开。
|
|
45
|
+
|
|
46
|
+
## 入口表
|
|
48
47
|
|
|
49
|
-
|
|
48
|
+
先按「改哪一类东西」选一行,再打开那一行点名的一份;同一步骤里的细节留到真正需要时再开。
|
|
50
49
|
|
|
51
|
-
|
|
50
|
+
| 改什么 | 从哪一份进 |
|
|
51
|
+
| --- | --- |
|
|
52
|
+
| 行为、库与程序的边界 | `steps/01-behavior.md`、`steps/02-boundary.md`;案例在 `references/design/examples/` |
|
|
53
|
+
| 文件槽位、包含守卫、声明顺序 | `references/layout/02-file-template.md`、`references/layout/03-declaration-order.md` |
|
|
54
|
+
| 命名与改名 | `references/naming/identifier-names.md`;案例在 `references/naming/examples/` |
|
|
55
|
+
| 声明注释与实现注释 | `references/comments/comment-rules.md`(写什么)与 `comment-style.md`(结构、版式、措辞);案例在 `references/comments/examples/` |
|
|
56
|
+
| 异常规则与异常案例 | `references/exceptions/throw-rules.md`;案例在 `references/exceptions/examples/` |
|
|
57
|
+
| 结果类型、语言细节、标准库、性能 | `references/language/` 下按四类选一份:`value-types/`(宽度、符号、整数角色、枚举、强类型、const 成员、`[[nodiscard]]`、比较、下标、float/bool)、`language-basics/`(对象、初始化、推导、const、表达式、函数、类、RAII、模板)、`standard-library/`(容器、访问、迭代、算法、string、format、time、random、files)、`performance/`(测量、复杂度、内存、未定义行为、陷阱、伪优化);每类末尾读完成清单(`standard-library/10-checklist.md`、`value-types/11-checklist.md`、`language-basics/10-checklist.md`、`performance/07-checklist.md`) |
|
|
58
|
+
| 操作判不准、规则冲突 | `references/editing/01-edit-operations.md`、`references/editing/02-rule-priority.md` |
|
|
59
|
+
|
|
60
|
+
案例目录里没有数字前缀的文件按语义选;数字前缀只表示同一主题内的阅读顺序,不是案例编号。
|
|
61
|
+
|
|
62
|
+
## 加载预算
|
|
63
|
+
|
|
64
|
+
- 只开当前步对应的一个步骤文件;同一改动域内不同时展开两个技能的步骤。
|
|
52
65
|
- 条文只开该步点名的一份;同号案例留到下一次激活。
|
|
53
66
|
- 标准档只打开项目技能声明的那一档,没有声明时用本技能已有的新工程默认,不把其余标准档读进来。
|
|
54
67
|
|
|
55
|
-
|
|
68
|
+
项目技能列出了检查命令时先跑它;无论有没有项目命令,都再跑本技能的 `scripts/checking-declaration-order.mjs`(定义顺序)与 `scripts/checking-comments.mjs`(注释);两者退出码为 0 后停在这一步,不再继续走没有失败的步骤。
|
|
56
69
|
|
|
57
|
-
|
|
70
|
+
## 四类改动
|
|
58
71
|
|
|
59
|
-
四类改动是操作内部的域:操作定入口,域定层次。四域的定义、边界与次序见 `references/
|
|
72
|
+
四类改动是操作内部的域:操作定入口,域定层次。四域的定义、边界与次序见 `references/editing/01-edit-operations.md`;一次改动混了两类时,按「内容 → 结构 → 版式 → 措辞」拆开做,前一类落定并经检查再进下一类。
|
|
60
73
|
|
|
61
74
|
| 类型 | 典型请求 | 入口步骤 |
|
|
62
75
|
| --- | --- | --- |
|
|
@@ -65,15 +78,14 @@ metadata:
|
|
|
65
78
|
| 版式 | 只改缩进、行宽、包含顺序或注释符号 | `steps/03-declaration.md` |
|
|
66
79
|
| 措辞 | 只改命名、只改注释措辞 | `steps/03-declaration.md` |
|
|
67
80
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
同一处命中多条规则时,先按 `references/priority.md` 的五级次序判:行为与契约 > 结构 > 清晰 > 一致 > 形式。高层未解决,不先做低层润色;低层改动碰到高层事实就停手退回。
|
|
81
|
+
只改格式时不动行为,只改注释时不动签名;条文由入口步骤按需打开。同一处命中多条规则时,按 `references/editing/02-rule-priority.md` 的五级次序判:行为与契约 > 结构 > 清晰 > 一致 > 形式;高层未解决,不先做低层润色。
|
|
71
82
|
|
|
72
83
|
## 完成判据
|
|
73
84
|
|
|
74
85
|
- [ ] 第 1 步的行为句能被用户或测试验收;有阶段表时只覆盖对应行,没有时只覆盖用户点名的行为。
|
|
75
86
|
- [ ] 第 2 步的库 target 不依赖终端、GUI 或脚本;程序 target 只做装配和输入输出;共享抽象有第二个真实使用方。
|
|
76
87
|
- [ ] 第 3 步的公共头文件自包含,命名、声明顺序和异常声明符合 `references/` 的条文。
|
|
77
|
-
- [ ] 第 4
|
|
78
|
-
- [ ]
|
|
88
|
+
- [ ] 第 4 步的实现只兑现声明;`.cpp` 定义顺序与头文件声明同序;同一文件里的函数按同一套分段约定,需要分阶段的都有阶段注释与空行;资源由 RAII 管理;失败是正常结果时用返回值,函数无法完成任务时抛异常,不拿异常做正常分支。
|
|
89
|
+
- [ ] `.cpp` 定义顺序检查通过:`node "<skill-dir>/scripts/checking-declaration-order.mjs" --root <项目根>` 退出码为 0;有乱序先修,不能跳过。
|
|
90
|
+
- [ ] 源码注释符合 `references/comments/comment-rules.md` 与 `comment-style.md` 的规范,`node "<skill-dir>/scripts/checking-comments.mjs" --root <项目根>` 退出码为 0,末行是「注释检查通过:N 个文件。」。
|
|
79
91
|
- [ ] 没有改 `CMakeLists.txt`、`.clang-*`、构建脚本,也没有把外部资料路径或项目专属类名写进通用条文。
|