Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/rtoolsHCK.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,10 @@ def handle_create_project_package(cmd_line, handler)
#
# +driver_path+:: Provide a driver path to include, (can be nil)
# +supplemental_path+:: Provide a supplemental path to include, (can be nil)
def create_project_package(project, playlist = nil, handler = nil, driver_path = nil, supplemental_path = nil)
# +remove_driver_signatures+:: If true, remove driver signatures before
# packaging (default: false)
def create_project_package(project, playlist = nil, handler = nil, driver_path = nil, supplemental_path = nil,
remove_driver_signatures: false)
handle_action_exceptions(__method__) do
cmd_line = ["createprojectpackage '#{project}' -rph"]
cmd_line << 'json' if @json
Expand All @@ -1051,6 +1054,7 @@ def create_project_package(project, playlist = nil, handler = nil, driver_path =

cmd_line << "-driver '#{driver_path}'" unless driver_path.nil?
cmd_line << "-supplemental '#{supplemental_path}'" unless supplemental_path.nil?
cmd_line << '-removedriversignatures' if remove_driver_signatures

handler = dummy_package_progress_info_handler if handler.nil?
handle_create_project_package(cmd_line.join(' '), handler)
Expand Down
72 changes: 65 additions & 7 deletions tools/toolsHCK.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ function New-PackageProgressInfo($current, $maximum, $message) {

#
# ProjectPackage
function New-ProjectPackage($name, $projectpackagepath) {
function New-ProjectPackage($name, $projectpackagepath, $iserror, $actionMessages) {
$projectpackage = New-Object PSObject
$projectpackage | Add-Member -type NoteProperty -Name name -Value $name
$projectpackage | Add-Member -type NoteProperty -Name projectpackagepath -Value $projectpackagepath
$projectpackage | Add-Member -type NoteProperty -Name iserror -Value $iserror
$projectpackage | Add-Member -type NoteProperty -Name messages -Value $actionMessages
return $projectpackage
}

Expand Down Expand Up @@ -2076,7 +2078,7 @@ function ziptestresultlogs {
# CreateProjectPackage
function createprojectpackage {
[CmdletBinding()]
param([Switch]$help, [Switch]$rph, [String]$playlist, [Parameter(Position=1)][String]$project, [Parameter(Position=2)][String]$package, [String]$driver, [String]$supplemental)
param([Switch]$help, [Switch]$rph, [Switch]$removedriversignatures, [String]$playlist, [Parameter(Position=1)][String]$project, [Parameter(Position=2)][String]$package, [String]$driver, [String]$supplemental)

function Usage {
Write-Output "createprojectpackage:"
Expand All @@ -2087,7 +2089,7 @@ function createprojectpackage {
Write-Output ""
Write-Output "Usage:"
Write-Output ""
Write-Output "createprojectpackage <projectname> [<package>] [-help] [-playlist]"
Write-Output "createprojectpackage <projectname> [<package>] [-help] [-playlist] [-driver <path>] [-supplemental <path>] [-rph] [-removedriversignatures]"
Write-Output ""
Write-Output "Any parameter in [] is optional."
Write-Output ""
Expand All @@ -2099,6 +2101,16 @@ function createprojectpackage {
Write-Output ""
Write-Output " playlist = Path to the playlist file."
Write-Output ""
Write-Output " driver = Path to the driver to add to the package."
Write-Output ""
Write-Output " supplemental = Path to supplemental files to add to the package."
Write-Output ""
Write-Output " rph = Enable progress action handler (interactive package progress)."
Write-Output ""
Write-Output "removedriversignatures = Remove driver signatures before packaging (default: do not remove)."
Write-Output ""
Write-Output "With [json], output is JSON with name, projectpackagepath, iserror, and messages."
Write-Output ""
Write-Output "NOTE: Windows HCK\HLK Studio should be installed on the machine running the script!"
}

Expand Down Expand Up @@ -2151,11 +2163,18 @@ function createprojectpackage {
}
}

$actionMessages = @()
$iserror = $false

$PlaylistManager = $null
if (-Not [String]::IsNullOrEmpty($playlist)) {
$PlaylistManager = New-Object Microsoft.Windows.Kits.Hardware.ObjectModel.PlaylistManager($WntdProject)

if (-Not $json) { Write-Output "Loading playlist $($playlist)..." }
if (-Not $json) {
Write-Output "Loading playlist $($playlist)..."
} else {
$actionMessages += "Loading playlist $($playlist)..."
}

$PlaylistManager.LoadPlaylist($playlist) | Out-Null
}
Expand Down Expand Up @@ -2198,16 +2217,47 @@ function createprojectpackage {
New-Item -ItemType Directory -Path $symbolPath | Out-Null
Get-ChildItem -Path $driver -Filter *.pdb -Recurse | ForEach-Object { Move-Item -Path $_.FullName -Destination $symbolPath -Force }

# Remove driver signatures before packaging to avoid embedded company signatures (only when -removeDriverSignatures)
if ($removedriversignatures) {
Get-ChildItem -Path $driver -Include *.sys, *.dll, *.exe -Recurse | ForEach-Object {
if (-Not $json) {
Write-Output "Removing signature from file '$($_.FullName)' before packaging"
} else {
$actionMessages += "Removing signature from file '$($_.FullName)' before packaging"
}

$process = Start-Process -Wait -FilePath "$env:WTTSTDIO\..\Tests\amd64\Signtool.exe" -ArgumentList 'remove', '/s', $_.FullName -PassThru
if ($process.ExitCode -ne 0) {
$iserror = $true
if (-Not $json) {
Write-Output "Warning: Failed to remove signature from file '$($_.FullName)'. Signtool exit code: $($process.ExitCode)"
} else {
$actionMessages += "Warning: Failed to remove signature from file '$($_.FullName)'. Signtool exit code: $($process.ExitCode)"
}
}
}
}

$AddDriverResult = $PackageWriter.AddDriver($driver, $symbolPath, $TargetList, $LocaleList, [ref]$ErrorMessages, [ref]$WarningMessages)

if (-Not $json) {
if ($AddDriverResult) {
Write-Output "Driver added to package from $driver"
} else {
$iserror = $true
Write-Output "Warning: Driver signability check did not pass"
foreach ($err in $ErrorMessages) { Write-Output " Error: $err" }
foreach ($warn in $WarningMessages) { Write-Output " Warning: $warn" }
}
} else {
if ($AddDriverResult) {
$actionMessages += "Driver added to package from $driver"
} else {
$iserror = $true
$actionMessages += "Warning: Driver signability check did not pass"
foreach ($err in $ErrorMessages) { $actionMessages += "Error: $err" }
foreach ($warn in $WarningMessages) { $actionMessages += "Warning: $warn" }
}
}
Comment on lines 2243 to 2261

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This block of code for handling the result of AddDriver has significant duplication between the if (-Not $json) and else branches. This reduces maintainability.

Additionally, there are inconsistencies in the messages being logged:

  • When $AddDriverResult is false, Write-Output prefixes the message with "Warning:", but the message added to $actionMessages does not.
  • The error and warning messages from $ErrorMessages and $WarningMessages are prefixed with two spaces ( ) for Write-Output, but not for $actionMessages.

Consider refactoring this to a single logic path that prepares the messages, and then either prints them or adds them to the array based on the $json flag. This would improve consistency and make the code easier to maintain.

}
}
Expand All @@ -2217,7 +2267,11 @@ function createprojectpackage {
if (-Not [String]::IsNullOrEmpty($supplemental)) {
if (Test-Path $supplemental) {
$PackageWriter.AddSupplementalFiles($supplemental)
if (-Not $json) { Write-Output "Supplemental files added from $supplemental" }
if (-Not $json) {
Write-Output "Supplemental files added from $supplemental"
} else {
$actionMessages += "Supplemental files added from $supplemental"
}
}
}

Expand All @@ -2226,15 +2280,19 @@ function createprojectpackage {
$PackageWriter.Dispose()

if ($PlaylistManager) {
if (-Not $json) { Write-Output "Unloading playlist" }
if (-Not $json) {
Write-Output "Unloading playlist"
} else {
$actionMessages += "Unloading playlist"
}

$PlaylistManager.UnloadPlaylist()
}

if (-Not $json) {
Write-Output "Packaged to $($PackagePath)..."
} else {
@(New-ProjectPackage $WntdProject.Name $PackagePath) | ConvertTo-Json -Compress
@(New-ProjectPackage $WntdProject.Name $PackagePath $iserror $actionMessages) | ConvertTo-Json -Compress
}
}
#
Expand Down