From f08de6b0be3427a032ae86d1cee487e769bf1c4e Mon Sep 17 00:00:00 2001 From: pomianowski Date: Sat, 17 Sep 2022 15:22:53 +0200 Subject: [PATCH] Initialize build scripts --- SECURITY.md | 13 +++ build.cmd | 4 + scripts/build_demo.ps1 | 1 + scripts/build_extension.ps1 | 1 + scripts/build_library.ps1 | 1 + scripts/dotnet_build.ps1 | 127 +++++++++++++++++++++++++++++ scripts/msbuild_build.ps1 | 158 ++++++++++++++++++++++++++++++++++++ 7 files changed, 305 insertions(+) create mode 100644 SECURITY.md create mode 100644 build.cmd create mode 100644 scripts/build_demo.ps1 create mode 100644 scripts/build_extension.ps1 create mode 100644 scripts/build_library.ps1 create mode 100644 scripts/dotnet_build.ps1 create mode 100644 scripts/msbuild_build.ps1 diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 000000000..eb998bf79 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,13 @@ +# Security Policy + +## Supported Versions + +At the moment, the only supported version of the **WPF UI** is the newest one. You can find it on _NuGet_. +https://www.nuget.org/packages/wpf-ui/ + +## Reporting a Vulnerability + +Security issues and bugs should be reported privately, by emailing support (at) lepo.co +lepo.co does not offer Bug Bounty for the **WPF UI** library. + +Please do not open issues for anything you think might have a security implication. diff --git a/build.cmd b/build.cmd new file mode 100644 index 000000000..242094145 --- /dev/null +++ b/build.cmd @@ -0,0 +1,4 @@ +@echo off +powershell -ExecutionPolicy ByPass -NoProfile -command "& """%~dp0scripts\build_demo.ps1"""" +@REM powershell -ExecutionPolicy ByPass -NoProfile -command "& """%~dp0scripts\build_extension.ps1"""" +exit /b %ErrorLevel% \ No newline at end of file diff --git a/scripts/build_demo.ps1 b/scripts/build_demo.ps1 new file mode 100644 index 000000000..537322dac --- /dev/null +++ b/scripts/build_demo.ps1 @@ -0,0 +1 @@ +. $PSScriptRoot\dotnet_build.ps1 -restore -build -solution Wpf.Ui.Demo.sln \ No newline at end of file diff --git a/scripts/build_extension.ps1 b/scripts/build_extension.ps1 new file mode 100644 index 000000000..c1cc56708 --- /dev/null +++ b/scripts/build_extension.ps1 @@ -0,0 +1 @@ +. $PSScriptRoot\msbuild_build.ps1 -restore -build -solution Wpf.Ui.Extension.sln \ No newline at end of file diff --git a/scripts/build_library.ps1 b/scripts/build_library.ps1 new file mode 100644 index 000000000..bb7aa2fb8 --- /dev/null +++ b/scripts/build_library.ps1 @@ -0,0 +1 @@ +. $PSScriptRoot\dotnet_build.ps1 -restore -build -solution Wpf.Ui.sln \ No newline at end of file diff --git a/scripts/dotnet_build.ps1 b/scripts/dotnet_build.ps1 new file mode 100644 index 000000000..f69f70b51 --- /dev/null +++ b/scripts/dotnet_build.ps1 @@ -0,0 +1,127 @@ +# Copyright 2022 Leszek Pomianowski and WPF UI Contributors + +[CmdletBinding(PositionalBinding = $false)] +Param( + [string][Alias('c')]$configuration = "Release", + [string][Alias('v')]$verbosity = "minimal", + [string][Alias('p')]$platform = "AnyCPU", + [string][Alias('s')]$solution = "", + [switch][Alias('r')]$restore, + [switch][Alias('b')]$build, + [switch] $nologo, + [switch] $help, + [Parameter(ValueFromRemainingArguments = $true)][String[]]$properties +) + +$Script:BuildPath = "" + +function Invoke-Help { + Write-Host "Common settings:" + Write-Host " -configuration Build configuration: 'Debug' or 'Release' (short: -c)" + Write-Host " -platform Platform configuration: 'x86', 'x64' or any valid Platform value to pass to msbuild" + Write-Host " -verbosity Msbuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic] (short: -v)" + Write-Host " -nologo Doesn't display the startup banner or the copyright message" + Write-Host " -help Print help and exit" + Write-Host "" + + Write-Host "Actions:" + Write-Host " -restore Restore dependencies (short: -r)" + Write-Host " -build Build solution (short: -b)" + Write-Host "" +} + +function Invoke-Hello { + if ($nologo) { + return + } + + $TextInfo = (Get-Culture).TextInfo + + Write-Host " -------------------" -ForegroundColor Cyan + Write-Host "| " -NoNewline -ForegroundColor Cyan + Write-Host " WPF UI" -NoNewline -ForegroundColor White + Write-Host " | "-ForegroundColor Cyan + Write-Host "| " -NoNewline -ForegroundColor Cyan + Write-Host " lepo.co 2021-$(Get-Date -UFormat "%Y")" -NoNewline -ForegroundColor Gray + Write-Host " | " -ForegroundColor Cyan + Write-Host " ------------------ - " -ForegroundColor Cyan + Write-Host "" + Write-Host "Solution: " -NoNewline + Write-Host "$($Script:Solution)" -ForegroundColor Cyan + Write-Host "Platform: " -NoNewline + Write-Host "$($TextInfo.ToTitleCase($platform))" -ForegroundColor Cyan + Write-Host "Configuration: " -NoNewline + Write-Host "$($TextInfo.ToTitleCase($configuration))" -ForegroundColor Cyan + Write-Host "Verbosity: " -NoNewline + Write-Host "$($TextInfo.ToTitleCase($verbosity))" -ForegroundColor Cyan + Write-Host "" +} + +function Invoke-ExitWithExitCode([int] $exitCode) { + if ($ci -and $prepareMachine) { + Stop-Processes + } + + exit $exitCode +} + +function Initialize-Script { + + if ((Test-Path "$($PSScriptRoot)\..\src\$($solution)") -eq $False) { + Write-Host "Solution $($PSScriptRoot)\..\src\$($solution) not found" -ForegroundColor Red + Invoke-ExitWithExitCode 1 + } + + $Script:BuildPath = (Resolve-Path -Path "$($PSScriptRoot)\..\src\$($solution)").ToString() +} + +function Initialize-Toolset { + +} + +function Invoke-Restore { + if (-not $restore) { + return + } + + dotnet restore $Script:BuildPath --verbosity $verbosity + + if ($lastExitCode -ne 0) { + Write-Host "Restore failed" -ForegroundColor Red + + Invoke-ExitWithExitCode $LastExitCode + } +} + +function Invoke-Build { + if (-not $build) { + return + } + + dotnet build $Script:BuildPath --configuration $configuration --verbosity $verbosity --no-restore --nologo + + if ($lastExitCode -ne 0) { + Write-Host "Build failed" -ForegroundColor Red + Invoke-ExitWithExitCode $LastExitCode + } +} + +if ($help) { + Invoke-Help + + exit 0 +} + +[timespan]$execTime = Measure-Command { + Invoke-Hello | Out-Default + Initialize-Script | Out-Default + Initialize-Toolset | Out-Default + Invoke-Restore | Out-Default + Invoke-Build | Out-Default +} + +Write-Host "Finished in " -NoNewline +Write-Host "$($execTime.Minutes) min $($execTime.Seconds),$($execTime.Milliseconds) s." -ForegroundColor Cyan + +Write-Host "Finished at " -NoNewline +Write-Host "$(Get-Date -UFormat "%d.%m.%Y %R")" -ForegroundColor Cyan \ No newline at end of file diff --git a/scripts/msbuild_build.ps1 b/scripts/msbuild_build.ps1 new file mode 100644 index 000000000..b1fc458e8 --- /dev/null +++ b/scripts/msbuild_build.ps1 @@ -0,0 +1,158 @@ +# Copyright 2022 Leszek Pomianowski and WPF UI Contributors + +[CmdletBinding(PositionalBinding = $false)] +Param( + [string][Alias('c')]$configuration = "Release", + [string][Alias('v')]$verbosity = "minimal", + [string][Alias('p')]$platform = "AnyCPU", + [string][Alias('s')]$solution = "", + [switch][Alias('r')]$restore, + [switch][Alias('b')]$build, + [switch] $nologo, + [switch] $help, + [Parameter(ValueFromRemainingArguments = $true)][String[]]$properties +) + +$Script:BuildPath = "" +$Script:VsPath = "" + +function Invoke-Help { + Write-Host "Common settings:" + Write-Host " -configuration Build configuration: 'Debug' or 'Release' (short: -c)" + Write-Host " -platform Platform configuration: 'x86', 'x64' or any valid Platform value to pass to msbuild" + Write-Host " -verbosity Msbuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic] (short: -v)" + Write-Host " -nologo Doesn't display the startup banner or the copyright message" + Write-Host " -help Print help and exit" + Write-Host "" + + Write-Host "Actions:" + Write-Host " -restore Restore dependencies (short: -r)" + Write-Host " -build Build solution (short: -b)" + Write-Host "" +} + +function Invoke-Hello { + if ($nologo) { + return + } + + $TextInfo = (Get-Culture).TextInfo + + Write-Host " -------------------" -ForegroundColor Cyan + Write-Host "| " -NoNewline -ForegroundColor Cyan + Write-Host " WPF UI" -NoNewline -ForegroundColor White + Write-Host " | "-ForegroundColor Cyan + Write-Host "| " -NoNewline -ForegroundColor Cyan + Write-Host " lepo.co 2021-$(Get-Date -UFormat "%Y")" -NoNewline -ForegroundColor Gray + Write-Host " | " -ForegroundColor Cyan + Write-Host " ------------------ - " -ForegroundColor Cyan + Write-Host "" + Write-Host "Solution: " -NoNewline + Write-Host "$($Script:Solution)" -ForegroundColor Cyan + Write-Host "Platform: " -NoNewline + Write-Host "$($TextInfo.ToTitleCase($platform))" -ForegroundColor Cyan + Write-Host "Configuration: " -NoNewline + Write-Host "$($TextInfo.ToTitleCase($configuration))" -ForegroundColor Cyan + Write-Host "Verbosity: " -NoNewline + Write-Host "$($TextInfo.ToTitleCase($verbosity))" -ForegroundColor Cyan + Write-Host "" +} + +function Invoke-ExitWithExitCode([int] $exitCode) { + if ($ci -and $prepareMachine) { + Stop-Processes + } + + exit $exitCode +} + +function Initialize-Script { + + if ((Test-Path "$($PSScriptRoot)\..\src\$($solution)") -eq $False) { + Write-Host "Solution $($PSScriptRoot)\..\src\$($solution) not found" -ForegroundColor Red + Invoke-ExitWithExitCode 1 + } + + $Script:BuildPath = (Resolve-Path -Path "$($PSScriptRoot)\..\src\$($solution)").ToString() +} + +function Initialize-VisualStudio { + + if ((Test-Path "C:\Program Files\Microsoft Visual Studio\2022\Community\Msbuild\Current\Bin") -ne $False) { + $Script:VsPath = "C:\Program Files\Microsoft Visual Studio\2022\Community\Msbuild\Current\Bin\"; + } + elseif ((Test-Path "C:\Program Files\Microsoft Visual Studio\2022\Preview\Msbuild\Current\Bin") -ne $False) { + $Script:VsPath = "C:\Program Files\Microsoft Visual Studio\2022\Preview\Msbuild\Current\Bin\"; + } + elseif ((Test-Path "C:\Program Files\Microsoft Visual Studio\2022\Professional\Msbuild\Current\Bin") -ne $False) { + $Script:VsPath = "C:\Program Files\Microsoft Visual Studio\2022\Professional\Msbuild\Current\Bin\"; + } + elseif ((Test-Path "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Msbuild\Current\Bin") -ne $False) { + $Script:VsPath = "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Msbuild\Current\Bin\"; + } + elseif ((Test-Path "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Msbuild\Current\Bin") -ne $False) { + $Script:VsPath = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Msbuild\Current\Bin\"; + } + elseif ((Test-Path "C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\Msbuild\Current\Bin") -ne $False) { + $Script:VsPath = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\Msbuild\Current\Bin\"; + } + elseif ((Test-Path "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Msbuild\Current\Bin") -ne $False) { + $Script:VsPath = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Msbuild\Current\Bin\"; + } + elseif ((Test-Path "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Msbuild\Current\Bin") -ne $False) { + $Script:VsPath = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Msbuild\Current\Bin\"; + } + else { + Write-Host "Visual Studio 2022 or 2019 not found." -ForegroundColor Red + Invoke-ExitWithExitCode 1 + } +} + +function Invoke-Build { + if (-not $build) { + return + } + + $msBuild = "$($Script:VsPath)MSBuild.exe" + + if ($platform.ToLower() -eq "anycpu") { + $platform = "Any CPU" + } + + if ($restore) { + & $msBuild $Script:BuildPath ` + /target:Clean ` + /target:Build ` + /p:Configuration=$configuration ` + /p:Platform="$($platform)" ` + --verbosity:$verbosity ` + --restore + } + else { + & $msBuild $Script:BuildPath ` + /target:Clean ` + /target:Build ` + /p:Configuration=$configuration ` + /p:Platform="$($platform)" ` + --verbosity:$verbosity + } +} + +if ($help) { + Invoke-Help + + exit 0 +} + +[timespan]$execTime = Measure-Command { + Invoke-Hello | Out-Default + Initialize-Script | Out-Default + Initialize-VisualStudio | Out-Default + Invoke-Build | Out-Default +} + +Write-Host "Finished in " -NoNewline +Write-Host "$($execTime.Minutes) min $($execTime.Seconds),$($execTime.Milliseconds) s." -ForegroundColor Cyan + +Write-Host "Finished at " -NoNewline +Write-Host "$(Get-Date -UFormat "%d.%m.%Y %R")" -ForegroundColor Cyan \ No newline at end of file