From 73c55fdc2e3d407ee39521ff4a1b2ea6791f134e Mon Sep 17 00:00:00 2001 From: Barry Golden Date: Fri, 12 Aug 2022 09:33:34 -0700 Subject: Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 5c81b7a5..2e55d980 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,10 @@ The Windows Driver Frameworks (WDF) are a set of libraries that make it simple t Use the samples in this repo to guide your Windows driver development. Whether you're just getting started or porting an older driver to the newest version of Windows, code samples are valuable guides on how to write drivers. +For information about important changes that need to be made to the WDK sample drivers before releasing device drivers based on the sample code, see the following topic: + +[From Sample Code to Production Driver - What to Change in the Samples](https://docs.microsoft.com/en-us/windows-hardware/drivers/gettingstarted/from-sample-code-to-production-driver) + ### Build your first driver If you're writing your first driver, use these exercises to get started. Each exercise is independent of the others, so you can do them in any order. -- cgit v1.3.1 From d504c54cf595e9185617a3e611e417617be8c0b8 Mon Sep 17 00:00:00 2001 From: Adonais Romero González Date: Fri, 26 Aug 2022 14:48:11 -0700 Subject: Add CI workflows for building and validating driver samples (#775) * Add scripts to build a set of samples, as well as individual solution folders. * Add GitHub workflows to use these scripts and build all samples on push and changed samples on pull request. For now samples will be built under Windows 2019 but eventually workflow will be moved to run under Windows 2022. --- .github/scripts/Build-ChangedProjects.ps1 | 34 ++++++++++++++++ .github/workflows/ci-pr.yml | 40 +++++++++++++++++++ .github/workflows/ci.yml | 35 +++++++++++++++++ .gitignore | 6 ++- Build-AllProjects.ps1 | 15 ++++++++ Build-Project.ps1 | 64 +++++++++++++++++++++++++++++++ Build-ProjectSet.ps1 | 38 ++++++++++++++++++ exclusions.csv | 15 ++++++++ 8 files changed, 246 insertions(+), 1 deletion(-) create mode 100644 .github/scripts/Build-ChangedProjects.ps1 create mode 100644 .github/workflows/ci-pr.yml create mode 100644 .github/workflows/ci.yml create mode 100644 Build-AllProjects.ps1 create mode 100644 Build-Project.ps1 create mode 100644 Build-ProjectSet.ps1 create mode 100644 exclusions.csv diff --git a/.github/scripts/Build-ChangedProjects.ps1 b/.github/scripts/Build-ChangedProjects.ps1 new file mode 100644 index 00000000..e163e5f9 --- /dev/null +++ b/.github/scripts/Build-ChangedProjects.ps1 @@ -0,0 +1,34 @@ +param ( + [array]$ChangedFiles +) + +$root = (Get-Location).Path + +# To include in CI gate +$projectSet = @{} +foreach ($file in $ChangedFiles) +{ + if (-not (Test-Path $file)) { + Write-Output "❔ Changed file $file cannot be found" + continue + } + $dir = (Get-Item $file).DirectoryName + while ((-not ($slnItems = (Get-ChildItem $dir '*.sln'))) -and ($dir -ne $root)) + { + $dir = (Get-Item $dir).Parent.FullName + } + if ($dir -eq $root) + { + Write-Output "❔ Changed file $file does not match a project." + continue + } + $projectName = $dir.Replace($root, '').Trim('\').Replace('\', '.').ToLower() + Write-Output "🔎 Found project [$projectName] at $dir from changed file $file" + if (-not ($projectSet.ContainsKey($projectName))) + { + $projectSet[$projectName] = $dir + } +} + +.\Build-ProjectSet -ProjectSet $projectSet + diff --git a/.github/workflows/ci-pr.yml b/.github/workflows/ci-pr.yml new file mode 100644 index 00000000..12062b34 --- /dev/null +++ b/.github/workflows/ci-pr.yml @@ -0,0 +1,40 @@ +name: Build changes to driver samples +on: + pull_request: + branches: + - main + - develop + paths-ignore: + - '**.md' + - 'LICENSE' +jobs: + build: + strategy: + fail-fast: false + matrix: + configuration: [Debug, Release] + platform: [x64, arm64] + runs-on: windows-2019 + env: + Solution_Path: general\echo\kmdf\kmdfecho.sln + steps: + - name: Check out repository code + uses: actions/checkout@v3 + with: + submodules: 'recursive' + + - name: Add MSBuild to PATH + uses: microsoft/setup-msbuild@v1.0.2 + + - name: Get changed files + id: get-changed-files + uses: tj-actions/changed-files@v27 + + - name: Retrieve and build solutions from changed files + id: build-changed-projects + run: | + $changedFiles = "${{ steps.get-changed-files.outputs.all_changed_files }}".Split(' ') + .\.github\scripts\Build-ChangedProjects.ps1 -ChangedFiles $changedFiles + env: + Configuration: ${{ matrix.configuration }} + Platform: ${{ matrix.platform }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..68b46552 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,35 @@ +name: Build all driver samples +on: + push: + branches: + - main + - develop + paths-ignore: + - '**.md' + - 'LICENSE' +jobs: + build: + strategy: + fail-fast: false + matrix: + configuration: [Debug, Release] + platform: [x64, arm64] + runs-on: windows-2019 + env: + Solution_Path: general\echo\kmdf\kmdfecho.sln + steps: + - name: Check out repository code + uses: actions/checkout@v3 + with: + submodules: 'recursive' + + - name: Add MSBuild to PATH + uses: microsoft/setup-msbuild@v1.0.2 + + - name: Retrieve and build all available solutions + id: build-all-projects + run: | + .\Build-AllProjects.ps1 + env: + Configuration: ${{ matrix.configuration }} + Platform: ${{ matrix.platform }} diff --git a/.gitignore b/.gitignore index f227925f..995bfc8e 100644 --- a/.gitignore +++ b/.gitignore @@ -20,9 +20,12 @@ bld/ [Bb]in/ [Oo]bj/ -# Visual Studo 2015 cache/options directory +# Visual Studio 2015 cache/options directory .vs/ +# Visual Studio Code directory +.vscode/ + # MSTest test Results [Tt]est[Rr]esult*/ [Bb]uild[Ll]og.* @@ -54,6 +57,7 @@ dlldata.c *.tmp *.tmp_proj *.log +*.tlog *.vspscc *.vssscc .builds diff --git a/Build-AllProjects.ps1 b/Build-AllProjects.ps1 new file mode 100644 index 00000000..4738907c --- /dev/null +++ b/Build-AllProjects.ps1 @@ -0,0 +1,15 @@ +$root = Get-Location +$solutionFiles = Get-ChildItem -Path $root -Recurse -Filter *.sln | Select-Object -ExpandProperty FullName + +# To include in CI gate +$projectSet = @{} +foreach ($file in $solutionFiles) +{ + $dir = (Get-Item $file).DirectoryName + $dir_norm = $dir.Replace($root, '').Trim('\').Replace('\', '.').ToLower() + echo "🔎 Found project [$dir_norm] at $dir" + $projectSet[$dir_norm] = $dir +} + +.\Build-ProjectSet -ProjectSet $projectSet + diff --git a/Build-Project.ps1 b/Build-Project.ps1 new file mode 100644 index 00000000..1f79b679 --- /dev/null +++ b/Build-Project.ps1 @@ -0,0 +1,64 @@ +param( + $Directory, + [string]$ProjectName, + $LogFilesDirectory = "_logfiles", + [string]$Configuration = "Debug", + [string]$Platform = "x64" +) + +# TODO Validate $Directory and $LogFilesDirectory +New-Item -ItemType Directory -Force -Path $LogFilesDirectory | Out-Null + +if ([string]::IsNullOrWhitespace($ProjectName)) +{ + $ProjectName = (Resolve-Path $Directory).Path.Replace((Get-Location), '').Replace('\', '.').Trim('.').ToLower() +} + +$solutionFile = Get-ChildItem -Path $Directory -Filter *.sln | Select-Object -ExpandProperty FullName -First 1 + +$configurationIsSupported = $false +$inSolutionConfigurationPlatformsSection = $false +foreach ($line in Get-Content -Path $solutionFile) +{ + if (-not $inSolutionConfigurationPlatformsSection -and $line -match "\s*GlobalSection\(SolutionConfigurationPlatforms\).*") + { + $inSolutionConfigurationPlatformsSection = $true; + continue; + } + elseif ($line -match "\s*EndGlobalSection.*") + { + $inSolutionConfigurationPlatformsSection = $false; + continue; + } + + if ($inSolutionConfigurationPlatformsSection) + { + [regex]$regex = ".*=\s*(?(?.*)\|(?.*))\s*" + $match = $regex.Match($line) + if ([string]::IsNullOrWhiteSpace($match.Groups["ConfigString"].Value) -or [string]::IsNullOrWhiteSpace($match.Groups["Platform"].Value)) + { + Write-Warning "Could not parse configuration entry $line from file $solutionFile." + continue; + } + if ($match.Groups["Configuration"].Value.Trim() -eq $Configuration -and $match.Groups["Platform"].Value.Trim() -eq $Platform) + { + $configurationIsSupported = $true; + } + } +} + +if (-not $configurationIsSupported) +{ + Write-Output "[$ProjectName] ⏩ Skipped. Configuration $Configuration|$Platform not supported." + exit 0 +} + +$errorLogFilePath = "$LogFilesDirectory\$ProjectName.err" +$warnLogFilePath = "$LogFilesDirectory\$ProjectName.wrn" +Write-Output "[$ProjectName] ⚒️ Building project..." +msbuild $solutionFile -clp:Verbosity=m -t:clean,build -property:Configuration=$Configuration -property:Platform=$Platform -p:TargetVersion=Windows10 -p:InfVerif_AdditionalOptions="/msft /sw1205 /sw1324 /sw1420 /sw1421" -p:SignToolWS=/fdws -p:DriverCFlagAddOn=/wd4996 -flp1:errorsonly`;logfile=$errorLogFilePath -flp2:WarningsOnly`;logfile=$warnLogFilePath -noLogo +if ($LASTEXITCODE -ne 0) +{ + Write-Warning "❌ Build failed. Log available at $errorLogFilePath" + exit 1 +} diff --git a/Build-ProjectSet.ps1 b/Build-ProjectSet.ps1 new file mode 100644 index 00000000..57c4ac32 --- /dev/null +++ b/Build-ProjectSet.ps1 @@ -0,0 +1,38 @@ +param( + [hashtable]$ProjectSet, + [string]$Configuration = $env:Configuration, + [string]$Platform = $env:Platform +) + +#TODO validate params + +$exclusionsSet = @{} +$failSet = @() +Import-Csv 'exclusions.csv' | ForEach-Object { + $exclusionsSet[$_.Path.Replace($root, '').Trim('\').Replace('\', '.').ToLower()] = $_.Reason +} + +$ProjectSet.GetEnumerator() | ForEach-Object { + $projectName = $_.Key + if ($exclusionsSet.ContainsKey($projectName)) + { + Write-Output "[$projectName] ⏩ Excluded and skipped. Reason: $($exclusionsSet[$projectName])" + return; + } + $directory = $_.Value + .\Build-Project -Directory $directory -ProjectName $ProjectName -Configuration $Configuration -Platform $Platform + if ($LASTEXITCODE -ne 0) + { + $failSet += $ProjectName + } +} + +if ($failSet.Count -gt 0) +{ + Write-Output "Some projects were built with errors:" + foreach ($failedProject in $failSet) + { + Write-Output "$failedProject" + } + Write-Error "Some projects were built with errors." +} \ No newline at end of file diff --git a/exclusions.csv b/exclusions.csv new file mode 100644 index 00000000..71b0edf3 --- /dev/null +++ b/exclusions.csv @@ -0,0 +1,15 @@ +Path,Reason +general\dchu\osrfx2_dchu_base,Wrong Toolset - needs migration +general\dchu\osrfx2_dchu_extension_loose,Needs fix for project not found +general\dchu\osrfx2_dchu_extension_tight,Wrong Toolset - needs migration +general\filehistory,Deprecated APIs +general\simplemediasource,ARM64 LNK1181: cannot open input file 'SimpleMediaSource.lib' +general\winhec 2017 lab\toaster driver,Needs input from end user +general\winhec 2017 lab\toaster support app,Needs input from end user +network\trans\stmedit,Invalid Win32 architecture +network\trans\wfpsampler,Missing INF section; missing libs +network\wlan\wdi,Invalid architecture +print\oem printer customization plug-in samples\c++,Invalid architecture +print\v4printdriversamples\printerextensionsample,Invalid architecture +tree,Missing headers +video\indirectdisplay,ARM64 Warning C4530: C++ exception handler used, but unwind semantics are not enabled \ No newline at end of file -- cgit v1.3.1 From 110e8c201d5a929fc01e333ceac0dc71b0267237 Mon Sep 17 00:00:00 2001 From: Adonais Romero González Date: Tue, 6 Sep 2022 16:36:33 -0700 Subject: Miscellaneous build scripts fixes (#779) Fix actions: escape emoji characters; add small validations to build scripts --- .github/scripts/Build-ChangedProjects.ps1 | 6 +++--- Build-AllProjects.ps1 | 2 +- Build-Project.ps1 | 6 +++--- Build-ProjectSet.ps1 | 31 +++++++++++++++++++++++++++++-- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/.github/scripts/Build-ChangedProjects.ps1 b/.github/scripts/Build-ChangedProjects.ps1 index e163e5f9..a13e3501 100644 --- a/.github/scripts/Build-ChangedProjects.ps1 +++ b/.github/scripts/Build-ChangedProjects.ps1 @@ -9,7 +9,7 @@ $projectSet = @{} foreach ($file in $ChangedFiles) { if (-not (Test-Path $file)) { - Write-Output "❔ Changed file $file cannot be found" + Write-Output "`u{2754} Changed file $file cannot be found" continue } $dir = (Get-Item $file).DirectoryName @@ -19,11 +19,11 @@ foreach ($file in $ChangedFiles) } if ($dir -eq $root) { - Write-Output "❔ Changed file $file does not match a project." + Write-Output "`u{2754} Changed file $file does not match a project." continue } $projectName = $dir.Replace($root, '').Trim('\').Replace('\', '.').ToLower() - Write-Output "🔎 Found project [$projectName] at $dir from changed file $file" + Write-Output "`u{1F50E} Found project [$projectName] at $dir from changed file $file" if (-not ($projectSet.ContainsKey($projectName))) { $projectSet[$projectName] = $dir diff --git a/Build-AllProjects.ps1 b/Build-AllProjects.ps1 index 4738907c..1c35d884 100644 --- a/Build-AllProjects.ps1 +++ b/Build-AllProjects.ps1 @@ -7,7 +7,7 @@ foreach ($file in $solutionFiles) { $dir = (Get-Item $file).DirectoryName $dir_norm = $dir.Replace($root, '').Trim('\').Replace('\', '.').ToLower() - echo "🔎 Found project [$dir_norm] at $dir" + Write-Output "`u{1F50E} Found project [$dir_norm] at $dir" $projectSet[$dir_norm] = $dir } diff --git a/Build-Project.ps1 b/Build-Project.ps1 index 1f79b679..b01d13a8 100644 --- a/Build-Project.ps1 +++ b/Build-Project.ps1 @@ -49,16 +49,16 @@ foreach ($line in Get-Content -Path $solutionFile) if (-not $configurationIsSupported) { - Write-Output "[$ProjectName] ⏩ Skipped. Configuration $Configuration|$Platform not supported." + Write-Output "[$ProjectName] `u{23E9} Skipped. Configuration $Configuration|$Platform not supported." exit 0 } $errorLogFilePath = "$LogFilesDirectory\$ProjectName.err" $warnLogFilePath = "$LogFilesDirectory\$ProjectName.wrn" -Write-Output "[$ProjectName] ⚒️ Building project..." +Write-Output "[$ProjectName] `u{2692} Building project..." msbuild $solutionFile -clp:Verbosity=m -t:clean,build -property:Configuration=$Configuration -property:Platform=$Platform -p:TargetVersion=Windows10 -p:InfVerif_AdditionalOptions="/msft /sw1205 /sw1324 /sw1420 /sw1421" -p:SignToolWS=/fdws -p:DriverCFlagAddOn=/wd4996 -flp1:errorsonly`;logfile=$errorLogFilePath -flp2:WarningsOnly`;logfile=$warnLogFilePath -noLogo if ($LASTEXITCODE -ne 0) { - Write-Warning "❌ Build failed. Log available at $errorLogFilePath" + Write-Warning "`u{274C} Build failed. Log available at $errorLogFilePath" exit 1 } diff --git a/Build-ProjectSet.ps1 b/Build-ProjectSet.ps1 index 57c4ac32..2557b5b9 100644 --- a/Build-ProjectSet.ps1 +++ b/Build-ProjectSet.ps1 @@ -4,7 +4,34 @@ param( [string]$Platform = $env:Platform ) -#TODO validate params +if ([string]::IsNullOrEmpty($Configuration)) +{ + $Configuration = "Debug" +} + +if ([string]::IsNullOrEmpty($Platform)) +{ + $Platform = "x64" +} + +$oldPreference = $ErrorActionPreference +$ErrorActionPreference = "stop" +try +{ + # Check that msbuild can be called before trying anything. + Get-Command "msbuild" | Out-Null +} +catch +{ + Write-Host "`u{274C} msbuild cannot be called from current environment. Check that msbuild is set in current path (for example, that it is called from a Visual Studio developer command)." + Write-Error "msbuild cannot be called from current environment." + exit 1 +} +finally +{ + $ErrorActionPreference = $oldPreference +} + $exclusionsSet = @{} $failSet = @() @@ -16,7 +43,7 @@ $ProjectSet.GetEnumerator() | ForEach-Object { $projectName = $_.Key if ($exclusionsSet.ContainsKey($projectName)) { - Write-Output "[$projectName] ⏩ Excluded and skipped. Reason: $($exclusionsSet[$projectName])" + Write-Output "[$projectName] `u{23E9} Excluded and skipped. Reason: $($exclusionsSet[$projectName])" return; } $directory = $_.Value -- cgit v1.3.1 From 239361d9ab5c4b2098896f7a29451b99b71d9063 Mon Sep 17 00:00:00 2001 From: Phan Trinh Ha <23308647+thpthp1@users.noreply.github.com> Date: Wed, 21 Sep 2022 09:48:21 -0700 Subject: [general/toaster] Handle non successful return value of WdfIoTargetStart in toastmon.c (#785) Handle non-successful return value of WdfIoTargetStart in toastmon.c --- general/toaster/toastDrv/kmdf/toastmon/toastmon.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/general/toaster/toastDrv/kmdf/toastmon/toastmon.c b/general/toaster/toastDrv/kmdf/toastmon/toastmon.c index 5967d019..3e1a8caf 100644 --- a/general/toaster/toastDrv/kmdf/toastmon/toastmon.c +++ b/general/toaster/toastDrv/kmdf/toastmon/toastmon.c @@ -334,7 +334,11 @@ Routine Description: for (i = 0; i < count; i ++) { ioTarget = WdfCollectionGetItem(deviceExtension->TargetDeviceCollection, i); - WdfIoTargetStart(ioTarget); + NTSTATUS status = WdfIoTargetStart(ioTarget); + if (!NT_SUCCESS(status)) { + KdPrint(("WdfIoTargetStart failed: 0x%x\n", status)); + continue; + } targetDeviceInfo = GetTargetDeviceInfo(ioTarget); WdfTimerStart(targetDeviceInfo->TimerForPostingRequests, -- cgit v1.3.1