From 11893b19ac369f574d2b2202ffdc1caa7214c27e Mon Sep 17 00:00:00 2001 From: İsa Yurdagül <38290414+isayrdgl@users.noreply.github.com> Date: Mon, 4 Jul 2022 14:51:50 +0300 Subject: Memory leakage in message "sizeof(SCANNER_MESSAGE) * threadCount * requestCount" bytes long memory is allocated but only "sizeof(SCANNER_MESSAGE) * threadCount" bytes long of it is freed. --- filesys/miniFilter/scanner/user/scanUser.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/filesys/miniFilter/scanner/user/scanUser.c b/filesys/miniFilter/scanner/user/scanUser.c index e766261c..3160d5b4 100644 --- a/filesys/miniFilter/scanner/user/scanUser.c +++ b/filesys/miniFilter/scanner/user/scanUser.c @@ -151,7 +151,6 @@ Return Value { PSCANNER_NOTIFICATION notification; SCANNER_REPLY_MESSAGE replyMessage; - PSCANNER_MESSAGE message; LPOVERLAPPED pOvlp; BOOL result; DWORD outSize; @@ -254,8 +253,6 @@ Return Value } } - free( message ); - return hr; } @@ -271,7 +268,7 @@ main ( HANDLE threads[SCANNER_MAX_THREAD_COUNT]; SCANNER_THREAD_CONTEXT context; HANDLE port, completion; - PSCANNER_MESSAGE msg; + PSCANNER_MESSAGE messages; DWORD threadId; HRESULT hr; DWORD i, j; @@ -342,12 +339,14 @@ main ( context.Port = port; context.Completion = completion; + messages = malloc(sizeof(SCANNER_MESSAGE) * threadCount * requestCount); + // // Create specified number of threads. // for (i = 0; i < threadCount; i++) { - + threads[i] = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE) ScannerWorker, @@ -372,14 +371,8 @@ main ( // Allocate the message. // -#pragma prefast(suppress:__WARNING_MEMORY_LEAK, "msg will not be leaked because it is freed in ScannerWorker") - msg = malloc( sizeof( SCANNER_MESSAGE ) ); - if (msg == NULL) { - - hr = ERROR_NOT_ENOUGH_MEMORY; - goto main_cleanup; - } + PSCANNER_MESSAGE msg = &(messages[i * j]); memset( &msg->Ovlp, 0, sizeof( OVERLAPPED ) ); @@ -393,8 +386,6 @@ main ( &msg->Ovlp ); if (hr != HRESULT_FROM_WIN32( ERROR_IO_PENDING )) { - - free( msg ); goto main_cleanup; } } @@ -403,7 +394,7 @@ main ( hr = S_OK; WaitForMultipleObjectsEx( i, threads, TRUE, INFINITE, FALSE ); - + main_cleanup: printf( "Scanner: All done. Result = 0x%08x\n", hr ); @@ -411,6 +402,8 @@ main_cleanup: CloseHandle( port ); CloseHandle( completion ); + free(messages); + return hr; } -- cgit v1.3.1 From 054b7fd9bddba6e5d52eb894c6449b8637d5a9bc Mon Sep 17 00:00:00 2001 From: İsa Yurdagül <38290414+isayrdgl@users.noreply.github.com> Date: Tue, 5 Jul 2022 14:07:19 +0300 Subject: Handles malloc function fail case --- filesys/miniFilter/scanner/user/scanUser.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/filesys/miniFilter/scanner/user/scanUser.c b/filesys/miniFilter/scanner/user/scanUser.c index 3160d5b4..23ab37f3 100644 --- a/filesys/miniFilter/scanner/user/scanUser.c +++ b/filesys/miniFilter/scanner/user/scanUser.c @@ -341,6 +341,12 @@ main ( messages = malloc(sizeof(SCANNER_MESSAGE) * threadCount * requestCount); + if (messages == NULL) { + + hr = ERROR_NOT_ENOUGH_MEMORY; + goto main_cleanup; + } + // // Create specified number of threads. // -- cgit v1.3.1 From f6b5a19b6e6327b6ad97ac94bdc0a26c2f01437e Mon Sep 17 00:00:00 2001 From: İsa Yurdagül <38290414+isayrdgl@users.noreply.github.com> Date: Wed, 6 Jul 2022 12:24:25 +0300 Subject: Refactors comment line --- filesys/miniFilter/scanner/user/scanUser.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/filesys/miniFilter/scanner/user/scanUser.c b/filesys/miniFilter/scanner/user/scanUser.c index 23ab37f3..13dd3494 100644 --- a/filesys/miniFilter/scanner/user/scanUser.c +++ b/filesys/miniFilter/scanner/user/scanUser.c @@ -339,6 +339,10 @@ main ( context.Port = port; context.Completion = completion; + // + // Allocate messages. + // + messages = malloc(sizeof(SCANNER_MESSAGE) * threadCount * requestCount); if (messages == NULL) { @@ -373,11 +377,6 @@ main ( for (j = 0; j < requestCount; j++) { - // - // Allocate the message. - // - - PSCANNER_MESSAGE msg = &(messages[i * j]); memset( &msg->Ovlp, 0, sizeof( OVERLAPPED ) ); -- cgit v1.3.1 From a0e28e02cbd274de30e64abd38d8690dd45396a9 Mon Sep 17 00:00:00 2001 From: İsa Yurdagül <38290414+isayrdgl@users.noreply.github.com> Date: Wed, 6 Jul 2022 12:41:08 +0300 Subject: Solves the miscalculation of the message index --- filesys/miniFilter/scanner/user/scanUser.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/filesys/miniFilter/scanner/user/scanUser.c b/filesys/miniFilter/scanner/user/scanUser.c index 13dd3494..b4605156 100644 --- a/filesys/miniFilter/scanner/user/scanUser.c +++ b/filesys/miniFilter/scanner/user/scanUser.c @@ -376,8 +376,8 @@ main ( } for (j = 0; j < requestCount; j++) { - - PSCANNER_MESSAGE msg = &(messages[i * j]); + + PSCANNER_MESSAGE msg = &(messages[i * requestCount + j]); memset( &msg->Ovlp, 0, sizeof( OVERLAPPED ) ); -- cgit v1.3.1 From 54466dac1149ba84e0ebff353eca8922cbdc5908 Mon Sep 17 00:00:00 2001 From: Fredrik Orderud Date: Mon, 11 Dec 2023 12:17:19 +0100 Subject: simbatt: Fix broken registry read-back The GetSimBattStateFromRegistry function is currently using default settings if GetSimBattStateFromRegistry succeeds, whereas settings from registry are only applied if GetSimBattStateFromRegistry fails. This does not make sense to me. Therefore proposing to remove the `!` negation from `if (!NT_SUCCESS(Status)) {` on the line after `Status = GetSimBattStateFromRegistry(Device, RegState);` so that default settings are loaded when registry read-back fails. --- simbatt/func/miniclass.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simbatt/func/miniclass.c b/simbatt/func/miniclass.c index ba2df340..612b4c66 100644 --- a/simbatt/func/miniclass.c +++ b/simbatt/func/miniclass.c @@ -202,7 +202,7 @@ Return Value: } Status = GetSimBattStateFromRegistry(Device, RegState); - if (!NT_SUCCESS(Status)) { + if (NT_SUCCESS(Status)) { RtlZeroMemory(RegState, sizeof(SIMBATT_STATE)); WdfWaitLockAcquire(DevExt->StateLock, NULL); -- cgit v1.3.1 From 59050f0d2a891f59987469ab79fe73411f5eb891 Mon Sep 17 00:00:00 2001 From: İsa Yurdagül <38290414+isayrdgl@users.noreply.github.com> Date: Thu, 23 May 2024 11:47:46 +0300 Subject: Issue of freeing memory without waiting completion of threads accessing it is fixed --- filesys/miniFilter/scanner/user/scanUser.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/filesys/miniFilter/scanner/user/scanUser.c b/filesys/miniFilter/scanner/user/scanUser.c index b4605156..82dc2fd5 100644 --- a/filesys/miniFilter/scanner/user/scanUser.c +++ b/filesys/miniFilter/scanner/user/scanUser.c @@ -151,6 +151,7 @@ Return Value { PSCANNER_NOTIFICATION notification; SCANNER_REPLY_MESSAGE replyMessage; + PSCANNER_MESSAGE message; LPOVERLAPPED pOvlp; BOOL result; DWORD outSize; @@ -265,13 +266,12 @@ main ( { DWORD requestCount = SCANNER_DEFAULT_REQUEST_COUNT; DWORD threadCount = SCANNER_DEFAULT_THREAD_COUNT; - HANDLE threads[SCANNER_MAX_THREAD_COUNT]; + HANDLE threads[SCANNER_MAX_THREAD_COUNT] = { NULL }; SCANNER_THREAD_CONTEXT context; HANDLE port, completion; PSCANNER_MESSAGE messages; DWORD threadId; HRESULT hr; - DWORD i, j; // // Check how many threads and per thread requests are desired. @@ -355,7 +355,7 @@ main ( // Create specified number of threads. // - for (i = 0; i < threadCount; i++) { + for (DWORD i = 0; i < threadCount; i++) { threads[i] = CreateThread( NULL, 0, @@ -375,7 +375,7 @@ main ( goto main_cleanup; } - for (j = 0; j < requestCount; j++) { + for (DWORD j = 0; j < requestCount; j++) { PSCANNER_MESSAGE msg = &(messages[i * requestCount + j]); @@ -397,11 +397,13 @@ main ( } hr = S_OK; - - WaitForMultipleObjectsEx( i, threads, TRUE, INFINITE, FALSE ); main_cleanup: + for (INT i = 0; threads[i] != NULL; ++i) { + WaitForSingleObjectEx(threads[i], INFINITE, FALSE); + } + printf( "Scanner: All done. Result = 0x%08x\n", hr ); CloseHandle( port ); -- cgit v1.3.1 From 015ee1d12e6f22c62aa3057668eea9ab737e5ed8 Mon Sep 17 00:00:00 2001 From: İsa Yurdagül <38290414+isayrdgl@users.noreply.github.com> Date: Fri, 24 May 2024 11:15:02 +0300 Subject: Fixes information leakage warning Fixes the issue of possible information leakage from uninitialized padding bytes --- filesys/miniFilter/scanner/user/scanUser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/filesys/miniFilter/scanner/user/scanUser.c b/filesys/miniFilter/scanner/user/scanUser.c index 82dc2fd5..201f0a45 100644 --- a/filesys/miniFilter/scanner/user/scanUser.c +++ b/filesys/miniFilter/scanner/user/scanUser.c @@ -343,7 +343,7 @@ main ( // Allocate messages. // - messages = malloc(sizeof(SCANNER_MESSAGE) * threadCount * requestCount); + messages = calloc(threadCount * requestCount, sizeof(SCANNER_MESSAGE)); if (messages == NULL) { -- cgit v1.3.1 From fcb15d6e90b644fd13e545ff1cb5f3672a828733 Mon Sep 17 00:00:00 2001 From: İsa Yurdagül <38290414+isayrdgl@users.noreply.github.com> Date: Sat, 25 May 2024 21:54:02 +0300 Subject: Avoids possible multiplication overflow warning --- filesys/miniFilter/scanner/user/scanUser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/filesys/miniFilter/scanner/user/scanUser.c b/filesys/miniFilter/scanner/user/scanUser.c index 201f0a45..f990c550 100644 --- a/filesys/miniFilter/scanner/user/scanUser.c +++ b/filesys/miniFilter/scanner/user/scanUser.c @@ -343,7 +343,7 @@ main ( // Allocate messages. // - messages = calloc(threadCount * requestCount, sizeof(SCANNER_MESSAGE)); + messages = calloc((DWORD) threadCount * requestCount, sizeof(SCANNER_MESSAGE)); if (messages == NULL) { -- cgit v1.3.1 From eeb01308a611b0f27e64aa7cca1e140b7ec902a0 Mon Sep 17 00:00:00 2001 From: İsa Yurdagül <38290414+isayrdgl@users.noreply.github.com> Date: Wed, 29 May 2024 21:24:30 +0300 Subject: Avoids possible multiplication overflow warning --- filesys/miniFilter/scanner/user/scanUser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/filesys/miniFilter/scanner/user/scanUser.c b/filesys/miniFilter/scanner/user/scanUser.c index f990c550..08b948b3 100644 --- a/filesys/miniFilter/scanner/user/scanUser.c +++ b/filesys/miniFilter/scanner/user/scanUser.c @@ -343,7 +343,7 @@ main ( // Allocate messages. // - messages = calloc((DWORD) threadCount * requestCount, sizeof(SCANNER_MESSAGE)); + messages = calloc(((size_t) threadCount) * requestCount, sizeof(SCANNER_MESSAGE)); if (messages == NULL) { -- cgit v1.3.1 From e59949f40da211f378e8f76bee383506d9b97243 Mon Sep 17 00:00:00 2001 From: Matt <138825652+middlemose@users.noreply.github.com> Date: Mon, 24 Jun 2024 11:14:36 -0700 Subject: CI Pipelines build with WDK Nuget Packages (#1179) Integrate nuget into the workflow pipelines --- .github/scripts/Install-Vsix.ps1 | 68 +++++++++++++++++++++++++++++++++++++ .github/workflows/Code-Scanning.yml | 56 +++++++++++++++--------------- .github/workflows/ci-pr.yml | 10 +++--- .github/workflows/ci.yml | 13 +++---- Build-SampleSet.ps1 | 24 +++++++++---- Env-Vars.ps1 | 9 +++++ 6 files changed, 135 insertions(+), 45 deletions(-) create mode 100644 .github/scripts/Install-Vsix.ps1 create mode 100644 Env-Vars.ps1 diff --git a/.github/scripts/Install-Vsix.ps1 b/.github/scripts/Install-Vsix.ps1 new file mode 100644 index 00000000..24c7ef45 --- /dev/null +++ b/.github/scripts/Install-Vsix.ps1 @@ -0,0 +1,68 @@ +<# + +.SYNOPSIS +Checks WDK vsix version and downloads and installs as necessary. + +#> + +[CmdletBinding()] +param( + [bool]$optimize = $false +) + +$root = Get-Location + +# launch developer powershell (if necessary) +if (-not $env:VSCMD_VER) { + Import-Module (Resolve-Path "$env:ProgramFiles\Microsoft Visual Studio\2022\*\Common7\Tools\Microsoft.VisualStudio.DevShell.dll") + Enter-VsDevShell -VsInstallPath (Resolve-Path "$env:ProgramFiles\Microsoft Visual Studio\2022\*") + cd $root +} + +# source environment variables +. .\Env-Vars.ps1 + +$version = $env:SAMPLES_VSIX_VERSION +$uri = $env:SAMPLES_VSIX_URI + +function PrintWdkVsix { + $installed = ls "${env:ProgramData}\Microsoft\VisualStudio\Packages\Microsoft.Windows.DriverKit,version=*" | Select -ExpandProperty Name + "WDK Vsix Version: $installed" +} + +function TestWdkVsix { + Test-Path "${env:ProgramData}\Microsoft\VisualStudio\Packages\Microsoft.Windows.DriverKit,version=$version" +} + +if ($optimize) { + "---> Downloading vsix and configuring build environment..." + Invoke-WebRequest -Uri "$uri" -OutFile wdk.zip + Expand-Archive ".\wdk.zip" .\ + cp ".\`$MSBuild\*" (Resolve-Path "$env:ProgramFiles\Microsoft Visual Studio\2022\*\MSBuild\") -Recurse -Force + "<--- Finished" +} +else { + "Getting installed WDK vsix..." + PrintWdkVsix + "Checking the WDK.vsix version installed..." + if (-not (TestWdkVsix)) { + "The correct WDK vsix is not installed." + "Will attempt to download and install now..." + Invoke-WebRequest -Uri "$uri" -OutFile wdk.vsix + "Finished downloading." + "Starting install process. This will take some time to complete..." + Start-Process vsixinstaller -ArgumentList "/f /q /sp .\wdk.vsix" -wait + "The install process has finished." + "Checking the WDK.vsix version installed..." + if (TestWdkVsix) { + PrintWdkVsix + "The WDK vsix version is OK" + } + else { + "The WDK vsix install FAILED" + Write-Host "`u{274C} wdk vsix install had an issue" + Write-Error "the wdk vsix cannot be installed at this time" + exit 1 + } + } +} \ No newline at end of file diff --git a/.github/workflows/Code-Scanning.yml b/.github/workflows/Code-Scanning.yml index a18bcf95..32bb5a65 100644 --- a/.github/workflows/Code-Scanning.yml +++ b/.github/workflows/Code-Scanning.yml @@ -32,31 +32,31 @@ jobs: language: [ 'cpp' ] steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - submodules: 'recursive' - - - name: Initialize CodeQL - uses: github/codeql-action/init@v3 - with: - languages: ${{ matrix.language }} - packs: microsoft/windows-drivers - - name: Add MSBuild to PATH - uses: microsoft/setup-msbuild@v2 - - - name: Retrieve and build all available solutions - run: | - .\Build-AllSamples.ps1 -Verbose -ThrottleLimit 1 - env: - WDS_Configuration: Debug - WDS_Platform: x64 - WDS_WipeOutputs: ${{ true }} - - - name: Perform CodeQL analysis - uses: github/codeql-action/analyze@v3 - with: - category: "/language:${{matrix.language}}" - - - + - name: Checkout repository + uses: actions/checkout@v4 + with: + submodules: 'recursive' + + - name: Install WDK VSIX + run: .\.github\scripts\Install-Vsix.ps1 -optimize:$true + + - name: Install Nuget Packages + run: nuget restore .\packages.config -PackagesDirectory .\packages\ + + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + with: + languages: ${{ matrix.language }} + packs: microsoft/windows-drivers + + - name: Retrieve and build all available solutions + run: .\Build-AllSamples.ps1 -Verbose -ThrottleLimit 1 + env: + WDS_Configuration: Debug + WDS_Platform: x64 + WDS_WipeOutputs: ${{ true }} + + - name: Perform CodeQL analysis + uses: github/codeql-action/analyze@v3 + with: + category: "/language:${{matrix.language}}" diff --git a/.github/workflows/ci-pr.yml b/.github/workflows/ci-pr.yml index 7640b966..a179127a 100644 --- a/.github/workflows/ci-pr.yml +++ b/.github/workflows/ci-pr.yml @@ -22,8 +22,11 @@ jobs: with: submodules: 'recursive' - - name: Add MSBuild to PATH - uses: microsoft/setup-msbuild@v2 + - name: Install WDK VSIX + run: .\.github\scripts\Install-Vsix.ps1 -optimize:$true + + - name: Install Nuget Packages + run: nuget restore .\packages.config -PackagesDirectory .\packages\ - name: Get changed files id: get-changed-files @@ -63,8 +66,7 @@ jobs: path: _logs - name: Join and generate global reports - run: | - .\.github\scripts\Join-CsvReports.ps1 + run: .\.github\scripts\Join-CsvReports.ps1 - name: Archive global overview build reports uses: actions/upload-artifact@v3 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ad92f83b..13563aa8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,12 +22,14 @@ jobs: with: submodules: 'recursive' - - name: Add MSBuild to PATH - uses: microsoft/setup-msbuild@v2 + - name: Install WDK VSIX + run: .\.github\scripts\Install-Vsix.ps1 -optimize:$true + + - name: Install Nuget Packages + run: nuget restore .\packages.config -PackagesDirectory .\packages\ - name: Retrieve and build all available solutions - run: | - .\Build-AllSamples.ps1 -Verbose + run: .\Build-AllSamples.ps1 -Verbose env: WDS_Configuration: ${{ matrix.configuration }} WDS_Platform: ${{ matrix.platform }} @@ -56,8 +58,7 @@ jobs: path: _logs - name: Join and generate global reports - run: | - .\.github\scripts\Join-CsvReports.ps1 + run: .\.github\scripts\Join-CsvReports.ps1 - name: Archive global overview build reports uses: actions/upload-artifact@v3 diff --git a/Build-SampleSet.ps1 b/Build-SampleSet.ps1 index b0da097a..2197b967 100644 --- a/Build-SampleSet.ps1 +++ b/Build-SampleSet.ps1 @@ -9,6 +9,17 @@ param( ) $root = Get-Location + +# launch developer powershell (if necessary) +if (-not $env:VSCMD_VER) { + Import-Module (Resolve-Path "$env:ProgramFiles\Microsoft Visual Studio\2022\*\Common7\Tools\Microsoft.VisualStudio.DevShell.dll") + Enter-VsDevShell -VsInstallPath (Resolve-Path "$env:ProgramFiles\Microsoft Visual Studio\2022\*") + cd $root +} + +# source environment variables +. .\Env-Vars.ps1 + $ThrottleFactor = 5 $LogicalProcessors = (Get-CIMInstance -Class 'CIM_Processor' -Verbose:$false).NumberOfLogicalProcessors @@ -51,21 +62,20 @@ finally { $build_environment="" $build_number=0 # -# WDK NuGet will require presence of a folder 'packages' +# In Github we build using Nuget only and source version from repo .\Env-Vars.ps1. # -# -# Hack: In GitHub we do not have an environment variable where we can see WDK build number, so we have it hard coded. -# -if (-not $env:GITHUB_REPOSITORY -eq '') { +if ($env:GITHUB_REPOSITORY) { $build_environment="GitHub" - $build_number=22621 + $build_number=$env:SAMPLES_BUILD_NUMBER } # +# WDK NuGet will require presence of a folder 'packages'. The version is sourced from repo .\Env-Vars.ps1. +# # Hack: If user has hydrated nuget packages, then use those. That will be indicated by presence of a folder named .\packages. # elseif(Test-Path(".\packages")) { $build_environment=("NuGet") - $build_number=26100 + $build_number=$env:SAMPLES_BUILD_NUMBER } # # EWDK sets environment variable BuildLab. For example 'ni_release_svc_prod1.22621.2428'. diff --git a/Env-Vars.ps1 b/Env-Vars.ps1 new file mode 100644 index 00000000..0d37e03c --- /dev/null +++ b/Env-Vars.ps1 @@ -0,0 +1,9 @@ +# Environment variables for script sourcing. +# Note: When a new WDK ships the following need to be updated: +# 1. Environment variables in .\Env-Vars.ps1 (this script) +# 2. Nuget package versions in .\packages.config +# 3. Nuget package versions in .\Directory.Build.props +# 4. SDK and WDK versions and WDK vsix link in .\configuration.dsc.yaml +$env:SAMPLES_VSIX_VERSION = "10.0.26100.0" +$env:SAMPLES_VSIX_URI = "https://marketplace.visualstudio.com/_apis/public/gallery/publishers/DriverDeveloperKits-WDK/vsextensions/WDKVsix/10.0.26100.0/vspackage?targetPlatform=5e3e564c-03bb-4499-8ae5-b2b35e9a86dc" +$env:SAMPLES_BUILD_NUMBER = "26100" -- cgit v1.3.1 From 1704d357a37623a8d03f0e5d2d6d4cfe45920b1c Mon Sep 17 00:00:00 2001 From: JakobL-MSFT <110699333+JakobL-MSFT@users.noreply.github.com> Date: Mon, 24 Jun 2024 18:56:23 -0700 Subject: FI from main to develop (#1188) Fix text and minor issues in Winget configuration files Co-authored-by: Adonais Romero Gonzalez --- configuration.dsc.yaml | 30 ++++++++++++------------------ configuration_vsonly.dsc.yaml | 6 +++--- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/configuration.dsc.yaml b/configuration.dsc.yaml index 3bb6b668..f8245c08 100644 --- a/configuration.dsc.yaml +++ b/configuration.dsc.yaml @@ -4,18 +4,18 @@ properties: - resource: Microsoft.WinGet.DSC/WinGetPackage id: vsPackage directives: - description: Install Visual Studio Community 2022 + description: Install Visual Studio 2022 Community allowPrerelease: true settings: id: Microsoft.VisualStudio.2022.Community source: winget + useLatest: true - resource: Microsoft.VisualStudio.DSC/VSComponents id: vsComponents dependsOn: - vsPackage directives: - description: Install required VS workloads - allowPrerelease: true + description: Install required VS workloads and components settings: productId: Microsoft.VisualStudio.Product.Community channelId: VisualStudio.17.Release @@ -42,28 +42,26 @@ properties: - Microsoft.VisualStudio.Component.VC.MFC.ARM64 - Microsoft.VisualStudio.Component.VC.MFC.ARM64.Spectre - Microsoft.VisualStudio.Workload.NativeDesktop - - resource: Microsoft.WinGet.DSC/WinGetPackage id: sdkPackage - dependsOn: - - vsComponents directives: - description: Install Windows SDK + description: Install Windows SDK version 26100 allowPrerelease: true settings: id: Microsoft.WindowsSDK.10.0.26100 source: winget + useLatest: true - resource: Microsoft.WinGet.DSC/WinGetPackage id: wdkPackage dependsOn: - sdkPackage - - vsComponents directives: - description: Install Windows Driver Kit + description: Install Windows Driver Kit version 26100 allowPrerelease: true settings: id: Microsoft.WindowsWDK.10.0.26100 source: winget + useLatest: true - resource: PSDscResources/Script id: wdkVsix dependsOn: @@ -73,15 +71,11 @@ properties: description: Install Windows Driver Kit VSIX settings: GetScript: | - return & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -nologo -latest -products Microsoft.VisualStudio.Product.Community -requires Microsoft.Windows.DriverKit -property installationVersion + return & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -nologo -version '[17.0,18.0)' -requires Microsoft.Windows.DriverKit -property installationVersion SetScript: | - $path = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -nologo -latest -products * -property enginePath | Join-Path -ChildPath 'VSIXInstaller.exe' - $arch = $env:PROCESSOR_ARCHITECTURE - if (Test-Path $path) { & $path /q "${env:ProgramFiles(x86)}\Windows Kits\10\Vsix\VS2022\10.0.26100.0\$arch\WDK.vsix" } + $installerPath = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -nologo -latest -products * -property enginePath | Join-Path -ChildPath 'VSIXInstaller.exe' + if (Test-Path $installerPath) { & $installerPath /q "${env:ProgramFiles(x86)}\Windows Kits\10\Vsix\VS2022\10.0.26100.0\${env:PROCESSOR_ARCHITECTURE}\WDK.vsix" } TestScript: | - $versionString = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -nologo -latest -products Microsoft.VisualStudio.Product.Community -requires Microsoft.Windows.DriverKit -Property installationVersion - if (-not $versionString) { return $false } - $versionArray = $versionString.Split('.') - if ($versionArray[0] -le 17) { return $false } - return $true + $versionString = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -nologo -version '[17.0,18.0)' -requires Microsoft.Windows.DriverKit -property installationVersion + return $versionString -match "^17\." configurationVersion: 0.2.0 diff --git a/configuration_vsonly.dsc.yaml b/configuration_vsonly.dsc.yaml index b7764f0f..6ce4fc83 100644 --- a/configuration_vsonly.dsc.yaml +++ b/configuration_vsonly.dsc.yaml @@ -4,18 +4,18 @@ properties: - resource: Microsoft.WinGet.DSC/WinGetPackage id: vsPackage directives: - description: Install Visual Studio Community 2022 + description: Install Visual Studio 2022 Community allowPrerelease: true settings: id: Microsoft.VisualStudio.2022.Community source: winget + useLatest: true - resource: Microsoft.VisualStudio.DSC/VSComponents id: vsComponents dependsOn: - vsPackage directives: - description: Install required VS workloads - allowPrerelease: true + description: Install required VS workloads and components settings: productId: Microsoft.VisualStudio.Product.Community channelId: VisualStudio.17.Release -- cgit v1.3.1 From 6dabe4ef5fa80d5a565705edeb6a0dcb98b30f80 Mon Sep 17 00:00:00 2001 From: Matt <138825652+middlemose@users.noreply.github.com> Date: Tue, 25 Jun 2024 10:51:36 -0700 Subject: Improve version info, vsix installation, and update building locally readme --- .github/scripts/Install-Vsix.ps1 | 40 ++++++++++++++++++++++++---------------- Build-SampleSet.ps1 | 23 ++++++++++++++--------- Building-Locally.md | 6 +++++- Env-Vars.ps1 | 9 --------- 4 files changed, 43 insertions(+), 35 deletions(-) delete mode 100644 Env-Vars.ps1 diff --git a/.github/scripts/Install-Vsix.ps1 b/.github/scripts/Install-Vsix.ps1 index 24c7ef45..8579b36b 100644 --- a/.github/scripts/Install-Vsix.ps1 +++ b/.github/scripts/Install-Vsix.ps1 @@ -12,34 +12,42 @@ param( $root = Get-Location -# launch developer powershell (if necessary) -if (-not $env:VSCMD_VER) { - Import-Module (Resolve-Path "$env:ProgramFiles\Microsoft Visual Studio\2022\*\Common7\Tools\Microsoft.VisualStudio.DevShell.dll") - Enter-VsDevShell -VsInstallPath (Resolve-Path "$env:ProgramFiles\Microsoft Visual Studio\2022\*") - cd $root -} +# launch developer powershell +Import-Module (Resolve-Path "$env:ProgramFiles\Microsoft Visual Studio\2022\*\Common7\Tools\Microsoft.VisualStudio.DevShell.dll") +Enter-VsDevShell -VsInstallPath (Resolve-Path "$env:ProgramFiles\Microsoft Visual Studio\2022\*") +cd $root + +# Automatically resolve the latest amd64 VSIX +$uri = "https://marketplace.visualstudio.com$((Invoke-WebRequest -Uri "https://marketplace.visualstudio.com/items?itemName=DriverDeveloperKits-WDK.WDKVsix").Links | Where-Object outerHTML -like '*(amd64)*' | select -expand href)" -# source environment variables -. .\Env-Vars.ps1 +# Set local version variable +$version = ([regex]'(\d+\.)(\d+\.)(\d+\.)(\d+)').Matches($uri).Value -$version = $env:SAMPLES_VSIX_VERSION -$uri = $env:SAMPLES_VSIX_URI +# Set github environment variable for vsix version +"SAMPLES_VSIX_VERSION=$version" | Out-File -FilePath "$env:GITHUB_ENV" -Append function PrintWdkVsix { - $installed = ls "${env:ProgramData}\Microsoft\VisualStudio\Packages\Microsoft.Windows.DriverKit,version=*" | Select -ExpandProperty Name - "WDK Vsix Version: $installed" + "WDK Vsix Version: $(ls "${env:ProgramData}\Microsoft\VisualStudio\Packages\Microsoft.Windows.DriverKit,version=*" | Select -ExpandProperty Name)" } function TestWdkVsix { Test-Path "${env:ProgramData}\Microsoft\VisualStudio\Packages\Microsoft.Windows.DriverKit,version=$version" } +# NOTE: The '$optimize' code path examines the '.vsixmanifest' when downloaded and then examines it again (in the 'MSBuild' directory) once +# the necessary extension files are copied. if ($optimize) { - "---> Downloading vsix and configuring build environment..." + $msbuild_path = (Resolve-Path "$env:ProgramFiles\Microsoft Visual Studio\2022\*\MSBuild\") + "---> Downloading vsix version: $version" Invoke-WebRequest -Uri "$uri" -OutFile wdk.zip Expand-Archive ".\wdk.zip" .\ - cp ".\`$MSBuild\*" (Resolve-Path "$env:ProgramFiles\Microsoft Visual Studio\2022\*\MSBuild\") -Recurse -Force - "<--- Finished" + "Downloaded VSIX Version: $(([xml](Get-Content .\extension.vsixmanifest)).PackageManifest.Metadata.Identity.Version)" + "<--- Download complete" + "---> Configuring build environment..." + cp ".\`$MSBuild\*" "$msbuild_path" -Recurse -Force + cp ".\extension.vsixmanifest" "$msbuild_path" + "Installed VSIX Version: $(([xml](Get-Content ${msbuild_path}\extension.vsixmanifest)).PackageManifest.Metadata.Identity.Version)" + "<--- Configuration complete" } else { "Getting installed WDK vsix..." @@ -65,4 +73,4 @@ else { exit 1 } } -} \ No newline at end of file +} diff --git a/Build-SampleSet.ps1 b/Build-SampleSet.ps1 index 2197b967..5be14dcf 100644 --- a/Build-SampleSet.ps1 +++ b/Build-SampleSet.ps1 @@ -10,16 +10,13 @@ param( $root = Get-Location -# launch developer powershell (if necessary) +# launch developer powershell (if necessary to prevent multiple developer sessions) if (-not $env:VSCMD_VER) { Import-Module (Resolve-Path "$env:ProgramFiles\Microsoft Visual Studio\2022\*\Common7\Tools\Microsoft.VisualStudio.DevShell.dll") Enter-VsDevShell -VsInstallPath (Resolve-Path "$env:ProgramFiles\Microsoft Visual Studio\2022\*") cd $root } -# source environment variables -. .\Env-Vars.ps1 - $ThrottleFactor = 5 $LogicalProcessors = (Get-CIMInstance -Class 'CIM_Processor' -Verbose:$false).NumberOfLogicalProcessors @@ -56,26 +53,30 @@ finally { } # -# Determine build environment: 'GitHub', 'NuGet', 'EWDK', or 'WDK'. Only used to determine build number. +# Determine build environment: 'GitHub', 'NuGet', 'EWDK', or 'WDK'. # Determine build number (used for exclusions based on build number). Five digits. Say, '22621'. # $build_environment="" $build_number=0 +$nuget_package_version=0 # # In Github we build using Nuget only and source version from repo .\Env-Vars.ps1. # if ($env:GITHUB_REPOSITORY) { $build_environment="GitHub" - $build_number=$env:SAMPLES_BUILD_NUMBER + $nuget_package_version=([regex]'(?<=x64\.)(\d+\.)(\d+\.)(\d+\.)(\d+)').Matches((Get-Childitem .\packages\*WDK.x64* -Name)).Value + $build_number=$nuget_package_version.split('.')[2] } # # WDK NuGet will require presence of a folder 'packages'. The version is sourced from repo .\Env-Vars.ps1. # -# Hack: If user has hydrated nuget packages, then use those. That will be indicated by presence of a folder named .\packages. +# Hack: If user has hydrated nuget packages, then use those. That will be indicated by presence of a folder named '.\packages'. +# Further, we need to test that the directory has been hydrated using '.\packages\*'. # -elseif(Test-Path(".\packages")) { +elseif(Test-Path(".\packages\*")) { $build_environment=("NuGet") - $build_number=$env:SAMPLES_BUILD_NUMBER + $nuget_package_version=([regex]'(?<=x64\.)(\d+\.)(\d+\.)(\d+\.)(\d+)').Matches((Get-Childitem .\packages\*WDK.x64* -Name)).Value + $build_number=$nuget_package_version.split('.')[2] } # # EWDK sets environment variable BuildLab. For example 'ni_release_svc_prod1.22621.2428'. @@ -164,6 +165,10 @@ $jresult = @{ $SolutionsTotal = $sampleSet.Count * $Configurations.Count * $Platforms.Count Write-Output ("Build Environment: " + $build_environment) +if (($build_environment -eq "GitHub") -or ($build_environment -eq "NuGet")) { + Write-Output ("Nuget Package Version: " + $nuget_package_version) +} +Write-Output ("WDK VSIX Version: " + ($env:SAMPLES_VSIX_VERSION) ? $env:SAMPLES_VSIX_VERSION : (ls "${env:ProgramData}\Microsoft\VisualStudio\Packages\Microsoft.Windows.DriverKit,version=*" | Select -ExpandProperty Name).split('=')[1]) Write-Output ("Build Number: " + $build_number) Write-Output ("Samples: " + $sampleSet.Count) Write-Output ("Configurations: " + $Configurations.Count + " (" + $Configurations + ")") diff --git a/Building-Locally.md b/Building-Locally.md index bb9fc610..e3db8dde 100644 --- a/Building-Locally.md +++ b/Building-Locally.md @@ -79,7 +79,11 @@ To build the Windows Driver Samples you need a "driver build environment". In e ### Option A: Use WDK NuGet Packages * See [Download the Windows Driver Kit (WDK)](https://learn.microsoft.com/en-us/windows-hardware/drivers/download-the-wdk) for instructions on how to install Visual Studio, but only complete "Step 1". You do not need to install the SDK or the WDK. -* Install the Visual Studio Windows Driver Kit Extension (WDK.vsix). Open Visual Studio -> Extensions -> Manage Extensions... -> Online -> Visual Studio Market Place -> Windows Driver Kit -> 10.0.26100.0 -> Download +* Install the Visual Studio Windows Driver Kit Extension (WDK.vsix). + * Open Visual Studio -> Extensions -> Manage Extensions... -> Browse. + * In the search bar type: `Windows Driver Kit`. + * Find the `Microsoft` signed extension. + * Click the Install button. * Launch a "Developer Command Prompt for VS 2022". * Restore WDK packages from feed : diff --git a/Env-Vars.ps1 b/Env-Vars.ps1 deleted file mode 100644 index 0d37e03c..00000000 --- a/Env-Vars.ps1 +++ /dev/null @@ -1,9 +0,0 @@ -# Environment variables for script sourcing. -# Note: When a new WDK ships the following need to be updated: -# 1. Environment variables in .\Env-Vars.ps1 (this script) -# 2. Nuget package versions in .\packages.config -# 3. Nuget package versions in .\Directory.Build.props -# 4. SDK and WDK versions and WDK vsix link in .\configuration.dsc.yaml -$env:SAMPLES_VSIX_VERSION = "10.0.26100.0" -$env:SAMPLES_VSIX_URI = "https://marketplace.visualstudio.com/_apis/public/gallery/publishers/DriverDeveloperKits-WDK/vsextensions/WDKVsix/10.0.26100.0/vspackage?targetPlatform=5e3e564c-03bb-4499-8ae5-b2b35e9a86dc" -$env:SAMPLES_BUILD_NUMBER = "26100" -- cgit v1.3.1 From 2e07f1b58a93eb36c616192045db654cf043a670 Mon Sep 17 00:00:00 2001 From: Matt <138825652+middlemose@users.noreply.github.com> Date: Tue, 25 Jun 2024 12:50:00 -0700 Subject: Fix printing vsix version --- Build-SampleSet.ps1 | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Build-SampleSet.ps1 b/Build-SampleSet.ps1 index 5be14dcf..2fccfdb8 100644 --- a/Build-SampleSet.ps1 +++ b/Build-SampleSet.ps1 @@ -164,12 +164,23 @@ $jresult = @{ $SolutionsTotal = $sampleSet.Count * $Configurations.Count * $Platforms.Count -Write-Output ("Build Environment: " + $build_environment) -if (($build_environment -eq "GitHub") -or ($build_environment -eq "NuGet")) { - Write-Output ("Nuget Package Version: " + $nuget_package_version) +# Find vsix version either from env variabel or from packages +$vsix_version = $env:SAMPLES_VSIX_VERSION +if (-not $vsix_version) { + $vsix_version = ls "${env:ProgramData}\Microsoft\VisualStudio\Packages\Microsoft.Windows.DriverKit,version=*" | Select -ExpandProperty Name + if ($vsix_version) { + $vsix_version = $vsix_version.split('=')[1] + } + else { + Write-Error "No version for the WDK VSIX could be found. The WDK VSIX is not installed." + exit 1 + } } -Write-Output ("WDK VSIX Version: " + ($env:SAMPLES_VSIX_VERSION) ? $env:SAMPLES_VSIX_VERSION : (ls "${env:ProgramData}\Microsoft\VisualStudio\Packages\Microsoft.Windows.DriverKit,version=*" | Select -ExpandProperty Name).split('=')[1]) + +Write-Output ("Build Environment: " + $build_environment) Write-Output ("Build Number: " + $build_number) +if (($build_environment -eq "GitHub") -or ($build_environment -eq "NuGet")) { Write-Output ("Nuget Package Version: " + $nuget_package_version) } +Write-Output ("WDK VSIX Version: " + $vsix_version) Write-Output ("Samples: " + $sampleSet.Count) Write-Output ("Configurations: " + $Configurations.Count + " (" + $Configurations + ")") Write-Output ("Platforms: " + $Platforms.Count + " (" + $Platforms + ")") -- cgit v1.3.1 From f9eb04d34edd823873e491a7da6e6ed7a064e823 Mon Sep 17 00:00:00 2001 From: Matt <138825652+middlemose@users.noreply.github.com> Date: Thu, 27 Jun 2024 14:17:05 -0700 Subject: Refactored vsix install and cleaned up build sampleset --- .github/scripts/Install-Vsix.ps1 | 94 +++++++++++-------------------------- .github/workflows/Code-Scanning.yml | 2 +- .github/workflows/ci-pr.yml | 2 +- .github/workflows/ci.yml | 2 +- Build-SampleSet.ps1 | 33 +++++++------ 5 files changed, 49 insertions(+), 84 deletions(-) diff --git a/.github/scripts/Install-Vsix.ps1 b/.github/scripts/Install-Vsix.ps1 index 8579b36b..50ef088b 100644 --- a/.github/scripts/Install-Vsix.ps1 +++ b/.github/scripts/Install-Vsix.ps1 @@ -1,76 +1,38 @@ <# .SYNOPSIS -Checks WDK vsix version and downloads and installs as necessary. +Download and install the latest WDK VSIX. #> -[CmdletBinding()] -param( - [bool]$optimize = $false -) - -$root = Get-Location - -# launch developer powershell -Import-Module (Resolve-Path "$env:ProgramFiles\Microsoft Visual Studio\2022\*\Common7\Tools\Microsoft.VisualStudio.DevShell.dll") -Enter-VsDevShell -VsInstallPath (Resolve-Path "$env:ProgramFiles\Microsoft Visual Studio\2022\*") -cd $root - -# Automatically resolve the latest amd64 VSIX +# set uri by resolving amd64 vsix $uri = "https://marketplace.visualstudio.com$((Invoke-WebRequest -Uri "https://marketplace.visualstudio.com/items?itemName=DriverDeveloperKits-WDK.WDKVsix").Links | Where-Object outerHTML -like '*(amd64)*' | select -expand href)" -# Set local version variable -$version = ([regex]'(\d+\.)(\d+\.)(\d+\.)(\d+)').Matches($uri).Value - -# Set github environment variable for vsix version -"SAMPLES_VSIX_VERSION=$version" | Out-File -FilePath "$env:GITHUB_ENV" -Append - -function PrintWdkVsix { - "WDK Vsix Version: $(ls "${env:ProgramData}\Microsoft\VisualStudio\Packages\Microsoft.Windows.DriverKit,version=*" | Select -ExpandProperty Name)" +# set download version +$uri_version = ([regex]'(\d+\.)(\d+\.)(\d+\.)(\d+)').Matches($uri).Value + +# set msbuild path +$msbuild_path = (Resolve-Path "$env:ProgramFiles\Microsoft Visual Studio\2022\*\MSBuild\") + +# download vsix, expand, and store the downloaded version extracted from the extension manifest +"Downloading WDK VSIX version: $uri_version..." +Invoke-WebRequest -Uri "$uri" -OutFile wdk.zip +"Expanding WDK VSIX archive..." +Expand-Archive ".\wdk.zip" .\ +"Extracting version from manifest..." +$downloaded_version = ([xml](Get-Content .\extension.vsixmanifest)).PackageManifest.Metadata.Identity.Version +"Downloaded WDK VSIX version: $downloaded_version" + +# copy msbuild files, extension manifest, and check installed version from the extension manifest +"Copying WDK extension files to build path..." +cp (".\`$MSBuild\*", ".\extension.vsixmanifest") "$msbuild_path" -Recurse -Force +"Extracting version from copied manifest..." +$installed_version = ([xml](Get-Content ${msbuild_path}\extension.vsixmanifest)).PackageManifest.Metadata.Identity.Version +"Installed WDK VSIX Version: $installed_version" +if (-not ("$downloaded_version" -eq "$installed_version")) { + "WDK VSIX installation failed due to version mismatch" + exit 1 } -function TestWdkVsix { - Test-Path "${env:ProgramData}\Microsoft\VisualStudio\Packages\Microsoft.Windows.DriverKit,version=$version" -} - -# NOTE: The '$optimize' code path examines the '.vsixmanifest' when downloaded and then examines it again (in the 'MSBuild' directory) once -# the necessary extension files are copied. -if ($optimize) { - $msbuild_path = (Resolve-Path "$env:ProgramFiles\Microsoft Visual Studio\2022\*\MSBuild\") - "---> Downloading vsix version: $version" - Invoke-WebRequest -Uri "$uri" -OutFile wdk.zip - Expand-Archive ".\wdk.zip" .\ - "Downloaded VSIX Version: $(([xml](Get-Content .\extension.vsixmanifest)).PackageManifest.Metadata.Identity.Version)" - "<--- Download complete" - "---> Configuring build environment..." - cp ".\`$MSBuild\*" "$msbuild_path" -Recurse -Force - cp ".\extension.vsixmanifest" "$msbuild_path" - "Installed VSIX Version: $(([xml](Get-Content ${msbuild_path}\extension.vsixmanifest)).PackageManifest.Metadata.Identity.Version)" - "<--- Configuration complete" -} -else { - "Getting installed WDK vsix..." - PrintWdkVsix - "Checking the WDK.vsix version installed..." - if (-not (TestWdkVsix)) { - "The correct WDK vsix is not installed." - "Will attempt to download and install now..." - Invoke-WebRequest -Uri "$uri" -OutFile wdk.vsix - "Finished downloading." - "Starting install process. This will take some time to complete..." - Start-Process vsixinstaller -ArgumentList "/f /q /sp .\wdk.vsix" -wait - "The install process has finished." - "Checking the WDK.vsix version installed..." - if (TestWdkVsix) { - PrintWdkVsix - "The WDK vsix version is OK" - } - else { - "The WDK vsix install FAILED" - Write-Host "`u{274C} wdk vsix install had an issue" - Write-Error "the wdk vsix cannot be installed at this time" - exit 1 - } - } -} +# set github environment variable for vsix version +"SAMPLES_VSIX_VERSION=$installed_version" | Out-File -FilePath "$env:GITHUB_ENV" -Append diff --git a/.github/workflows/Code-Scanning.yml b/.github/workflows/Code-Scanning.yml index 32bb5a65..cd0d8abf 100644 --- a/.github/workflows/Code-Scanning.yml +++ b/.github/workflows/Code-Scanning.yml @@ -38,7 +38,7 @@ jobs: submodules: 'recursive' - name: Install WDK VSIX - run: .\.github\scripts\Install-Vsix.ps1 -optimize:$true + run: .\.github\scripts\Install-Vsix.ps1 - name: Install Nuget Packages run: nuget restore .\packages.config -PackagesDirectory .\packages\ diff --git a/.github/workflows/ci-pr.yml b/.github/workflows/ci-pr.yml index a179127a..c04f4adb 100644 --- a/.github/workflows/ci-pr.yml +++ b/.github/workflows/ci-pr.yml @@ -23,7 +23,7 @@ jobs: submodules: 'recursive' - name: Install WDK VSIX - run: .\.github\scripts\Install-Vsix.ps1 -optimize:$true + run: .\.github\scripts\Install-Vsix.ps1 - name: Install Nuget Packages run: nuget restore .\packages.config -PackagesDirectory .\packages\ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 13563aa8..c35a81ec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: submodules: 'recursive' - name: Install WDK VSIX - run: .\.github\scripts\Install-Vsix.ps1 -optimize:$true + run: .\.github\scripts\Install-Vsix.ps1 - name: Install Nuget Packages run: nuget restore .\packages.config -PackagesDirectory .\packages\ diff --git a/Build-SampleSet.ps1 b/Build-SampleSet.ps1 index 2fccfdb8..adae8bb0 100644 --- a/Build-SampleSet.ps1 +++ b/Build-SampleSet.ps1 @@ -55,17 +55,21 @@ finally { # # Determine build environment: 'GitHub', 'NuGet', 'EWDK', or 'WDK'. # Determine build number (used for exclusions based on build number). Five digits. Say, '22621'. +# Determine NuGet package version (if applicable). +# Determine WDK vsix version. # $build_environment="" $build_number=0 $nuget_package_version=0 +$vsix_version="" # -# In Github we build using Nuget only and source version from repo .\Env-Vars.ps1. +# In Github we build using NuGet and get the version from packages and vsix version from env var set from the install vsix step. # if ($env:GITHUB_REPOSITORY) { $build_environment="GitHub" $nuget_package_version=([regex]'(?<=x64\.)(\d+\.)(\d+\.)(\d+\.)(\d+)').Matches((Get-Childitem .\packages\*WDK.x64* -Name)).Value $build_number=$nuget_package_version.split('.')[2] + $vsix_version = $env:SAMPLES_VSIX_VERSION } # # WDK NuGet will require presence of a folder 'packages'. The version is sourced from repo .\Env-Vars.ps1. @@ -102,7 +106,19 @@ else { Write-Error "Could not determine build environment." exit 1 } - +# +# Get the vsix version from packages if not set +if (-not $vsix_version) { + $vsix_version = ls "${env:ProgramData}\Microsoft\VisualStudio\Packages\Microsoft.Windows.DriverKit,version=*" | Select -ExpandProperty Name + if ($vsix_version) { + $vsix_version = $vsix_version.split('=')[1] + } + else { + Write-Error "No version of the WDK VSIX could be found. The WDK VSIX is not installed." + exit 1 + } +} +# # # InfVerif_AdditionalOptions # @@ -164,19 +180,6 @@ $jresult = @{ $SolutionsTotal = $sampleSet.Count * $Configurations.Count * $Platforms.Count -# Find vsix version either from env variabel or from packages -$vsix_version = $env:SAMPLES_VSIX_VERSION -if (-not $vsix_version) { - $vsix_version = ls "${env:ProgramData}\Microsoft\VisualStudio\Packages\Microsoft.Windows.DriverKit,version=*" | Select -ExpandProperty Name - if ($vsix_version) { - $vsix_version = $vsix_version.split('=')[1] - } - else { - Write-Error "No version for the WDK VSIX could be found. The WDK VSIX is not installed." - exit 1 - } -} - Write-Output ("Build Environment: " + $build_environment) Write-Output ("Build Number: " + $build_number) if (($build_environment -eq "GitHub") -or ($build_environment -eq "NuGet")) { Write-Output ("Nuget Package Version: " + $nuget_package_version) } -- cgit v1.3.1