8000 Rename log and logerror to Write-Log [$message] [-error] (#6333) · kalgiz/PowerShell@0c845b9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0c845b9

Browse files
dantraMSFTTravisEz13
authored andcommitted
Rename log and logerror to Write-Log [$message] [-error] (PowerShell#6333)
Fix PowerShell#6332 This change renames log and logerror functions to a single Write-Log [$message] [-error] function to avoid conflicting with the log command on MacOS.
1 parent 28bf189 commit 0c845b9

File tree

4 files changed

+97
-88
lines changed

4 files changed

+97
-88
lines changed

build.psm1

Lines changed: 66 additions & 57 deletions

Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ function Start-BuildNativeWindowsBinaries {
228228
throw "Could not find Visual Studio vcvarsall.bat at $vcvarsallbatPath. Please ensure the optional feature 'Common Tools for Visual C++' is installed."
229229
}
230230

231-
log "Start building native Windows binaries"
231+
Write-Log "Start building native Windows binaries"
232232

233233
if ($Clean) {
234234
git clean -fdx
@@ -263,7 +263,7 @@ function Start-BuildNativeWindowsBinaries {
263263
$command = @"
264264
cmd.exe /C cd /d "$currentLocation" "&" "$vcvarsallbatPath" "$Arch" "&" mc.exe -o -d -c -U "$($_.FullName)" -h "$currentLocation\$nativeResourcesFolder" -r "$currentLocation\$nativeResourcesFolder"
265265
"@
266-
log " Executing mc.exe Command: $command"
266+
Write-Log " Executing mc.exe Command: $command"
267267
Start-NativeExecution { Invoke-Expression -Command:$command }
268268
}
269269
}
@@ -276,7 +276,7 @@ cmd.exe /C cd /d "$currentLocation" "&" "$vcvarsallbatPath" "$Arch" "&" mc.exe -
276276
$command = @"
277277
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"
278278
"@
279-
log " Executing Build Command: $command"
279+
Write-Log " Executing Build Command: $command"
280280
Start-NativeExecution { Invoke-Expression -Command:$command }
281281

282282
# Copy the binaries from the local build directory to the packaging directory
@@ -285,7 +285,7 @@ cmd.exe /C cd /d "$currentLocation" "&" "$vcvarsallbatPath" "$Arch" "&" "$cmakeP
285285
$FilesToCopy | ForEach-Object {
286286
$srcPath = [IO.Path]::Combine((Get-Location), "bin", $Configuration, "CoreClr/$_")
287287

288-
log " Copying $srcPath to $dstPath"
288+
Write-Log " Copying $srcPath to $dstPath"
289289
Copy-Item $srcPath $dstPath
290290
}
291291

@@ -300,7 +300,7 @@ cmd.exe /C cd /d "$currentLocation" "&" "$vcvarsallbatPath" "$Arch" "&" "$cmakeP
300300
$command = @"
301301
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"
302302
"@
303-
log " Executing Build Command for PowerShell.Core.Instrumentation: $command"
303+
Write-Log " Executing Build Command for PowerShell.Core.Instrumentation: $command"
304304
Start-NativeExecution { Invoke-Expression -Command:$command }
305305

306306
# Copy the binary to the packaging directory
@@ -354,7 +354,7 @@ function Start-BuildNativeUnixBinaries {
354354

355355
$Native = "$PSScriptRoot/src/libpsl-native"
356356
$Lib = "$PSScriptRoot/src/powershell-unix/libpsl-native.$Ext"
357-
log "Start building $Lib"
357+
Write-Log "Start building $Lib"
358358

359359
git clean -qfdX $Native
360360

@@ -439,7 +439,7 @@ function Start-PSBuild {
439439
}
440440

441441
if ($Clean) {
442-
log "Cleaning your working directory. You can also do it with 'git clean -fdX'"
442+
Write-Log "Cleaning your working directory. You can also do it with 'git clean -fdX'"
443443
Push-Location $PSScriptRoot
444444
try {
445445
git clean -fdX
@@ -537,23 +537,23 @@ Fix steps:
537537
}
538538

539539
($srcProjectDirs + $testProjectDirs) | ForEach-Object {
540-
log "Run dotnet restore $_ $RestoreArguments"
540+
Write-Log "Run dotnet restore $_ $RestoreArguments"
541541
Start-NativeExecution { dotnet restore $_ $RestoreArguments }
542542
}
543543
}
544544

545545
# handle ResGen
546546
# Heuristic to run ResGen on the fresh machine
547547
if ($ResGen -or -not (Test-Path "$PSScriptRoot/src/Microsoft.PowerShell.ConsoleHost/gen")) {
548-
log "Run ResGen (generating C# bindings for resx files)"
548+
Write-Log "Run ResGen (generating C# bindings for resx files)"
549549
Start-ResGen
550550
}
551551

552552
# Handle TypeGen
553553
# .inc file name must be different for Windows and Linux to allow build on Windows and WSL.
554554
$incFileName = "powershell_$($Options.Runtime).inc"
555555
if ($TypeGen -or -not (Test-Path "$PSScriptRoot/src/TypeCatalogGen/$incFileName")) {
556-
log "Run TypeGen (generating CorePsTypeCatalog.cs)"
556+
Write-Log "Run TypeGen (generating CorePsTypeCatalog.cs)"
557557
Start-TypeGen -IncFileName $incFileName
558558
}
559559

@@ -562,14 +562,14 @@ Fix steps:
562562
try {
563563
# Relative paths do not work well if cwd is not changed to project
564564
Push-Location $Options.Top
565-
log "Run dotnet $Arguments from $pwd"
565+
Write-Log "Run dotnet $Arguments from $pwd"
566566
Start-NativeExecution { dotnet $Arguments }
567567

568568
if ($CrossGen) {
569569
Start-CrossGen -PublishPath $publishPath -Runtime $script:Options.Runtime
570-
log "pwsh.exe with ngen binaries is available at: $($Options.Output)"
570+
Write-Log "pwsh.exe with ngen binaries is available at: $($Options.Output)"
571571
} else {
572-
log "PowerShell output: $($Options.Output)"
572+
Write-Log "PowerShell output: $($Options.Output)"
573573
}
574574
} finally {
575575
Pop-Location
@@ -652,7 +652,7 @@ function Restore-PSModuleToBuild
652652
$CI
653653
)
654654

655-
log "Restore PowerShell modules to $publishPath"
655+
Write-Log "Restore PowerShell modules to $publishPath"
656656

657657
$modulesDir = Join-Path -Path $publishPath -ChildPath "Modules"
658658

@@ -1271,12 +1271,12 @@ function Show-PSPesterError
12711271
throw 'Unknown Show-PSPester parameter set'
12721272
}
12731273

1274-
logerror ("Description: " + $description)
1275-
logerror ("Name: " + $name)
1276-
logerror "message:"
1277-
logerror $message
1278-
logerror "stack-trace:"
1279-
logerror $stackTrace
1274+
Write-Log -Error ("Description: " + $description)
1275+
Write-Log -Error ("Name: " + $name)
1276+
Write-Log -Error "message:"
1277+
Write-Log -Error $message
1278+
Write-Log -Error "stack-trace:"
1279+
Write-Log -Error $stackTrace
12801280

12811281
}
12821282

@@ -1316,12 +1316,12 @@ function Test-XUnitTestResults
13161316
$message = $failure.test.failure.message.'#cdata-section'
13171317
$stackTrace = $failure.test.failure.'stack-trace'.'#cdata-section'
13181318

1319-
logerror ("Description: " + $description)
1320-
logerror ("Name: " + $name)
1321-
logerror "message:"
1322-
logerror $message
1323-
logerror "stack-trace:"
1324-
logerror $stackTrace
1319+
Write-Log -Error ("Description: " + $description)
1320+
Write-Log -Error ("Name: " + $name)
1321+
Write-Log -Error "message:"
1322+
Write-Log -Error $message
1323+
Write-Log -Error "stack-trace:"
1324+
Write-Log -Error $stackTrace
13251325
}
13261326

13271327
throw "$($failedTests.failed) tests failed"
@@ -1352,7 +1352,7 @@ function Test-PSPesterResults
13521352
$x = [xml](Get-Content -raw $testResultsFile)
13531353
if ([int]$x.'test-results'.failures -gt 0)
13541354
{
1355-
logerror "TEST FAILURES"
1355+
Write-Log -Error "TEST FAILURES"
13561356
# switch between methods, SelectNode is not available on dotnet core
13571357
if ( "System.Xml.XmlDocumentXPathExtensions" -as [Type] )
13581358
{
@@ -1377,7 +1377,7 @@ function Test-PSPesterResults
13771377
}
13781378
elseif ($ResultObject.FailedCount -gt 0)
13791379
{
1380-
logerror 'TEST FAILURES'
1380+
Write-Log -Error 'TEST FAILURES'
13811381

13821382
$ResultObject.TestResult | Where-Object {$_.Passed -eq $false} | ForEach-Object {
13831383
Show-PSPesterError -testFailureObject $_
@@ -1535,7 +1535,7 @@ function Start-PSBootstrap {
15351535
[switch]$Force
15361536
)
15371537

1538-
log "Installing PowerShell build dependencies"
1538+
Write-Log "Installing PowerShell build dependencies"
15391539

15401540
Push-Location $PSScriptRoot/tools
15411541

@@ -1668,36 +1668,36 @@ function Start-PSBootstrap {
16681668

16691669
if(!$dotNetExists -or $dotNetVersion -ne $dotnetCLIRequiredVersion -or $Force.IsPresent) {
16701670
if($Force.IsPresent) {
1671-
log "Installing dotnet due to -Force."
1671+
Write-Log "Installing dotnet due to -Force."
16721672
}
16731673
elseif(!$dotNetExistis) {
1674-
log "dotnet not present. Installing dotnet."
1674+
Write-Log "dotnet not present. Installing dotnet."
16751675
}
16761676
else {
1677-
log "dotnet out of date ($dotNetVersion). Updating dotnet."
1677+
Write-Log "dotnet out of date ($dotNetVersion). Updating dotnet."
16781678
}
16791679

16801680
$DotnetArguments = @{ Channel=$Channel; Version=$Version; NoSudo=$NoSudo }
16811681
Install-Dotnet @DotnetArguments
16821682
}
16831683
else {
1684-
log "dotnet is already installed. Skipping installation."
1684+
Write-Log "dotnet is already installed. Skipping installation."
16851685
}
16861686
16871687
# Install Windows dependencies if `-Package` or `-BuildWindowsNative` is specified
16881688
if ($Environment.IsWindows) {
16891689
## The VSCode build task requires 'pwsh.exe' to be found in Path
16901690
if (-not (Get-Command -Name pwsh.ex F438 e -CommandType Application -ErrorAction SilentlyContinue))
16911691
{
1692-
log "pwsh.exe not found. Install latest PowerShell Core release and add it to Path"
1692+
Write-Log "pwsh.exe not found. Install latest PowerShell Core release and add it to Path"
16931693
$psInstallFile = [System.IO.Path]::Combine($PSScriptRoot, "tools", "install-powershell.ps1")
16941694
& $psInstallFile -AddToPath
16951695
}
16961696

16971697
## need RCEdit to modify the binaries embedded resources
16981698
if (-not (Test-Path "~/.rcedit/rcedit-x64.exe"))
16991699
{
1700-
log "Install RCEdit for modifying exe resources"
1700+
Write-Log "Install RCEdit for modifying exe resources"
17011701
$rceditUrl = "https://github.com/electron/rcedit/releases/download/v1.0.0/rcedit-x64.exe"
17021702
New-Item -Path "~/.rcedit" -Type Directory -Force > $null
17031703

@@ -1708,7 +1708,7 @@ function Start-PSBootstrap {
17081708
}
17091709

17101710
if ($BuildWindowsNative) {
1711-
log "Install Windows dependencies for building PSRP plugin"
1711+
Write-Log "Install Windows dependencies for building PSRP plugin"
17121712

17131713
$machinePath = [Environment]::GetEnvironmentVariable('Path', 'MACHINE')
17141714
$newMachineEnvironmentPath = $machinePath
@@ -1720,56 +1720,56 @@ function Start-PSBootstrap {
17201720
$chocolateyPath = "$env:AllUsersProfile\chocolatey\bin"
17211721

17221722
if(precheck 'choco' $null) {
1723-
log "Chocolatey is already installed. Skipping installation."
1723+
Write-Log "Chocolatey is already installed. Skipping installation."
17241724
}
17251725
elseif(($cmakePresent -eq $false) -or ($sdkPresent -eq $false)) {
1726-
log "Chocolatey not present. Installing chocolatey."
1726+
Write-Log "Chocolatey not present. Installing chocolatey."
17271727
if ($Force -or $PSCmdlet.ShouldProcess("Install chocolatey via https://chocolatey.org/install.ps1")) {
17281728
Invoke-Expression ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
17291729
if (-not ($machinePath.ToLower().Contains($chocolateyPath.ToLower()))) {
1730-
log "Adding $chocolateyPath to Path environment variable"
1730+
Write-Log "Adding $chocolateyPath to Path environment variable"
17311731
$env:Path += ";$chocolateyPath"
17321732
$newMachineEnvironmentPath += ";$chocolateyPath"
17331733
} else {
1734-
log "$chocolateyPath already present in Path environment variable"
1734+
Write-Log "$chocolateyPath already present in Path environment variable"
17351735
}
17361736
} else {
17371737
Write-Error "Chocolatey is required to install missing dependencies. Please install it from https://chocolatey.org/ manually. Alternatively, install cmake and Windows 10 SDK."
17381738
return
17391739
}
17401740
} else {
1741-
log "Skipping installation of chocolatey, cause both cmake and Win 10 SDK are present."
1741+
Write-Log "Skipping installation of chocolatey, cause both cmake and Win 10 SDK are present."
17421742
}
17431743

17441744
# Install cmake
17451745
$cmakePath = "${env:ProgramFiles}\CMake\bin"
17461746
if($cmakePresent -and !($force.IsPresent)) {
1747-
log "Cmake is already installed. Skipping installation."
1747+
Write-Log "Cmake is already installed. Skipping installation."
17481748
} else {
1749-
log "Cmake not present or -Force used. Installing cmake."
1749+
Write-Log "Cmake not present or -Force used. Installing cmake."
17501750
Start-NativeExecution { choco install cmake -y --version 3.10.0 }
17511751
if (-not ($machinePath.ToLower().Contains($cmakePath.ToLower()))) {
1752-
log "Adding $cmakePath to Path environment variable"
1752+
Write-Log "Adding $cmakePath to Path environment variable"
17531753
$env:Path += ";$cmakePath"
17541754
$newMachineEnvironmentPath = "$cmakePath;$newMachineEnvironmentPath"
17551755
} else {
1756-
log "$cmakePath already present in Path environment variable"
1756+
Write-Log "$cmakePath already present in Path environment variable"
17571757
}
17581758
}
17591759

17601760
# Install Windows 10 SDK
17611761
$packageName = "windows-sdk-10.0"
17621762

17631763
if (-not $sdkPresent) {
1764-
log "Windows 10 SDK not present. Installing $packageName."
1764+
Write-Log "Windows 10 SDK not present. Installing $packageName."
17651765
Start-NativeExecution { choco install windows-sdk-10.0 -y }
17661766
} else {
1767-
log "Windows 10 SDK present. Skipping installation."
1767+
Write-Log "Windows 10 SDK present. Skipping installation."
17681768
}
17691769

17701770
# Update path machine environment variable
17711771
if ($newMachineEnvironmentPath -ne $machinePath) {
1772-
log "Updating Path machine environment variable"
1772+
Write-Log "Updating Path machine environment variable"
17731773
if ($Force -or $PSCmdlet.ShouldProcess("Update Path machine environment variable to $newMachineEnvironmentPath")) {
17741774
[Environment]::SetEnvironmentVariable('Path', $newMachineEnvironmentPath, 'MACHINE')
17751775
}
@@ -2017,18 +2017,27 @@ function script:Use-MSBuild {
20172017
Set-Alias msbuild $frameworkMsBuildLocation -Scope Script
20182018
}
20192019

2020-
function script:log([string]$message) {
2021-
Write-Host -Foreground Green $message
2022-
#reset colors for older package to at return to default after error message on a compilation error
2023-
[console]::ResetColor()
2024-
}
2020+
function script:Write-Log
2021+
{
2022+
param
2023+
(
2024+
[Parameter(Position=0, Mandatory)]
2025+
[ValidateNotNullOrEmpty()]
2026+
[string] $message,
20252027

2026-
function script:logerror([string]$message) {
2027-
Write-Host -Foreground Red $message
2028+
[switch] $error
2029+
)
2030+
if ($error)
2031+
{
2032+
Write-Host -Foreground Red $message
2033+
}
2034+
else
2035+
{
2036+
Write-Host -Foreground Green $message
2037+
}
20282038
#reset colors for older package to at return to default after error message on a compilation error
20292039
[console]::ResetColor()
20302040
}
2031-
20322041
function script:precheck([string]$command, [string]$missedMessage) {
20332042
$c = Get-Command $command -ErrorAction SilentlyContinue
20342043
if (-not $c) {
@@ -2327,7 +2336,7 @@ function Copy-PSGalleryModules
23272336
foreach ($m in $psGalleryProj.Project.ItemGroup.PackageReference) {
23282337
$name = $m.Include
23292338
$version = $m.Version
2330-
log "Name='$Name', Version='$version', Destination='$Destination'"
2339+
Write-Log "Name='$Name', Version='$version', Destination='$Destination'"
23312340

23322341
# Remove the build revision from the src (nuget drops it).
23332342
$srcVer = if ($version -match "(\d+.\d+.\d+).\d+") {

tools/appveyor.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ function Invoke-AppveyorFinish
544544

545545
if($env:NUGET_KEY -and $env:NUGET_URL -and [system.io.path]::GetExtension($_) -ieq '.nupkg')
546546
{
547-
log "pushing $_ to $env:NUGET_URL"
547+
Write-Log "pushing $_ to $env:NUGET_URL"
548548
Start-NativeExecution -sb {dotnet nuget push $_ --api-key $env:NUGET_KEY --source "$env:NUGET_URL/api/v2/package"} -IgnoreExitcode
549549
}
550550
}

0 commit comments

Comments
 (0)
0