Skip to content

Commit

Permalink
Improve version info, vsix installation, and update building locally …
Browse files Browse the repository at this point in the history
…readme
  • Loading branch information
middlemose authored Jun 25, 2024
1 parent e59949f commit 6dabe4e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 35 deletions.
40 changes: 24 additions & 16 deletions .github/scripts/Install-Vsix.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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..."
Expand All @@ -65,4 +73,4 @@ else {
exit 1
}
}
}
}
23 changes: 14 additions & 9 deletions Build-SampleSet.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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'.
Expand Down Expand Up @@ -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 + ")")
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
9 changes: 0 additions & 9 deletions Env-Vars.ps1

This file was deleted.

0 comments on commit 6dabe4e

Please sign in to comment.