Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 60 additions & 28 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ function Start-PSBuild {
# If this parameter is not provided it will get determined automatically.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adityapatwardhan, your last commit had 1 failures in PowerShell-CI-windows
Set/New/Remove-Service cmdlet tests.Get-Service can get the 'UserName' of a service

Expected a value, but got $null or empty.
at <ScriptBlock>, D:\a\1\s\test\powershell\Modules\Microsoft.PowerShell.Management\Set-Service.Tests.ps1: line 304
304:             $service | Should -Not -BeNullOrEmpty

[ValidateSet("alpine-x64",
"fxdependent",
"fxdependent-win-desktop",
"linux-arm",
"linux-arm64",
"linux-x64",
Expand Down Expand Up @@ -328,7 +329,7 @@ Fix steps:
$Arguments += "--output", (Split-Path $Options.Output)
}

if ($Options.Runtime -like 'win*' -or ($Options.Runtime -eq 'fxdependent' -and $Environment.IsWindows)) {
if ($Options.Runtime -like 'win*' -or ($Options.Runtime -like 'fxdependent*' -and $Environment.IsWindows)) {
$Arguments += "/property:IsWindows=true"
}
else {
Expand Down Expand Up @@ -380,30 +381,50 @@ Fix steps:
}

try {
# Relative paths do not work well if cwd is not changed to project
Push-Location $Options.Top
Write-Log "Run dotnet $Arguments from $pwd"
Start-NativeExecution { dotnet $Arguments }

if ($CrossGen -and $Options.Runtime -ne 'fxdependent') {
## fxdependent package cannot be CrossGen'ed
Start-CrossGen -PublishPath $publishPath -Runtime $script:Options.Runtime
Write-Log "pwsh.exe with ngen binaries is available at: $($Options.Output)"
} else {

if ($Options.Runtime -notlike 'fxdependent*') {
# Relative paths do not work well if cwd is not changed to project
Push-Location $Options.Top

if ($Options.Runtime -like 'win-arm*') {
$Arguments += "/property:SDKToUse=Microsoft.NET.Sdk"
} else {
$Arguments += "/property:SDKToUse=Microsoft.NET.Sdk.WindowsDesktop"
}

Write-Log "Run dotnet $Arguments from $pwd"
Start-NativeExecution { dotnet $Arguments }
Write-Log "PowerShell output: $($Options.Output)"

if ($CrossGen) {
## fxdependent package cannot be CrossGen'ed
Start-CrossGen -PublishPath $publishPath -Runtime $script:Options.Runtime
Write-Log "pwsh.exe with ngen binaries is available at: $($Options.Output)"
}

} else {
$globalToolSrcFolder = Resolve-Path (Join-Path $Options.Top "../Microsoft.PowerShell.GlobalTool.Shim") | Select-Object -ExpandProperty Path

if ($Options.Runtime -eq 'fxdependent') {
$globalToolSrcFolder = Resolve-Path (Join-Path $Options.Top "../Microsoft.PowerShell.GlobalTool.Shim") | Select-Object -ExpandProperty Path
$Arguments += "/property:SDKToUse=Microsoft.NET.Sdk"
} elseif ($Options.Runtime -eq 'fxdependent-win-desktop') {
$Arguments += "/property:SDKToUse=Microsoft.NET.Sdk.WindowsDesktop"
}

try {
Push-Location $globalToolSrcFolder
$Arguments += "--output", $publishPath
Write-Log "Run dotnet $Arguments from $pwd to build global tool entry point"
Start-NativeExecution { dotnet $Arguments }
}
finally {
Pop-Location
}
# Relative paths do not work well if cwd is not changed to project
Push-Location $Options.Top
Write-Log "Run dotnet $Arguments from $pwd"
Start-NativeExecution { dotnet $Arguments }
Write-Log "PowerShell output: $($Options.Output)"

try {
Push-Location $globalToolSrcFolder
$Arguments += "--output", $publishPath
Write-Log "Run dotnet $Arguments from $pwd to build global tool entry point"
Start-NativeExecution { dotnet $Arguments }
}
finally {
Pop-Location
}
}
} finally {
Expand Down Expand Up @@ -479,17 +500,27 @@ function Restore-PSPackage
{
$ProjectDirs = @($Options.Top, "$PSScriptRoot/src/TypeCatalogGen", "$PSScriptRoot/src/ResGen", "$PSScriptRoot/src/Modules")

if ($Options.Runtime -eq 'fxdependent') {
if ($Options.Runtime -like 'fxdependent*') {
$ProjectDirs += "$PSScriptRoot/src/Microsoft.PowerShell.GlobalTool.Shim"
}
}

if ($Force -or (-not (Test-Path "$($Options.Top)/obj/project.assets.json"))) {

if($Options.Runtime -ne 'fxdependent') {
$RestoreArguments = @("--runtime",$Options.Runtime, "--verbosity")
$sdkToUse = if (($Options.Runtime -eq 'fxdependent-win-desktop' -or $Options.Runtime -like 'win*')) { # this is fxd or some windows runtime
if ($Options.Runtime -like 'win-arm*') {
'Microsoft.NET.Sdk'
} else {
'Microsoft.NET.Sdk.WindowsDesktop'
}
} else {
'Microsoft.NET.Sdk'
}

if ($Options.Runtime -notlike 'fxdependent*') {
$RestoreArguments = @("--runtime", $Options.Runtime, "/property:SDKToUse=$sdkToUse", "--verbosity")
} else {
$RestoreArguments = @("--verbosity")
$RestoreArguments = @("/property:SDKToUse=$sdkToUse", "--verbosity")
}

if ($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent) {
Expand Down Expand Up @@ -580,6 +611,7 @@ function New-PSOptions {
[ValidateSet("",
"alpine-x64",
"fxdependent",
"fxdependent-win-desktop",
"linux-arm",
"linux-arm64",
"linux-x64",
Expand Down Expand Up @@ -638,7 +670,7 @@ function New-PSOptions {
}
}

$PowerShellDir = if ($Runtime -like 'win*' -or ($Runtime -eq 'fxdependent' -and $Environment.IsWindows)) {
$PowerShellDir = if ($Runtime -like 'win*' -or ($Runtime -like 'fxdependent*' -and $Environment.IsWindows)) {
"powershell-win-core"
} else {
"powershell-unix"
Expand All @@ -652,7 +684,7 @@ function New-PSOptions {
Write-Verbose "Using framework '$Framework'"
}

$Executable = if ($Runtime -eq 'fxdependent') {
$Executable = if ($Runtime -like 'fxdependent*') {
"pwsh.dll"
} elseif ($Environment.IsLinux -or $Environment.IsMacOS) {
"pwsh"
Expand All @@ -662,7 +694,7 @@ function New-PSOptions {

# Build the Output path
if (!$Output) {
if ($Runtime -eq 'fxdependent') {
if ($Runtime -like 'fxdependent*') {
$Output = [IO.Path]::Combine($Top, "bin", $Configuration, $Framework, "publish", $Executable)
} else {
$Output = [IO.Path]::Combine($Top, "bin", $Configuration, $Framework, $Runtime, "publish", $Executable)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project ToolsVersion="15.0">

<Import Project="..\..\PowerShell.Common.props" />
<PropertyGroup>
Expand All @@ -8,4 +8,10 @@
<RootNamespace>Microsoft.PowerShell.GlobalTool.Shim</RootNamespace>
</PropertyGroup>

<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" Condition="'$(SDKToUse)' == 'Microsoft.NET.Sdk' " />
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" Condition="'$(SDKToUse)' == 'Microsoft.NET.Sdk' " />

<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk.WindowsDesktop" Condition="'$(SDKToUse)' == 'Microsoft.NET.Sdk.WindowsDesktop' " />
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk.WindowsDesktop" Condition="'$(SDKToUse)' == 'Microsoft.NET.Sdk.WindowsDesktop' " />

</Project>
8 changes: 4 additions & 4 deletions src/powershell-win-core/powershell-win-core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
<ApplicationManifest>..\..\assets\pwsh.manifest</ApplicationManifest>
</PropertyGroup>

<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" Condition="'$(RuntimeIdentifier)' == 'win-arm' or '$(RuntimeIdentifier)' == 'win-arm64'" />
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" Condition="'$(RuntimeIdentifier)' == 'win-arm' or '$(RuntimeIdentifier)' == 'win-arm64'" />
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" Condition="'$(SDKToUse)' == 'Microsoft.NET.Sdk' " />
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" Condition="'$(SDKToUse)' == 'Microsoft.NET.Sdk' " />

<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk.WindowsDesktop" Condition="'$(RuntimeIdentifier)' != 'win-arm' and '$(RuntimeIdentifier)' != 'win-arm64'" />
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk.WindowsDesktop" Condition="'$(RuntimeIdentifier)' != 'win-arm' and '$(RuntimeIdentifier)' != 'win-arm64'" />
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk.WindowsDesktop" Condition="'$(SDKToUse)' == 'Microsoft.NET.Sdk.WindowsDesktop' " />
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk.WindowsDesktop" Condition="'$(SDKToUse)' == 'Microsoft.NET.Sdk.WindowsDesktop' " />

<ItemGroup>
<Compile Include="..\powershell\Program.cs" Exclude="bin\**;obj\**;**\*.xproj;packages\**" />
Expand Down
32 changes: 21 additions & 11 deletions tools/packaging/packaging.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function Start-PSPackage {
[string]$Name = "powershell",

# Ubuntu, CentOS, Fedora, macOS, and Windows packages are supported
[ValidateSet("msix", "deb", "osxpkg", "rpm", "msi", "zip", "nupkg", "tar", "tar-arm", "tar-arm64", "tar-alpine", "fxdependent")]
[ValidateSet("msix", "deb", "osxpkg", "rpm", "msi", "zip", "nupkg", "tar", "tar-arm", "tar-arm64", "tar-alpine", "fxdependent", "fxdependent-win-desktop")]
[string[]]$Type,

# Generate windows downlevel package
Expand All @@ -41,7 +41,7 @@ function Start-PSPackage {
)

DynamicParam {
if ("zip" -eq $Type -or "fxdependent" -eq $Type) {
if ("zip" -eq $Type -or "fxdependent" -eq $Type -or "fxdependent-win-desktop" -eq $Type) {
# Add a dynamic parameter '-IncludeSymbols' when the specified package type is 'zip' only.
# The '-IncludeSymbols' parameter can be used to indicate that the package should only contain powershell binaries and symbols.
$ParameterAttr = New-Object "System.Management.Automation.ParameterAttribute"
Expand Down Expand Up @@ -88,6 +88,9 @@ function Start-PSPackage {
if ($Type -eq 'fxdependent') {
$NameSuffix = "win-fxdependent"
Write-Log "Packaging : '$Type'; Packaging Configuration: '$Configuration'"
} elseif ($Type -eq 'fxdependent-win-desktop') {
$NameSuffix = "win-fxdependentWinDesktop"
Write-Log "Packaging : '$Type'; Packaging Configuration: '$Configuration'"
} else {
Write-Log "Packaging RID: '$Runtime'; Packaging Configuration: '$Configuration'"
}
Expand Down Expand Up @@ -120,7 +123,7 @@ function Start-PSPackage {
$actualParams += '-PSModuleRestore'
}

$precheckFailed = if ($Type -eq 'fxdependent' -or $Type -eq 'tar-alpine') {
$precheckFailed = if ($Type -like 'fxdependent*' -or $Type -eq 'tar-alpine') {
## We do not check for runtime and crossgen for framework dependent package.
-not $Script:Options -or ## Start-PSBuild hasn't been executed yet
-not $PSModuleRestoreCorrect -or ## Last build didn't specify '-PSModuleRestore' correctly
Expand Down Expand Up @@ -152,7 +155,7 @@ function Start-PSPackage {
$params = @('-Clean')

# CrossGen cannot be done for framework dependent package as it is runtime agnostic.
if ($Type -ne 'fxdependent') {
if ($Type -notlike 'fxdependent*') {
$params += '-CrossGen'
}

Expand All @@ -164,6 +167,8 @@ function Start-PSPackage {

if ($Type -eq 'fxdependent') {
$params += '-Runtime', 'fxdependent'
} elseif ($Type -eq 'fxdependent-win-desktop') {
$params += '-Runtime', 'fxdependent-win-desktop'
} else {
$params += '-Runtime', $Runtime
}
Expand Down Expand Up @@ -282,7 +287,8 @@ function Start-PSPackage {
New-ZipPackage @Arguments
}
}
"fxdependent" {

{ $_ -like "fxdependent*" } {
## Remove PDBs from package to reduce size.
if(-not $IncludeSymbols.IsPresent) {
Get-ChildItem $Source -Filter *.pdb | Remove-Item -Force
Expand Down Expand Up @@ -3230,6 +3236,7 @@ function New-GlobalToolNupkg
param(
[Parameter(Mandatory)] [string] $LinuxBinPath,
[Parameter(Mandatory)] [string] $WindowsBinPath,
[Parameter(Mandatory)] [string] $WindowsDesktopBinPath,
[Parameter(Mandatory)] [string] $PackageVersion,
[Parameter(Mandatory)] [string] $DestinationPath,
[Parameter(ParameterSetName="UnifiedPackage")] [switch] $UnifiedPackage
Expand All @@ -3241,13 +3248,13 @@ function New-GlobalToolNupkg
Remove-Item -Path (Join-Path $LinuxBinPath 'libssl.so.1.0.0') -Verbose -Force -Recurse

## Remove unnecessary xml files
Get-ChildItem -Path $LinuxBinPath, $WindowsBinPath -Filter *.xml | Remove-Item -Verbose
Get-ChildItem -Path $LinuxBinPath, $WindowsBinPath, $WindowsDesktopBinPath -Filter *.xml | Remove-Item -Verbose

if ($UnifiedPackage)
{
Write-Log "Creating a unified package"
$packageInfo += @{ RootFolder = (New-TempFolder); PackageName = "PowerShell"; Type = "Unified"}
$ShimDllPath = Join-Path $WindowsBinPath "Microsoft.PowerShell.GlobalTool.Shim.dll"
$ShimDllPath = Join-Path $WindowsDesktopBinPath "Microsoft.PowerShell.GlobalTool.Shim.dll"
}
else
{
Expand All @@ -3257,6 +3264,9 @@ function New-GlobalToolNupkg
Write-Log "Reducing size of Windows package"
ReduceFxDependentPackage -Path $WindowsBinPath -KeepWindowsRuntimes

Write-Log "Reducing size of WindowsDesktop package"
ReduceFxDependentPackage -Path $WindowsDesktopBinPath -KeepWindowsRuntimes

Write-Log "Creating a Linux and Windows packages"
$packageInfo += @{ RootFolder = (New-TempFolder); PackageName = "PowerShell.Linux.Alpine"; Type = "PowerShell.Linux.Alpine"}
$packageInfo += @{ RootFolder = (New-TempFolder); PackageName = "PowerShell.Linux.x64"; Type = "PowerShell.Linux.x64"}
Expand All @@ -3279,8 +3289,8 @@ function New-GlobalToolNupkg
$winFolder = New-Item (Join-Path $ridFolder "win") -ItemType Directory
$unixFolder = New-Item (Join-Path $ridFolder "unix") -ItemType Directory

Write-Log "Copying runtime assemblies from $WindowsBinPath"
Copy-Item "$WindowsBinPath\*" -Destination $winFolder -Recurse
Write-Log "Copying runtime assemblies from $WindowsDesktopBinPath"
Copy-Item "$WindowsDesktopBinPath\*" -Destination $winFolder -Recurse

Write-Log "Copying runtime assemblies from $LinuxBinPath"
Copy-Item "$LinuxBinPath\*" -Destination $unixFolder -Recurse
Expand Down Expand Up @@ -3341,8 +3351,8 @@ function New-GlobalToolNupkg

"PowerShell.Windows.x64"
{
Write-Log "Copying runtime assemblies from $WindowsBinPath for $packageType"
Copy-Item "$WindowsBinPath/*" -Destination $ridFolder -Recurse
Write-Log "Copying runtime assemblies from $WindowsDesktopBinPath for $packageType"
Copy-Item "$WindowsDesktopBinPath/*" -Destination $ridFolder -Recurse
Remove-Item -Path $ridFolder/runtimes/win-arm -Recurse -Force
$toolSettings = $packagingStrings.GlobalToolSettingsFile -f "pwsh.dll"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ param (

[string] $destination = "$env:WORKSPACE",

[ValidateSet("win7-x64", "win7-x86", "win-arm", "win-arm64", "fxdependent")]
[ValidateSet("win7-x64", "win7-x86", "win-arm", "win-arm64", "fxdependent", "fxdependent-win-desktop")]
[string]$Runtime = 'win7-x64',

[switch] $Wait,
Expand Down Expand Up @@ -79,7 +79,7 @@ try{
if ($PSCmdlet.ParameterSetName -eq 'packageSigned')
{
Write-Verbose "Expanding signed build..." -verbose
if($Runtime -eq 'fxdependent')
if($Runtime -like 'fxdependent*')
{
Expand-PSSignedBuild -BuildZip $BuildZip -SkipPwshExeCheck
}
Expand All @@ -93,7 +93,7 @@ try{
else
{
Write-Verbose "Starting powershell build for RID: $Runtime and ReleaseTag: $ReleaseTag ..." -verbose
$buildParams = @{'CrossGen'= $Runtime -notmatch "arm" -and $Runtime -ne "fxdependent"}
$buildParams = @{'CrossGen'= $Runtime -notmatch "arm" -and $Runtime -notlike "fxdependent*"}

if($Symbols.IsPresent)
{
Expand All @@ -111,25 +111,29 @@ try{
{
$pspackageParams = @{'Type'='fxdependent'}
}
elseif ($Runtime -eq 'fxdependent-win-desktop')
{
$pspackageParams = @{'Type'='fxdependent-win-desktop'}
}
else
{
$pspackageParams = @{'Type'='msi'; 'WindowsRuntime'=$Runtime}
}

if (!$ComponentRegistration.IsPresent -and !$Symbols.IsPresent -and $Runtime -notmatch 'arm' -and $Runtime -ne 'fxdependent')
if (!$ComponentRegistration.IsPresent -and !$Symbols.IsPresent -and $Runtime -notmatch 'arm' -and $Runtime -notlike 'fxdependent*')
{
Write-Verbose "Starting powershell packaging(msi)..." -verbose
Start-PSPackage @pspackageParams @releaseTagParam
}

if (!$ComponentRegistration.IsPresent -and !$Symbols.IsPresent -and $Runtime -notin 'win7-x86','fxdependent')
if (!$ComponentRegistration.IsPresent -and !$Symbols.IsPresent -and $Runtime -notin 'win7-x86','fxdependent', 'fxdependent-win-desktop')
{
$pspackageParams['Type']='msix'
Write-Verbose "Starting powershell packaging(msix)..." -verbose
Start-PSPackage @pspackageParams @releaseTagParam
}

if (!$ComponentRegistration.IsPresent -and $Runtime -ne 'fxdependent')
if (!$ComponentRegistration.IsPresent -and $Runtime -notlike 'fxdependent*')
{
$pspackageParams['Type']='zip'
$pspackageParams['IncludeSymbols']=$Symbols.IsPresent
Expand All @@ -144,7 +148,7 @@ try{
Copy-Item -Path $file -Destination "$destination\" -Force
}
}
elseif (!$ComponentRegistration.IsPresent -and $Runtime -eq 'fxdependent')
elseif (!$ComponentRegistration.IsPresent -and $Runtime -like 'fxdependent*')
{
## Add symbols for just like zip package.
$pspackageParams['IncludeSymbols']=$Symbols.IsPresent
Expand Down
Loading