Skip to content

Commit

Permalink
51217363
Browse files Browse the repository at this point in the history
  • Loading branch information
JakobL-MSFT committed Jun 28, 2024
2 parents 6c5f4fc + b3af8c8 commit 9db6642
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 98 deletions.
38 changes: 38 additions & 0 deletions .github/scripts/Install-Vsix.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<#
.SYNOPSIS
Download and install the latest WDK 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 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
}

# set github environment variable for vsix version
"SAMPLES_VSIX_VERSION=$installed_version" | Out-File -FilePath "$env:GITHUB_ENV" -Append
56 changes: 28 additions & 28 deletions .github/workflows/Code-Scanning.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

- 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}}"
10 changes: 6 additions & 4 deletions .github/workflows/ci-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

- name: Install Nuget Packages
run: nuget restore .\packages.config -PackagesDirectory .\packages\

- name: Get changed files
id: get-changed-files
Expand Down Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

- 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 }}
Expand Down Expand Up @@ -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
Expand Down
51 changes: 40 additions & 11 deletions Build-SampleSet.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ param(
)

$root = Get-Location

# 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
}

$ThrottleFactor = 5
$LogicalProcessors = (Get-CIMInstance -Class 'CIM_Processor' -Verbose:$false).NumberOfLogicalProcessors

Expand Down Expand Up @@ -45,27 +53,34 @@ 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'.
# Determine NuGet package version (if applicable).
# Determine WDK vsix version.
#
$build_environment=""
$build_number=0
$nuget_package_version=0
$vsix_version=""
#
# WDK NuGet will require presence of a folder 'packages'
# In Github we build using NuGet and get the version from packages and vsix version from env var set from the install vsix step.
#
#
# 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
$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
}
#
# Hack: If user has hydrated nuget packages, then use those. That will be indicated by presence of a folder named .\packages.
# 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'.
# 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=26100
$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'.
Expand All @@ -91,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
#
Expand Down Expand Up @@ -155,6 +182,8 @@ $SolutionsTotal = $sampleSet.Count * $Configurations.Count * $Platforms.Count

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 + ")")
Expand Down
6 changes: 5 additions & 1 deletion Building-Locally.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 :

Expand Down
30 changes: 12 additions & 18 deletions configuration.dsc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -44,28 +44,26 @@ properties:
- Microsoft.VisualStudio.Workload.NativeDesktop
- Microsoft.Net.Component.4.7.2.TargetingPack
- Microsoft.Net.Component.4.8.1.SDK

- 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:
Expand All @@ -75,15 +73,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
6 changes: 3 additions & 3 deletions configuration_vsonly.dsc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 9db6642

Please sign in to comment.