-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgenerate.ps1
More file actions
67 lines (56 loc) · 1.61 KB
/
Copy pathgenerate.ps1
File metadata and controls
67 lines (56 loc) · 1.61 KB
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
#!/usr/bin/env pwsh
param(
[Parameter(Mandatory)]
[string]$Winmd,
[Parameter(Mandatory)]
[string]$Namespace,
[string]$ClassName,
[string]$RefList,
[string]$Codegen = "dynwinrt-codegen"
)
$ErrorActionPreference = "Stop"
$caller = (Get-Location).Path
function Resolve-CallerPath([string]$Path) {
if ([System.IO.Path]::IsPathRooted($Path)) {
return [System.IO.Path]::GetFullPath($Path)
}
return [System.IO.Path]::GetFullPath((Join-Path $caller $Path))
}
$Winmd = Resolve-CallerPath $Winmd
if (-not (Test-Path -LiteralPath $Winmd -PathType Leaf)) {
throw "WinMD was not found: $Winmd"
}
if ($RefList) {
$RefList = Resolve-CallerPath $RefList
if (-not (Test-Path -LiteralPath $RefList -PathType Leaf)) {
throw "Reference list was not found: $RefList"
}
}
$codegenCandidate = Resolve-CallerPath $Codegen
if (Test-Path -LiteralPath $codegenCandidate -PathType Leaf) {
$codegenCommand = $codegenCandidate
} else {
$codegenCommand = (Get-Command $Codegen -ErrorAction Stop).Source
}
$output = Join-Path $PSScriptRoot "generated"
if (Test-Path -LiteralPath $output) {
Remove-Item -LiteralPath $output -Recurse -Force
}
$arguments = @(
"generate",
"--winmd", $Winmd,
"--namespace", $Namespace,
"--lang", "py",
"--output", $output
)
if ($ClassName) {
$arguments += @("--class-name", $ClassName)
}
if ($RefList) {
$arguments += @("--ref-list", $RefList)
}
& $codegenCommand @arguments
if ($LASTEXITCODE -ne 0) {
throw "dynwinrt-codegen failed with exit code $LASTEXITCODE"
}
Write-Host "Generated custom WinMD bindings in $output"