From 8fcdc01827c2a7063e7511ae9cf25adc7fc0741c Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Thu, 2 Nov 2017 13:52:17 -0700 Subject: [PATCH] Refactor for signing (#5300) --- build.psm1 | 8 ++- tools/packaging/packaging.psm1 | 49 ++++++++++++++++--- .../PowerShellPackage.ps1 | 5 +- 3 files changed, 51 insertions(+), 11 deletions(-) diff --git a/build.psm1 b/build.psm1 index 99e00c228c..c87fe1aeb2 100644 --- a/build.psm1 +++ b/build.psm1 @@ -438,6 +438,7 @@ Fix steps: Configuration=$Configuration Verbose=$true SMAOnly=[bool]$SMAOnly + PSModuleRestore=$PSModuleRestore } $script:Options = New-PSOptions @OptionsArguments @@ -602,7 +603,9 @@ function New-PSOptions { [string]$Output, - [switch]$SMAOnly + [switch]$SMAOnly, + + [switch]$PSModuleRestore ) # Add .NET CLI tools to PATH @@ -716,7 +719,8 @@ function New-PSOptions { Framework = $Framework; Runtime = $Runtime; Output = $Output; - CrossGen = $CrossGen } + CrossGen = $CrossGen + PSModuleRestore = $PSModuleRestore } } # Get the Options of the last build diff --git a/tools/packaging/packaging.psm1 b/tools/packaging/packaging.psm1 index 8f9aed023a..9604009042 100644 --- a/tools/packaging/packaging.psm1 +++ b/tools/packaging/packaging.psm1 @@ -83,11 +83,19 @@ function Start-PSPackage { # crossgen doesn't support arm32 yet $crossGenCorrect = $true } - elseif(-not $IncludeSymbols.IsPresent -and $Script:Options.CrossGen) { + elseif($Script:Options.CrossGen) { $crossGenCorrect = $true } - elseif ($IncludeSymbols.IsPresent) { - $crossGenCorrect = $true + + $PSModuleRestoreCorrect = $false + + # Require PSModuleRestore for packaging without symbols + # But Disallow it when packaging with symbols + if (!$IncludeSymbols.IsPresent -and $Script:Options.PSModuleRestore) { + $PSModuleRestoreCorrect = $true + } + elseif ($IncludeSymbols.IsPresent -and !$Script:Options.PSModuleRestore) { + $PSModuleRestoreCorrect = $true } # Make sure the most recent build satisfies the package requirement @@ -108,10 +116,11 @@ function Start-PSPackage { # also ensure `Start-PSPackage` does what the user asks/expects, because once packages # are generated, it'll be hard to verify if they were built from the correct content. $params = @('-Clean') - if(-not $IncludeSymbols.IsPresent) - { - $params += '-CrossGen' + $params += '-CrossGen' + if (!$IncludeSymbols.IsPresent) { + $params += '-PSModuleRestore' } + $params += '-Runtime', $Runtime $params += '-Configuration', $Configuration @@ -140,9 +149,35 @@ function Start-PSPackage { # If building a symbols package, don't include the publish build. if ($IncludeSymbols.IsPresent) { + $publishSource = $Source $buildSource = Split-Path -Path $Source -Parent $Source = New-TempFolder - Get-ChildItem -Path $buildSource | Where-Object {$_.Name -ine 'Publish'} | Copy-Item -Destination $Source -Recurse + + # files not to include as individual files. These files will be included in publish.zip + $toExclude = @( + 'hostfxr.dll' + 'hostpolicy.dll' + 'libhostfxr.so' + 'libhostpolicy.so' + 'libhostfxr.dylib' + 'libhostpolicy.dylib' + 'Publish' + ) + Get-ChildItem -Path $buildSource | Where-Object {$toExclude -inotcontains $_.Name} | Copy-Item -Destination $Source -Recurse + + # Replace binaries with crossgen'ed binaires from publish folder. + Get-ChildItem -Recurse $Source | ForEach-Object { + $relativePath = $_.FullName -replace $Source, '' + $publishPath = Join-Path $publishSource -ChildPath $relativePath + if (Test-Path -Path $publishPath) + { + Copy-Item -Path $publishPath -Destination $_.FullName -Force + } + } + + $zipSource = Join-Path $publishSource -ChildPath '*' + $zipPath = Join-Path -Path $Source -ChildPath 'publish.zip' + Compress-Archive -Path $zipSource -DestinationPath $zipPath } log "Packaging Source: '$Source'" diff --git a/tools/releaseBuild/Images/microsoft_powershell_windowsservercore/PowerShellPackage.ps1 b/tools/releaseBuild/Images/microsoft_powershell_windowsservercore/PowerShellPackage.ps1 index eb41c6bf48..b8f9d9eb5b 100644 --- a/tools/releaseBuild/Images/microsoft_powershell_windowsservercore/PowerShellPackage.ps1 +++ b/tools/releaseBuild/Images/microsoft_powershell_windowsservercore/PowerShellPackage.ps1 @@ -61,12 +61,13 @@ try{ Write-Verbose "Starting powershell build for RID: $Runtime and ReleaseTag: $ReleaseTag ..." -verbose $buildParams = @{} + $buildParams['CrossGen'] = $true if(!$Symbols.IsPresent) { - $buildParams['CrossGen'] = $true + $buildParams['PSModuleRestore'] = $true } - Start-PSBuild -Clean -PSModuleRestore -Runtime $Runtime -Configuration Release @releaseTagParam @buildParams + Start-PSBuild -Clean -Runtime $Runtime -Configuration Release @releaseTagParam @buildParams $pspackageParams = @{'Type'='msi'} if ($Runtime -ne 'win10-x64')