@chengzhao-dev/dsh-cpp-workflow 0.7.6 → 0.7.8

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.
Files changed (98) hide show
  1. package/README.en.md +8 -8
  2. package/README.md +10 -10
  3. package/lib/client.js +7 -3
  4. package/lib/comment-policy.js +7 -3
  5. package/lib/index.js +2 -1
  6. package/lib/workspace.js +17 -3
  7. package/package.json +1 -1
  8. package/skills/building-cpp/SKILL.md +6 -6
  9. package/skills/building-cpp/assets/config/.clang-format +8 -8
  10. package/skills/building-cpp/assets/config/.clang-tidy +0 -4
  11. package/skills/building-cpp/assets/config/.vscode/settings.json +11 -0
  12. package/skills/building-cpp/assets/templates/projects/common/running-build.sh +50 -43
  13. package/skills/building-cpp/assets/templates/projects/multi/CMakeLists.txt +6 -10
  14. package/skills/building-cpp/assets/templates/projects/multi/include/greeting.h +1 -4
  15. package/skills/building-cpp/assets/templates/projects/multi/src/greeting.cpp +2 -2
  16. package/skills/building-cpp/assets/templates/projects/multi/src/main.cpp +2 -2
  17. package/skills/building-cpp/assets/templates/projects/shared-library/CMakeLists.txt +6 -10
  18. package/skills/building-cpp/assets/templates/projects/shared-library/greeting/CMakeLists.txt +3 -10
  19. package/skills/building-cpp/assets/templates/projects/shared-library/greeting/include/greeting.h +1 -4
  20. package/skills/building-cpp/assets/templates/projects/shared-library/greeting/src/greeting.cpp +2 -2
  21. package/skills/building-cpp/assets/templates/projects/shared-library/src/main.cpp +2 -2
  22. package/skills/building-cpp/assets/templates/projects/single/CMakeLists.txt +4 -8
  23. package/skills/building-cpp/assets/templates/projects/single/src/main.cpp +4 -4
  24. package/skills/building-cpp/assets/templates/projects/static-library/CMakeLists.txt +4 -8
  25. package/skills/building-cpp/assets/templates/projects/static-library/greeting/CMakeLists.txt +3 -10
  26. package/skills/building-cpp/assets/templates/projects/static-library/greeting/include/greeting.h +1 -4
  27. package/skills/building-cpp/assets/templates/projects/static-library/greeting/src/greeting.cpp +2 -2
  28. package/skills/building-cpp/assets/templates/projects/static-library/src/main.cpp +2 -2
  29. package/skills/building-cpp/references/01-build-script.md +8 -23
  30. package/skills/building-cpp/references/02-environment.md +9 -8
  31. package/skills/building-cpp/scripts/checking-environment.mjs +45 -13
  32. package/skills/building-cpp/steps/01-build.md +5 -4
  33. package/skills/building-cpp/steps/02-tooling.md +6 -6
  34. package/skills/building-cpp/steps/03-check.md +8 -6
  35. package/skills/building-cpp/steps/04-vscode.md +4 -4
  36. package/skills/developing-cpp/SKILL.md +4 -5
  37. package/skills/developing-cpp/references/comments/01-comment-rules.md +6 -6
  38. package/skills/developing-cpp/references/comments/02-style.md +20 -7
  39. package/skills/developing-cpp/references/comments/examples/01-declaration-class.md +2 -2
  40. package/skills/developing-cpp/references/comments/examples/04-declaration-file.md +5 -3
  41. package/skills/developing-cpp/references/comments/examples/05-declaration-function.md +1 -1
  42. package/skills/developing-cpp/references/comments/glossary/01-comment-terms.md +5 -5
  43. package/skills/developing-cpp/references/design/01-project-design.md +1 -1
  44. package/skills/developing-cpp/references/design/session-layer.md +10 -10
  45. package/skills/developing-cpp/references/exceptions/01-exception-rules.md +1 -1
  46. package/skills/developing-cpp/references/index.md +12 -11
  47. package/skills/developing-cpp/references/language/glossary/01-language-terms.md +2 -2
  48. package/skills/developing-cpp/references/language/language-basics/02-initialization.md +2 -2
  49. package/skills/developing-cpp/references/language/language-basics/05-expressions.md +2 -2
  50. package/skills/developing-cpp/references/language/language-basics/06-functions.md +4 -3
  51. package/skills/developing-cpp/references/language/language-basics/07-classes.md +1 -1
  52. package/skills/developing-cpp/references/language/performance/02-complexity.md +2 -3
  53. package/skills/developing-cpp/references/language/performance/03-memory.md +1 -1
  54. package/skills/developing-cpp/references/language/performance/05-pitfalls.md +1 -1
  55. package/skills/developing-cpp/references/language/standard-library/04-algorithms.md +1 -1
  56. package/skills/developing-cpp/references/language/standard-library/06-format.md +1 -31
  57. package/skills/developing-cpp/references/language/standard-library/11-format-ecosystem.md +32 -0
  58. package/skills/developing-cpp/references/language/value-types/02-signed.md +2 -2
  59. package/skills/developing-cpp/references/language/value-types/03-integer-roles.md +3 -2
  60. package/skills/developing-cpp/references/language/value-types/04-enum.md +4 -4
  61. package/skills/developing-cpp/references/layout/01-source-layout.md +1 -1
  62. package/skills/developing-cpp/references/layout/02-file-template.md +30 -43
  63. package/skills/developing-cpp/references/layout/03-declaration-order.md +8 -10
  64. package/skills/developing-cpp/references/naming/01-identifier-names.md +9 -3
  65. package/skills/developing-cpp/references/naming/glossary/04-square.md +1 -1
  66. package/skills/developing-cpp/references/style/01-google-cpp-style.md +10 -10
  67. package/skills/developing-cpp/scripts/checking-comments.mjs +33 -10
  68. package/skills/developing-cpp/scripts/checking-declaration-order.mjs +77 -10
  69. package/skills/developing-cpp/steps/03-declaration.md +5 -5
  70. package/skills/developing-cpp/steps/04-implementation.md +3 -3
  71. package/skills/engineering/SKILL.md +7 -6
  72. package/skills/engineering/references/cmake/assets/CompileSettings.cmake +100 -100
  73. package/skills/engineering/references/cmake/assets/LinkSettings.cmake +25 -25
  74. package/skills/engineering/references/cmake/assets/OutputSettings.cmake +38 -0
  75. package/skills/engineering/references/cmake/linking/01-libraries.md +1 -1
  76. package/skills/engineering/references/cmake/modules/01-functions.md +11 -10
  77. package/skills/engineering/references/cmake/standards/c++11/cmake-snippet.cmake +3 -3
  78. package/skills/engineering/references/cmake/standards/c++14/cmake-snippet.cmake +3 -3
  79. package/skills/engineering/references/cmake/standards/c++17/cmake-snippet.cmake +3 -3
  80. package/skills/engineering/references/cmake/standards/c++20/cmake-snippet.cmake +3 -3
  81. package/skills/engineering/references/cmake/standards/c++23/cmake-snippet.cmake +3 -3
  82. package/skills/engineering/references/cmake/standards/index.md +6 -6
  83. package/skills/engineering/references/cmake/standards/versions.md +1 -1
  84. package/skills/engineering/references/cmake/targets/01-target-rules.md +8 -18
  85. package/skills/engineering/references/formatting/01-encoding.md +6 -3
  86. package/skills/engineering/references/formatting/02-clang-format.md +3 -3
  87. package/skills/engineering/references/formatting/03-clang-tidy.md +2 -2
  88. package/skills/engineering/references/formatting/04-clangd.md +4 -4
  89. package/skills/engineering/references/formatting/examples/01-clang-format.md +2 -2
  90. package/skills/engineering/references/formatting/examples/04-config-comments.md +43 -0
  91. package/skills/engineering/references/index.md +4 -3
  92. package/skills/engineering/scripts/checking-encoding.mjs +2 -1
  93. package/skills/engineering/steps/01-targets.md +3 -3
  94. package/skills/engineering/steps/02-modules.md +3 -9
  95. package/skills/engineering/steps/03-check.md +1 -1
  96. package/skills/shared/operations.md +1 -1
  97. package/skills/shared/rule-priority.md +1 -1
  98. package/templates/cpp-workflow-project/SKILL.md +5 -3
package/README.en.md CHANGED
@@ -19,7 +19,7 @@ The exception material follows the C++ Core Guidelines' Error handling section a
19
19
  Fixed-version npm install:
20
20
 
21
21
  ```bash
22
- dsh plugin --profile <profile> add npm:@chengzhao-dev/dsh-cpp-workflow@0.7.6
22
+ dsh plugin --profile <profile> add npm:@chengzhao-dev/dsh-cpp-workflow@0.7.8
23
23
  ```
24
24
 
25
25
  This page follows each release; run `npm view @chengzhao-dev/dsh-cpp-workflow version` if you need to confirm the current version on the registry.
@@ -27,7 +27,7 @@ This page follows each release; run `npm view @chengzhao-dev/dsh-cpp-workflow ve
27
27
  GitHub tag installs use the tag with the same version number:
28
28
 
29
29
  ```bash
30
- dsh plugin --profile <profile> add github:chengzhao-dev/dsh-cpp-workflow#v0.7.6
30
+ dsh plugin --profile <profile> add github:chengzhao-dev/dsh-cpp-workflow#v0.7.8
31
31
  ```
32
32
 
33
33
  Replace `--profile` with the profile you actually run. The desktop app always runs the `desktop` profile, and that profile is owned by the app; if the command-line `add` is rejected, add the plugin in the app settings and use the same pinned npm version. A Git tag install uses the prebuilt `lib/` committed in the repository and runs no build on the target machine; the package has no install script that needs approval.
@@ -36,11 +36,11 @@ Replace `--profile` with the profile you actually run. The desktop app always ru
36
36
 
37
37
  The plugin page's "C++ Workflow" card is the only entry point and manages the comment symbol and file-header tags: the symbol is `///` or `/** ... */`, `@file` is always the file name, and every file-header, type, and declaration tag is on by default except the fixed `//` body symbol; empty values are skipped. `@param` is required for every parameter; `@return` may be omitted when the condition is self-evident; `@throws` only when the function throws; `@pre`, `@post`, `@retval`, `@tparam`, `@note`, and `@see` are on by default and can be switched off individually. The preview follows the switches, saving takes effect on the next skill read, and existing sources are never rewritten. The plugin page no longer duplicates navigation.
38
38
 
39
- If the page still reports that it is not connected to a configuration form after an upgrade, the window is still running the previous client bundle: restart DeepSeek Harness or select "Reload page" on the plugin page. The page retries the connection while open and switches to the editable form as soon as the host serves it; reinstalling is unnecessary. After a successful save, the status line shows the written `~/.dsh/profiles/<profile>/cordis.patch.yml`. Discard changes, Restore defaults and Save are separate: discard returns to the last value read from the host, restore fills the draft, and only Save writes it.
39
+ If the page still reports that it is not connected to a configuration form after an upgrade, the window is still running the previous client bundle: restart DeepSeek Harness or select "Reload page" on the plugin page. The page does not poll or retry; restart the host or select "Reload page" while the form is read-only. Reinstalling is unnecessary. After a successful save, the status line shows the written `~/.dsh/profiles/<profile>/cordis.patch.yml`. Discard changes, Restore defaults and Save are separate: discard returns to the last value read from the host, restore fills the draft, and only Save writes it.
40
40
 
41
41
  ## Workspace gate
42
42
 
43
- Only one condition must hold before any of the three skills appears: walking up from the current directory to the Git root, the path contains `.agents/skills/cpp-workflow-project/SKILL.md`.
43
+ Only one condition must hold before any of the three skills appears: walking up from the current directory to the Git root, the path contains `.agents/skills/cpp-workflow-project/SKILL.md` (a repository may instead name that directory `cpp_workflow_project`; both are accepted).
44
44
 
45
45
  The project skill marker is the repository's opt-in declaration. The plugin no longer requires a first-party `CMakeLists.txt` or C++ source file in the same repository: a docs-only repository, a repository that only copied the template, or a repository with no source files yet still matches; with an empty environment axis, the four source steps still work but build setup stops. Without the marker the list is empty, even when the repository contains CMake or `.cpp` files. Scan limits and boundary cases are in [docs/plugin-boundaries.md](https://github.com/chengzhao-dev/dsh-cpp-workflow/blob/main/docs/plugin-boundaries.md).
46
46
 
@@ -48,7 +48,7 @@ The packaged skills use rank 550. A project `.agents/skills` skill uses rank 200
48
48
 
49
49
  ## Project conventions
50
50
 
51
- Copy [templates/cpp-workflow-project](templates/cpp-workflow-project) into the target repository's `.agents/skills/` directory, keeping the `cpp-workflow-project` directory name. Add only files that do not exist; do not overwrite existing source, `CMakeLists.txt`, or `.clang-*` files. The project skill records project-specific facts; the template's "common workflow conventions" carry the shared workflow, editor, and completion rules, so the project skill does not repeat them:
51
+ Copy [templates/cpp-workflow-project](templates/cpp-workflow-project) into the target repository's `.agents/skills/` directory, keeping the `cpp-workflow-project` directory name (the plugin also accepts the underscore form `cpp_workflow_project`, so a repository that renamed it still passes the gate). Add only files that do not exist; do not overwrite existing source, `CMakeLists.txt`, or `.clang-*` files. The project skill records project-specific facts; the template's "common workflow conventions" carry the shared workflow, editor, and completion rules, so the project skill does not repeat them:
52
52
 
53
53
  - project and component names, source root;
54
54
  - library/program boundary and public header location;
@@ -66,9 +66,9 @@ Keep one `environment.json` per repository. Its first three environment axes are
66
66
  | `compiler` | `clang`, `gcc` | One compiler per configuration |
67
67
  | `standard` | `c++11`, `c++14`, `c++17`, `c++20`, `c++23` | New projects default to `c++23`; one standard per project |
68
68
 
69
- The standard lives in `environment.json` as `standard` and must match the CMake target and compile database; on the CMake side, prefer `engineering`'s `compile_settings_set_cxx_standard` function. New projects default to C++23; for C++11–C++20, lower `standard`, `cxx_std_*`, `CXX_STANDARD`, and the `.clang-format` parsing level together, not one at a time. Per-standard facilities, tooling, and downgrade tables are in the [standard directory](skills/engineering/references/cmake/standards/index.md); the CMake two-layer declaration is in [01-cxx-standard.md](skills/engineering/references/cmake/standards/01-cxx-standard.md).
69
+ The standard lives in `environment.json` as `standard` and must match the CMake target and compile database; on the CMake side, prefer `engineering`'s `set_target_cxx_standard` function. New projects default to C++23; for C++11–C++20, lower `standard`, `cxx_std_*`, `CXX_STANDARD`, and the `.clang-format` parsing level together, not one at a time. Per-standard facilities, tooling, and downgrade tables are in the [standard directory](skills/engineering/references/cmake/standards/index.md); the CMake two-layer declaration is in [01-cxx-standard.md](skills/engineering/references/cmake/standards/01-cxx-standard.md).
70
70
 
71
- The generator is always Ninja. Build directories are `build/clang/` and `build/gcc/`; they are never shared. Analysis tools are always `clang-format`, `clang-tidy`, and `clangd`; GCC mode does not switch to another analyzer.
71
+ The generator is always Ninja. Build directories default to `build/clang/` and `build/gcc/` and are never shared; a project skill may declare a single build directory (this book uses `games/tictactoe/build/`). Analysis tools are always `clang-format`, `clang-tidy`, and `clangd`; GCC mode does not switch to another analyzer.
72
72
 
73
73
  Run the declaration check first, then the live check on the build host. `<skill-dir>` is the installed `building-cpp` directory, not a directory in the target project:
74
74
 
@@ -96,7 +96,7 @@ npm ci
96
96
  npm test # main pre-commit gate: build, structural/encoding/workflow checks, and unit tests
97
97
  npm run test:matrix # real build matrix: 4 templates x 5 standards
98
98
  npm run pack:check # inspect the npm package contents
99
- npm run ci # replay the Ubuntu CI job: install, test, package check
99
+ npm run ci # local replay: install, test, package check (no matrix; the Ubuntu CI job also runs test:matrix)
100
100
  npm run ci:full # ci plus the standard matrix; needs a POSIX host
101
101
  ```
102
102
 
package/README.md CHANGED
@@ -19,7 +19,7 @@
19
19
  npm 安装固定版本:
20
20
 
21
21
  ```bash
22
- dsh plugin --profile <profile> add npm:@chengzhao-dev/dsh-cpp-workflow@0.7.6
22
+ dsh plugin --profile <profile> add npm:@chengzhao-dev/dsh-cpp-workflow@0.7.8
23
23
  ```
24
24
 
25
25
  本页版本号随发布更新;安装前可用 `npm view @chengzhao-dev/dsh-cpp-workflow version` 确认 registry 上的最新版本。
@@ -27,28 +27,28 @@ dsh plugin --profile <profile> add npm:@chengzhao-dev/dsh-cpp-workflow@0.7.6
27
27
  GitHub 标签安装使用同一版本号的标签,地址中的版本与标签同号:
28
28
 
29
29
  ```bash
30
- dsh plugin --profile <profile> add github:chengzhao-dev/dsh-cpp-workflow#v0.7.6
30
+ dsh plugin --profile <profile> add github:chengzhao-dev/dsh-cpp-workflow#v0.7.8
31
31
  ```
32
32
 
33
33
  `--profile` 换成你实际运行的那个 profile。桌面应用固定跑 `desktop` profile,且该 profile 由应用独占管理;命令行 `add` 被拒绝时,在应用设置里添加插件,地址填同一个 npm 版本。Git 标签安装使用仓库内已构建的 `lib/`,不在目标机器上重新构建;包内也不含需要授权执行的安装脚本。
34
34
 
35
35
  ### 设置
36
36
 
37
- 插件页的「C++ 工程流程」是唯一入口:注释符号可选 `///` 或 `/** ... */`,页面按注释符号、文件头、类型、函数声明与只读预览分块。`@file` 固定为文件名;除它和函数体 `//` 外,文件头、类型与函数声明标签的开关出厂全开,空值跳过。函数参数要求 `@param`,返回值要求 `@return`(成立条件自明时可省),会抛才要求 `@throws`;`@pre`、`@post`、`@retval` 与类型块的 `@tparam`、`@note`、`@see` 也出厂开启,需要时可逐项关掉。函数体固定用 `//`。预览随改动即时更新,保存后下一次读取技能即生效,已有源码不会被改写。插件页不再重复列一份导航。
37
+ 插件页的「C++ 工程流程」是唯一入口:注释符号可选 `///` 或 `/** ... */`,页面按注释符号、文件头、类型、函数声明与只读预览分块。标签开关、`@param` / `@return` / `@throws` 的要求、预览生效时机与导航行为见 [docs/plugin-flow.md](https://github.com/chengzhao-dev/dsh-cpp-workflow/blob/main/docs/plugin-flow.md)。
38
38
 
39
- 升级插件后如果这一页暂时只显示出厂值,说明当前窗口还挂着旧的前端产物:重启 DeepSeek Harness,或在插件页点“重新载入页面”即可编辑,不需要重装插件。页面会在打开后自动重试连接,拿到表单就切换为可编辑;保存成功后,状态行会显示写入的 `~/.dsh/profiles/<profile>/cordis.patch.yml`。保存、撤销修改与恢复默认值分三个按钮:撤销只回到最近一次读到的值,恢复默认值只填草稿,点保存才写盘。
39
+ 升级插件后如果这一页暂时只显示出厂值,说明当前窗口还挂着旧的前端产物:重启 DeepSeek Harness,或在插件页点“重新载入页面”即可编辑,不需要重装插件。页面不会轮询重试;表单仍只读时重启宿主或点“重新载入页面”。保存成功后,状态行会显示写入的 `~/.dsh/profiles/<profile>/cordis.patch.yml`。保存、撤销修改与恢复默认值分三个按钮:撤销只回到最近一次读到的值,恢复默认值只填草稿,点保存才写盘。
40
40
 
41
41
  ## 工作区门禁
42
42
 
43
- 会话满足一个条件,技能就会出现:从当前目录向上、停在 git 根,沿途有 `.agents/skills/cpp-workflow-project/SKILL.md`。
43
+ 会话满足一个条件,技能就会出现:从当前目录向上、停在 git 根,沿途有 `.agents/skills/cpp-workflow-project/SKILL.md`(新仓库可把目录名写成下划线 `cpp_workflow_project`,两种都认)。
44
44
 
45
45
  项目技能标记就是仓库选择加入本工作流的声明。插件不再要求同一仓库里已经有第一方 `CMakeLists.txt` 或 C++ 源文件:纯文档仓库、只复制了模板、还没有任何源文件的仓库也会出现;环境轴为空时,源码四步仍能做,但定构建会停。没有标记就返回空列表,即使仓库里有 CMake 或 `.cpp`。扫描上限和边界情形见 [docs/plugin-boundaries.md](https://github.com/chengzhao-dev/dsh-cpp-workflow/blob/main/docs/plugin-boundaries.md)。
46
46
 
47
- 插件技能 rank 550。项目自己的 `.agents/skills` 技能 rank 200、用户级技能 rank 500,两者都会以同名覆盖插件;不要在项目或用户目录里复制 `developing-cpp`、`engineering` 或 `building-cpp`。
47
+ 插件技能与项目 `.agents/skills`、用户级技能的同名覆盖顺序见 [docs/plugin-boundaries.md](https://github.com/chengzhao-dev/dsh-cpp-workflow/blob/main/docs/plugin-boundaries.md#覆盖关系);不要在项目或用户目录里复制 `developing-cpp`、`engineering` 或 `building-cpp`。
48
48
 
49
49
  ## 项目级约定
50
50
 
51
- 把 [templates/cpp-workflow-project](templates/cpp-workflow-project) 整个复制到目标仓库的 `.agents/skills/` 下,目录名保持 `cpp-workflow-project`;只补还不存在的文件,不覆盖已有的源码、`CMakeLists.txt` 或 `.clang-*`。项目技能写本工程特有的事实;通用工作流、编辑器与完成判据由模板的「通用工作流约定」承担,不在项目技能里重复:
51
+ 把 [templates/cpp-workflow-project](templates/cpp-workflow-project) 整个复制到目标仓库的 `.agents/skills/` 下,目录名保持 `cpp-workflow-project`(插件同时接受下划线目录名 `cpp_workflow_project`,改了名的仓库也能通过门禁);只补还不存在的文件,不覆盖已有的源码、`CMakeLists.txt` 或 `.clang-*`。项目技能写本工程特有的事实;通用工作流、编辑器与完成判据由模板的「通用工作流约定」承担,不在项目技能里重复:
52
52
 
53
53
  - 工程名、组件名和源码根;
54
54
  - 库与程序的边界、公共头位置;
@@ -66,9 +66,9 @@ dsh plugin --profile <profile> add github:chengzhao-dev/dsh-cpp-workflow#v0.7.6
66
66
  | `compiler` | `clang`、`gcc` | 一次配置一个编译器 |
67
67
  | `standard` | `c++11`、`c++14`、`c++17`、`c++20`、`c++23` | 新工程默认 `c++23`;一个工程一个标准 |
68
68
 
69
- 标准写在 `environment.json` 的 `standard`,并同步到 CMake target 和编译数据库;CMake 侧优先调用 `engineering` 提供的 `compile_settings_set_cxx_standard` 函数。新工程默认 C++23;C++11–C++20 工程把 `standard`、`cxx_std_*`、`CXX_STANDARD` 和 `.clang-format` 的解析档位一起降级,不要只改一处。每档的设施、工具和降档表见 [标准目录](skills/engineering/references/cmake/standards/index.md),CMake 两层声明见 [01-cxx-standard.md](skills/engineering/references/cmake/standards/01-cxx-standard.md)。
69
+ 标准写在 `environment.json` 的 `standard`,并同步到 CMake target 和编译数据库;CMake 侧优先调用 `engineering` 提供的 `set_target_cxx_standard` 函数。新工程默认 C++23;C++11–C++20 工程把 `standard`、`cxx_std_*`、`CXX_STANDARD` 和 `.clang-format` 的解析档位一起降级,不要只改一处。每档的设施、工具和降档表见 [标准目录](skills/engineering/references/cmake/standards/index.md),CMake 两层声明见 [01-cxx-standard.md](skills/engineering/references/cmake/standards/01-cxx-standard.md)。
70
70
 
71
- 生成器固定 Ninja,构建目录是 `build/clang/` 与 `build/gcc/`,不共用 `build/`。诊断工具固定 `clang-format`、`clang-tidy`、`clangd`;GCC 模式也不换成别的分析器。
71
+ 生成器固定 Ninja,默认构建目录是 `build/clang/` 与 `build/gcc/`,不共用同一目录;项目技能声明单一构建目录时(本书 `games/tictactoe/build/`)以项目为准。诊断工具固定 `clang-format`、`clang-tidy`、`clangd`;GCC 模式也不换成别的分析器。
72
72
 
73
73
  构建前先跑声明校验,再在构建宿主上跑活动校验。`<skill-dir>` 是插件安装后的 `building-cpp` 目录,不是目标工程里的目录:
74
74
 
@@ -96,7 +96,7 @@ npm ci
96
96
  npm test # 提交前主门:构建、结构/编码/工作流检查与单元测试
97
97
  npm run test:matrix # 四套模板 × 五档标准的真实构建矩阵
98
98
  npm run pack:check # 核对 npm 包内容
99
- npm run ci # 复现 Ubuntu CI:安装、测试、打包检查(不含标准矩阵)
99
+ npm run ci # 本地复现:安装、测试、打包检查(不含标准矩阵;Ubuntu CI 另跑 test:matrix)
100
100
  npm run ci:full # 在 ci 之上再跑标准矩阵,需 POSIX 宿主
101
101
  ```
102
102
 
package/lib/client.js CHANGED
@@ -9,7 +9,7 @@ window.__ModuleLoader__.load({
9
9
  * 注释标签策略:设置页的预览、技能快照与检查器参数共用这一份。
10
10
  *
11
11
  * 配置只描述「写注释时默认带哪些标签、声明用哪种注释符号」,不描述写法本身;
12
- * 写法在 `skills/developing-cpp/references/comments/01-rules.md`。设置页保存的值由宿主
12
+ * 写法在 `skills/developing-cpp/references/comments/01-comment-rules.md`。设置页保存的值由宿主
13
13
  * 写回插件 Config,服务端 `apply(ctx, config)` 用它生成本页快照与检查器参数。
14
14
  *
15
15
  * 这份文件被 `tsc` 编进 `lib/comment-policy.js`,打包客户端半侧时再内联进
@@ -151,8 +151,10 @@ function previewParts(raw, sampleName) {
151
151
  header[briefIndex] = header[briefIndex].replace(/@brief$/, `@brief ${SAMPLE_BRIEF}`);
152
152
  }
153
153
  const contract = [];
154
- if (config.param)
154
+ if (config.param) {
155
155
  contract.push('@param row 目标行号。');
156
+ contract.push('@param column 目标列号。');
157
+ }
156
158
  if (config.returns)
157
159
  contract.push('@return 放置成功时为 true。');
158
160
  if (config.throws)
@@ -230,7 +232,9 @@ function snapshotText(raw) {
230
232
  off.push(TAG_LABEL[tag]);
231
233
  }
232
234
  const style = config.commentStyle === 'block' ? '/** ... */' : '///';
233
- const line = `- 声明符号:${style}(函数体固定 //);开启 ${on.join('、')};未填值 ${unset.join('、') || '无'};关闭 ${off.join('、') || '无'}。`;
235
+ const args = checkerArgs(config);
236
+ const argLine = args.length > 0 ? args.join(' ') : '无';
237
+ const line = `- 声明符号:${style}(函数体固定 //);开启 ${on.join('、')};未填值 ${unset.join('、') || '无'};关闭 ${off.join('、') || '无'};检查器参数:${argLine}。`;
234
238
  return `## 当前注释配置(profile)\n\n${line}`;
235
239
  }
236
240
 
@@ -2,7 +2,7 @@
2
2
  * 注释标签策略:设置页的预览、技能快照与检查器参数共用这一份。
3
3
  *
4
4
  * 配置只描述「写注释时默认带哪些标签、声明用哪种注释符号」,不描述写法本身;
5
- * 写法在 `skills/developing-cpp/references/comments/01-rules.md`。设置页保存的值由宿主
5
+ * 写法在 `skills/developing-cpp/references/comments/01-comment-rules.md`。设置页保存的值由宿主
6
6
  * 写回插件 Config,服务端 `apply(ctx, config)` 用它生成本页快照与检查器参数。
7
7
  *
8
8
  * 这份文件被 `tsc` 编进 `lib/comment-policy.js`,打包客户端半侧时再内联进
@@ -144,8 +144,10 @@ export function previewParts(raw, sampleName) {
144
144
  header[briefIndex] = header[briefIndex].replace(/@brief$/, `@brief ${SAMPLE_BRIEF}`);
145
145
  }
146
146
  const contract = [];
147
- if (config.param)
147
+ if (config.param) {
148
148
  contract.push('@param row 目标行号。');
149
+ contract.push('@param column 目标列号。');
150
+ }
149
151
  if (config.returns)
150
152
  contract.push('@return 放置成功时为 true。');
151
153
  if (config.throws)
@@ -223,6 +225,8 @@ export function snapshotText(raw) {
223
225
  off.push(TAG_LABEL[tag]);
224
226
  }
225
227
  const style = config.commentStyle === 'block' ? '/** ... */' : '///';
226
- const line = `- 声明符号:${style}(函数体固定 //);开启 ${on.join('、')};未填值 ${unset.join('、') || '无'};关闭 ${off.join('、') || '无'}。`;
228
+ const args = checkerArgs(config);
229
+ const argLine = args.length > 0 ? args.join(' ') : '无';
230
+ const line = `- 声明符号:${style}(函数体固定 //);开启 ${on.join('、')};未填值 ${unset.join('、') || '无'};关闭 ${off.join('、') || '无'};检查器参数:${argLine}。`;
227
231
  return `## 当前注释配置(profile)\n\n${line}`;
228
232
  }
package/lib/index.js CHANGED
@@ -5,7 +5,8 @@
5
5
  // 示例与资产都由安装后的包内解析。
6
6
  //
7
7
  // 门禁只认显式启用的工作区:会话 cwd 到 git 根的路径上必须有
8
- // `.agents/skills/cpp-workflow-project/SKILL.md`,否则 `list()` 返回空。
8
+ // `.agents/skills/cpp-workflow-project/SKILL.md`(或下划线目录 `cpp_workflow_project`),
9
+ // 否则 `list()` 返回空。
9
10
  // C++ 或 CMake 证据刻意不参与:刚复制的模板还没有源码,空工程也可以停在
10
11
  // 构建步骤;检出之外的 C++ 示例看不到这些技能名,标记查找也不进兄弟目录。
11
12
  //
package/lib/workspace.js CHANGED
@@ -5,7 +5,12 @@
5
5
  // git 根是仓库边界:标记查找不进兄弟目录,也不向根之上继续。
6
6
  import { access } from 'node:fs/promises';
7
7
  import path from 'node:path';
8
- export const PROJECT_SKILL = path.join('.agents', 'skills', 'cpp-workflow-project', 'SKILL.md');
8
+ /** 项目技能目录名,按优先顺序排列;下划线与连字符两种写法等价,连字符是模板与文档的默认写法。 */
9
+ export const PROJECT_SKILL_DIRS = ['cpp_workflow_project', 'cpp-workflow-project'];
10
+ /** 首选标记文件;查找时按 `PROJECT_SKILL_MARKERS` 逐个尝试。 */
11
+ export const PROJECT_SKILL = path.join('.agents', 'skills', PROJECT_SKILL_DIRS[0], 'SKILL.md');
12
+ /** 所有可接受的标记文件,顺序同 `PROJECT_SKILL_DIRS`。 */
13
+ export const PROJECT_SKILL_MARKERS = PROJECT_SKILL_DIRS.map((name) => path.join('.agents', 'skills', name, 'SKILL.md'));
9
14
  export const MAX_ASCENT = 64;
10
15
  async function exists(target) {
11
16
  try {
@@ -16,6 +21,15 @@ async function exists(target) {
16
21
  return false;
17
22
  }
18
23
  }
24
+ /** 在一层目录里按优先顺序找项目技能标记,返回第一个存在的。 */
25
+ async function findMarker(root) {
26
+ for (const marker of PROJECT_SKILL_MARKERS) {
27
+ const file = path.join(root, marker);
28
+ if (await exists(file))
29
+ return file;
30
+ }
31
+ return undefined;
32
+ }
19
33
  /** 最近的上级 git 检出;worktree 的 `.git` 文件也算。 */
20
34
  export async function findGitRoot(cwd) {
21
35
  if (typeof cwd !== 'string' || cwd.trim() === '')
@@ -64,8 +78,8 @@ export async function findProjectSkill(cwd, gitRoot) {
64
78
  }
65
79
  }
66
80
  for (let depth = 0; depth < MAX_ASCENT; depth += 1) {
67
- const file = path.join(cursor, PROJECT_SKILL);
68
- if (await exists(file))
81
+ const file = await findMarker(cursor);
82
+ if (file !== undefined)
69
83
  return { file, root: cursor };
70
84
  if (cursor === gitRoot)
71
85
  return undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chengzhao-dev/dsh-cpp-workflow",
3
- "version": "0.7.6",
3
+ "version": "0.7.8",
4
4
  "description": "写 C++ 源码、配 CMake、用 Clang 构建;头文件用 /// Doxygen 文档注释,函数体用 // 分段说明,文件头标签可在设置里改。",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -14,10 +14,10 @@ metadata:
14
14
  - **负责**:环境四轴与构建入口;工具配置的复制、落地与检查(规则条文归 `engineering`);编码、声明校验、活动校验、项目入口命令的次序。
15
15
  - **不负责**:`CMakeLists.txt` 与 `cmake/` 下的 target、属性、标准与模块开 `engineering`,本技能只读它们来配置和检查,不在这一步改 target 图;函数体、类型、命名、异常与源码注释开 `developing-cpp`。
16
16
  - **交接**:一次改动同时碰到源码和构建文件时,先开 `developing-cpp` 定行为、边界与实现;需要新增或移动源文件、改库与程序的边界、补测试 target 时,转 `engineering` 把文件写进 CMake;最后回到本技能定工具配置并通过检查。只改函数体、命名、异常或注释且入口命令可运行时,定实现后只开本技能的通过检查。
17
- - **前置**:存在项目技能 `cpp-workflow-project` 时先读它的 `SKILL.md`、`environment.json` 和 `stages/stage-table.md`。三个环境轴为空、`standard` 非法或组合非法时停在定构建,不猜 WSL、Clang 或构建目录;`standard` 缺失或为空时按默认 `c++23` 继续并提示声明升级;`windows` + `native` 直接拒绝,提示「本版本不能在 Windows 原生壳里构建」,不给补 PowerShell 的路线。
17
+ - **前置**:存在项目技能 `cpp-workflow-project` 时先读它的 `SKILL.md`、`environment.json` 和 `stages/stage-table.md`。声明非法时停在定构建,不猜 WSL、Clang 或构建目录;判定规则与取值见 `../building-cpp/references/02-environment.md`「合法组合」。
18
18
  - **分因**:编译失败时先看诊断指向哪一层。函数体问题回 `developing-cpp` 的定实现;找不到头、链接失败、target 不存在或标准不对转 `engineering` 的对应步骤;没有编译数据库、format/tidy 不在 PATH 或配置不生效留在本技能的定工具配置。
19
- - **编码**:源码与构建文件用 UTF-8 无 BOM、检出 LF,`.bat` / `.cmd` 用 CRLF,`.clang-format` 写 `LineEnding: LF`;MSVC 原生构建优先加 `/utf-8`,不靠 BOM 过关。完整规则见 `../engineering/references/formatting/01-encoding.md`,机器规则以仓库根 `.gitattributes` 与 `.editorconfig` 为准。
20
- - **编辑器**:工程根已有 `.vscode/` 时按 `steps/04-vscode.md` 接线;从当前目录向上到 git 根都没有 `.vscode/` 时不打开、也不新建。配置、构建、运行和调试都从 CMake Tools 进入,构建仍以 `running-build.sh` 为准。
19
+ - **编码**:源码与构建文件用 UTF-8 无 BOM、检出 LF,`.bat` / `.cmd` 用 CRLF,`.clang-format` 写 `LineEnding: LF`;MSVC 不是受支持的环境轴;`/utf-8` 配方只留在资产注释里,当前构建仍用 clang/gcc。完整规则见 `../engineering/references/formatting/01-encoding.md`,机器规则以仓库根 `.gitattributes` 与 `.editorconfig` 为准。
20
+ - **编辑器**:工程根已有 `.vscode/` 时按 `steps/04-vscode.md` 接线;从当前目录向上到工程根(含 `CMakeLists.txt` 的目录)都没有 `.vscode/` 时不打开、也不新建,外层仓库根或书根的 `.vscode/` 不算工程配置。配置、构建、运行和调试都从 CMake Tools 进入,构建仍以 `running-build.sh` 为准。
21
21
 
22
22
  ## 三种操作
23
23
 
@@ -61,7 +61,7 @@ metadata:
61
61
 
62
62
  加载预算见 [budget.md](../shared/budget.md);building-cpp 的步骤固定 4 份。
63
63
 
64
- 项目技能列出了检查命令时只跑那一条,没有时跑本技能自己的 `scripts/checking-environment.mjs` 与 `../engineering/scripts/checking-encoding.mjs`;退出码为 0 后停在这一步,不再继续走没有失败的步骤。入口脚本只做配置、构建、CTest 与最小运行;`clang-format` 与 `clang-tidy` 的手动检查留在定工具配置,不塞进入口脚本。`environment.json` 的三个环境轴与 `standard` 是唯一来源,缺项就停。
64
+ 项目技能列出了检查命令时先跑那一条;没有时跑本技能自己的 `scripts/checking-environment.mjs` 与 `../engineering/scripts/checking-encoding.mjs`。这些命令只覆盖各自那一段,完成判据还要求入口命令、CTest 与格式化检查,按 `steps/03-check.md` 的顺序跑完再停在这一步。入口脚本只做配置、构建、CTest 与最小运行;`clang-format` 与 `clang-tidy` 的手动检查留在定工具配置,不塞进入口脚本。`environment.json` 的三个环境轴是唯一来源;取值与合法性见 `references/02-environment.md`「合法组合」,脚本行为见 `scripts/checking-environment.mjs`。
65
65
 
66
66
  ## 四类改动
67
67
 
@@ -77,8 +77,8 @@ metadata:
77
77
  ## 完成判据
78
78
 
79
79
  - [ ] 项目 `environment.json` 的三个环境轴齐全且是合法组合,`standard` 在 `c++11`–`c++23` 内;新工程默认 `c++23`,没有靠猜。
80
- - [ ] 配置命令固定 Ninja 和单一编译器,`build/<compiler>/compile_commands.json` 存在,根 `build/compile_commands.json` 指向当前编译器。
81
- - [ ] target 契约已经成立:程序 `app`、库 target、公共 include、标准与输出目录都已由 `engineering` 写好;本技能没有偷偷改 CMake 来绕过失败。
80
+ - [ ] 配置命令固定 Ninja 和单一编译器,`build/<compiler>/compile_commands.json` 存在;项目技能没有声明单一构建目录时,根 `build/compile_commands.json` 还要指向当前编译器。
81
+ - [ ] target 契约已经成立:程序 target(模板默认 `app`,本书 `terminal`)、库 target、公共 include、标准与输出目录都已由 `engineering` 写好;本技能没有偷偷改 CMake 来绕过失败。
82
82
  - [ ] `clang-format --dry-run --Werror` 与 `clang-tidy` 在项目源码上零告警;只扫描项目源码和项目头。
83
83
  - [ ] CTest 全绿,程序从该编译器的构建目录启动;有测试时注册用 `gtest_discover_tests` 或项目既有机制,运行带 `--output-on-failure --no-tests=error`,失败时报告的是具体角色和原因。
84
84
  - [ ] 没有改源码语义,没有覆盖已有工程文件,也没有安装或下载任何工具。
@@ -1,25 +1,25 @@
1
1
  # C++ 代码排版配置。
2
2
  #
3
- # Google 基线,缩进用 Tab(4 列),对齐用空格,列宽 120。
3
+ # Google 基线,缩进用 4 个空格,对齐用空格,列宽 120。
4
4
 
5
5
  # 只处理 C++ 源文件。
6
6
  Language: Cpp
7
- # 以 Google 预设为基线,只覆盖本文件写出的项。
7
+ # 只覆盖本文件写出的项,其余沿用预设。
8
8
  BasedOnStyle: Google
9
9
  # 工具不接受 c++23 取值,改用 Latest 跟随其支持的最高标准。
10
10
  Standard: Latest
11
11
 
12
- # 包含分块保持人工分组,块内按 Google 预设排序。
12
+ # include 保持现有空行分组,组内按 Google 预设排序。
13
13
  IncludeBlocks: Preserve
14
14
 
15
15
  # 每行最多 120 列。
16
16
  ColumnLimit: 120
17
- # 一级缩进 4 列;与 TabWidth 相同,每级恰好一个 Tab。
17
+ # 一级缩进 4 个空格。
18
18
  IndentWidth: 4
19
- # Tab 按 4 列显示。
19
+ # Tab 按 4 列显示,只用于阅读既有文件。
20
20
  TabWidth: 4
21
- # 只有缩进用 Tab,行内对齐仍用空格。
22
- UseTab: ForIndentation
21
+ # 缩进与对齐都用空格,不写 Tab。
22
+ UseTab: Never
23
23
  # 续行多缩进 8 个空格。
24
24
  ContinuationIndentWidth: 8
25
25
  # 访问修饰符不缩进,与 class/struct 左对齐。
@@ -27,5 +27,5 @@ AccessModifierOffset: -4
27
27
  # 构造函数初始化列表尽量排在一行。
28
28
  PackConstructorInitializers: BinPack
29
29
 
30
- # 行尾统一为 LF,格式化不会改回 CRLF。
30
+ # 行尾统一为 LF。
31
31
  LineEnding: LF
@@ -5,7 +5,6 @@ InheritParentConfig: false
5
5
  Checks: >
6
6
  -*,
7
7
  google-*,
8
- portability-avoid-pragma-once,
9
8
  readability-identifier-naming
10
9
 
11
10
  WarningsAsErrors: '*'
@@ -59,6 +58,3 @@ CheckOptions:
59
58
  value: lower_case
60
59
  - key: readability-identifier-naming.MacroDefinitionCase
61
60
  value: UPPER_CASE
62
- # 包含守卫按 Google 规则以 _H_ 结尾,UPPER_CASE 会把它判成多余下划线。
63
- - key: readability-identifier-naming.MacroDefinitionIgnoredRegexp
64
- value: '^[A-Z][A-Z0-9_]*_H_$'
@@ -9,9 +9,13 @@
9
9
  // VSCode 的配置、构建、运行和调试入口都留在 CMake Tools。
10
10
  // 不另建 launch.json / tasks.json,避免出现第二套构建或启动路径。
11
11
  "cmake.buildDirectory": "${workspaceFolder}/build/clang",
12
+ // 构建固定用 Ninja,与工程入口脚本一致;换生成器要同步脚本。
12
13
  "cmake.generator": "Ninja",
14
+ // 打开工程时不自动配置,配置时机由入口脚本决定。
13
15
  "cmake.configureOnOpen": false,
16
+ // 运行前先构建,避免跑到旧产物。
14
17
  "cmake.buildBeforeRun": true,
18
+ // 生成 compile_commands.json,供 clangd 与 clang-tidy 读取。
15
19
  "cmake.exportCompileCommandsFile": true,
16
20
  // CMake Tools 的快速调试默认使用 C/C++ 扩展的 cppdbg 适配器;
17
21
  // 这里只把它的调试后端改成 LLDB。GCC 模式改成 gdb + /usr/bin/gdb。
@@ -26,22 +30,29 @@
26
30
  // cpptools 只作为 CMake 的调试后端,不再提供 IntelliSense;
27
31
  // 补全、跳转、诊断和格式化都由读取 compile_commands.json 的 clangd 负责。
28
32
  "C_Cpp.intelliSenseEngine": "disabled",
33
+ // 保存即格式化;实际排版交给 clangd,不在构建脚本里跑 clang-format -i。
29
34
  "editor.formatOnSave": true,
35
+ // C/C++ 的默认格式化器都交给 clangd。
30
36
  "[cpp]": {
31
37
  "editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd"
32
38
  },
33
39
  "[c]": {
34
40
  "editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd"
35
41
  },
42
+ // 项目头文件统一按 C++ 解析,避免被当成 C。
36
43
  "files.associations": {
37
44
  "*.h": "cpp"
38
45
  },
46
+ // 文件统一按 UTF-8 保存,与 .editorconfig 的 charset 一致。
39
47
  "files.encoding": "utf8",
48
+ // 行尾统一 LF,与 .gitattributes 和 .clang-format 的 LineEnding 一致。
40
49
  "files.eol": "\n",
50
+ // 构建产物与本地缓存不显示在资源管理器里。
41
51
  "files.exclude": {
42
52
  "**/build": true,
43
53
  "**/.cache": true
44
54
  },
55
+ // 同一批目录也不进入搜索结果。
45
56
  "search.exclude": {
46
57
  "**/build": true,
47
58
  "**/.cache": true
@@ -3,79 +3,86 @@
3
3
  # 配置、构建、测试并运行当前 C++11–C++23 工程(默认 C++23)。
4
4
  #
5
5
  # 用法:./running-build.sh [clang|gcc];省略时用 clang。
6
- # 构建目录:build/<compiler>;
7
- # 编译数据库:build/<compiler>/compile_commands.json。
6
+ # 程序名、构建目录与构建根可用 APP_NAME、BUILD_DIR、BUILD_ROOT 覆盖;默认 app、build/<compiler> 与 build。
7
+ # 单一构建目录时把 BUILD_ROOT 设为与 BUILD_DIR 相同,脚本不再补 build/compile_commands.json 链接。
8
+ # 编译数据库:默认 build/<compiler>/compile_commands.json,随 BUILD_DIR 走。
8
9
  # 适用于 Linux、macOS 和 Windows + WSL,不支持 Windows 原生壳。
9
10
 
10
11
  set -euo pipefail
11
12
  cd "$(dirname "$0")"
12
13
 
13
- readonly APP_NAME="app"
14
- readonly BUILD_ROOT="build"
14
+ APP_NAME="${APP_NAME:-app}"
15
+ BUILD_ROOT="${BUILD_ROOT:-build}"
15
16
 
16
17
  # 解析编译器参数,只接受 clang 与 gcc。
17
18
  COMPILER="${1:-clang}"
18
19
  case "${COMPILER}" in
19
- clang)
20
- readonly CXX="clang++"
21
- ;;
22
- gcc)
23
- readonly CXX="g++"
24
- ;;
25
- *)
26
- printf '用法: %s [clang|gcc]\n' "$0" >&2
27
- exit 2
28
- ;;
20
+ clang)
21
+ readonly CXX="clang++"
22
+ ;;
23
+ gcc)
24
+ readonly CXX="g++"
25
+ ;;
26
+ *)
27
+ printf '用法: %s [clang|gcc]\n' "$0" >&2
28
+ exit 2
29
+ ;;
29
30
  esac
30
31
  readonly COMPILER CXX
31
- readonly BUILD_DIR="${BUILD_ROOT}/${COMPILER}"
32
+ BUILD_DIR="${BUILD_DIR:-${BUILD_ROOT}/${COMPILER}}"
32
33
 
33
34
  # 打印阶段标题。
34
35
  header() {
35
- printf '\n== %s ==\n' "$1"
36
+ printf '\n== %s ==\n' "$1"
36
37
  }
37
38
 
38
39
  # 打印错误。
39
40
  err() {
40
- printf '错误: %s\n' "$1" >&2
41
+ printf '错误: %s\n' "$1" >&2
41
42
  }
42
43
 
43
44
  # 命令失败时打印退出码与命令。
44
45
  on_error() {
45
- local status=$?
46
- printf '失败(退出码 %s):%s\n' "${status}" "${BASH_COMMAND}" >&2
46
+ local status=$?
47
+ printf '失败(退出码 %s):%s\n' "${status}" "${BASH_COMMAND}" >&2
47
48
  }
48
49
  trap on_error ERR
49
50
 
50
- # 入口:配置、构建、链接编译数据库、测试并运行。
51
+ # 入口:配置、构建、导出编译数据库、测试并运行。
51
52
  main() {
52
- header "配置 (${COMPILER})"
53
- cmake -S . -B "${BUILD_DIR}" -G Ninja \
54
- -DCMAKE_BUILD_TYPE=Debug \
55
- -DCMAKE_C_COMPILER="${COMPILER}" \
56
- -DCMAKE_CXX_COMPILER="${CXX}" \
57
- -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
53
+ header "配置 (${COMPILER})"
54
+ cmake -S . -B "${BUILD_DIR}" -G Ninja \
55
+ -DCMAKE_BUILD_TYPE=Debug \
56
+ -DCMAKE_C_COMPILER="${COMPILER}" \
57
+ -DCMAKE_CXX_COMPILER="${CXX}" \
58
+ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
58
59
 
59
- header "构建"
60
- cmake --build "${BUILD_DIR}"
60
+ header "构建"
61
+ cmake --build "${BUILD_DIR}"
61
62
 
62
- header "编译数据库"
63
- rm -f "${BUILD_ROOT}/compile_commands.json"
64
- ln -s "${COMPILER}/compile_commands.json" \
65
- "${BUILD_ROOT}/compile_commands.json"
63
+ header "编译数据库"
64
+ if [ "${BUILD_DIR}" != "${BUILD_ROOT}" ]; then
65
+ rm -f "${BUILD_ROOT}/compile_commands.json"
66
+ target="${BUILD_DIR}/compile_commands.json"
67
+ case "${target}" in
68
+ "${BUILD_ROOT}"/*) relative="${target#"${BUILD_ROOT}/"}" ;;
69
+ *) relative="${target}" ;;
70
+ esac
71
+ ln -s "${relative}" "${BUILD_ROOT}/compile_commands.json"
72
+ fi
66
73
 
67
- header "测试"
68
- if [ -d tests ]; then
69
- ctest --test-dir "${BUILD_DIR}" --output-on-failure --no-tests=error
70
- else
71
- ctest --test-dir "${BUILD_DIR}" --output-on-failure
72
- fi
74
+ header "测试"
75
+ if [ -d tests ]; then
76
+ ctest --test-dir "${BUILD_DIR}" --output-on-failure --no-tests=error
77
+ else
78
+ ctest --test-dir "${BUILD_DIR}" --output-on-failure --no-tests=ignore
79
+ fi
73
80
 
74
- header "运行 ${APP_NAME}"
75
- (
76
- cd "${BUILD_DIR}/bin"
77
- "./${APP_NAME}"
78
- )
81
+ header "运行 ${APP_NAME}"
82
+ (
83
+ cd "${BUILD_DIR}/bin"
84
+ "./${APP_NAME}"
85
+ )
79
86
  }
80
87
 
81
88
  main "$@"
@@ -4,19 +4,15 @@ project({{PROJECT_NAME}} VERSION 0.1.0 LANGUAGES CXX)
4
4
  set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
5
5
  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
6
6
 
7
- enable_testing()
8
-
9
7
  add_executable(app
10
- src/main.cpp
11
- src/greeting.cpp
8
+ src/main.cpp
9
+ src/greeting.cpp
12
10
  )
13
11
  target_include_directories(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
14
12
  target_compile_features(app PRIVATE cxx_std_23)
15
13
  set_target_properties(app PROPERTIES
16
- CXX_STANDARD 23
17
- CXX_STANDARD_REQUIRED ON
18
- CXX_EXTENSIONS OFF
14
+ CXX_STANDARD 23
15
+ CXX_STANDARD_REQUIRED ON
16
+ CXX_EXTENSIONS OFF
19
17
  )
20
- target_compile_options(app PRIVATE -Wall -Wextra -Werror)
21
-
22
- add_test(NAME app_smoke COMMAND app)
18
+ # 警告与 -Werror 由工程按需要打开(set_target_warnings),模板不默认加在 target 上。
@@ -1,5 +1,4 @@
1
- #ifndef CPP_WORKFLOW_TEMPLATE_MULTI_INCLUDE_GREETING_H_
2
- #define CPP_WORKFLOW_TEMPLATE_MULTI_INCLUDE_GREETING_H_
1
+ #pragma once
3
2
 
4
3
  #include <string>
5
4
 
@@ -8,5 +7,3 @@ namespace greeting {
8
7
  std::string MakeGreeting(const std::string& name);
9
8
 
10
9
  } // namespace greeting
11
-
12
- #endif // CPP_WORKFLOW_TEMPLATE_MULTI_INCLUDE_GREETING_H_
@@ -9,9 +9,9 @@ namespace greeting {
9
9
 
10
10
  std::string MakeGreeting(const std::string& name) {
11
11
  #if __cplusplus >= 202002L
12
- return std::format("Hello, {}!", name);
12
+ return std::format("Hello, {}!", name);
13
13
  #else
14
- return "Hello, " + name + "!";
14
+ return "Hello, " + name + "!";
15
15
  #endif
16
16
  }
17
17
 
@@ -3,6 +3,6 @@
3
3
  #include "greeting.h"
4
4
 
5
5
  int main() {
6
- std::cout << greeting::MakeGreeting("C++23") << '\n';
7
- return 0;
6
+ std::cout << greeting::MakeGreeting("C++23") << '\n';
7
+ return 0;
8
8
  }