-
Notifications
You must be signed in to change notification settings - Fork 276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix package pattern in json schema configuration registry #1429
Fix package pattern in json schema configuration registry #1429
Conversation
498a54d
to
c9090c1
Compare
Format failures fixed in #1433 |
64800ac
to
e03dc04
Compare
Schema param(
[string]$VcpkgSrcDir = (Join-Path $PSScriptRoot '../..' | Resolve-Path),
[string]$TempWorkDir = (New-Item -ItemType Directory Temp:/$(New-Guid)).FullName
)
$ErrorActionPreference = 'Stop'
# . $PSScriptRoot/../end-to-end-tests-prelude.ps1
$VcpkgJsonSchema = @{
Artifact = 'artifact.schema.json'
Configuration = 'vcpkg-configuration.schema.json'
Definitions = 'vcpkg-schema-definitions.schema.json'
Port = 'vcpkg.schema.json'
}
# remove `$id` in schema for error 'Test-Json: Cannot parse the JSON schema.'
$VcpkgJsonSchema.Values
| ForEach-Object {
Copy-Item -Path (Join-path $VcpkgSrcDir 'docs' $_) -Destination $TempWorkDir
Join-Path $TempWorkDir $_
}
| ForEach-Object {
(Get-Content -Raw -Path $_) -replace '(?s)\n "\$id".+?\n', "`n"
| Set-Content -NoNewline -Path $_
}
| Out-Null
[scriptblock]$_Gen__ = {
param(
[Parameter(Mandatory)][bool]$Expected,
[Parameter(Mandatory)][string[]]$PackageArray,
[string]$Baseline = '0' * 40
)
return @(
$Expected,
@{
registries = @(
[pscustomobject]@{
kind = 'git'
repository = ''
baseline = $Baseline
packages = $PackageArray
}
)
}
)
}
# See src/vcpkg-test/registries.cpp "check valid package patterns"
@{
$VcpkgJsonSchema.Configuration =
@{
'packages: ["a"]' = & $_Gen__ $true @('a')
'packages: empty' = & $_Gen__ $false [string[]]@('')
'packages: blank' = & $_Gen__ $false @(' ')
'packages: baseline 39' = & $_Gen__ $false @('a') ('0' * 39)
'packages: hashtag ["*"]' = & $_Gen__ $true @('*')
'packages: hashtag ["a*"]' = & $_Gen__ $true @('a*')
'packages: hashtag ["*a"]' = & $_Gen__ $false @('*a')
'packages: hashtag ["b-*"]' = & $_Gen__ $true @('b-*')
'packages: hashtag ["c-d-*"]' = & $_Gen__ $true @('c-d-*')
'packages: hashtag dup ["a**"]' = & $_Gen__ $false @('a**')
'packages: hashtag dup ["b-**"]' = & $_Gen__ $false @('b-**')
'packages: hashtag dup ["c--*"]' = & $_Gen__ $false @('c--*')
'packages: hashtag dup ["d-*-*"]' = & $_Gen__ $false @('d-*-*')
'packages: hashtag mid ["a*b"]' = & $_Gen__ $false @('a*b')
'packages: mix array ["a*","b"]' = & $_Gen__ $true @('a*', 'b')
'packages: symbols ["a+"]' = & $_Gen__ $false @('a+')
'packages: symbols ["a?"]' = & $_Gen__ $false @('a?')
}
$VcpkgJsonSchema.Port =
@{
# test identifiers
'port-name: "co"' = $true, @{name = 'co' }
'port-name: "rapidjson"' = $true, @{name = 'rapidjson' }
'port-name: "boost-tuple"' = $true, @{name = 'boost-tuple' }
'port-name: "vcpkg-boost-helper"' = $true, @{name = 'vcpkg-boost-helper' }
'port-name: "lpt"' = $true, @{name = 'lpt' }
'port-name: "com"' = $true, @{name = 'com' }
# reject invalid characters
'port-name: ""' = $false, @{name = '' }
'port-name: " "' = $false, @{name = ' ' }
'port-name: "boost_tuple"' = $false, @{name = 'boost_tuple' }
'port-name: "boost.' = $false, @{name = 'boost.' }
'port-name: "boost.tuple"' = $false, @{name = 'boost.tuple' }
'port-name: "boost@1"' = $false, @{name = 'boost@1' }
'port-name: "boost#1"' = $false, @{name = 'boost#1' }
'port-name: "boost:x64-windows"' = $false, @{name = 'boost:x64-windows' }
# accept legacy
'port-name: "all_modules"' = $false, @{name = 'all_modules' } # removed in json-schema
# reject reserved keywords
'port-name: "prn"' = $false, @{name = 'prn' }
'port-name: "aux"' = $false, @{name = 'aux' }
'port-name: "nul"' = $false, @{name = 'nul' }
'port-name: "con"' = $false, @{name = 'con' }
'port-name: "core"' = $false, @{name = 'core' }
'port-name: "default"' = $false, @{name = 'default' }
'port-name: "lpt0"' = $false, @{name = 'lpt0' }
'port-name: "lpt9"' = $false, @{name = 'lpt9' }
'port-name: "com0"' = $false, @{name = 'com0' }
'port-name: "com9"' = $false, @{name = 'com9' }
# reject incomplete segments
'port-name: "-a"' = $false, @{name = '-a' }
'port-name: "a-"' = $false, @{name = 'a-' }
'port-name: "a--"' = $false, @{name = 'a--' }
'port-name: "---"' = $false, @{name = '---' }
}
}.GetEnumerator()
| ForEach-Object {
@{
SchemaName = $_.Key
JsonCases = $_.Value.GetEnumerator() | ForEach-Object { @{Title = $_.Key; Expected = $_.Value[0]; Json = ConvertTo-Json -InputObject $_.Value[1] -Depth 5 -Compress } }
}
}
| ForEach-Object {
$_SchemaName = $_.SchemaName
$_SchemaPath = Join-Path $TempWorkDir $_SchemaName
$_.JsonCases | ForEach-Object {
$_Title = $_.Title
$_Expected = $_.Expected
$_Actual = Test-Json -ea:0 -Json $_.Json -SchemaFile $_SchemaPath
$_Result = $_.Expected -eq $_Actual ? 'Pass':'Fail'
if ($_Result -eq 'Fail') {
throw "$_SchemaName validate fail with $_Title, expected $_Expected"
}
[pscustomobject]@{
SchemaName = $_SchemaName
Title = $_Title
Expected = $_Expected
Actual = $_Actual
Result = $_Result
}
}
}
| Sort-Object SchemaName, Title
| Format-Table
Remove-Item -Recurse -Force $TempWorkDir Schema param(
[string]$VcpkgSrcDir = (Join-Path $PSScriptRoot '../..' | Resolve-Path),
[string]$VcpkgRegistryDir = $env:VCPKG_ROOT,
[string]$TempWorkDir = (New-Item -ItemType Directory Temp:/$(New-Guid)).FullName
)
$ErrorActionPreference = 'Stop'
# . $PSScriptRoot/../end-to-end-tests-prelude.ps1
$VcpkgJsonSchema = @{
Artifact = 'artifact.schema.json'
Configuration = 'vcpkg-configuration.schema.json'
Definitions = 'vcpkg-schema-definitions.schema.json'
Port = 'vcpkg.schema.json'
}
# remove `$id` in schema for error 'Test-Json: Cannot parse the JSON schema.'
$VcpkgJsonSchema.Values
| ForEach-Object {
Copy-Item -Path (Join-path $VcpkgSrcDir 'docs' $_) -Destination $TempWorkDir
Join-Path $TempWorkDir $_
}
| ForEach-Object {
(Get-Content -Raw -Path $_) -replace '(?s)\n "\$id".+?\n', "`n"
| Set-Content -NoNewline -Path $_
}
| Out-Null
$VcpkgPortSchemaPath = Join-Path $TempWorkDir $VcpkgJsonSchema.Port
Get-ChildItem -Directory -Path (Join-Path $VcpkgRegistryDir 'ports')
| ForEach-Object -Parallel {
$PortName = $_.Name
$PortDir = $_.FullName
$PortJsonPath = Join-Path $PortDir 'vcpkg.json'
$Schema = $using:VcpkgPortSchemaPath
$_Actual = Test-Json -ea:0 -LiteralPath $PortJsonPath -SchemaFile $Schema
[pscustomobject]@{
PortName = $PortName
Actual = $_Actual
}
}
| ForEach-Object { Write-Host $_; $_ }
| Where-Object Actual -EQ $false
| ForEach-Object { Write-Error $_; $_ }
Remove-Item -Recurse -Force $TempWorkDir |
e03dc04
to
5b68e3c
Compare
Is this actually accepted by the product code? |
This was done to give better intellisense behavior / descriptive text. But I think it's fine to remove it. |
5b68e3c
to
3237f31
Compare
There are some places to parse the pattern:
And there are some test cases covering it:
|
3237f31
to
374a145
Compare
55a31ac
to
9b04d30
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This 'request changes' is only for the nonstandard tests being in end-to-end-tests-dir
, all other comments in here are extreme nitpicks you can take or leave.
azure-pipelines/end-to-end-tests-dir/json-schema-bvt-generic.ps1
Outdated
Show resolved
Hide resolved
azure-pipelines/end-to-end-tests-dir/json-schema-bvt-generic.ps1
Outdated
Show resolved
Hide resolved
Oh, and thanks for the fixes! |
9b04d30
to
ea20077
Compare
ea20077
to
c143456
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix!
Fix microsoft/vcpkg/issues/39259 for package pattern with an optional trailing *.
Change
definitions/reserved-name
for reuse^(core|default)$
^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\\.[^.]+)*$
, which includeCOM0
andLPT0
. See documentsdefinitions/package-pattern
to fix optional trailing*
^([a-z0-9]+-)*([a-z0-9]+[*]?|[*])$
to match wildcard or ‘boost*’ or ‘boost-*’definitions/port-name
withdefinitions/identifier
port-name
matches 'dot-separated identifier'. No relevant documents found, remove this definition.identifier
matches 'lowercase with digits and dashes'#
to$schema
pr.yaml
Test
Schema
vcpkg.schema.json
validated all portsvcpkg.json
withjson-schema-tests-dir/vcpkg-ports-json.test.ps1
.Schema
vcpkg-configuration.schema.json
tested pass withjson-schema-tests-dir/json-schema-bvt.test.ps1