From 020cdad9b897b10e62a1481c5c6140bacaea57dc Mon Sep 17 00:00:00 2001 From: Gianni Trevisiol Date: Fri, 23 Jun 2023 18:47:59 -0700 Subject: [PATCH] Add VC++ Debug redist deployment to `deploy-ebpf.ps1`. (#2613) * Add VC++ Debug redist deployment. * wip * Update doc. * indent * adjust $null checks in all PS scripts * fix --- docs/InstallEbpf.md | 2 +- scripts/deploy-ebpf.ps1.in | 40 +++++++++++++++++--- scripts/run_driver_tests.psm1 | 2 +- tools/bpf2c/Convert-BpfToNative.ps1.template | 2 +- 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/docs/InstallEbpf.md b/docs/InstallEbpf.md index b77fdd4ee..94047cf15 100644 --- a/docs/InstallEbpf.md +++ b/docs/InstallEbpf.md @@ -82,7 +82,7 @@ C:\Windows\system32\msiexec.exe /i eBPF-for-Windows.x.x.x.msi /l This method uses a machine that has already built the binaries for `x64/Debug` or `x64/Release`. -1. Deploy the binaries to `C:\Temp` in your VM, as follows: +1. Deploy the binaries to `C:\Temp` in your VM, as follows (from within a "*Developer PowerShell for VS 2022*"): - If you **built the binaries from inside the VM**, then from your `ebpf-for-windows` directory in the VM, run: diff --git a/scripts/deploy-ebpf.ps1.in b/scripts/deploy-ebpf.ps1.in index 70950a9db..f099dd9aa 100644 --- a/scripts/deploy-ebpf.ps1.in +++ b/scripts/deploy-ebpf.ps1.in @@ -21,13 +21,10 @@ $source_directory="." "ebpfnetsh.pdb", "export_program_info.exe", "export_program_info.pdb", - "MSVCP140D.dll", "NetEbpfExt.sys", "NetEbpfExt.pdb", "net-ebpf-ext.guid", - "ucrtbased.dll", - "VCRUNTIME140_1D.dll", - "VCRUNTIME140D.dll") + "ucrtbased.dll") [System.Collections.ArrayList]$built_runtime_jit_files=@( "ebpfsvc.exe", @@ -212,6 +209,8 @@ $source_directory="." $destination_directory="C:\Temp" $error.clear() $vm="Windows 10 dev environment" +$vc_redist_dir = Join-Path -Path $env:VCToolsRedistDir '\debug_nonredist\x64\Microsoft.VC143.DebugCRT\' +$copy_redist=$false ## ## Process command-line options @@ -249,7 +248,7 @@ OPTIONS: $vm=($arg -split "=")[1]; break } - "^(?:-l|--list)(?:=(.+))?$" + "^(?:-l|--local)(?:=(.+))?$" { if ($matches[1]) { $destination_directory = $matches[1] @@ -267,11 +266,13 @@ OPTIONS: { @("-t", "--test") -contains $_ } { $built_files= $built_runtime_files + $built_test_files + $copy_redist=$true break } { @("-t", "--jittest") -contains $_ } { $built_files= $built_runtime_files + $built_runtime_jit_files + $built_test_files + $copy_redist=$true break } default @@ -297,6 +298,21 @@ if ($vm -eq $null) { Copy-Item "$source_path" -Destination "$destination_path" -ErrorAction Stop } + if ($copy_redist) { + Write-Host "Copying the VC++ Redist (Debug) files from `"$vc_redist_dir`" to `"$destination_directory`"" + $files = Get-ChildItem -Path $vc_redist_dir -File + foreach ($file in $files) { + $source_path = $file.FullName + $destination_path = Join-Path -Path $destination_directory -ChildPath $file.Name + $destination_full_directory = Split-Path $destination_path -Parent + Write-Host " $source_path -> $destination_path" + if (!(Test-Path $destination_full_directory)) { + New-Item -Type Directory $destination_full_directory -ErrorAction Stop | Write-Verbose + } + Copy-Item -Path $source_path -Destination $destination_path -ErrorAction Stop + } + } + Write-Host "Copying files from `"$source_directory`" to `"$destination_directory`"" foreach ( $file in $source_files ) { $source_path = "$source_directory\$file" @@ -346,3 +362,17 @@ foreach ( $file in $source_files ) { exit 1 } } + +if ($copy_redist) { + Write-Host "Copying the VC++ Redist (Debug) files from `"$vc_redist_dir`" to `"$destination_directory`" in VM `"$vm`"..." + $files = Get-ChildItem -Path $vc_redist_dir -File + foreach ($file in $files) { + $source_path = $file.FullName + $destination_path = Join-Path -Path $destination_directory -ChildPath $file.Name + Write-Host " $source_path -> $destination_path" + Copy-VMFile "$vm" -SourcePath "$source_path" -DestinationPath "$destination_path" -CreateFullPath -FileSource Host -Force + if (! $?) { + exit 1 + } + } +} diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index d2b2bfb3c..239df77d6 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -75,7 +75,7 @@ function Invoke-Test } # Parse output to check for errors. - if ($null -eq $Output) { + if ($Output -eq $null) { throw ("No output generated by $TestName.") } Out-String -InputObject $Output | Write-Log diff --git a/tools/bpf2c/Convert-BpfToNative.ps1.template b/tools/bpf2c/Convert-BpfToNative.ps1.template index 22cef69ad..76abb4b93 100644 --- a/tools/bpf2c/Convert-BpfToNative.ps1.template +++ b/tools/bpf2c/Convert-BpfToNative.ps1.template @@ -94,7 +94,7 @@ if ($Configuration -eq "Release" -and $SkipVerification) { throw "Invalid parameter. SkipVerification is only supported for Debug builds" } -if ($null -eq (Get-Command 'msbuild.exe' -ErrorAction SilentlyContinue)) { +if ((Get-Command 'msbuild.exe' -ErrorAction SilentlyContinue) -eq $null) { throw "Unable to locate msbuild.exe. This command needs to run within a 'Developer Command Prompt'" }