proxy-pool/scripts/verify-proto.ps1

52 lines
1.8 KiB
PowerShell

param(
[string]$Protoc = "protoc",
[string]$IncludePath = $env:PROTOC_INCLUDE,
[string]$OutputPath = ""
)
$ErrorActionPreference = "Stop"
$repositoryRoot = Split-Path -Parent $PSScriptRoot
$protoRoot = Join-Path $repositoryRoot "api/proto"
$source = Join-Path $protoRoot "controlplane/v1/controlplane.proto"
$protocCommand = Get-Command $Protoc -ErrorAction Stop
if ([string]::IsNullOrWhiteSpace($IncludePath)) {
$installationRoot = Split-Path (Split-Path $protocCommand.Source -Parent) -Parent
$candidates = @(
(Join-Path $installationRoot "include"),
"/usr/include",
"/usr/local/include"
)
$IncludePath = $candidates |
Where-Object { Test-Path (Join-Path $_ "google/protobuf/timestamp.proto") } |
Select-Object -First 1
}
if ([string]::IsNullOrWhiteSpace($IncludePath) -or
-not (Test-Path (Join-Path $IncludePath "google/protobuf/timestamp.proto"))) {
throw "protoc well-known type include directory was not found; set PROTOC_INCLUDE"
}
if ([string]::IsNullOrWhiteSpace($OutputPath)) {
$outputDirectory = Join-Path $repositoryRoot ".tmp-proto"
New-Item -ItemType Directory -Force -Path $outputDirectory | Out-Null
$OutputPath = Join-Path $outputDirectory "controlplane.pb"
}
& $protocCommand.Source `
"--proto_path=$protoRoot" `
"--proto_path=$IncludePath" `
"--include_imports" `
"--include_source_info" `
"--descriptor_set_out=$OutputPath" `
$source
if ($LASTEXITCODE -ne 0) {
throw "protoc descriptor compilation failed with exit code $LASTEXITCODE"
}
$descriptor = Get-Item -LiteralPath $OutputPath
if ($descriptor.Length -le 0) {
throw "protoc produced an empty descriptor set"
}
Write-Host "descriptor: $($descriptor.FullName) ($($descriptor.Length) bytes)"