@@ -8,7 +8,7 @@ Import-Module $PSScriptRoot\OpenSSHCommonUtils.psm1 -Force
8
8
[bool ] $script :Verbose = $false
9
9
[string ] $script :BuildLogFile = $null
10
10
<#
11
- Called by Write-BuildMsg to write to the build log, if it exists.
11
+ Called by Write-BuildMsg to write to the build log, if it exists.
12
12
#>
13
13
function Write-Log
14
14
{
@@ -22,7 +22,7 @@ function Write-Log
22
22
if (-not ([string ]::IsNullOrEmpty($script :BuildLogFile )))
23
23
{
24
24
Add-Content - Path $script :BuildLogFile - Value $Message
25
- }
25
+ }
26
26
}
27
27
28
28
<#
@@ -94,7 +94,7 @@ function Write-BuildMsg
94
94
return
95
95
}
96
96
97
- if ($PSBoundParameters.ContainsKey (" AsInfo" ))
97
+ if ($PSBoundParameters.ContainsKey (" AsInfo" ))
98
98
{
99
99
Write-Log - Message " INFO: $message "
100
100
if (-not $Silent )
@@ -151,7 +151,7 @@ function Start-OpenSSHBootstrap
151
151
152
152
# Add git\cmd to the path
153
153
$machinePath = [Environment ]::GetEnvironmentVariable(' Path' , ' MACHINE' )
154
- $newMachineEnvironmentPath = $machinePath
154
+ $newMachineEnvironmentPath = $machinePath
155
155
$gitCmdPath = " $env: ProgramFiles \git\cmd"
156
156
if (-not ($machinePath.ToLower ().Contains($gitCmdPath.ToLower ())))
157
157
{
@@ -171,10 +171,10 @@ function Start-OpenSSHBootstrap
171
171
if ($newMachineEnvironmentPath -ne $machinePath )
172
172
{
173
173
[Environment ]::SetEnvironmentVariable(' Path' , $newMachineEnvironmentPath , ' MACHINE' )
174
- }
174
+ }
175
175
176
176
$sdkVersion = Get-Windows10SDKVersion
177
- if ($null -eq $sdkVersion )
177
+ if ($null -eq $sdkVersion )
178
178
{
179
179
Get-Chocolatey
180
180
$packageName = " windows-sdk-10.1"
@@ -196,7 +196,7 @@ function Start-OpenSSHBootstrap
196
196
else {
197
197
$MSBuildPath = Get-VS2015BuildToolPath
198
198
}
199
- if ($MSBuildPath | Select-String " 2022" )
199
+ if ($MSBuildPath | Select-String " 2022" )
200
200
{
201
201
$env: vctargetspath = Join-Path $VisualStudioPath " MSBuild\Microsoft\VC\v170\"
202
202
if ($null -eq $env: VS170COMNTOOLS )
@@ -205,11 +205,11 @@ function Start-OpenSSHBootstrap
205
205
}
206
206
elseif (-not (Test-Path $env: VS170COMNTOOLS ))
207
207
{
208
- Write-BuildMsg - AsError - ErrorAction Stop - Message " $env: VS170COMNTOOLS build tools path is invalid"
208
+ Write-BuildMsg - AsError - ErrorAction Stop - Message " $env: VS170COMNTOOLS build tools path is invalid"
209
209
}
210
210
$VSBuildToolsPath = Get-Item (Join-Path $VisualStudioPath ' vc/auxiliary/build' )
211
211
}
212
- elseif ($MSBuildPath | Select-String " 2019" )
212
+ elseif ($MSBuildPath | Select-String " 2019" )
213
213
{
214
214
$env: vctargetspath = Join-Path $VisualStudioPath " Common7\IDE\VC\VCTargets"
215
215
Write-BuildMsg - AsVerbose - Message " Setting vctargetspath env var to ${env: vctargetspath} "
@@ -219,11 +219,11 @@ function Start-OpenSSHBootstrap
219
219
}
220
220
elseif (-not (Test-Path $env: VS160COMNTOOLS ))
221
221
{
222
- Write-BuildMsg - AsError - ErrorAction Stop - Message " $env: VS160COMNTOOLS build tools path is invalid"
222
+ Write-BuildMsg - AsError - ErrorAction Stop - Message " $env: VS160COMNTOOLS build tools path is invalid"
223
223
}
224
224
$VSBuildToolsPath = Get-Item (Join-Path $VisualStudioPath ' vc/auxiliary/build' )
225
225
}
226
- elseif ($MSBuildPath | Select-String " 2017" )
226
+ elseif ($MSBuildPath | Select-String " 2017" )
227
227
{
228
228
$env: vctargetspath = Join-Path $VisualStudioPath " Common7\IDE\VC\VCTargets"
229
229
if ($null -eq $env: VS150COMNTOOLS )
@@ -232,11 +232,11 @@ function Start-OpenSSHBootstrap
232
232
}
233
233
elseif (-not (Test-Path $env: VS150COMNTOOLS ))
234
234
{
235
- Write-BuildMsg - AsError - ErrorAction Stop - Message " $env: VS150COMNTOOLS build tools path is invalid"
235
+ Write-BuildMsg - AsError - ErrorAction Stop - Message " $env: VS150COMNTOOLS build tools path is invalid"
236
236
}
237
237
$VSBuildToolsPath = Get-Item (Join-Path $VisualStudioPath ' vc/auxiliary/build' )
238
238
}
239
- else
239
+ else
240
240
{
241
241
if ($NativeHostArch.ToLower ().Startswith(' arm' ))
242
242
{
@@ -246,7 +246,7 @@ function Start-OpenSSHBootstrap
246
246
247
247
$VSBuildToolsPath = Get-Item (Join-Path - Path $env: VS140COMNTOOLS - ChildPath ' ../../vc' )
248
248
Write-BuildMsg - AsVerbose - Message ' VC++ 2015 Build Tools already present.'
249
-
249
+
250
250
if (! $MSBuildPath -or ($null -eq $env: VS140COMNTOOLS )) {
251
251
Get-Chocolatey
252
252
$packageName = " vcbuildtools"
@@ -287,15 +287,15 @@ function Start-OpenSSHBootstrap
287
287
Write-BuildMsg - AsVerbose - Message " vcPath: $script :vcPath " - Silent:$silent
288
288
if ((Test-Path - Path " $script :vcPath \vcvarsall.bat" ) -eq $false )
289
289
{
290
- Write-BuildMsg - AsError - ErrorAction Stop - Message " Could not find Visual Studio vcvarsall.bat at $script :vcPath , which means some required develop kits are missing on the machine."
290
+ Write-BuildMsg - AsError - ErrorAction Stop - Message " Could not find Visual Studio vcvarsall.bat at $script :vcPath , which means some required develop kits are missing on the machine."
291
291
}
292
292
}
293
293
294
294
function Start-OpenSSHPackage
295
295
{
296
- [CmdletBinding (SupportsShouldProcess = $false )]
296
+ [CmdletBinding (SupportsShouldProcess = $false )]
297
297
param
298
- (
298
+ (
299
299
[ValidateSet (' x86' , ' x64' , ' arm64' , ' arm' )]
300
300
[string ]$NativeHostArch = " x64" ,
301
301
@@ -314,10 +314,10 @@ function Start-OpenSSHPackage
314
314
if ($NativeHostArch -ieq ' x86' )
315
315
{
316
316
$folderName = " Win32"
317
- }
317
+ }
318
318
319
319
$buildDir = Join-Path $repositoryRoot (" bin\" + $folderName + " \" + $Configuration )
320
- $payload = " sshd.exe" , " sshd-session.exe" , " ssh.exe" , " ssh-agent.exe" , " ssh-add.exe" , " sftp.exe"
320
+ $payload = " sshd.exe" , " sshd-auth.exe " , " sshd- session.exe" , " ssh.exe" , " ssh-agent.exe" , " ssh-add.exe" , " sftp.exe"
321
321
$payload += " sftp-server.exe" , " scp.exe" , " ssh-shellhost.exe" , " ssh-keygen.exe" , " ssh-keyscan.exe" , " ssh-sk-helper.exe" , " ssh-pkcs11-helper.exe"
322
322
$payload += " sshd_config_default" , " install-sshd.ps1" , " uninstall-sshd.ps1"
323
323
$payload += " FixHostFilePermissions.ps1" , " FixUserFilePermissions.ps1" , " OpenSSHUtils.psm1" , " OpenSSHUtils.psd1"
@@ -335,20 +335,20 @@ function Start-OpenSSHPackage
335
335
}
336
336
337
337
while ((($service = Get-Service ssh- agent - ErrorAction SilentlyContinue) -ne $null ) -and ($service.Status -ine ' Stopped' ))
338
- {
338
+ {
339
339
Stop-Service ssh- agent - Force
340
- # sleep to wait the servicelog file write
340
+ # sleep to wait the servicelog file write
341
341
Start-Sleep 5
342
342
}
343
343
344
344
$packageDir = Join-Path $buildDir $packageName
345
345
Remove-Item $packageDir - Recurse - Force - ErrorAction SilentlyContinue
346
346
New-Item $packageDir - Type Directory | Out-Null
347
-
347
+
348
348
$symbolsDir = Join-Path $buildDir ($packageName + ' _Symbols' )
349
349
Remove-Item $symbolsDir - Recurse - Force - ErrorAction SilentlyContinue
350
350
New-Item $symbolsDir - Type Directory | Out-Null
351
-
351
+
352
352
foreach ($file in $payload ) {
353
353
if ((-not (Test-Path (Join-Path $buildDir $file )))) {
354
354
Throw " Cannot find $file under $buildDir . Did you run Build-OpenSSH?"
@@ -367,7 +367,7 @@ function Start-OpenSSHPackage
367
367
# copy libcrypto dll
368
368
$libreSSLPath = Join-Path $PSScriptRoot " LibreSSL"
369
369
if (-not $NoOpenSSL.IsPresent )
370
- {
370
+ {
371
371
if ($OneCore )
372
372
{
373
373
Copy-Item - Path $ (Join-Path $libreSSLPath " bin\onecore\$NativeHostArch \libcrypto.dll" ) - Destination $packageDir - Force - ErrorAction Stop
@@ -378,10 +378,10 @@ function Start-OpenSSHPackage
378
378
Copy-Item - Path $ (Join-Path $libreSSLPath " bin\desktop\$NativeHostArch \libcrypto.dll" ) - Destination $packageDir - Force - ErrorAction Stop
379
379
Copy-Item - Path $ (Join-Path $libreSSLPath " bin\desktop\$NativeHostArch \libcrypto.pdb" ) - Destination $symbolsDir - Force - ErrorAction Stop
380
380
}
381
- }
381
+ }
382
382
383
383
if ($DestinationPath -ne " " ) {
384
- if (Test-Path $DestinationPath ) {
384
+ if (Test-Path $DestinationPath ) {
385
385
Remove-Item $DestinationPath \* - Force - Recurse - ErrorAction SilentlyContinue
386
386
}
387
387
else {
@@ -403,7 +403,7 @@ function Start-OpenSSHPackage
403
403
}
404
404
}
405
405
Remove-Item $packageDir - Recurse - Force - ErrorAction SilentlyContinue
406
-
406
+
407
407
if ($DestinationPath -ne " " ) {
408
408
Copy-Item - Path $symbolsDir \* - Destination $DestinationPath - Force - Recurse
409
409
Write-BuildMsg - AsInfo - Message " Copied symbols to $DestinationPath "
@@ -425,9 +425,9 @@ function Start-OpenSSHPackage
425
425
426
426
function Copy-OpenSSHUnitTests
427
427
{
428
- [CmdletBinding (SupportsShouldProcess = $false )]
428
+ [CmdletBinding (SupportsShouldProcess = $false )]
429
429
param
430
- (
430
+ (
431
431
[ValidateSet (' x86' , ' x64' , ' arm64' , ' arm' )]
432
432
[string ]$NativeHostArch = " x64" ,
433
433
@@ -447,18 +447,18 @@ function Copy-OpenSSHUnitTests
447
447
}
448
448
$buildDir = Join-Path $repositoryRoot (" bin\" + $folderName + " \" + $Configuration )
449
449
$unittestsDir = Join-Path $buildDir " unittests"
450
- $unitTestFolders = Get-ChildItem - Directory $buildDir \unittest-*
451
-
450
+ $unitTestFolders = Get-ChildItem - Directory $buildDir \unittest-*
451
+
452
452
if ($DestinationPath -ne " " ) {
453
453
if (-not (Test-Path $DestinationPath - PathType Container)) {
454
454
New-Item - ItemType Directory $DestinationPath - Force | Out-Null
455
455
}
456
456
foreach ($folder in $unitTestFolders ) {
457
457
Copy-Item $folder.FullName $DestinationPath \$ ($folder.Name ) - Recurse - Force
458
458
Write-BuildMsg - AsInfo - Message " Copied $ ( $folder.FullName ) to $DestinationPath \$ ( $folder.Name ) ."
459
- }
459
+ }
460
460
}
461
- else {
461
+ else {
462
462
if (Test-Path ($unittestsDir + ' .zip' ) - PathType Leaf) {
463
463
Remove-Item ($unittestsDir + ' .zip' ) - Force - ErrorAction SilentlyContinue
464
464
}
@@ -476,9 +476,9 @@ function Copy-OpenSSHUnitTests
476
476
477
477
function Start-OpenSSHBuild
478
478
{
479
- [CmdletBinding (SupportsShouldProcess = $false )]
479
+ [CmdletBinding (SupportsShouldProcess = $false )]
480
480
param
481
- (
481
+ (
482
482
[ValidateSet (' x86' , ' x64' , ' arm64' , ' arm' )]
483
483
[string ]$NativeHostArch = " x64" ,
484
484
@@ -488,7 +488,7 @@ function Start-OpenSSHBuild
488
488
[switch ]$NoOpenSSL ,
489
489
490
490
[switch ]$OneCore
491
- )
491
+ )
492
492
$script :BuildLogFile = $null
493
493
494
494
[System.IO.DirectoryInfo ] $repositoryRoot = Get-RepositoryRoot
@@ -512,8 +512,8 @@ function Start-OpenSSHBuild
512
512
Start-OpenSSHBootstrap - NativeHostArch $NativeHostArch - OneCore:$OneCore
513
513
514
514
$PathTargets = Join-Path - Path $PSScriptRoot - ChildPath ' paths.targets'
515
- if ($NoOpenSSL )
516
- {
515
+ if ($NoOpenSSL )
516
+ {
517
517
[XML ]$xml = Get-Content $PathTargets
518
518
$xml.Project.PropertyGroup.UseOpenSSL = ' false'
519
519
$xml.Project.PropertyGroup.SSLLib = [string ]::Empty
@@ -523,11 +523,11 @@ function Start-OpenSSHBuild
523
523
(Get-Content $f ).Replace(' #define OPENSSL_HAS_ECC 1' , ' ' ) | Set-Content $f
524
524
(Get-Content $f ).Replace(' #define OPENSSL_HAS_NISTP521 1' , ' ' ) | Set-Content $f
525
525
}
526
-
526
+
527
527
$win10SDKVer = Get-Windows10SDKVersion
528
528
[XML ]$xml = Get-Content $PathTargets
529
529
$xml.Project.PropertyGroup.WindowsSDKVersion = $win10SDKVer.ToString ()
530
-
530
+
531
531
if ($NativeHostArch.ToLower ().Startswith(' arm' ))
532
532
{
533
533
$arch = $NativeHostArch.ToUpper ()
@@ -538,7 +538,7 @@ function Start-OpenSSHBuild
538
538
$newElement = $xml.CreateElement ($nodeName , $xml.Project.xmlns )
539
539
$newNode = $xml.Project.PropertyGroup.AppendChild ($newElement )
540
540
$null = $newNode.AppendChild ($xml.CreateTextNode (" true" ))
541
- }
541
+ }
542
542
else
543
543
{
544
544
$node.InnerText = " true"
@@ -553,18 +553,18 @@ function Start-OpenSSHBuild
553
553
$xml.Project.PropertyGroup.WindowsSDKVersion = $win10SDKVer
554
554
$xml.Project.PropertyGroup.AdditionalDependentLibs = ' onecore.lib;shlwapi.lib'
555
555
$xml.Project.PropertyGroup.MinimalCoreWin = ' true'
556
-
556
+
557
557
# Use onecore libcrypto binaries
558
558
$xml.Project.PropertyGroup ." LibreSSL-x86-Path" = ' $(SolutionDir)\LibreSSL\bin\onecore\x86\'
559
559
$xml.Project.PropertyGroup ." LibreSSL-x64-Path" = ' $(SolutionDir)\LibreSSL\bin\onecore\x64\'
560
560
$xml.Project.PropertyGroup ." LibreSSL-arm-Path" = ' $(SolutionDir)\LibreSSL\bin\onecore\arm\'
561
561
$xml.Project.PropertyGroup ." LibreSSL-arm64-Path" = ' $(SolutionDir)\LibreSSL\bin\onecore\arm64\'
562
-
562
+
563
563
$xml.Save ($PathTargets )
564
564
}
565
-
565
+
566
566
$solutionFile = Get-SolutionFile - root $repositoryRoot.FullName
567
- $cmdMsg = @ (" ${solutionFile} " , " /t:Rebuild" , " /p:Platform=${NativeHostArch} " , " /p:Configuration=${Configuration} " , " /m" , " /nologo" , " /fl" , " /flp:LogFile=${ script:BuildLogFile } `;Append`;Verbosity=diagnostic" )
567
+ $cmdMsg = @ (" ${solutionFile} " , " /t:Rebuild" , " /p:Platform=${NativeHostArch} " , " /p:Configuration=${Configuration} " , " /m" , " /nologo" , " /fl" , " /flp:LogFile=${ script:BuildLogFile } `;Append`;Verbosity=diagnostic" )
568
568
if ($silent )
569
569
{
570
570
$cmdMsg += " /noconlog"
@@ -588,7 +588,7 @@ function Start-OpenSSHBuild
588
588
if ($errorCode -ne 0 )
589
589
{
590
590
Write-BuildMsg - AsError - ErrorAction Stop - Message " Build failed for OpenSSH.`n ExitCode: $errorCode ."
591
- }
591
+ }
592
592
593
593
Write-BuildMsg - AsInfo - Message " SSH build successful."
594
594
}
@@ -683,13 +683,13 @@ function Get-BuildToolPath
683
683
if (-not (Test-Path ($buildToolsPath )))
684
684
{
685
685
Write-BuildMsg - AsError - ErrorAction Stop - Message " $packageName installation failed with error code $LASTEXITCODE ."
686
- }
687
- }
686
+ }
687
+ }
688
688
return $buildToolsPath
689
689
}
690
690
691
691
function Get-Windows10SDKVersion
692
- {
692
+ {
693
693
# # Search for latest windows sdk available on the machine
694
694
$windowsSDKPath = Join-Path ${env: ProgramFiles(x86)} " Windows Kits\10\Lib"
695
695
$minSDKVersion = [version ]" 10.0.17763.0"
@@ -719,7 +719,7 @@ function Get-BuildLogFile
719
719
720
720
[ValidateSet (' x86' , ' x64' , ' arm64' , ' arm' )]
721
721
[string ]$NativeHostArch = " x64" ,
722
-
722
+
723
723
[ValidateSet (' Debug' , ' Release' )]
724
724
[string ]$Configuration = " Release"
725
725
)
@@ -738,7 +738,7 @@ function Get-SolutionFile
738
738
[Parameter (Mandatory = $true )]
739
739
[ValidateNotNull ()]
740
740
[System.IO.DirectoryInfo ] $root
741
- )
741
+ )
742
742
if ($root.FullName -ieq $PSScriptRoot )
743
743
{
744
744
return Join-Path - Path $PSScriptRoot - ChildPath " Win32-OpenSSH.sln"
@@ -761,7 +761,7 @@ function Get-Chocolatey {
761
761
}
762
762
763
763
$machinePath = [Environment ]::GetEnvironmentVariable(' Path' , ' MACHINE' )
764
- $newMachineEnvironmentPath = $machinePath
764
+ $newMachineEnvironmentPath = $machinePath
765
765
766
766
if (-not ($machinePath.ToLower ().Contains($chocolateyPath.ToLower ())))
767
767
{
@@ -781,7 +781,7 @@ function Get-Chocolatey {
781
781
if ($newMachineEnvironmentPath -ne $machinePath )
782
782
{
783
783
[Environment ]::SetEnvironmentVariable(' Path' , $newMachineEnvironmentPath , ' MACHINE' )
784
- }
784
+ }
785
785
}
786
786
787
787
Export-ModuleMember - Function Start-OpenSSHBuild , Get-BuildLogFile , Start-OpenSSHPackage , Copy-OpenSSHUnitTests
0 commit comments