aboutsummaryrefslogtreecommitdiff
path: root/scripts/azure-pipelines/generate-skip-list.ps1
blob: 6c533595faf9c917acaf3d4fc1ad6109c594c23f (plain)
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
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: MIT
#

<#
.SYNOPSIS
Generates a list of ports to skip in the CI.

.DESCRIPTION
generate-skip-list takes a triplet, and the path to the ci.baseline.txt
file, and generates a skip list string to pass to vcpkg.

.PARAMETER Triplet
The triplet to find skipped ports for.

.PARAMETER BaselineFile
The path to the ci.baseline.txt file.
#>
[CmdletBinding()]
Param(
    [string]$Triplet,
    [string]$BaselineFile,
    [switch]$SkipFailures = $false,
    [String[]]$AdditionalSkips = @()
)

$ErrorActionPreference = 'Stop'

if (-not (Test-Path -Path $BaselineFile)) {
    Write-Error "Unable to find baseline file $BaselineFile"
    throw
}

#read in the file, strip out comments and blank lines and spaces
$baselineListRaw = Get-Content -Path $BaselineFile `
    | Where-Object { -not ($_ -match "\s*#") } `
    | Where-Object { -not ( $_ -match "^\s*$") } `
    | ForEach-Object { $_ -replace "\s" }

###############################################################
# This script is running at the beginning of the CI test, so do a little extra
# checking so things can fail early.

#verify everything has a valid value
$missingValues = $baselineListRaw | Where-Object { -not ($_ -match "=\w") }

if ($missingValues) {
    Write-Error "The following are missing values: $missingValues"
    throw
}

$invalidValues = $baselineListRaw `
    | Where-Object { -not ($_ -match "=(skip|pass|fail|ignore)$") }

if ($invalidValues) {
    Write-Error "The following have invalid values: $invalidValues"
    throw
}

$baselineForTriplet = $baselineListRaw `
    | Where-Object { $_ -match ":$Triplet=" }

# Verify there are no duplicates (redefinitions are not allowed)
$file_map = @{ }
foreach ($port in $baselineForTriplet | ForEach-Object { $_ -replace ":.*$" }) {
    if ($null -ne $file_map[$port]) {
        Write-Error `
            "$($port):$($Triplet) has multiple definitions in $baselineFile"
        throw
    }
    $file_map[$port] = $true
}

# Format the skip list for the command line
if ($SkipFailures) {
    $targetRegex = "=(?:skip|fail)$"
} else {
    $targetRegex = "=skip$"
}

$skip_list = $baselineForTriplet `
    | Where-Object { $_ -match $targetRegex } `
    | ForEach-Object { $_ -replace ":.*$" }
$skip_list += $AdditionalSkips
[string]::Join(",", $skip_list)