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
2 changes: 1 addition & 1 deletion assets/GroupPolicy/InstallPSCorePolicyDefinitions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ param
[ValidateNotNullOrEmpty()]
[string] $Path = $PSScriptRoot
)
Set-StrictMode -Version Latest
Set-StrictMode -Version 3.0
$ErrorActionPreference = 'Stop'

function Test-Elevated
Expand Down
91 changes: 52 additions & 39 deletions build.psm1
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

Set-StrictMode -Version 3.0

# On Unix paths is separated by colon
# On Windows paths is separated by semicolon
$script:TestModulePathSeparator = [System.IO.Path]::PathSeparator
$script:Options = $null

$dotnetCLIChannel = 'release'
$dotnetCLIRequiredVersion = $(Get-Content $PSScriptRoot/global.json | ConvertFrom-Json).Sdk.Version
Expand Down Expand Up @@ -292,7 +295,7 @@ function Start-PSBuild {
$PSModuleRestore = $true
}

if ($Runtime -eq "linux-arm" -and -not $environment.IsUbuntu) {
if ($Runtime -eq "linux-arm" -and $environment.IsLinux -and -not $environment.IsUbuntu) {
throw "Cross compiling for linux-arm is only supported on Ubuntu environment"
}

Expand Down Expand Up @@ -499,32 +502,34 @@ Fix steps:
$psVersion = git --git-dir="$PSScriptRoot/.git" describe
}

if ($environment.IsRedHatFamily -or $environment.IsDebian) {
# Symbolic links added here do NOT affect packaging as we do not build on Debian.
# add two symbolic links to system shared libraries that libmi.so is dependent on to handle
# platform specific changes. This is the only set of platforms needed for this currently
# as Ubuntu has these specific library files in the platform and macOS builds for itself
# against the correct versions.

if ($environment.IsDebian10 -or $environment.IsDebian11){
$sslTarget = "/usr/lib/x86_64-linux-gnu/libssl.so.1.1"
$cryptoTarget = "/usr/lib/x86_64-linux-gnu/libcrypto.so.1.1"
}
elseif ($environment.IsDebian9){
# NOTE: Debian 8 doesn't need these symlinks
$sslTarget = "/usr/lib/x86_64-linux-gnu/libssl.so.1.0.2"
$cryptoTarget = "/usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.2"
}
else { #IsRedHatFamily
$sslTarget = "/lib64/libssl.so.10"
$cryptoTarget = "/lib64/libcrypto.so.10"
}
if ($environment.IsLinux) {
if ($environment.IsRedHatFamily -or $environment.IsDebian) {
# Symbolic links added here do NOT affect packaging as we do not build on Debian.
# add two symbolic links to system shared libraries that libmi.so is dependent on to handle
# platform specific changes. This is the only set of platforms needed for this currently
# as Ubuntu has these specific library files in the platform and macOS builds for itself
# against the correct versions.

if ($environment.IsDebian10 -or $environment.IsDebian11){
$sslTarget = "/usr/lib/x86_64-linux-gnu/libssl.so.1.1"
$cryptoTarget = "/usr/lib/x86_64-linux-gnu/libcrypto.so.1.1"
}
elseif ($environment.IsDebian9){
# NOTE: Debian 8 doesn't need these symlinks
$sslTarget = "/usr/lib/x86_64-linux-gnu/libssl.so.1.0.2"
$cryptoTarget = "/usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.2"
}
else { #IsRedHatFamily
$sslTarget = "/lib64/libssl.so.10"
$cryptoTarget = "/lib64/libcrypto.so.10"
}

if ( ! (test-path "$publishPath/libssl.so.1.0.0")) {
$null = New-Item -Force -ItemType SymbolicLink -Target $sslTarget -Path "$publishPath/libssl.so.1.0.0" -ErrorAction Stop
}
if ( ! (test-path "$publishPath/libcrypto.so.1.0.0")) {
$null = New-Item -Force -ItemType SymbolicLink -Target $cryptoTarget -Path "$publishPath/libcrypto.so.1.0.0" -ErrorAction Stop
if ( ! (test-path "$publishPath/libssl.so.1.0.0")) {
$null = New-Item -Force -ItemType SymbolicLink -Target $sslTarget -Path "$publishPath/libssl.so.1.0.0" -ErrorAction Stop
}
if ( ! (test-path "$publishPath/libcrypto.so.1.0.0")) {
$null = New-Item -Force -ItemType SymbolicLink -Target $cryptoTarget -Path "$publishPath/libcrypto.so.1.0.0" -ErrorAction Stop
}
}
}

Expand Down Expand Up @@ -579,6 +584,7 @@ Fix steps:

function Restore-PSPackage
{
[CmdletBinding()]
param(
[ValidateNotNullOrEmpty()]
[Parameter()]
Expand Down Expand Up @@ -618,7 +624,7 @@ function Restore-PSPackage
$RestoreArguments = @("/property:SDKToUse=$sdkToUse", "--verbosity")
}

if ($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent) {
if ($VerbosePreference -eq 'Continue') {
$RestoreArguments += "detailed"
} else {
$RestoreArguments += "quiet"
Expand Down Expand Up @@ -837,7 +843,7 @@ function Get-PSOptions {
$DefaultToNew
)

if(!$script:Options -and $DefaultToNew.IsPresent)
if (!$script:Options -and $DefaultToNew.IsPresent)
{
return New-PSOptions
}
Expand Down Expand Up @@ -876,7 +882,14 @@ function Get-PesterTag {
$fullname = $_.fullname
$tok = $err = $null
$ast = [System.Management.Automation.Language.Parser]::ParseFile($FullName, [ref]$tok,[ref]$err)
$des = $ast.FindAll({$args[0] -is "System.Management.Automation.Language.CommandAst" -and $args[0].CommandElements[0].Value -eq "Describe"},$true)
$des = $ast.FindAll({
$args[0] -is [System.Management.Automation.Language.CommandAst] `
-and $args[0].CommandElements.GetType() -in @(
[System.Management.Automation.Language.StringConstantExpressionAst],
[System.Management.Automation.Language.ExpandableStringExpressionAst]
) `
-and $args[0].CommandElements[0].Value -eq "Describe"
}, $true)
foreach( $describe in $des) {
$elements = $describe.CommandElements
$lineno = $elements[0].Extent.StartLineNumber
Expand Down Expand Up @@ -1079,7 +1092,7 @@ function Start-PSPester {
$publishArgs = @{ }
# if we are building for Alpine, we must include the runtime as linux-x64
# will not build runnable test tools
if ( $environment.IsAlpine ) {
if ( $environment.IsLinux -and $environment.IsAlpine ) {
$publishArgs['runtime'] = 'alpine-x64'
}
Publish-PSTestTools @publishArgs | ForEach-Object {Write-Host $_}
Expand Down Expand Up @@ -1615,7 +1628,7 @@ function Install-Dotnet {
$curl = Get-Command -Name curl -CommandType Application -TotalCount 1 -ErrorAction Stop

# Uninstall all previous dotnet packages
$uninstallScript = if ($environment.IsUbuntu) {
$uninstallScript = if ($environment.IsLinux -and $environment.IsUbuntu) {
"dotnet-uninstall-debian-packages.sh"
} elseif ($environment.IsMacOS) {
"dotnet-uninstall-pkgs.sh"
Expand Down Expand Up @@ -1687,14 +1700,14 @@ function Start-PSBootstrap {
# Note that when it is null, Invoke-Expression (but not &) must be used to interpolate properly
$sudo = if (!$NoSudo) { "sudo" }

if ($BuildLinuxArm -and -not $environment.IsUbuntu) {
if ($BuildLinuxArm -and $environment.IsLinux -and -not $environment.IsUbuntu) {
Write-Error "Cross compiling for linux-arm is only supported on Ubuntu environment"
return
}

# Install ours and .NET's dependencies
$Deps = @()
if ($environment.IsUbuntu) {
if ($environment.IsLinux -and $environment.IsUbuntu) {
# Build tools
$Deps += "curl", "g++", "cmake", "make"

Expand Down Expand Up @@ -1724,7 +1737,7 @@ function Start-PSBootstrap {
# change the apt frontend back to the original
$env:DEBIAN_FRONTEND=$originalDebianFrontEnd
}
} elseif ($environment.IsRedHatFamily) {
} elseif ($environment.IsLinux -and $environment.IsRedHatFamily) {
# Build tools
$Deps += "which", "curl", "gcc-c++", "cmake", "make"

Expand All @@ -1748,7 +1761,7 @@ function Start-PSBootstrap {
Start-NativeExecution {
Invoke-Expression "$baseCommand $Deps"
}
} elseif ($environment.IsSUSEFamily) {
} elseif ($environment.IsLinux -and $environment.IsSUSEFamily) {
# Build tools
$Deps += "gcc", "cmake", "make"

Expand Down Expand Up @@ -1784,7 +1797,7 @@ function Start-PSBootstrap {
# Install dependencies
# ignore exitcode, because they may be already installed
Start-NativeExecution ([ScriptBlock]::Create("$PackageManager install $Deps")) -IgnoreExitcode
} elseif ($environment.IsAlpine) {
} elseif ($environment.IsLinux -and $environment.IsAlpine) {
$Deps += 'libunwind', 'libcurl', 'bash', 'cmake', 'clang', 'build-base', 'git', 'curl'

Start-NativeExecution {
Expand Down Expand Up @@ -2105,8 +2118,8 @@ function script:Start-NativeExecution
[switch]$IgnoreExitcode,
[switch]$VerboseOutputOnError
)
$backupEAP = $script:ErrorActionPreference
$script:ErrorActionPreference = "Continue"
$backupEAP = $ErrorActionPreference
$ErrorActionPreference = "Continue"
try {
if($VerboseOutputOnError.IsPresent)
{
Expand Down Expand Up @@ -2139,7 +2152,7 @@ function script:Start-NativeExecution
throw "Execution of {$sb} failed with exit code $LASTEXITCODE"
}
} finally {
$script:ErrorActionPreference = $backupEAP
$ErrorActionPreference = $backupEAP
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/PowerShell.Core.Instrumentation/RegisterManifest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ param

[switch] $Unregister
)
Set-StrictMode -Version Latest
Set-StrictMode -Version 3.0
$ErrorActionPreference = 'Stop'

function Start-NativeExecution([scriptblock]$sb, [switch]$IgnoreExitcode)
Expand Down
4 changes: 2 additions & 2 deletions src/powershell-native/Install-PowerShellRemoting.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ param
$PowerShellHome
)

Set-StrictMode -Version Latest
Set-StrictMode -Version 3.0

if (! ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
{
Expand Down Expand Up @@ -123,7 +123,7 @@ function Install-PluginEndpoint {
# Install the plugin #
# #
######################

if (-not [String]::IsNullOrEmpty($PowerShellHome))
{
$targetPsHome = $PowerShellHome
Expand Down
2 changes: 1 addition & 1 deletion test/powershell/Host/Logging.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Licensed under the MIT License.
using namespace System.Text

Set-StrictMode -Version Latest
Set-StrictMode -Version 3.0
$ErrorActionPreference = 'Stop'

Import-Module HelpersCommon
Expand Down
2 changes: 1 addition & 1 deletion test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Describe "TabCompletion" -Tags CI {
}

It 'Should complete "Get-Process -Id " with Id and name in tooltip' {
Set-StrictMode -Version latest
Set-StrictMode -Version 3.0
$cmd = 'Get-Process -Id '
[System.Management.Automation.CommandCompletion]$res = TabExpansion2 -inputScript $cmd -cursorColumn $cmd.Length
$res.CompletionMatches[0].CompletionText -match '^\d+$' | Should -BeTrue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ class A

[int] GetX([Foo.Bar]$bar)
{
Set-StrictMode -Version latest
Set-StrictMode -Version 3.0
return $bar.x
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ namespace DotNetInterop
param($Script)

try {
Set-StrictMode -Version latest
Set-StrictMode -Version 3.0
& $Script | Should -Be $null
} finally {
Set-StrictMode -Off
Expand Down Expand Up @@ -225,7 +225,7 @@ namespace DotNetInterop

It "Get access of an indexer that returns ByRef-like type should fail gracefully in strict mode" {
try {
Set-StrictMode -Version latest
Set-StrictMode -Version 3.0
{ $testObj[1] } | Should -Throw -ErrorId "CannotIndexWithByRefLikeReturnType"
} finally {
Set-StrictMode -Off
Expand All @@ -242,7 +242,7 @@ namespace DotNetInterop
}

Context "Passing value that is implicitly/explicitly castable to ByRef-like parameter in method invocation" {

BeforeAll {
$ps = [powershell]::Create()

Expand Down Expand Up @@ -302,7 +302,7 @@ namespace DotNetInterop

It "Return null for getter access of a CodeProperty that returns a ByRef-like type, even in strict mode" {
$result = $ps.AddScript(
'try { Set-StrictMode -Version latest; $test.TestName } finally { Set-StrictMode -Off }').Invoke()
'try { Set-StrictMode -Version 3.0; $test.TestName } finally { Set-StrictMode -Off }').Invoke()
$ps.Commands.Clear()
$result.Count | Should -Be 1
$result[0] | Should -Be $null
Expand Down
2 changes: 1 addition & 1 deletion test/powershell/engine/Help/HelpSystem.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Describe "Validate that the Help function can Run in strict mode" -Tags @('CI')

$help = & {
# run in nested scope to keep strict mode from affecting other tests
Set-StrictMode -Version Latest
Set-StrictMode -Version 3.0
Help
}
# the help function renders the help content as text so just verify that there is content
Expand Down
2 changes: 1 addition & 1 deletion test/tools/Modules/HelpersDebugger/HelpersDebugger.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
trap {throw $_}

# Strict mode FTW.
Set-StrictMode -Version Latest
Set-StrictMode -Version 3.0

# Enable explicit export so that there are no surprises with commands exported from the module.
Export-ModuleMember
Expand Down
8 changes: 4 additions & 4 deletions test/tools/Modules/PSSysLog/PSSysLog.psm1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

Set-StrictMode -Version Latest
Set-StrictMode -Version 3.0

<#
os_log notes:
Expand Down Expand Up @@ -187,7 +187,7 @@ class PSLogItem

hidden static [int] GetMonth([string] $value)
{
Set-StrictMode -Version Latest
Set-StrictMode -Version 3.0
for ($x = 0; $x -lt [PSLogItem]::monthNames.Count; $x++)
{
[string] $monthName = [PSLogItem]::monthNames[$x]
Expand All @@ -201,7 +201,7 @@ class PSLogItem

static [PSLogItem] ConvertSysLog([string] $content, [string] $id, [Nullable[DateTime]] $after)
{
Set-StrictMode -Version Latest
Set-StrictMode -Version 3.0
<#
MMM dd HH:MM:SS machinename id[PID]: (commitid:TID:CHANNEL) [EventName] Message
Expecting split to return
Expand Down Expand Up @@ -339,7 +339,7 @@ class PSLogItem

static [object] ConvertOsLog([string] $content, [string] $id, [Nullable[DateTime]] $after)
{
Set-StrictMode -Version Latest
Set-StrictMode -Version 3.0
<#
Expecting split to return
0: date 2018-02-07
Expand Down
10 changes: 8 additions & 2 deletions tools/ci.psm1
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

Set-StrictMode -Version 3.0

$ErrorActionPreference = 'continue'
$repoRoot = Join-Path $PSScriptRoot '..'
$script:administratorsGroupSID = "S-1-5-32-544"
Expand Down Expand Up @@ -479,7 +481,7 @@ function Invoke-CIFinish
{
$null = $artifacts.Add($package)
}
elseif($package -is [pscustomobject] -and $package.msi)
elseif($package -is [pscustomobject] -and $package.psobject.Properties['msi'])
{
$null = $artifacts.Add($package.msi)
$null = $artifacts.Add($package.wixpdb)
Expand All @@ -497,7 +499,7 @@ function Invoke-CIFinish
$packagingTestResult = Invoke-Pester -Script (Join-Path $repoRoot '.\test\packaging\windows\') -PassThru

# fail the CI job if the tests failed, or nothing passed
if($packagingTestResult.FailedCount -ne 0 -or !$packagingTestResult.PassedCount)
if(-not $packagingTestResult -is [pscustomobject] -or $packagingTestResult.FailedCount -ne 0 -or $packagingTestResult.PassedCount -eq 0)
{
throw "Packaging tests failed ($($packagingTestResult.FailedCount) failed/$($packagingTestResult.PassedCount) passed)"
}
Expand Down Expand Up @@ -579,6 +581,10 @@ function Invoke-LinuxTestsCore
$testResultsNoSudo = "$PWD/TestResultsNoSudo.xml"
$testResultsSudo = "$PWD/TestResultsSudo.xml"
$testExcludeTag = $ExcludeTag + 'RequireSudoOnUnix'
$pesterPassThruNoSudoObject = $null
$pesterPassThruSudoObject = $null
$noSudoResultsWithExpFeatures = $null
$sudoResultsWithExpFeatures = $null

$noSudoPesterParam = @{
'BinDir' = $output
Expand Down
Loading