forked from microsoft/msquic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge-coverage.ps1
85 lines (66 loc) · 2.24 KB
/
merge-coverage.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
<#
.SYNOPSIS
This script merges the coverage data.
.PARAMETER Config
Specifies the build configuration to test.
.PARAMETER Arch
The CPU architecture to test.
.PARAMETER Tls
The TLS library test.
.PARAMETER Local
Indicates local execution/usage (not Azure Pipelines) of the script.
#>
param (
[Parameter(Mandatory = $false)]
[ValidateSet("Debug", "Release")]
[string]$Config = "Debug",
[Parameter(Mandatory = $false)]
[ValidateSet("x86", "x64", "arm", "arm64")]
[string]$Arch = "x64",
[Parameter(Mandatory = $false)]
[ValidateSet("schannel", "openssl")]
[string]$Tls = "",
[Parameter(Mandatory = $false)]
[switch]$Local = $false
)
Set-StrictMode -Version 'Latest'
$PSDefaultParameterValues['*:ErrorAction'] = 'Stop'
# Default TLS based on current platform.
if ("" -eq $Tls) {
if ($IsWindows) {
$Tls = "schannel"
} else {
$Tls = "openssl"
}
}
# Root directory of the project.
$RootDir = Split-Path $PSScriptRoot -Parent
# Path to the coverage tool.
$CoverageExe = 'C:\"Program Files"\OpenCppCoverage\OpenCppCoverage.exe'
# The input directory to search for files. When run locally (not on Azure Pipelines)
# the files are in a different location.
$CoverageDir = Join-Path $RootDir "artifacts\coverage\windows\$($Arch)_$($Config)_$($Tls)"
if ($Local) {
$CoverageDir = Join-Path $RootDir "artifacts\coverage"
}
# Build up the args with the list of input files.
$CoverageMergeParams = ""
foreach ($file in $(Get-ChildItem -Path $CoverageDir -Filter '*.cov')) {
$CoverageMergeParams += " --input_coverage $(Join-Path $CoverageDir $file.Name)"
}
if ($CoverageMergeParams -eq "") {
Write-Error "No coverage results to merge!"
}
if ($Local) {
# Locally, output the HTML report.
$CoverageMergeParams += " --export_type html:$(Join-Path $CoverageDir "report")"
} else {
# Use cobertura format for Azure Pipelines.
$CoverageMergeParams += " --export_type cobertura:$(Join-Path $CoverageDir "msquiccoverage.xml")"
}
# Call the tool to merge the files into the appropriate format.
Invoke-Expression ($CoverageExe + $CoverageMergeParams) | Out-Null
if ($Local) {
# Open up the HTML report that was just generated.
start (Join-Path $CoverageDir "report\index.html")
}