Skip to content

Commit

Permalink
Initialize build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
pomianowski committed Sep 17, 2022
1 parent 3b3c5b7 commit f08de6b
Show file tree
Hide file tree
Showing 7 changed files with 305 additions and 0 deletions.
13 changes: 13 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 4 additions & 0 deletions build.cmd
Original file line number Diff line number Diff line change
@@ -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%
1 change: 1 addition & 0 deletions scripts/build_demo.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
. $PSScriptRoot\dotnet_build.ps1 -restore -build -solution Wpf.Ui.Demo.sln
1 change: 1 addition & 0 deletions scripts/build_extension.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
. $PSScriptRoot\msbuild_build.ps1 -restore -build -solution Wpf.Ui.Extension.sln
1 change: 1 addition & 0 deletions scripts/build_library.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
. $PSScriptRoot\dotnet_build.ps1 -restore -build -solution Wpf.Ui.sln
127 changes: 127 additions & 0 deletions scripts/dotnet_build.ps1
Original file line number Diff line number Diff line change
@@ -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 <value> Build configuration: 'Debug' or 'Release' (short: -c)"
Write-Host " -platform <value> Platform configuration: 'x86', 'x64' or any valid Platform value to pass to msbuild"
Write-Host " -verbosity <value> 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
158 changes: 158 additions & 0 deletions scripts/msbuild_build.ps1
Original file line number Diff line number Diff line change
@@ -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 <value> Build configuration: 'Debug' or 'Release' (short: -c)"
Write-Host " -platform <value> Platform configuration: 'x86', 'x64' or any valid Platform value to pass to msbuild"
Write-Host " -verbosity <value> 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

0 comments on commit f08de6b

Please sign in to comment.