@@ -228,7 +228,7 @@ function Start-BuildNativeWindowsBinaries {
228
228
throw " Could not find Visual Studio vcvarsall.bat at $vcvarsallbatPath . Please ensure the optional feature 'Common Tools for Visual C++' is installed."
229
229
}
230
230
231
- log " Start building native Windows binaries"
231
+ Write-Log " Start building native Windows binaries"
232
232
233
233
if ($Clean ) {
234
234
git clean - fdx
@@ -263,7 +263,7 @@ function Start-BuildNativeWindowsBinaries {
263
263
$command = @"
264
264
cmd.exe /C cd /d "$currentLocation " "&" "$vcvarsallbatPath " "$Arch " "&" mc.exe -o -d -c -U "$ ( $_.FullName ) " -h "$currentLocation \$nativeResourcesFolder " -r "$currentLocation \$nativeResourcesFolder "
265
265
"@
266
- log " Executing mc.exe Command: $command "
266
+ Write-Log " Executing mc.exe Command: $command "
267
267
Start-NativeExecution { Invoke-Expression - Command:$command }
268
268
}
269
269
}
@@ -276,7 +276,7 @@ cmd.exe /C cd /d "$currentLocation" "&" "$vcvarsallbatPath" "$Arch" "&" mc.exe -
276
276
$command = @"
277
277
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 "
278
278
"@
279
- log " Executing Build Command: $command "
279
+ Write-Log " Executing Build Command: $command "
280
280
Start-NativeExecution { Invoke-Expression - Command:$command }
281
281
282
282
# 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
285
285
$FilesToCopy | ForEach-Object {
286
286
$srcPath = [IO.Path ]::Combine((Get-Location ), " bin" , $Configuration , " CoreClr/$_ " )
287
287
288
- log " Copying $srcPath to $dstPath "
288
+ Write-Log " Copying $srcPath to $dstPath "
289
289
Copy-Item $srcPath $dstPath
290
290
}
291
291
@@ -300,7 +300,7 @@ cmd.exe /C cd /d "$currentLocation" "&" "$vcvarsallbatPath" "$Arch" "&" "$cmakeP
300
300
$command = @"
301
301
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 "
302
302
"@
303
- log " Executing Build Command for PowerShell.Core.Instrumentation: $command "
303
+ Write-Log " Executing Build Command for PowerShell.Core.Instrumentation: $command "
304
304
Start-NativeExecution { Invoke-Expression - Command:$command }
305
305
306
306
# Copy the binary to the packaging directory
@@ -354,7 +354,7 @@ function Start-BuildNativeUnixBinaries {
354
354
355
355
$Native = " $PSScriptRoot /src/libpsl-native"
356
356
$Lib = " $PSScriptRoot /src/powershell-unix/libpsl-native.$Ext "
357
- log " Start building $Lib "
357
+ Write-Log " Start building $Lib "
358
358
359
359
git clean - qfdX $Native
360
360
@@ -439,7 +439,7 @@ function Start-PSBuild {
439
439
}
440
440
441
441
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'"
443
443
Push-Location $PSScriptRoot
444
444
try {
445
445
git clean - fdX
@@ -537,23 +537,23 @@ Fix steps:
537
537
}
538
538
539
539
($srcProjectDirs + $testProjectDirs ) | ForEach-Object {
540
- log " Run dotnet restore $_ $RestoreArguments "
540
+ Write-Log " Run dotnet restore $_ $RestoreArguments "
541
541
Start-NativeExecution { dotnet restore $_ $RestoreArguments }
542
542
}
543
543
}
544
544
545
545
# handle ResGen
546
546
# Heuristic to run ResGen on the fresh machine
547
547
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)"
549
549
Start-ResGen
550
550
}
551
551
552
552
# Handle TypeGen
553
553
# .inc file name must be different for Windows and Linux to allow build on Windows and WSL.
554
554
$incFileName = " powershell_$ ( $Options.Runtime ) .inc"
555
555
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)"
557
557
Start-TypeGen - IncFileName $incFileName
558
558
}
559
559
@@ -562,14 +562,14 @@ Fix steps:
562
562
try {
563
563
# Relative paths do not work well if cwd is not changed to project
564
564
Push-Location $Options.Top
565
- log " Run dotnet $Arguments from $pwd "
565
+ Write-Log " Run dotnet $Arguments from $pwd "
566
566
Start-NativeExecution { dotnet $Arguments }
567
567
568
568
if ($CrossGen ) {
569
569
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 ) "
571
571
} else {
572
- log " PowerShell output: $ ( $Options.Output ) "
572
+ Write-Log " PowerShell output: $ ( $Options.Output ) "
573
573
}
574
574
} finally {
575
575
Pop-Location
@@ -652,7 +652,7 @@ function Restore-PSModuleToBuild
652
652
$CI
653
653
)
654
654
655
- log " Restore PowerShell modules to $publishPath "
655
+ Write-Log " Restore PowerShell modules to $publishPath "
656
656
657
657
$modulesDir = Join-Path - Path $publishPath - ChildPath " Modules"
658
658
@@ -1271,12 +1271,12 @@ function Show-PSPesterError
1271
1271
throw ' Unknown Show-PSPester parameter set'
1272
1272
}
1273
1273
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
1280
1280
1281
1281
}
1282
1282
@@ -1316,12 +1316,12 @@ function Test-XUnitTestResults
1316
1316
$message = $failure.test.failure.message .' #cdata-section'
1317
1317
$stackTrace = $failure.test.failure .' stack-trace' .' #cdata-section'
1318
1318
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
1325
1325
}
1326
1326
1327
1327
throw " $ ( $failedTests.failed ) tests failed"
@@ -1352,7 +1352,7 @@ function Test-PSPesterResults
1352
1352
$x = [xml ](Get-Content - raw $testResultsFile )
1353
1353
if ([int ]$x .' test-results' .failures -gt 0 )
1354
1354
{
1355
- logerror " TEST FAILURES"
1355
+ Write-Log - Error " TEST FAILURES"
1356
1356
# switch between methods, SelectNode is not available on dotnet core
1357
1357
if ( " System.Xml.XmlDocumentXPathExtensions" -as [Type ] )
1358
1358
{
@@ -1377,7 +1377,7 @@ function Test-PSPesterResults
1377
1377
}
1378
1378
elseif ($ResultObject.FailedCount -gt 0 )
1379
1379
{
1380
- logerror ' TEST FAILURES'
1380
+ Write-Log - Error ' TEST FAILURES'
1381
1381
1382
1382
$ResultObject.TestResult | Where-Object {$_.Passed -eq $false } | ForEach-Object {
1383
1383
Show-PSPesterError - testFailureObject $_
@@ -1535,7 +1535,7 @@ function Start-PSBootstrap {
1535
1535
[switch ]$Force
1536
1536
)
1537
1537
1538
- log " Installing PowerShell build dependencies"
1538
+ Write-Log " Installing PowerShell build dependencies"
1539
1539
1540
1540
Push-Location $PSScriptRoot / tools
1541
1541
@@ -1668,36 +1668,36 @@ function Start-PSBootstrap {
1668
1668
1669
1669
if (! $dotNetExists -or $dotNetVersion -ne $dotnetCLIRequiredVersion -or $Force.IsPresent ) {
1670
1670
if ($Force.IsPresent ) {
1671
- log " Installing dotnet due to -Force."
1671
+ Write-Log " Installing dotnet due to -Force."
1672
1672
}
1673
1673
elseif (! $dotNetExistis ) {
1674
- log " dotnet not present. Installing dotnet."
1674
+ Write-Log " dotnet not present. Installing dotnet."
1675
1675
}
1676
1676
else {
1677
- log " dotnet out of date ($dotNetVersion ). Updating dotnet."
1677
+ Write-Log " dotnet out of date ($dotNetVersion ). Updating dotnet."
1678
1678
}
1679
1679
1680
1680
$DotnetArguments = @ { Channel = $Channel ; Version = $Version ; NoSudo = $NoSudo }
1681
1681
Install-Dotnet @DotnetArguments
1682
1682
}
1683
1683
else {
1684
- log " dotnet is already installed. Skipping installation."
1684
+ Write-Log " dotnet is already installed. Skipping installation."
1685
1685
}
1686
1686
1687
1687
# Install Windows dependencies if `-Package` or `-BuildWindowsNative` is specified
1688
1688
if ($Environment.IsWindows ) {
1689
1689
# # The VSCode build task requires 'pwsh.exe' to be found in Path
1690
1690
if (-not (Get-Command - Name pwsh.ex
F438
e - CommandType Application - ErrorAction SilentlyContinue))
1691
1691
{
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"
1693
1693
$psInstallFile = [System.IO.Path ]::Combine($PSScriptRoot , " tools" , " install-powershell.ps1" )
1694
1694
& $psInstallFile - AddToPath
1695
1695
}
1696
1696
1697
1697
# # need RCEdit to modify the binaries embedded resources
1698
1698
if (-not (Test-Path " ~/.rcedit/rcedit-x64.exe" ))
1699
1699
{
1700
- log " Install RCEdit for modifying exe resources"
1700
+ Write-Log " Install RCEdit for modifying exe resources"
1701
1701
$rceditUrl = " https://github.com/electron/rcedit/releases/download/v1.0.0/rcedit-x64.exe"
1702
1702
New-Item - Path " ~/.rcedit" - Type Directory - Force > $null
1703
1703
@@ -1708,7 +1708,7 @@ function Start-PSBootstrap {
1708
1708
}
1709
1709
1710
1710
if ($BuildWindowsNative ) {
1711
- log " Install Windows dependencies for building PSRP plugin"
1711
+ Write-Log " Install Windows dependencies for building PSRP plugin"
1712
1712
1713
1713
$machinePath = [Environment ]::GetEnvironmentVariable(' Path' , ' MACHINE' )
1714
1714
$newMachineEnvironmentPath = $machinePath
@@ -1720,56 +1720,56 @@ function Start-PSBootstrap {
1720
1720
$chocolateyPath = " $env: AllUsersProfile \chocolatey\bin"
1721
1721
1722
1722
if (precheck ' choco' $null ) {
1723
- log " Chocolatey is already installed. Skipping installation."
1723
+ Write-Log " Chocolatey is already installed. Skipping installation."
1724
1724
}
1725
1725
elseif (($cmakePresent -eq $false ) -or ($sdkPresent -eq $false )) {
1726
- log " Chocolatey not present. Installing chocolatey."
1726
+ Write-Log " Chocolatey not present. Installing chocolatey."
1727
1727
if ($Force -or $PSCmdlet.ShouldProcess (" Install chocolatey via https://chocolatey.org/install.ps1" )) {
1728
1728
Invoke-Expression ((new-object net.webclient).DownloadString(' https://chocolatey.org/install.ps1' ))
1729
1729
if (-not ($machinePath.ToLower ().Contains($chocolateyPath.ToLower ()))) {
1730
- log " Adding $chocolateyPath to Path environment variable"
1730
+ Write-Log " Adding $chocolateyPath to Path environment variable"
1731
1731
$env: Path += " ;$chocolateyPath "
1732
1732
$newMachineEnvironmentPath += " ;$chocolateyPath "
1733
1733
} else {
1734
- log " $chocolateyPath already present in Path environment variable"
1734
+ Write-Log " $chocolateyPath already present in Path environment variable"
1735
1735
}
1736
1736
} else {
1737
1737
Write-Error " Chocolatey is required to install missing dependencies. Please install it from https://chocolatey.org/ manually. Alternatively, install cmake and Windows 10 SDK."
1738
1738
return
1739
1739
}
1740
1740
} 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."
1742
1742
}
1743
1743
1744
1744
# Install cmake
1745
1745
$cmakePath = " ${env: ProgramFiles} \CMake\bin"
1746
1746
if ($cmakePresent -and ! ($force.IsPresent )) {
1747
- log " Cmake is already installed. Skipping installation."
1747
+ Write-Log " Cmake is already installed. Skipping installation."
1748
1748
} else {
1749
- log " Cmake not present or -Force used. Installing cmake."
1749
+ Write-Log " Cmake not present or -Force used. Installing cmake."
1750
1750
Start-NativeExecution { choco install cmake - y -- version 3.10 .0 }
1751
1751
if (-not ($machinePath.ToLower ().Contains($cmakePath.ToLower ()))) {
1752
- log " Adding $cmakePath to Path environment variable"
1752
+ Write-Log " Adding $cmakePath to Path environment variable"
1753
1753
$env: Path += " ;$cmakePath "
1754
1754
$newMachineEnvironmentPath = " $cmakePath ;$newMachineEnvironmentPath "
1755
1755
} else {
1756
- log " $cmakePath already present in Path environment variable"
1756
+ Write-Log " $cmakePath already present in Path environment variable"
1757
1757
}
1758
1758
}
1759
1759
1760
1760
# Install Windows 10 SDK
1761
1761
$packageName = " windows-sdk-10.0"
1762
1762
1763
1763
if (-not $sdkPresent ) {
1764
- log " Windows 10 SDK not present. Installing $packageName ."
1764
+ Write-Log " Windows 10 SDK not present. Installing $packageName ."
1765
1765
Start-NativeExecution { choco install windows- sdk- 10.0 - y }
1766
1766
} else {
1767
- log " Windows 10 SDK present. Skipping installation."
1767
+ Write-Log " Windows 10 SDK present. Skipping installation."
1768
1768
}
1769
1769
1770
1770
# Update path machine environment variable
1771
1771
if ($newMachineEnvironmentPath -ne $machinePath ) {
1772
- log " Updating Path machine environment variable"
1772
+ Write-Log " Updating Path machine environment variable"
1773
1773
if ($Force -or $PSCmdlet.ShouldProcess (" Update Path machine environment variable to $newMachineEnvironmentPath " )) {
1774
1774
[Environment ]::SetEnvironmentVariable(' Path' , $newMachineEnvironmentPath , ' MACHINE' )
1775
1775
}
@@ -2017,18 +2017,27 @@ function script:Use-MSBuild {
2017
2017
Set-Alias msbuild $frameworkMsBuildLocation - Scope Script
2018
2018
}
2019
2019
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 ,
2025
2027
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
+ }
2028
2038
# reset colors for older package to at return to default after error message on a compilation error
2029
2039
[console ]::ResetColor()
2030
2040
}
2031
-
2032
2041
function script :precheck ([string ]$command , [string ]$missedMessage ) {
2033
2042
$c = Get-Command $command - ErrorAction SilentlyContinue
2034
2043
if (-not $c ) {
@@ -2327,7 +2336,7 @@ function Copy-PSGalleryModules
2327
2336
foreach ($m in $psGalleryProj.Project.ItemGroup.PackageReference ) {
2328
2337
$name = $m.Include
2329
2338
$version = $m.Version
2330
- log " Name='$Name ', Version='$version ', Destination='$Destination '"
2339
+ Write-Log " Name='$Name ', Version='$version ', Destination='$Destination '"
2331
2340
2332
2341
# Remove the build revision from the src (nuget drops it).
2333
2342
$srcVer = if ($version -match " (\d+.\d+.\d+).\d+" ) {
0 commit comments