diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 5d5786259dc..8b5a7ffba21 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -148,6 +148,10 @@ Additional references: Even better, all contributors are free to contribute the documentation themselves. (See [Contributing to documentation related to PowerShell](#contributing-to-documentation-related-to-powershell) for more info.) +### Pull Request - Work in Progress + +* If your pull request is not ready to merge, please add the prefix `WIP:` to the beginning of the title and remove the prefix when the PR is ready. + #### Pull Request - Automatic Checks * If this is your first contribution to PowerShell, diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 40a2a1fcc02..a97cbf433a4 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -13,3 +13,5 @@ Note: Please mark anything not applicable to this PR `NA`. - [ ] [Change is not breaking](https://github.com/PowerShell/PowerShell/blob/master/.github/CONTRIBUTING.md#making-breaking-changes) - [ ] [Make sure you've added a new test if existing tests do not effectively test the code changed](https://github.com/PowerShell/PowerShell/blob/master/.github/CONTRIBUTING.md#before-submitting) - [ ] [Add `[feature]` if the change is significant or affectes feature tests](https://github.com/PowerShell/PowerShell/blob/master/docs/testing-guidelines/testing-guidelines.md#requesting-additional-tests-for-a-pr) +- [ ] This PR is ready to merge and is not [Work in Progress](https://github.com/PowerShell/PowerShell/blob/master/.github/CONTRIBUTING.md#pull-request---work-in-progress). + - If the PR is work in progress, please add the prefix `WIP:` to the beginning of the title and remove the prefix when the PR is ready. diff --git a/assets/macDialog.png b/assets/macDialog.png new file mode 100644 index 00000000000..e2610971a06 Binary files /dev/null and b/assets/macDialog.png differ diff --git a/build.psm1 b/build.psm1 index a5f4a1c540d..ae3e4dfc6fd 100644 --- a/build.psm1 +++ b/build.psm1 @@ -172,8 +172,12 @@ function Start-BuildNativeWindowsBinaries { [ValidateSet('Debug', 'Release')] [string]$Configuration = 'Release', - [ValidateSet('x64', 'x86')] - [string]$Arch = 'x64' + # The `x64_arm` syntax is the build environment for VS2017, `x64` means the host is an x64 machine and will use + # the x64 built tool. The `arm` refers to the target architecture when doing cross compilation. + [ValidateSet('x64', 'x86', 'x64_arm64', 'x64_arm')] + [string]$Arch = 'x64', + + [switch]$Clean ) if (-not $Environment.IsWindows) { @@ -193,8 +197,16 @@ function Start-BuildNativeWindowsBinaries { throw 'Win 10 SDK not found. Run "Start-PSBootstrap -BuildWindowsNative" or install Microsoft Windows 10 SDK from https://developer.microsoft.com/en-US/windows/downloads/windows-10-sdk' } - $vcPath = (Get-Item(Join-Path -Path "$env:VS140COMNTOOLS" -ChildPath '../../vc')).FullName + if ($env:VS140COMNTOOLS -ne $null) { + $vcPath = (Get-Item(Join-Path -Path "$env:VS140COMNTOOLS" -ChildPath '../../vc')).FullName + } else { + $vcPath = (Get-ChildItem "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2017" -Filter "VC" -Directory -Recurse | Select-Object -First 1).FullName + } + $atlMfcIncludePath = Join-Path -Path $vcPath -ChildPath 'atlmfc/include' + if (!(Test-Path $atlMfcIncludePath)) { # for VS2017, need to search for it + $atlMfcIncludePath = (Get-ChildItem $vcPath -Filter AtlBase.h -Recurse -File | Select-Object -First 1).DirectoryName + } # atlbase.h is included in the pwrshplugin project if ((Test-Path -Path $atlMfcIncludePath\atlbase.h) -eq $false) { @@ -202,42 +214,62 @@ function Start-BuildNativeWindowsBinaries { } # vcvarsall.bat is used to setup environment variables - if ((Test-Path -Path $vcPath\vcvarsall.bat) -eq $false) { - throw "Could not find Visual Studio vcvarsall.bat at $vcPath. Please ensure the optional feature 'Common Tools for Visual C++' is installed." + $vcvarsallbatPath = "$vcPath\vcvarsall.bat" + if (!(Test-Path -Path $vcvarsallbatPath)) { # for VS2017, need to search for it + $vcvarsallbatPath = (Get-ChildItem $vcPath -Filter vcvarsall.bat -Recurse -File | Select-Object -First 1).FullName + } + + if ((Test-Path -Path $vcvarsallbatPath) -eq $false) { + throw "Could not find Visual Studio vcvarsall.bat at $vcvarsallbatPath. Please ensure the optional feature 'Common Tools for Visual C++' is installed." } log "Start building native Windows binaries" + if ($Clean) { + git clean -fdx + Remove-Item $HOME\source\cmakecache.txt -ErrorAction SilentlyContinue + } + try { Push-Location "$PSScriptRoot\src\powershell-native" # setup cmakeGenerator + $cmakeGeneratorPlatform = "" if ($Arch -eq 'x86') { - $cmakeGenerator = 'Visual Studio 14 2015' + $cmakeGenerator = 'Visual Studio 15 2017' + $cmakeArch = 'x86' + } elseif ($Arch -eq 'x64_arm') { + $cmakeGenerator = 'Visual Studio 15 2017 ARM' + $cmakeArch = 'arm' + } elseif ($Arch -eq 'x64_arm64') { + $cmakeGenerator = 'Visual Studio 15 2017' + $cmakeArch = 'arm64' + $cmakeGeneratorPlatform = "-A ARM64" } else { - $cmakeGenerator = 'Visual Studio 14 2015 Win64' + $cmakeGenerator = 'Visual Studio 15 2017 Win64' + $cmakeArch = 'x64' } # Compile native resources $currentLocation = Get-Location - @("nativemsh/pwrshplugin") | ForEach-Object { + @("nativemsh\pwrshplugin") | ForEach-Object { $nativeResourcesFolder = $_ Get-ChildItem $nativeResourcesFolder -Filter "*.mc" | ForEach-Object { $command = @" -cmd.exe /C cd /d "$currentLocation" "&" "$($vcPath)\vcvarsall.bat" "$Arch" "&" mc.exe -o -d -c -U "$($_.FullName)" -h "$nativeResourcesFolder" -r "$nativeResourcesFolder" +cmd.exe /C cd /d "$currentLocation" "&" "$vcvarsallbatPath" "$Arch" "&" mc.exe -o -d -c -U "$($_.FullName)" -h "$currentLocation\$nativeResourcesFolder" -r "$currentLocation\$nativeResourcesFolder" "@ log " Executing mc.exe Command: $command" - Start-NativeExecution { Invoke-Expression -Command:$command 2>&1 } + Start-NativeExecution { Invoke-Expression -Command:$command } } } + # make sure we use version we installed and not from VS + $cmakePath = (Get-Command cmake).Source # Disabling until I figure out if it is necessary # $overrideFlags = "-DCMAKE_USER_MAKE_RULES_OVERRIDE=$PSScriptRoot\src\powershell-native\windows-compiler-override.txt" $overrideFlags = "" - $location = Get-Location - $command = @" -cmd.exe /C cd /d "$location" "&" "$($vcPath)\vcvarsall.bat" "$Arch" "&" cmake "$overrideFlags" -DBUILD_ONECORE=ON -DBUILD_TARGET_ARCH=$Arch -G "$cmakeGenerator" . "&" msbuild ALL_BUILD.vcxproj "/p:Configuration=$Configuration" +cmd.exe /C cd /d "$currentLocation" "&" "$vcvarsallbatPath" "$Arch" "&" "$cmakePath" "$overrideFlags" -DBUILD_ONECORE=ON -DBUILD_TARGET_ARCH=$cmakeArch -G "$cmakeGenerator" $cmakeGeneratorPlatform "$currentLocation" "&" msbuild ALL_BUILD.vcxproj "/p:Configuration=$Configuration" "@ log " Executing Build Command: $command" Start-NativeExecution { Invoke-Expression -Command:$command } @@ -258,15 +290,18 @@ cmd.exe /C cd /d "$location" "&" "$($vcPath)\vcvarsall.bat" "$Arch" "&" cmake "$ $location = "$PSScriptRoot\src\PowerShell.Core.Instrumentation" Set-Location -Path $location + Remove-Item $HOME\source\cmakecache.txt -ErrorAction SilentlyContinue + $command = @" -cmd.exe /C cd /d "$location" "&" "$($vcPath)\vcvarsall.bat" "$Arch" "&" cmake "$overrideFlags" -DBUILD_ONECORE=ON -DBUILD_TARGET_ARCH=$Arch -G "$cmakeGenerator" . "&" msbuild ALL_BUILD.vcxproj "/p:Configuration=$Configuration" +cmd.exe /C cd /d "$location" "&" "$vcvarsallbatPath" "$Arch" "&" "$cmakePath" "$overrideFlags" -DBUILD_ONECORE=ON -DBUILD_TARGET_ARCH=$cmakeArch -G "$cmakeGenerator" $cmakeGeneratorPlatform "$location" "&" msbuild ALL_BUILD.vcxproj "/p:Configuration=$Configuration" "@ log " Executing Build Command for PowerShell.Core.Instrumentation: $command" Start-NativeExecution { Invoke-Expression -Command:$command } # Copy the binary to the packaging directory # NOTE: No PDB file; it's a resource-only DLL. - $srcPath = [IO.Path]::Combine($location, $Configuration, 'PowerShell.Core.Instrumentation.dll') + # VS2017 puts this in $HOME\source + $srcPath = [IO.Path]::Combine($HOME, "source", $Configuration, 'PowerShell.Core.Instrumentation.dll') Copy-Item -Path $srcPath -Destination $dstPath } finally { @@ -364,7 +399,9 @@ function Start-PSBuild { "win7-x86", "osx.10.12-x64", "linux-x64", - "linux-arm")] + "linux-arm", + "win-arm", + "win-arm64")] [string]$Runtime, [ValidateSet('Linux', 'Debug', 'Release', 'CodeCoverage', '')] # We might need "Checked" as well @@ -381,6 +418,10 @@ function Start-PSBuild { throw "Cross compiling for linux-arm is only supported on Ubuntu environment" } + if ("win-arm","win-arm64" -contains $Runtime -and -not $Environment.IsWindows) { + throw "Cross compiling for win-arm or win-arm64 is only supported on Windows environment" + } + function Stop-DevPowerShell { Get-Process pwsh* | Where-Object { @@ -652,7 +693,9 @@ function New-PSOptions { "win7-x64", "osx.10.12-x64", "linux-x64", - "linux-arm")] + "linux-arm", + "win-arm", + "win-arm64")] [string]$Runtime, [switch]$CrossGen, @@ -1631,11 +1674,11 @@ function Start-PSBootstrap { # Install cmake $cmakePath = "${env:ProgramFiles}\CMake\bin" - if($cmakePresent) { + if($cmakePresent -and !($force.IsPresent)) { log "Cmake is already installed. Skipping installation." } else { - log "Cmake not present. Installing cmake." - Start-NativeExecution { choco install cmake -y --version 3.6.0 } + log "Cmake not present or -Force used. Installing cmake." + Start-NativeExecution { choco install cmake -y --version 3.10.0 } if (-not ($machinePath.ToLower().Contains($cmakePath.ToLower()))) { log "Adding $cmakePath to Path environment variable" $env:Path += ";$cmakePath" @@ -2132,7 +2175,9 @@ function Start-CrossGen { "win7-x64", "osx.10.12-x64", "linux-x64", - "linux-arm")] + "linux-arm", + "win-arm", + "win-arm64")] [string] $Runtime ) @@ -2186,8 +2231,10 @@ function Start-CrossGen { $crossGenRuntime = if ($Environment.IsWindows) { if ($Runtime -match "-x86") { "win-x86" - } else { + } elseif ($Runtime -match "-x64") { "win-x64" + } elseif (!($env:PROCESSOR_ARCHITECTURE -match "arm")) { + throw "crossgen for 'win-arm' and 'win-arm64' must be run on that platform" } } elseif ($Runtime -eq "linux-arm") { throw "crossgen is not available for 'linux-arm'" diff --git a/src/powershell-native/CMakeLists.txt b/src/powershell-native/CMakeLists.txt index 4889c163f42..051d880ca58 100644 --- a/src/powershell-native/CMakeLists.txt +++ b/src/powershell-native/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.8.4) +cmake_minimum_required(VERSION 3.10.0) project(PowerShellNative) @@ -11,9 +11,6 @@ endif () # # Normalize the platform name -# -# TODO: Only x64 and x86 are supported right now. This needs to be expanded to arm and arm64 to match CoreCLR -# SET(BUILD_ARCH_ARM 0) SET(BUILD_ARCH_ARM64 0) SET(BUILD_ARCH_X86 0) @@ -21,8 +18,9 @@ SET(BUILD_ARCH_AMD64 0) if (BUILD_TARGET_ARCH) SET(WindowsSDKPlatform ${BUILD_TARGET_ARCH}) + message(STATUS "Building for " ${BUILD_TARGET_ARCH}) else () - message(FATAL_ERROR "Target architecture value should be specified through BUILD_TARGET_ARCH. Supported values are x64 or x86.") + message(FATAL_ERROR "Target architecture value should be specified through BUILD_TARGET_ARCH. Supported values are x64, x86, arm, or arm64") endif (BUILD_TARGET_ARCH) if (WindowsSDKPlatform STREQUAL "x64" OR WindowsSDKPlatform STREQUAL "X64" OR WindowsSDKPlatform STREQUAL "amd64" OR WindowsSDKPlatform STREQUAL "AMD64") @@ -31,6 +29,12 @@ if (WindowsSDKPlatform STREQUAL "x64" OR WindowsSDKPlatform STREQUAL "X64" OR Wi elseif (WindowsSDKPlatform STREQUAL "x86" OR WindowsSDKPlatform STREQUAL "X86") SET(WindowsSDKPlatform "x86") SET(BUILD_ARCH_X86 1) +elseif (WindowsSDKPlatform STREQUAL "arm" OR WindowsSDKPlatform STREQUAL "ARM") + SET(WindowsSDKPlatform "arm") + SET(BUILD_ARCH_ARM 1) +elseif (WindowsSDKPlatform STREQUAL "arm64" OR WindowsSDKPlatform STREQUAL "ARM64") + SET(WindowsSDKPlatform "arm64") + SET(BUILD_ARCH_ARM64 1) else() message(FATAL_ERROR "Unsupported WindowsSDKPlatform: " ${WindowsSDKPlatform}) endif () diff --git a/src/powershell-native/Install-PowerShellRemoting.ps1 b/src/powershell-native/Install-PowerShellRemoting.ps1 index dbada625e8a..5bfbf0e6b99 100644 --- a/src/powershell-native/Install-PowerShellRemoting.ps1 +++ b/src/powershell-native/Install-PowerShellRemoting.ps1 @@ -44,38 +44,37 @@ function Register-WinRmPlugin $pluginEndpointName ) - $header = "Windows Registry Editor Version 5.00`n`n" - - $regKeyFormatString = "[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WSMAN\Plugin\{0}]`n" + $regKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WSMAN\Plugin\$pluginEndpointName" $regKeyName = '"ConfigXML"="{0}"' - # - # Example Values: - # - # Filename = %windir%\\system32\\PowerShell\\6.0.0\\pwrshplugin.dll - # Name = PowerShell.6.0.0 - # $pluginArchitecture = "64" - if ($env:PROCESSOR_ARCHITECTURE -match "x86") + if ($env:PROCESSOR_ARCHITECTURE -match "x86" -or $env:PROCESSOR_ARCHITECTURE -eq "ARM") { $pluginArchitecture = "32" } - $regKeyValueFormatString = '' + $regKeyValueFormatString = @" + + + + + + + + + + + + +"@ $valueString = $regKeyValueFormatString -f $pluginEndpointName, $pluginAbsolutePath, $pluginArchitecture - $keyValuePair = $regKeyName -f $valueString - - $regKey = $regKeyFormatString -f $pluginEndpointName - - $fileName = "$pluginEndpointName.reg" - - Set-Content -path .\$fileName "$header$regKey$keyValuePair`n" - - Write-Verbose "Performing WinRM registration with: $fileName" - reg.exe import .\$fileName - # Clean up - Remove-Item .\$fileName + New-Item $regKey -Force > $null + New-ItemProperty -Path $regKey -Name ConfigXML -Value $valueString > $null } function Generate-PluginConfigFile @@ -98,7 +97,7 @@ function Generate-PluginConfigFile Set-Content -Path $pluginFile -Value "PSHOMEDIR=$targetPsHomeDir" Add-Content -Path $pluginFile -Value "CORECLRDIR=$targetPsHomeDir" - Write-Verbose "Created Plugin Config File: $pluginFile" + Write-Verbose "Created Plugin Config File: $pluginFile" -Verbose } ###################### @@ -140,20 +139,18 @@ else $resolvedPluginAbsolutePath = Resolve-Path $pluginBasePath } -# The registration reg file requires "\\" instead of "\" in its path so it is properly escaped in the XML -$pluginRawPath = Join-Path $resolvedPluginAbsolutePath "pwrshplugin.dll" -$fixedPluginPath = $pluginRawPath -replace '\\','\\' +$pluginPath = Join-Path $resolvedPluginAbsolutePath "pwrshplugin.dll" # This is forced to ensure the the file is placed correctly Copy-Item $targetPsHome\pwrshplugin.dll $resolvedPluginAbsolutePath -Force -Verbose $pluginFile = Join-Path $resolvedPluginAbsolutePath "RemotePowerShellConfig.txt" -Generate-PluginConfigFile $pluginFile $targetPsHome +Generate-PluginConfigFile $pluginFile (Resolve-Path $targetPsHome) $pluginEndpointName = "powershell.$targetPsVersion" # Register the plugin -Register-WinRmPlugin $fixedPluginPath $pluginEndpointName +Register-WinRmPlugin $pluginPath $pluginEndpointName #################################################################### # # @@ -174,13 +171,13 @@ if (! (Test-Path $resolvedPluginAbsolutePath\pwrshplugin.dll)) try { Write-Host "`nGet-PSSessionConfiguration $pluginEndpointName" -foregroundcolor "green" - Get-PSSessionConfiguration $pluginEndpointName + Get-PSSessionConfiguration $pluginEndpointName -ErrorAction Stop } catch [Microsoft.PowerShell.Commands.WriteErrorException] { - Write-Error "No remoting session configuration matches the name $pluginEndpointName." + throw "No remoting session configuration matches the name $pluginEndpointName." } -Write-Host "Restarting WinRM to ensure that the plugin configuration change takes effect.`nThis is required for WinRM running on Windows SKUs prior to Windows 10." -foregroundcolor "green" +Write-Host "Restarting WinRM to ensure that the plugin configuration change takes effect.`nThis is required for WinRM running on Windows SKUs prior to Windows 10." -foregroundcolor Magenta Restart-Service winrm diff --git a/src/powershell-native/coreclr_defs.cmake b/src/powershell-native/coreclr_defs.cmake index b0d26adc1eb..1b6ea3eeb5e 100644 --- a/src/powershell-native/coreclr_defs.cmake +++ b/src/powershell-native/coreclr_defs.cmake @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.8.4) +cmake_minimum_required(VERSION 3.10.0) set(CMAKE_CXX_STANDARD_LIBRARIES "") # do not link against standard win32 libs i.e. kernel32, uuid, user32, etc. @@ -61,16 +61,20 @@ if (BUILD_ARCH_AMD64) add_definitions(-D_WIN64) add_definitions(-DAMD64) add_definitions(-DBIT64=1) + add_definitions(-D_M_AMD64) elseif (BUILD_ARCH_X86) add_definitions(-D_X86_) elseif (BUILD_ARCH_ARM) add_definitions(-D_ARM_) + add_definitions(-D_WIN32) + add_definitions(-D_M_ARM) add_definitions(-DARM) elseif (BUILD_ARCH_ARM64) add_definitions(-D_ARM64_) add_definitions(-DARM64) add_definitions(-D_WIN64) add_definitions(-DBIT64=1) + add_definitions(-D_M_ARM64) endif () # Define the CRT lib references that link into Desktop imports @@ -146,6 +150,8 @@ if (BUILD_ARCH_AMD64) add_definitions(-D_TARGET_AMD64_=1) elseif (BUILD_ARCH_ARM) add_definitions(-D_TARGET_ARM_=1) +elseif (BUILD_ARCH_ARM64) + add_definitions(-D_TARGET_ARM64_=1) elseif (BUILD_ARCH_X86) add_definitions(-D_TARGET_X86_=1) endif (BUILD_ARCH_AMD64) diff --git a/src/powershell-native/nativemsh/pwrshcommon/ConfigFileReader.cpp b/src/powershell-native/nativemsh/pwrshcommon/ConfigFileReader.cpp index b3b65874f3c..33b79046a43 100644 --- a/src/powershell-native/nativemsh/pwrshcommon/ConfigFileReader.cpp +++ b/src/powershell-native/nativemsh/pwrshcommon/ConfigFileReader.cpp @@ -44,9 +44,12 @@ namespace NativeMsh } else if (*iter == L'p' || *iter == L'P') { - this->pathToPowerShellAssemblies = this->getValueFromLine(line, psHomeDirTag); - if (this->pathToPowerShellAssemblies.size() > 0) // Found a match + std::wstring psHomeDir = this->getValueFromLine(line, psHomeDirTag); + HANDLE dirHandle = CreateFileW(psHomeDir.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); + if (INVALID_HANDLE_VALUE != dirHandle) { + CloseHandle(dirHandle); + this->pathToPowerShellAssemblies = psHomeDir; std::wstring::const_iterator slashIter = this->pathToPowerShellAssemblies.end(); slashIter--; if (*slashIter != L'\\') @@ -59,9 +62,12 @@ namespace NativeMsh } else if (*iter == L'c' || *iter == L'C') { - this->coreClrDirectory = this->getValueFromLine(line, coreClrDirTag); - if (this->coreClrDirectory.size() > 0) // Found a match + std::wstring coreClrDir = this->getValueFromLine(line, coreClrDirTag); + HANDLE dirHandle = CreateFileW(coreClrDir.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); + if (INVALID_HANDLE_VALUE != dirHandle) { + CloseHandle(dirHandle); + this->coreClrDirectory = coreClrDir; std::wstring::const_iterator slashIter = this->coreClrDirectory.end(); slashIter--; if (*slashIter != L'\\') diff --git a/test/tools/CodeCoverageAutomation/Start-CodeCoverageRun.ps1 b/test/tools/CodeCoverageAutomation/Start-CodeCoverageRun.ps1 index 086b92ac116..bd3fd21eae4 100644 --- a/test/tools/CodeCoverageAutomation/Start-CodeCoverageRun.ps1 +++ b/test/tools/CodeCoverageAutomation/Start-CodeCoverageRun.ps1 @@ -241,8 +241,11 @@ try } # grab the commitID, we need this to grab the right sources - $gitCommitId = & "$psBinPath\pwsh.exe" -noprofile -command { $PSVersiontable.GitCommitId } - $commitId = $gitCommitId.substring($gitCommitId.LastIndexOf('-g') + 2) + $assemblyLocation = & "$psBinPath\pwsh.exe" -noprofile -command { Get-Item ([psobject].Assembly.Location) } + $productVersion = $assemblyLocation.VersionInfo.productVersion + $commitId = $productVersion.split(" ")[-1] + + Write-LogPassThru -Message "Using GitCommitId: $commitId" # download the src directory try diff --git a/tools/packaging/packaging.psm1 b/tools/packaging/packaging.psm1 index 60cd317875d..080617ae9e3 100644 --- a/tools/packaging/packaging.psm1 +++ b/tools/packaging/packaging.psm1 @@ -582,7 +582,7 @@ function New-UnixPackage { } } - # Verify depenecies are installed and in the path + # Verify dependencies are installed and in the path Test-Dependencies $Description = $packagingStrings.Description @@ -653,8 +653,7 @@ function New-UnixPackage { if($pscmdlet.ShouldProcess("Add macOS launch application")) { # Generate launcher app folder - $appsfolder = New-MacOSLauncher -Version $Version - $Arguments += "$appsfolder=/" + $AppsFolder = New-MacOSLauncher -Version $Version } } @@ -681,7 +680,9 @@ function New-UnixPackage { -ManGzipFile $ManGzipInfo.GzipFile ` -ManDestination $ManGzipInfo.ManFile ` -LinkSource $LinkSource ` - -LinkDestination $Link + -LinkDestination $Link ` + -AppsFolder $AppsFolder ` + -ErrorAction Stop # Build package try { @@ -702,10 +703,10 @@ function New-UnixPackage { } } if ($AfterScriptInfo.AfterInstallScript) { - Remove-Item -erroraction 'silentlycontinue' $AfterScriptInfo.AfterInstallScript + Remove-Item -erroraction 'silentlycontinue' $AfterScriptInfo.AfterInstallScript -Force } if ($AfterScriptInfo.AfterRemoveScript) { - Remove-Item -erroraction 'silentlycontinue' $AfterScriptInfo.AfterRemoveScript + Remove-Item -erroraction 'silentlycontinue' $AfterScriptInfo.AfterRemoveScript -Force } Remove-Item -Path $ManGzipInfo.GzipFile -Force -ErrorAction SilentlyContinue } @@ -714,22 +715,9 @@ function New-UnixPackage { $createdPackage = Get-Item (Join-Path $PWD (($Output[-1] -split ":path=>")[-1] -replace '["{}]')) if ($Environment.IsMacOS) { - if ($pscmdlet.ShouldProcess("Fix package name")) + if ($pscmdlet.ShouldProcess("Add distribution information and Fix PackageName")) { - # Add the OS information to the macOS package file name. - $packageExt = [System.IO.Path]::GetExtension($createdPackage.Name) - $packageNameWithoutExt = [System.IO.Path]::GetFileNameWithoutExtension($createdPackage.Name) - - $newPackageName = "{0}-{1}{2}" -f $packageNameWithoutExt, $script:Options.Runtime, $packageExt - $newPackagePath = Join-Path $createdPackage.DirectoryName $newPackageName - - # -Force is not deleting the NewName if it exists, so delete it if it does - if ($Force -and (Test-Path -Path $newPackagePath)) - { - Remove-Item -Force $newPackagePath - } - - $createdPackage = Rename-Item -Path $createdPackage.FullName -NewName $newPackagePath -PassThru -ErrorAction Stop + $createdPackage = New-MacOsDistributionPackage -FpmPackage $createdPackage } } @@ -745,7 +733,71 @@ function New-UnixPackage { } } +function New-MacOsDistributionPackage +{ + param( + [Parameter(Mandatory,HelpMessage='The FileInfo of the file created by FPM')] + [System.IO.FileInfo]$FpmPackage + ) + + if(!$Environment.IsMacOS) + { + throw 'New-MacOsDistributionPackage is only supported on macOS!' + } + + $packageName = Split-Path -leaf -Path $FpmPackage + + # Create a temp directory to store the needed files + $tempDir = Join-Path ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName()) + New-Item -ItemType Directory -Path $tempDir -Force > $null + + $resourcesDir = Join-Path -path $tempDir -childPath 'resources' + New-Item -ItemType Directory -Path $resourcesDir -Force > $null + #Copy background file to temp directory + $backgroundFile = Join-Path $PSScriptRoot "/../../assets/macDialog.png" + Copy-Item -Path $backgroundFile -Destination $resourcesDir + # Move the current package to the temp directory + $tempPackagePath = Join-Path -path $tempDir -ChildPath $packageName + Move-Item -Path $FpmPackage -Destination $tempPackagePath -Force + + # Add the OS information to the macOS package file name. + $packageExt = [System.IO.Path]::GetExtension($FpmPackage.Name) + $packageNameWithoutExt = [System.IO.Path]::GetFileNameWithoutExtension($FpmPackage.Name) + + $newPackageName = "{0}-{1}{2}" -f $packageNameWithoutExt, $script:Options.Runtime, $packageExt + $newPackagePath = Join-Path $FpmPackage.DirectoryName $newPackageName + + # -Force is not deleting the NewName if it exists, so delete it if it does + if ($Force -and (Test-Path -Path $newPackagePath)) + { + Remove-Item -Force $newPackagePath + } + + # Create the distribution xml + $distributionXmlPath = Join-Path -Path $tempDir -ChildPath 'powershellDistribution.xml' + + # format distribution template with: + # 0 - title + # 1 - version + # 2 - package path + # 2 - minimum os version + $PackagingStrings.OsxDistributionTemplate -f "PowerShell - $Version", $Version, $packageName, '10.12' | Out-File -Encoding ascii -FilePath $distributionXmlPath -Force + + log "Applying distribution.xml to package..." + Push-Location $tempDir + try + { + # productbuild is an xcode command line tool, and those tools are installed when you install brew + Start-NativeExecution -sb {productbuild --distribution $distributionXmlPath --resources $resourcesDir $newPackagePath} + } + finally + { + Pop-Location + Remove-item -Path $tempDir -Recurse -Force + } + return $newPackagePath +} function Get-FpmArguments { param( @@ -814,7 +866,18 @@ function Get-FpmArguments } return $true })] - [String]$AfterRemoveScript + [String]$AfterRemoveScript, + + [Parameter(HelpMessage='AppsFolder used to add macOS launcher')] + [AllowNull()] + [ValidateScript({ + if ($Environment.IsMacOS -and !$_) + { + throw "Must not be null on this environment." + } + return $true + })] + [String]$AppsFolder ) $Arguments = @( @@ -858,6 +921,11 @@ function Get-FpmArguments "$LinkSource=$LinkDestination" ) + if($AppsFolder) + { + $Arguments += "$AppsFolder=/" + } + return $Arguments } diff --git a/tools/packaging/packaging.strings.psd1 b/tools/packaging/packaging.strings.psd1 index ac94321c0d6..ffec1a6cba3 100644 --- a/tools/packaging/packaging.strings.psd1 +++ b/tools/packaging/packaging.strings.psd1 @@ -48,4 +48,29 @@ case "$1" in ;; esac '@ +# see https://developer.apple.com/library/content/documentation/DeveloperTools/Reference/DistributionDefinitionRef/Chapters/Distribution_XML_Ref.html +OsxDistributionTemplate = @' + + + {0} + + + + + + + + + + + + + + + + + + {2} + +'@ } diff --git a/tools/releaseBuild/Images/GenericLinuxFiles/PowerShellPackage.ps1 b/tools/releaseBuild/Images/GenericLinuxFiles/PowerShellPackage.ps1 index 9b18349222f..74b3762e79c 100644 --- a/tools/releaseBuild/Images/GenericLinuxFiles/PowerShellPackage.ps1 +++ b/tools/releaseBuild/Images/GenericLinuxFiles/PowerShellPackage.ps1 @@ -12,8 +12,9 @@ param ( [ValidateNotNullOrEmpty()] [string]$ReleaseTag, - [ValidateSet("AppImage", "tar")] - [string[]]$ExtraPackage + [switch]$AppImage, + [switch]$TarX64, + [switch]$TarArm ) $releaseTagParam = @{} @@ -32,10 +33,14 @@ try { Start-PSBuild -Crossgen -PSModuleRestore @releaseTagParam Start-PSPackage @releaseTagParam - switch ($ExtraPackage) - { - "AppImage" { Start-PSPackage -Type AppImage @releaseTagParam } - "tar" { Start-PSPackage -Type tar @releaseTagParam } + if ($AppImage) { Start-PSPackage -Type AppImage @releaseTagParam } + if ($TarX64) { Start-PSPackage -Type tar @releaseTagParam } + + if ($TarArm) { + ## Build 'linux-arm' and create 'tar.gz' package for it. + ## Note that 'linux-arm' can only be built on Ubuntu environment. + Start-PSBuild -Runtime linux-arm -PSModuleRestore @releaseTagParam + Start-PSPackage -Type tar-arm @releaseTagParam } } finally diff --git a/tools/releaseBuild/build.json b/tools/releaseBuild/build.json index cdeddbc0e37..49a6da80cb1 100644 --- a/tools/releaseBuild/build.json +++ b/tools/releaseBuild/build.json @@ -9,7 +9,7 @@ "3968m" ], "DockerFile": ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\DockerFile", - "AdditionalContextFiles" :[ + "AdditionalContextFiles" :[ ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\PowerShellPackage.ps1", ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\wix.psm1", ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\dockerInstall.psm1" @@ -26,7 +26,7 @@ "3968m" ], "DockerFile": ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\DockerFile", - "AdditionalContextFiles" :[ + "AdditionalContextFiles" :[ ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\PowerShellPackage.ps1", ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\wix.psm1", ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\dockerInstall.psm1" @@ -43,7 +43,7 @@ "3968m" ], "DockerFile": ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\DockerFile", - "AdditionalContextFiles" :[ + "AdditionalContextFiles" :[ ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\PowerShellPackage.ps1", ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\wix.psm1", ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\dockerInstall.psm1" @@ -62,7 +62,7 @@ "3968m" ], "DockerFile": ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\DockerFile", - "AdditionalContextFiles" :[ + "AdditionalContextFiles" :[ ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\PowerShellPackage.ps1", ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\wix.psm1", ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\dockerInstall.psm1" @@ -81,7 +81,7 @@ "3968m" ], "DockerFile": ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\DockerFile", - "AdditionalContextFiles" :[ + "AdditionalContextFiles" :[ ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\PowerShellPackage.ps1", ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\wix.psm1", ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\dockerInstall.psm1" @@ -99,7 +99,7 @@ "3968m" ], "DockerFile": ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\DockerFile", - "AdditionalContextFiles" :[ + "AdditionalContextFiles" :[ ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\PowerShellPackage.ps1", ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\wix.psm1", ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\dockerInstall.psm1" @@ -113,7 +113,7 @@ { "Name": "ubuntu.14.04", "RepoDestinationPath": "/PowerShell", - "BuildCommand": "/PowerShellPackage.ps1 -location _RepoDestinationPath_ -destination _DockerVolume_ -ReleaseTag _ReleaseTag_ -ExtraPackage AppImage", + "BuildCommand": "/PowerShellPackage.ps1 -location _RepoDestinationPath_ -destination _DockerVolume_ -ReleaseTag _ReleaseTag_ -AppImage -TarX64 -TarArm", "BuildDockerOptions": [ "--cap-add", "SYS_ADMIN", @@ -140,7 +140,7 @@ { "Name": "centos.7", "RepoDestinationPath": "/PowerShell", - "BuildCommand": "/PowerShellPackage.ps1 -location _RepoDestinationPath_ -destination _DockerVolume_ -ReleaseTag _ReleaseTag_ -ExtraPackage tar", + "BuildCommand": "/PowerShellPackage.ps1 -location _RepoDestinationPath_ -destination _DockerVolume_ -ReleaseTag _ReleaseTag_", "AdditionalContextFiles" :[ "./tools/releaseBuild/Images/GenericLinuxFiles/PowerShellPackage.ps1"], "DockerFile": "./tools/releaseBuild/Images/microsoft_powershell_centos7/Dockerfile", "DockerImageName": "ps-centos-7", diff --git a/tools/releaseBuild/packagesigning.xml b/tools/releaseBuild/packagesigning.xml index 8dd67835c9c..a243e5fbd98 100644 --- a/tools/releaseBuild/packagesigning.xml +++ b/tools/releaseBuild/packagesigning.xml @@ -1,6 +1,6 @@ - + diff --git a/tools/releaseBuild/signing.xml b/tools/releaseBuild/signing.xml index dab6785735c..8a4070d69cd 100644 --- a/tools/releaseBuild/signing.xml +++ b/tools/releaseBuild/signing.xml @@ -1,7 +1,7 @@ - + @@ -14,17 +14,17 @@ - + --> - + - - + +