Skip to content

Commit

Permalink
Enable CodeQL to work thru reasonable workarounds - Cherry pick to ma…
Browse files Browse the repository at this point in the history
…in (microsoft#863)

Enable CodeQL to work thru reasonable workarounds.  (microsoft#857)
  • Loading branch information
JakobL-MSFT authored Feb 8, 2023
1 parent 0860787 commit d717aac
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 36 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/Code-Scanning.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ jobs:
- name: Retrieve and build all available solutions
id: build-all-samples
run: |
.\Build-AllSamples.ps1 -Verbose
.\Build-AllSamples.ps1 -Verbose -ThrottleLimit 1
env:
Configuration: Debug
Platform: x64
WDS_Configuration: Debug
WDS_Platform: x64
WDS_WipeOutputs: ${{ true }}

- name: Perform CodeQL analysis
uses: github/codeql-action/analyze@v2
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ jobs:
$changedFiles = "${{ steps.get-changed-files.outputs.all_changed_files }}".Split(',')
.\.github\scripts\Build-ChangedSamples.ps1 -ChangedFiles $changedFiles -Verbose
env:
Configuration: ${{ matrix.configuration }}
Platform: ${{ matrix.platform }}
WDS_Configuration: ${{ matrix.configuration }}
WDS_Platform: ${{ matrix.platform }}
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ jobs:
run: |
.\Build-AllSamples.ps1 -Verbose
env:
Configuration: ${{ matrix.configuration }}
Platform: ${{ matrix.platform }}
WDS_Configuration: ${{ matrix.configuration }}
WDS_Platform: ${{ matrix.platform }}
20 changes: 11 additions & 9 deletions Build-AllSamples.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ This script searches for all available Visual Studio Solutions (.sln files) and
A regular expression matching the samples to be built. Default is '' that matches all samples. Examples include '^tools.' or '.dchu'.
.PARAMETER Configurations
A list of configurations to build samples under. Values available are 'Debug' and 'Release'. By default, $env:Configuration will be used as the sole configuration to build for. If this environment variable is not set the default is 'Debug' and 'Release'.
A list of configurations to build samples under. Values available are 'Debug' and 'Release'. By default, $env:WDS_Configuration will be used as the sole configuration to build for. If this environment variable is not set the default is 'Debug' and 'Release'.
.PARAMETER Platforms
A list of platforms to build samples under (e.g. 'x64', 'arm64'). By default, $env:Platform will be used as the sole platform to build for. If this environment variable is not set the default is 'x64' and'arm64'.
A list of platforms to build samples under (e.g. 'x64', 'arm64'). By default, $env:WDS_Platform will be used as the sole platform to build for. If this environment variable is not set the default is 'x64' and'arm64'.
.PARAMETER LogFilesDirectory
Path to a directory where the log files will be written to. If not provided, outputs will be logged to the '_logs' directory within the current working directory.
.PARAMETER ThrottleLimit
An integer indicating how many combinations to build in parallel. If 0 or not provided this defaults to 5 x number of logical processors.
.INPUTS
None.
Expand All @@ -27,16 +30,17 @@ None.
.\Build-AllSamples
.EXAMPLE
.\Build-AllSamples -Samples '^tools.' -Configurations 'Debug','Release' -Platforms 'x64','arm64' -LogFilesDirectory .\_logs
.\Build-AllSamples -Samples '^tools.' -Configurations 'Debug','Release' -Platforms 'x64','arm64'
#>

[CmdletBinding()]
param(
[string]$Samples = "",
[string[]]$Configurations = @([string]::IsNullOrEmpty($env:Configuration) ? ('Debug','Release') : $env:Configuration),
[string[]]$Platforms = @([string]::IsNullOrEmpty($env:Platform) ? ('x64','arm64') : $env:Platform),
[string]$LogFilesDirectory = (Join-Path (Get-Location) "_logs")
[string[]]$Configurations = @([string]::IsNullOrEmpty($env:WDS_Configuration) ? ('Debug','Release') : $env:WDS_Configuration),
[string[]]$Platforms = @([string]::IsNullOrEmpty($env:WDS_Platform) ? ('x64','arm64') : $env:WDS_Platform),
[string]$LogFilesDirectory = (Join-Path (Get-Location) "_logs"),
[int]$ThrottleLimit
)

$Verbose = $false
Expand All @@ -63,6 +67,4 @@ foreach ($file in $solutionFiles) {
}
}



.\Build-SampleSet -SampleSet $sampleSet -Configurations $Configurations -Platform $Platforms -LogFilesDirectory $LogFilesDirectory -Verbose:$Verbose
.\Build-SampleSet -SampleSet $sampleSet -Configurations $Configurations -Platform $Platforms -LogFilesDirectory $LogFilesDirectory -Verbose:$Verbose -ThrottleLimit $ThrottleLimit
6 changes: 6 additions & 0 deletions Build-Sample.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ $OutLogFilePath = "$LogFilesDirectory\$SampleName.$Configuration.$Platform.out"
Write-Verbose "Building Sample: $SampleName; Configuration: $Configuration; Platform: $Platform {"

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 > $OutLogFilePath
if ($env:WDS_WipeOutputs -ne $null)
{
Write-Verbose ("WipeOutputs: "+$Directory+" "+(((Get-Volume ($DriveLetter=(Get-Item ".").PSDrive.Name)).SizeRemaining/1GB)))
Get-ChildItem -path $Directory -Recurse -Include x64|Remove-Item -Recurse
Get-ChildItem -path $Directory -Recurse -Include arm64|Remove-Item -Recurse
}

if ($LASTEXITCODE -ne 0)
{
Expand Down
32 changes: 18 additions & 14 deletions Build-SampleSet.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
[CmdletBinding()]
param(
[hashtable]$SampleSet,
[string[]]$Configurations = @([string]::IsNullOrEmpty($env:Configuration) ? "Debug" : $env:Configuration),
[string[]]$Platforms = @([string]::IsNullOrEmpty($env:Platform) ? "x64" : $env:Platform),
$LogFilesDirectory = (Get-Location)
[string[]]$Configurations = @([string]::IsNullOrEmpty($env:WDS_Configuration) ? "Debug" : $env:WDS_Configuration),
[string[]]$Platforms = @([string]::IsNullOrEmpty($env:WDS_Platform) ? "x64" : $env:WDS_Platform),
$LogFilesDirectory = (Get-Location),
[int]$ThrottleLimit
)

$ThrottleFactor = 5
$LogicalProcessors = (Get-CIMInstance -Class 'CIM_Processor' -Verbose:$false).NumberOfLogicalProcessors
$ThrottleLimit = $ThrottleLimit -eq 0 ? ($ThrottleFactor * $LogicalProcessors) : $ThrottleLimit

$Verbose = $false
if ($PSBoundParameters.ContainsKey('Verbose')) {
$Verbose = $PsBoundParameters.Get_Item('Verbose')
Expand All @@ -18,10 +23,6 @@ $sampleBuilderFilePath = "$LogFilesDirectory\overview.htm"
Remove-Item -Recurse -Path $LogFilesDirectory 2>&1 | Out-Null
New-Item -ItemType Directory -Force -Path $LogFilesDirectory | Out-Null

$NumberOfLogicalProcessors = (Get-CIMInstance -Class 'CIM_Processor' -Verbose:$false).NumberOfLogicalProcessors
$Throttlefactor = 5
$SolutionsInParallel = $Throttlefactor * $NumberOfLogicalProcessors

$oldPreference = $ErrorActionPreference
$ErrorActionPreference = "stop"
try {
Expand Down Expand Up @@ -58,9 +59,11 @@ Write-Output ("Samples: "+$sampleSet.Count)
Write-Output ("Configurations: "+$Configurations.Count+" ("+$Configurations+")")
Write-Output ("Platforms: "+$Platforms.Count+" ("+$Platforms+")")
Write-Output "Combinations: $SolutionsTotal"
Write-Output "Logical Processors: $NumberOfLogicalProcessors"
Write-Output "Throttle factor: $Throttlefactor"
Write-Output "Throttle limit: $SolutionsInParallel"
Write-Output "LogicalProcessors: $LogicalProcessors"
Write-Output "ThrottleFactor: $ThrottleFactor"
Write-Output "ThrottleLimit: $ThrottleLimit"
Write-Output "WDS_WipeOutputs: $env:WDS_WipeOutputs"
Write-Output ("Disk Remaining (GB): "+(((Get-Volume ($DriveLetter=(Get-Item ".").PSDrive.Name)).SizeRemaining/1GB)))
Write-Output ""
Write-Output "T: Combinations"
Write-Output "B: Built"
Expand All @@ -78,7 +81,7 @@ $Results = @()

$sw = [Diagnostics.Stopwatch]::StartNew()

$SampleSet.GetEnumerator() | ForEach-Object -ThrottleLimit $SolutionsInParallel -Parallel {
$SampleSet.GetEnumerator() | ForEach-Object -ThrottleLimit $ThrottleLimit -Parallel {
$LogFilesDirectory = $using:LogFilesDirectory
$exclusionsSet = $using:exclusionsSet
$Configurations = $using:Configurations
Expand Down Expand Up @@ -133,11 +136,11 @@ $SampleSet.GetEnumerator() | ForEach-Object -ThrottleLimit $SolutionsInParallel
($using:jresult).SolutionsUnsupported += $thisunsupported
($using:jresult).SolutionsFailed += $thisfailed
$SolutionsTotal = $using:SolutionsTotal
$SolutionsInParallel = $using:SolutionsInParallel
$ThrottleLimit = $using:ThrottleLimit
$SolutionsBuilt = ($using:jresult).SolutionsBuilt
$SolutionsRemaining = $SolutionsTotal - $SolutionsBuilt
$SolutionsRunning = $SolutionsRemaining -ge $SolutionsInParallel ? ($SolutionsInParallel) : ($SolutionsRemaining)
$SolutionsPending = $SolutionsRemaining -ge $SolutionsInParallel ? ($SolutionsRemaining - $SolutionsInParallel) : (0)
$SolutionsRunning = $SolutionsRemaining -ge $ThrottleLimit ? ($ThrottleLimit) : ($SolutionsRemaining)
$SolutionsPending = $SolutionsRemaining -ge $ThrottleLimit ? ($SolutionsRemaining - $ThrottleLimit) : (0)
$SolutionsBuiltPercent = [Math]::Round(100 * ($SolutionsBuilt / $using:SolutionsTotal))
$TBRP = "T:" + ($SolutionsTotal) + "; B:" + (($using:jresult).SolutionsBuilt) + "; R:" + ($SolutionsRunning) + "; P:" + ($SolutionsPending)
$rstr = "S:" + (($using:jresult).SolutionsSucceeded) + "; E:" + (($using:jresult).SolutionsExcluded) + "; U:" + (($using:jresult).SolutionsUnsupported) + "; F:" + (($using:jresult).SolutionsFailed)
Expand Down Expand Up @@ -181,6 +184,7 @@ Write-Output ""
Write-Output "Built all combinations."
Write-Output ""
Write-Output "Elapsed time: $min minutes, $seconds seconds."
Write-Output ("Disk Remaining (GB): "+(((Get-Volume ($DriveLetter=(Get-Item ".").PSDrive.Name)).SizeRemaining/1GB)))
Write-Output ("Samples: "+$sampleSet.Count)
Write-Output ("Configurations: "+$Configurations.Count+" ("+$Configurations+")")
Write-Output ("Platforms: "+$Platforms.Count+" ("+$Platforms+")")
Expand Down
9 changes: 3 additions & 6 deletions Building-Locally.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ You can also just download and mount the EWDK as well and in the following examp
* Mount ISO image
* Open a terminal
* `.\LaunchBuildEnv`
* `set PLATFORM=`

Note: The last command to clear the PLATFORM variable is added so as to allow the next part to iterate over all platforms automatically without having to add explicit arguments.


## Step 3: Clone Windows Driver Samples and checkout main branch

```
Expand All @@ -33,12 +30,12 @@ cd Windows-driver-samples
pwsh
.\Build-AllSamples
```
Above builds all samples for all configurations and archictures.
Above builds all samples for all configurations and platforms.

You can refine, for example as follows:
```
pwsh
.\Build-AllSamples -Samples 'tools.' -Configurations 'Debug','Release' -Platforms 'x64','arm64' -LogFilesDirectory .\_logs
.\Build-AllSamples -Samples '^tools.' -Configurations 'Debug','Release' -Platforms 'x64','arm64'
```

Expected output:
Expand Down

0 comments on commit d717aac

Please sign in to comment.