fix encoding in created files
This commit is contained in:
parent
cfad0a4346
commit
e373f4ffb1
@ -1,139 +1,139 @@
|
|||||||
function Get-SwiftWinRTVersion {
|
function Get-SwiftWinRTVersion {
|
||||||
$Projections = Get-Content -Path $PSScriptRoot\projections.json | ConvertFrom-Json
|
$Projections = Get-Content -Path $PSScriptRoot\projections.json | ConvertFrom-Json
|
||||||
return $Projections."swift-winrt"
|
return $Projections."swift-winrt"
|
||||||
}
|
}
|
||||||
|
|
||||||
function Get-PackageString {
|
function Get-PackageString {
|
||||||
param(
|
param(
|
||||||
$Package
|
$Package
|
||||||
)
|
)
|
||||||
if ($Package) {
|
if ($Package) {
|
||||||
return " <package id=""$($Package.Id)"" version=""$($Package.Version)"" />`n"
|
return " <package id=""$($Package.Id)"" version=""$($Package.Version)"" />`n"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function Restore-Nuget {
|
function Restore-Nuget {
|
||||||
param(
|
param(
|
||||||
[string]$PackagesDir
|
[string]$PackagesDir
|
||||||
)
|
)
|
||||||
$NugetDownloadPath = Join-Path $env:TEMP "nuget.exe"
|
$NugetDownloadPath = Join-Path $env:TEMP "nuget.exe"
|
||||||
if (-not (Test-Path $NugetDownloadPath)) {
|
if (-not (Test-Path $NugetDownloadPath)) {
|
||||||
Invoke-WebRequest -Uri "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -OutFile $NugetDownloadPath
|
Invoke-WebRequest -Uri "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -OutFile $NugetDownloadPath
|
||||||
}
|
}
|
||||||
|
|
||||||
$Projections = Get-Content -Path $PSScriptRoot\projections.json | ConvertFrom-Json
|
$Projections = Get-Content -Path $PSScriptRoot\projections.json | ConvertFrom-Json
|
||||||
$SwiftWinRTVersion = Get-SwiftWinRTVersion
|
$SwiftWinRTVersion = Get-SwiftWinRTVersion
|
||||||
$PackagesConfigContent = "<?xml version=""1.0"" encoding=""utf-8""?>`n"
|
$PackagesConfigContent = "<?xml version=""1.0"" encoding=""utf-8""?>`n"
|
||||||
$PackagesConfigContent += "<packages>`n"
|
$PackagesConfigContent += "<packages>`n"
|
||||||
$PackagesConfigContent += " <package id=""TheBrowserCompany.SwiftWinRT"" version=""$SwiftWinRTVersion"" />`n"
|
$PackagesConfigContent += " <package id=""TheBrowserCompany.SwiftWinRT"" version=""$SwiftWinRTVersion"" />`n"
|
||||||
if ($Projections.Package) {
|
if ($Projections.Package) {
|
||||||
$PackagesConfigContent += Get-PackageString -Package $Projections.Package
|
$PackagesConfigContent += Get-PackageString -Package $Projections.Package
|
||||||
}
|
}
|
||||||
|
|
||||||
$Projections.Packages | ForEach-Object {
|
$Projections.Packages | ForEach-Object {
|
||||||
$PackagesConfigContent += Get-PackageString -Package $_
|
$PackagesConfigContent += Get-PackageString -Package $_
|
||||||
}
|
}
|
||||||
$Projections.Dependencies | ForEach-Object {
|
$Projections.Dependencies | ForEach-Object {
|
||||||
$PackagesConfigContent += Get-PackageString -Package $_
|
$PackagesConfigContent += Get-PackageString -Package $_
|
||||||
}
|
}
|
||||||
$PackagesConfigContent += "</packages>"
|
$PackagesConfigContent += "</packages>"
|
||||||
if (-not (Test-Path "$PSScriptRoot\.packages")) {
|
if (-not (Test-Path "$PSScriptRoot\.packages")) {
|
||||||
New-Item -ItemType Directory -Path "$PSScriptRoot\.packages" | Out-Null
|
New-Item -ItemType Directory -Path "$PSScriptRoot\.packages" | Out-Null
|
||||||
}
|
}
|
||||||
$PackagesConfigPath = Join-Path $PSScriptRoot ".packages\packages.config"
|
$PackagesConfigPath = Join-Path $PSScriptRoot ".packages\packages.config"
|
||||||
$PackagesConfigContent | Out-File -FilePath $PackagesConfigPath
|
$PackagesConfigContent | Out-File -FilePath $PackagesConfigPath -Encoding ascii
|
||||||
|
|
||||||
& $NugetDownloadPath restore $PackagesConfigPath -PackagesDirectory $PackagesDir | Out-Null
|
& $NugetDownloadPath restore $PackagesConfigPath -PackagesDirectory $PackagesDir | Out-Null
|
||||||
if ($LASTEXITCODE -ne 0) {
|
if ($LASTEXITCODE -ne 0) {
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Get-WinMDInputs() {
|
function Get-WinMDInputs() {
|
||||||
param(
|
param(
|
||||||
$Package
|
$Package
|
||||||
)
|
)
|
||||||
$Id = $Package.Id
|
$Id = $Package.Id
|
||||||
$Version = $Package.Version
|
$Version = $Package.Version
|
||||||
return Get-ChildItem -Path $PackagesDir\$Id.$Version\ -Filter *.winmd -Recurse
|
return Get-ChildItem -Path $PackagesDir\$Id.$Version\ -Filter *.winmd -Recurse
|
||||||
}
|
}
|
||||||
|
|
||||||
function Copy-Project {
|
function Copy-Project {
|
||||||
param(
|
param(
|
||||||
[string]$OutputLocation,
|
[string]$OutputLocation,
|
||||||
[string]$ProjectName
|
[string]$ProjectName
|
||||||
)
|
)
|
||||||
|
|
||||||
if ($ProjectName) {
|
if ($ProjectName) {
|
||||||
$ProjectGeneratedDir = if ($ProjectName -eq "CWinRT") { "$ProjectName" } else { "$ProjectName\Generated" }
|
$ProjectGeneratedDir = if ($ProjectName -eq "CWinRT") { "$ProjectName" } else { "$ProjectName\Generated" }
|
||||||
|
|
||||||
$ProjectDir = Join-Path $PSScriptRoot "Sources\$ProjectGeneratedDir"
|
$ProjectDir = Join-Path $PSScriptRoot "Sources\$ProjectGeneratedDir"
|
||||||
if (Test-Path $ProjectDir) {
|
if (Test-Path $ProjectDir) {
|
||||||
Remove-Item -Path $ProjectDir -Recurse -Force
|
Remove-Item -Path $ProjectDir -Recurse -Force
|
||||||
}
|
}
|
||||||
Copy-Item -Path $OutputLocation\Sources\$ProjectName -Destination $ProjectDir -Recurse -Force
|
Copy-Item -Path $OutputLocation\Sources\$ProjectName -Destination $ProjectDir -Recurse -Force
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Invoke-SwiftWinRT() {
|
function Invoke-SwiftWinRT() {
|
||||||
param(
|
param(
|
||||||
[string]$PackagesDir
|
[string]$PackagesDir
|
||||||
)
|
)
|
||||||
$Projections = Get-Content -Path $PSScriptRoot\projections.json | ConvertFrom-Json
|
$Projections = Get-Content -Path $PSScriptRoot\projections.json | ConvertFrom-Json
|
||||||
|
|
||||||
$SwiftWinRTVersion = Get-SwiftWinRTVersion
|
$SwiftWinRTVersion = Get-SwiftWinRTVersion
|
||||||
# write generated bindings to a temp directory since swiftwinrt will generate all dependencies and the CWinRT
|
# write generated bindings to a temp directory since swiftwinrt will generate all dependencies and the CWinRT
|
||||||
$OutputLocation = Join-Path $PSScriptRoot ".generated"
|
$OutputLocation = Join-Path $PSScriptRoot ".generated"
|
||||||
if (Test-Path $OutputLocation) {
|
if (Test-Path $OutputLocation) {
|
||||||
Remove-Item -Path $OutputLocation -Recurse -Force
|
Remove-Item -Path $OutputLocation -Recurse -Force
|
||||||
}
|
}
|
||||||
|
|
||||||
$RspParams = "-output $OutputLocation`n"
|
$RspParams = "-output $OutputLocation`n"
|
||||||
|
|
||||||
# read projections.json and for each "include" write to -include param. for each "exclude" write to -exclude param
|
# read projections.json and for each "include" write to -include param. for each "exclude" write to -exclude param
|
||||||
$Projections.Include | ForEach-Object {
|
$Projections.Include | ForEach-Object {
|
||||||
$RspParams += "-include $_`n"
|
$RspParams += "-include $_`n"
|
||||||
}
|
}
|
||||||
$Projections.Exclude | ForEach-Object {
|
$Projections.Exclude | ForEach-Object {
|
||||||
$RspParams += "-exclude $_`n"
|
$RspParams += "-exclude $_`n"
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($Projections.Package) {
|
if ($Projections.Package) {
|
||||||
Get-WinMDInputs -Package $Package | ForEach-Object {
|
Get-WinMDInputs -Package $Package | ForEach-Object {
|
||||||
$RspParams += "-input $($_.FullName)`n"
|
$RspParams += "-input $($_.FullName)`n"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$Projections.Packages | ForEach-Object {
|
$Projections.Packages | ForEach-Object {
|
||||||
Get-WinMDInputs -Package $Package | ForEach-Object {
|
Get-WinMDInputs -Package $Package | ForEach-Object {
|
||||||
$RspParams += "-input $($_.FullName)`n"
|
$RspParams += "-input $($_.FullName)`n"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$Projections.Dependencies | ForEach-Object {
|
$Projections.Dependencies | ForEach-Object {
|
||||||
Get-WinMDInputs -Package $Package | ForEach-Object {
|
Get-WinMDInputs -Package $Package | ForEach-Object {
|
||||||
$RspParams += "-input $($_.FullName)`n"
|
$RspParams += "-input $($_.FullName)`n"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# write rsp params to file
|
# write rsp params to file
|
||||||
$RspFile = Join-Path $PSScriptRoot "swift-winrt.rsp"
|
$RspFile = Join-Path $PSScriptRoot "swift-winrt.rsp"
|
||||||
$RspParams | Out-File -FilePath $RspFile
|
$RspParams | Out-File -FilePath $RspFile -Encoding ascii
|
||||||
& $PackagesDir\TheBrowserCompany.SwiftWinRT.$SwiftWinRTVersion\bin\swiftwinrt.exe "@$RspFile"
|
& $PackagesDir\TheBrowserCompany.SwiftWinRT.$SwiftWinRTVersion\bin\swiftwinrt.exe "@$RspFile"
|
||||||
|
|
||||||
if ($LASTEXITCODE -ne 0) {
|
if ($LASTEXITCODE -ne 0) {
|
||||||
Write-Host "swiftwinrt failed with error code $LASTEXITCODE" -ForegroundColor Red
|
Write-Host "swiftwinrt failed with error code $LASTEXITCODE" -ForegroundColor Red
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
$Projections.Projects | ForEach-Object {
|
$Projections.Projects | ForEach-Object {
|
||||||
Copy-Project -OutputLocation $OutputLocation -ProjectName $_
|
Copy-Project -OutputLocation $OutputLocation -ProjectName $_
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($Projections.Project) {
|
if ($Projections.Project) {
|
||||||
Copy-Project -OutputLocation $OutputLocation -ProjectName $Projections.Project
|
Copy-Project -OutputLocation $OutputLocation -ProjectName $Projections.Project
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$PackagesDir = Join-Path $PSScriptRoot ".packages"
|
$PackagesDir = Join-Path $PSScriptRoot ".packages"
|
||||||
Restore-Nuget -PackagesDir $PackagesDir
|
Restore-Nuget -PackagesDir $PackagesDir
|
||||||
Invoke-SwiftWinRT -PackagesDir $PackagesDir
|
Invoke-SwiftWinRT -PackagesDir $PackagesDir
|
||||||
Write-Host "SwiftWinRT bindings generated successfully!" -ForegroundColor Green
|
Write-Host "SwiftWinRT bindings generated successfully!" -ForegroundColor Green
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user