Skip to content

Commit

Permalink
Support building assembly with Debug configuration (pester#2339)
Browse files Browse the repository at this point in the history
  • Loading branch information
fflaten authored May 6, 2023
1 parent e1f2361 commit 548b002
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
.PARAMETER Clean
Cleans the build folder ./bin and rebuilds the assemblies.
.PARAMETER Configuration
The configuration used to build the assemblies. Only used in combination with -Clean. Defaults to Release.
.PARAMETER LockedRestore
Restore nuget packages using the nuget lock file. Useful only for CI.
Expand All @@ -45,12 +48,17 @@
$env:PESTER_BUILD_INLINE=1 environment variable is used to force inlining in files that don't provide
the -Inline parameter. When this gets stuck, and you see your module inline even when it should not,
use -Inline:$false to reset it to 0.
.PARAMETER Inline
Builds the module as a single Pester.psm1-file, instead of dot-sourcing the files. This is the mode used in release build.
#>

[CmdletBinding()]
param (
[switch] $Load,
[switch] $Clean,
[ValidateSet('Debug', 'Release')]
[string] $Configuration = 'Release',
[switch] $LockedRestore,
[switch] $Inline,
[switch] $Import
Expand All @@ -60,7 +68,7 @@ $ErrorActionPreference = 'Stop'
Get-Module Pester | Remove-Module

if ($Clean -and $PSVersionTable.PSVersion -lt [version]'5.1') {
throw "Clean build of Pester requires PowerShell 5.1 or greater. If you have already compiled the assemblies and only modified powershell-files, try calling ./build.ps1 without -Clean."
throw 'Clean build of Pester requires PowerShell 5.1 or greater. If you have already compiled the assemblies and only modified powershell-files, try calling ./build.ps1 without -Clean.'
}

if ($Clean -and (Test-Path "$PSScriptRoot/bin")) {
Expand All @@ -71,16 +79,16 @@ if ($Clean) {
# Import-LocalizedData (and ModuleVersion-property) used as workaround due to unknown error on PS3 build with Test-ModuleManifest
# and because Test-ModuleManifest needs the psd1 and psm1 to be complete, but we want to generate help for config from the type
# so we need to build up here, and not after the module build, so xml based solution is better than one that validates the manifest
$manifest = Import-LocalizedData -FileName "Pester.psd1" -BaseDirectory "$PSScriptRoot/src"
$manifest = Import-LocalizedData -FileName 'Pester.psd1' -BaseDirectory "$PSScriptRoot/src"
if (-not $LockedRestore) {
dotnet restore "$PSScriptRoot/src/csharp/Pester.sln"
}
else {
else {
dotnet restore "$PSScriptRoot/src/csharp/Pester.sln" --locked-mode
}
dotnet build "$PSScriptRoot/src/csharp/Pester.sln" --no-restore --configuration Release -p:VersionPrefix="$($manifest.ModuleVersion)" -p:VersionSuffix="$($manifest.PrivateData.PSData.Prerelease)"
dotnet build "$PSScriptRoot/src/csharp/Pester.sln" --no-restore --configuration $Configuration -p:VersionPrefix="$($manifest.ModuleVersion)" -p:VersionSuffix="$($manifest.PrivateData.PSData.Prerelease)"
if (0 -ne $LASTEXITCODE) {
throw "build failed!"
throw 'build failed!'
}
}

Expand All @@ -106,10 +114,10 @@ $content = @(

if ($Clean) {
$content += @(
, ("$PSScriptRoot/src/csharp/Pester/bin/Release/net452/Pester.dll", "$PSScriptRoot/bin/bin/net452/")
, ("$PSScriptRoot/src/csharp/Pester/bin/Release/net452/Pester.pdb", "$PSScriptRoot/bin/bin/net452/")
, ("$PSScriptRoot/src/csharp/Pester/bin/Release/netstandard2.0/Pester.dll", "$PSScriptRoot/bin/bin/netstandard2.0/")
, ("$PSScriptRoot/src/csharp/Pester/bin/Release/netstandard2.0/Pester.pdb", "$PSScriptRoot/bin/bin/netstandard2.0/")
, ("$PSScriptRoot/src/csharp/Pester/bin/$Configuration/net452/Pester.dll", "$PSScriptRoot/bin/bin/net452/")
, ("$PSScriptRoot/src/csharp/Pester/bin/$Configuration/net452/Pester.pdb", "$PSScriptRoot/bin/bin/net452/")
, ("$PSScriptRoot/src/csharp/Pester/bin/$Configuration/netstandard2.0/Pester.dll", "$PSScriptRoot/bin/bin/netstandard2.0/")
, ("$PSScriptRoot/src/csharp/Pester/bin/$Configuration/netstandard2.0/Pester.pdb", "$PSScriptRoot/bin/bin/netstandard2.0/")
)
}

Expand Down Expand Up @@ -160,10 +168,10 @@ if ($Clean) {
}

# generate help for config object and insert it
$configuration = [PesterConfiguration]::Default
$configObject = [PesterConfiguration]::Default
$eol = [Environment]::NewLine
$generatedConfig = foreach ($p in $configuration.PSObject.Properties.Name) {
$section = $configuration.($p)
$generatedConfig = foreach ($p in $configObject.PSObject.Properties.Name) {
$section = $configObject.($p)
"${p}:"
foreach ($r in $section.PSObject.Properties.Name) {
$option = $section.$r
Expand All @@ -174,9 +182,9 @@ if ($Clean) {

$p = "$PSScriptRoot/src/Pester.RSpec.ps1"
# in older versions utf8 means with BOM
$e = if ($PSVersionTable.PSVersion.Major -ge 7) { "utf8BOM" } else { "utf8" }
$e = if ($PSVersionTable.PSVersion.Major -ge 7) { 'utf8BOM' } else { 'utf8' }
$f = Get-Content $p -Encoding $e
$sbf = [System.Text.StringBuilder]""
$sbf = [System.Text.StringBuilder]''
$generated = $false
foreach ($l in $f) {
if ($l -match '^(?<margin>\s*)Sections and options:\s*$') {
Expand All @@ -199,7 +207,7 @@ if ($Clean) {
}
}
}
elseif ($generated -and ($l -match "^\s*(.PARAMETER|.EXAMPLE).*")) {
elseif ($generated -and ($l -match '^\s*(.PARAMETER|.EXAMPLE).*')) {
$generated = $false
}

Expand All @@ -211,7 +219,7 @@ if ($Clean) {
Set-Content -Encoding $e -Value $sbf.ToString().TrimEnd() -Path $p

# generate PesterConfiguration.Format.ps1xml to ensure list view for all sections
$configSections = $configuration.GetType().Assembly.GetExportedTypes() | Where-Object { $_.BaseType -eq [Pester.ConfigurationSection] }
$configSections = $configObject.GetType().Assembly.GetExportedTypes() | Where-Object { $_.BaseType -eq [Pester.ConfigurationSection] }
# Get internal ctor as public ctor always returns instanceId = zero guid prior to PS v7.1.0
$formatViewCtor = [System.Management.Automation.FormatViewDefinition].GetConstructors('Instance,NonPublic')
# Generate listcontrol views for all configuration sections
Expand Down

0 comments on commit 548b002

Please sign in to comment.