owned this note
owned this note
Published
Linked with GitHub
# 建置 VScode Ceedling MSYS2 的環境 (UCRT) + Code Coverage Analysis
## 安裝MSYS2
https://www.msys2.org
下載MSYS
pacman -Syu
關閉MSYS2
pacman -Syu
pacman -S mingw-w64-ucrt-x86_64-toolchain
pacman -S mingw-w64-ucrt-x86_64-cmake mingw-w64-ucrt-x86_64-ninja
## 只設定VSCode 不要設定Path 最安全


### 歷史淵源
直接使用MSYS2 底下的 UCRT64
https://zhuanlan.zhihu.com/p/401188789
## 在VSCode 裡面新增 MSYS2 的Terminal
https://stackoverflow.com/questions/43302853/using-msys-shell-in-visual-studio-code
## 在windows 安裝Ruby
Path 設定在 Ceedling 裡面比較好。
## 在windows 安裝 Pyhon
### 安裝 gcovr
pip install gcovr
gcovr Path 設定gcov 在 gcovr.cfg 裡面比較好。
```ini
gcov-executable = C:\\msys64\\ucrt64\\bin\\gcov.exe
```
gcovr Path 設定在 projecy.yml 裡面比較好
```ruby
:environment:
- :path:
- C:\Users\[Username]\AppData\Local\Programs\Python\Python311\Scripts\
```
運行測試的Command
ceedling gcov:all utils:gcov
在這裏面可以看報表
\build\artifacts\gcov
## 在MSYS 安裝 Gcc Gdb
```shell
pacman -S mingw-w64-x86_64-gcc
```
```shell
pacman -S mingw-w64-x86_64-gdb
pacman -S mingw-w64-x86_64-global
```
## 在MSYS 安裝 Gcc Gdb
```shell=
pacman -S mingw-w64-x86_64-gcc
```
```shell
pacman -S mingw-w64-x86_64-gdb
pacman -S mingw-w64-x86_64-global
```
```shell
pacman -S mingw-w64-ucrt-x86_64-toolchain
pacman -S mingw-w64-ucrt-x86_64-cmake mingw-w64-ucrt-x86_64-ninja
```
## 在PowerSehell 透過Ruby 安裝 Ceedling
```shell=
gem install ceedling
```
# Ceedling Project.yml

- C:\msys64\ucrt64\bin

- xml_tests_report
## Ceedling 小撇步
如果修改過test_*.c include 的 .h 需要回到test_*.c ctrl+s 一下
## 整合以上都放在VsCode 裡面
https://hackmd.io/jKVp08McS96nv9TRNE39cQ
### launch.json
```json=
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "ceedling_gdb",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/test/out/${command:ceedlingExplorer.debugTestExecutable}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:/Ruby25-x64/msys64/mingw64/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
```

### Task.json
```json=
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe build active file",
"command": "C:/msys64/mingw32/bin/gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-IC:/msys64/mingw32/include",
"-LC:/msys64/mingw32/lib",
"-lmingw32",
"-lSDL2main",
"-lSDL2",
"-mwindows"
],
"options": {
"cwd": "C:/msys64/mingw32/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
```
### c_cpp_properties.json
```json=
{
"configurations": [
{
"name": "MSYS2_RELEASE",
"includePath": [
"${workspaceFolder}/**",
"C:/msys64/mingw32/lib/gcc/i686-w64-mingw32/12.1.0/include/**",
"C:/msys64/mingw64/include"
],
"defines": [],
"windowsSdkVersion": "10.0.19041.0",
"compilerPath": "C:/msys64/mingw64/bin/gcc.exe",
"cStandard": "c99",
"cppStandard": "c++17",
"intelliSenseMode": "windows-gcc-x64",
"mergeConfigurations": false,
"browse": {
"path": [
"${workspaceFolder}/**",
"C:/msys64/mingw32/lib/gcc/i686-w64-mingw32/12.1.0/include/**",
"C:/msys64/mingw64/include"
],
"limitSymbolsToIncludedHeaders": true
}
},
{
"name": "CEEDLING_TEST",
"includePath": [
"${workspaceFolder}/**",
"C:/msys64/mingw32/lib/gcc/i686-w64-mingw32/12.1.0/include/",
"C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/ceedling-0.31.1/vendor/unity/src",
"C:/msys64/mingw64/include"
],
"defines": [
"TEST"
],
"windowsSdkVersion": "10.0.19041.0",
"compilerPath": "C:/msys64/mingw32/bin/gcc.exe",
"cStandard": "c99",
"cppStandard": "c++17",
"intelliSenseMode": "windows-gcc-x64",
"mergeConfigurations": false,
"browse": {
"path": [
"${workspaceFolder}/**"
],
"limitSymbolsToIncludedHeaders": true
}
}
],
"version": 4
}
```
## SDL2 跟 VScode
https://hackmd.io/iPx4AQdFTEGHHs2aGx3h5w