-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.ps1
258 lines (224 loc) · 10 KB
/
make.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
<#
.SYNOPSIS
Script to assist with CMake configuraiton and build.
.DESCRIPTION
Use this script to easily configure and build several variants of the soniclib
library. Both chx01 (whitney) and icu (shasta) variants are built.
.PARAMETER Clean
Set to clean the project (no configure/build triggered).
.PARAMETER BuildTypes
Specify the build types to configure and build as a list of strings. Default is
to build Release, MinSizeRel, RelWithDebInfo, and Debug.
.PARAMETER InitFwOptions
(shasta-only) Specify which init FW to use in the build. Options are FULL,
NO_TX_OPTIMIZATION, and NONE. Default is to build all.
.PARAMETER MainFwOptions
Specify which main FW to use in the build. Options are NONE,
GPT, CH101_GPR, CH201_GPRMT, and CHX01_FREQSWEEP. Default is to build GPT is SensorType is SHASTA and all if SensorType is Whitney.
.PARAMETER CMakeToolchainFile
Specify the path to the CMakeToolchain file. The deafult is arm-non-eabi-m4.cmake.
.PARAMETER Generator
The CMake generator to use. Default is "MinGW Makefiles".
.PARAMETER SensorTypes
List of sensor types to build for. Options are SHASTA (ICU-x0201) and WHITNEY
(CH-x01).
.PARAMETER Install
Define to run the install step. Currently this just copies the compile_comamnds.json
file to the directory containing the main CMakeLists.txt
.PARAMETER RunTests
Define to run the unit tests by calling CTest.
.PARAMETER BuildDir
The build directory to create (or use if it already exists).
.INPUTS
None.
.OUTPUTS
None.
.EXAMPLE
PS> .\make.ps1
#>
param(
[switch]$Clean,
[string[]]$BuildTypes = ("Release", "MinSizeRel", "RelWithDebInfo", "Debug"),
[string[]]$InitFwOptions = ("FULL", "NO_TX_OPTIMIZATION", "NONE"),
[string[]]$MainFwOptions = ("GPT", "CH101_GPR", "CH201_GPRMT", "CHX01_FREQSWEEP", "NONE"),
[string]$CMakeToolchainFile = "CMakeToolchains/arm-none-eabi-m4.cmake",
[string]$Generator = "MinGW Makefiles",
[string[]]$LogLevels = ("Disabled", "Min", "Max"),
[switch]$Install,
[switch]$RunTests,
[switch]$Coverage,
[string[]]$SensorTypes = ("SHASTA", "WHITNEY"),
[string]$BuildDir = "build",
[string]$MingwGccPath
)
function Build-Project {
param(
$BuildDir
)
cmake --build "$BuildDir" -- -j4
if ($LASTEXITCODE) { throw "make failed with status $LASTEXITCODE." }
}
if ($Clean) {
Remove-Item -Recurse -Force "$BuildDir" -ErrorAction SilentlyContinue
exit 0
}
New-Item -ItemType Directory $BuildDir -ErrorAction SilentlyContinue
$source_dir = "./invn/soniclib/"
$MingwGccPath = $MingwGccPath -replace '\\', '/'
# Copied from ch_log.h
enum ChLogLevels
{
CH_LOG_LEVEL_TRACE = 0
CH_LOG_LEVEL_DEBUG = 1
CH_LOG_LEVEL_INFO = 2
CH_LOG_LEVEL_WARNING = 3
CH_LOG_LEVEL_ERROR = 4
CH_LOG_LEVEL_APP = 5
CH_LOG_LEVEL_DISABLE = 6
}
$RUN_UNIT_TEST = ''
if ($RunTests) {
$RUN_UNIT_TEST = "-DRUN_UNIT_TEST:BOOL=ON"
}
if ($Coverage) {
$coverage_dir = "$BuildDir/coverage"
New-Item -ItemType Directory -Path $coverage_dir -Force | Out-Null
python -m gcovr `
--merge-mode-functions=separate `
--branches `
--calls `
--decisions `
--sort-percentage `
--html-details "$coverage_dir/coverage.html" `
--add-tracefile "$BuildDir/**/*_coverage.json" `
--root $source_dir
Write-Output "`nMerged coverages available in $coverage_dir/coverage.html"
exit 0
}
ForEach ($BuildType in $BuildTypes) {
ForEach($SensorType in $SensorTypes) {
# shasta build
if ($SensorType -Contains "SHASTA") {
$MainFwOptions = $MainFwOptions|where{$_ -match "(GPT|NONE)"} # Keep only shasta fw
ForEach ($InitFwOption in $InitFwOptions) {
ForEach ($MainFwOption in $MainFwOptions) {
ForEach ($LogLevel in $LogLevels) {
if ($BuildType -eq "Debug") {
Switch($LogLevel) {
"Disabled" {$LogLevelInt = ([ChLogLevels]::CH_LOG_LEVEL_DISABLE).value__}
"Min" {$LogLevelInt = ([ChLogLevels]::CH_LOG_LEVEL_ERROR).value__}
"Max" {$LogLevelInt = ([ChLogLevels]::CH_LOG_LEVEL_TRACE).value__}
}
$LogLevelInt = ([ChLogLevels]::CH_LOG_LEVEL_ERROR).value__
} else {
# For other builds, always use the default log level
if ($LogLevel -eq "Min") {
$LogLevelInt = ([ChLogLevels]::CH_LOG_LEVEL_ERROR).value__
} else {
# return # continue
continue
}
}
$BuildConfig = "shasta_$InitFwOption`_Fw_$MainFwOption`_$BuildType`_log$LogLevel".ToLower()
$SubBuildDir = Join-Path "$BuildDir" "$BuildConfig"
cmake -G "$Generator" `
-DCMAKE_TOOLCHAIN_FILE="$CMakeToolchainFile" `
-DINCLUDE_SHASTA_SUPPORT:BOOL=ON `
-DCMAKE_BUILD_TYPE:STRING="$BuildType" `
-DCHIRP_INIT_FW_TYPE="$InitFwOption" `
-B "$SubBuildDir" `
-DCHIRP_MAIN_FW_TYPE="$MainFwOption" `
-DCHIRP_LOG_LEVEL="$LogLevelInt" `
-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON `
$RUN_UNIT_TEST
if ($LASTEXITCODE) { exit $LASTEXITCODE }
try {
Build-Project "$SubBuildDir"
if ($RunTests) {
# ctest --test-dir "$SubBuildDir/test/unit_test" --output-junit "junitoutput.xml" # CMake 3.21+
ctest --test-dir "$SubBuildDir/test/unit_test" -VV --output-on-failure --no-compress-output "-D" "ExperimentalTest"
# Generate coverage report
python -m gcovr `
--print-summary `
--branches `
--calls `
--decisions `
--json "$SubBuildDir/$BuildConfig`_coverage.json" --json-pretty `
--gcov-executable "$MingwGccPath/bin/gcov.exe" `
--root $source_dir `
"$SubBuildDir/CMakeFiles/soniclib.dir/invn/soniclib"
}
if ($Install) {
cmake --install "$SubBuildDir"
}
}
catch {
Write-Output $_
exit 1
}
}
}
}
}
# whitney build
if ($SensorType -Contains "WHITNEY") {
ForEach ($LogLevel in $LogLevels) {
if ($BuildType -eq "Debug") {
Switch($LogLevel) {
"Disabled" {$LogLevelInt = ([ChLogLevels]::CH_LOG_LEVEL_DISABLE).value__}
"Min" {$LogLevelInt = ([ChLogLevels]::CH_LOG_LEVEL_ERROR).value__}
"Max" {$LogLevelInt = ([ChLogLevels]::CH_LOG_LEVEL_TRACE).value__}
}
$LogLevelInt = ([ChLogLevels]::CH_LOG_LEVEL_ERROR).value__
} else {
# For other builds, always use the default log level
if ($LogLevel -eq "Min") {
$LogLevelInt = ([ChLogLevels]::CH_LOG_LEVEL_ERROR).value__
} else {
# return # continue
continue
}
}
$MainFwOptions = $MainFwOptions|where{$_ -match "(CH101_GPR|CH201_GPRMT|CHX01_FREQSWEEP)"} # Keep only whitney fw
ForEach ($MainFwOption in $MainFwOptions) {
$BuildConfig = "whitney_Fw_$MainFwOption`_$BuildType`_log$LogLevel".ToLower()
$SubBuildDir = Join-Path "$BuildDir" "$BuildConfig"
cmake -G "$Generator" `
-DCMAKE_TOOLCHAIN_FILE="$CMakeToolchainFile" `
-DCMAKE_BUILD_TYPE:STRING="$BuildType" `
-B "$SubBuildDir" `
-DCHIRP_MAIN_FW_TYPE="$MainFwOption" `
-DCHIRP_LOG_LEVEL="$LogLevelInt" `
-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON `
$RUN_UNIT_TEST
if ($LASTEXITCODE) { exit $LASTEXITCODE }
try {
Build-Project "$SubBuildDir"
if ($RunTests) {
# ctest --test-dir "$SubBuildDir/test/unit_test" --output-junit "junitoutput.xml" # CMake 3.21+
ctest --test-dir "$SubBuildDir/test/unit_test" --no-compress-output "-D" "ExperimentalTest"
# Generate coverage report
python -m gcovr `
--print-summary `
--branches `
--calls `
--decisions `
--json "$SubBuildDir/$BuildConfig`_coverage.json" --json-pretty `
--gcov-executable "$MingwGccPath/bin/gcov.exe" `
--root $source_dir `
"$SubBuildDir/CMakeFiles/soniclib.dir/invn/soniclib"
}
if ($Install) {
cmake --install "$SubBuildDir"
}
}
catch {
Write-Output $_
exit 1
}
}
}
}
}
}
exit 0