From c94c79a0573b60c7b1162e674ebcaa884fd72a2e Mon Sep 17 00:00:00 2001 From: Jeremy Sinclair <4016293+snickler@users.noreply.github.com> Date: Fri, 27 Jan 2023 10:08:15 -0500 Subject: [PATCH] [Build][Installer] Fix Runtime Parsing for .NET Runtime and WPF dependencies (#23626) * Update parseRuntimes to use separate JSON for .NET Runtime / WPF * Update parseRuntimes script to filter duplicate dlls from WPF Runtime List * Fix spelling * Override dlls --------- Co-authored-by: Stefan Markovic --- .github/actions/spell-check/expect.txt | 2 + installer/PowerToysSetup/Awake.wxs | 2 +- installer/PowerToysSetup/ColorPicker.wxs | 2 +- installer/PowerToysSetup/FancyZones.wxs | 2 +- .../PowerToysSetup/FileExplorerPreview.wxs | 4 +- installer/PowerToysSetup/FileLocksmith.wxs | 2 +- installer/PowerToysSetup/Hosts.wxs | 2 +- installer/PowerToysSetup/ImageResizer.wxs | 2 +- installer/PowerToysSetup/MeasureTool.wxs | 2 +- installer/PowerToysSetup/PowerAccent.wxs | 2 +- installer/PowerToysSetup/Run.wxs | 2 +- installer/PowerToysSetup/Settings.wxs | 2 +- installer/PowerToysSetup/TextExtractor.wxs | 2 +- .../PowerToysSetupCustomActions.vcxproj | 2 +- .../parseRuntimes.ps1 | 64 ++++++++++++------- 15 files changed, 56 insertions(+), 38 deletions(-) diff --git a/.github/actions/spell-check/expect.txt b/.github/actions/spell-check/expect.txt index 03f9f0a34d..d09e6d483e 100644 --- a/.github/actions/spell-check/expect.txt +++ b/.github/actions/spell-check/expect.txt @@ -1525,6 +1525,7 @@ RUNLEVEL runsettings runtimeclass runtimeconfig +runtimedepsjsonpath runtimeobject runtimepack runtimes @@ -2069,6 +2070,7 @@ workspaces wox wparam wpf +wpfdepsjsonpath wpftmp wpr wprp diff --git a/installer/PowerToysSetup/Awake.wxs b/installer/PowerToysSetup/Awake.wxs index 49c8304fe7..645cb61cf5 100644 --- a/installer/PowerToysSetup/Awake.wxs +++ b/installer/PowerToysSetup/Awake.wxs @@ -4,7 +4,7 @@ - + diff --git a/installer/PowerToysSetup/ColorPicker.wxs b/installer/PowerToysSetup/ColorPicker.wxs index 9c8606b52f..85beb55268 100644 --- a/installer/PowerToysSetup/ColorPicker.wxs +++ b/installer/PowerToysSetup/ColorPicker.wxs @@ -4,7 +4,7 @@ - + diff --git a/installer/PowerToysSetup/FancyZones.wxs b/installer/PowerToysSetup/FancyZones.wxs index 6e07dcc4ff..555c46057c 100644 --- a/installer/PowerToysSetup/FancyZones.wxs +++ b/installer/PowerToysSetup/FancyZones.wxs @@ -4,7 +4,7 @@ - + diff --git a/installer/PowerToysSetup/FileExplorerPreview.wxs b/installer/PowerToysSetup/FileExplorerPreview.wxs index 1691569c7b..88f8e97d2b 100644 --- a/installer/PowerToysSetup/FileExplorerPreview.wxs +++ b/installer/PowerToysSetup/FileExplorerPreview.wxs @@ -5,9 +5,9 @@ - + - + diff --git a/installer/PowerToysSetup/FileLocksmith.wxs b/installer/PowerToysSetup/FileLocksmith.wxs index 1f9edbe93b..c2ee5f2571 100644 --- a/installer/PowerToysSetup/FileLocksmith.wxs +++ b/installer/PowerToysSetup/FileLocksmith.wxs @@ -4,7 +4,7 @@ - + diff --git a/installer/PowerToysSetup/Hosts.wxs b/installer/PowerToysSetup/Hosts.wxs index 530bafaa3a..217251e054 100644 --- a/installer/PowerToysSetup/Hosts.wxs +++ b/installer/PowerToysSetup/Hosts.wxs @@ -4,7 +4,7 @@ - + diff --git a/installer/PowerToysSetup/ImageResizer.wxs b/installer/PowerToysSetup/ImageResizer.wxs index bc0de24cce..88a1fea3e7 100644 --- a/installer/PowerToysSetup/ImageResizer.wxs +++ b/installer/PowerToysSetup/ImageResizer.wxs @@ -4,7 +4,7 @@ - + diff --git a/installer/PowerToysSetup/MeasureTool.wxs b/installer/PowerToysSetup/MeasureTool.wxs index 6f5412917a..d6223c11ea 100644 --- a/installer/PowerToysSetup/MeasureTool.wxs +++ b/installer/PowerToysSetup/MeasureTool.wxs @@ -4,7 +4,7 @@ - + diff --git a/installer/PowerToysSetup/PowerAccent.wxs b/installer/PowerToysSetup/PowerAccent.wxs index a74b374113..928a3ca488 100644 --- a/installer/PowerToysSetup/PowerAccent.wxs +++ b/installer/PowerToysSetup/PowerAccent.wxs @@ -4,7 +4,7 @@ - + diff --git a/installer/PowerToysSetup/Run.wxs b/installer/PowerToysSetup/Run.wxs index 27ac9e0673..e8df425b90 100644 --- a/installer/PowerToysSetup/Run.wxs +++ b/installer/PowerToysSetup/Run.wxs @@ -45,7 +45,7 @@ - + diff --git a/installer/PowerToysSetup/Settings.wxs b/installer/PowerToysSetup/Settings.wxs index 849fb081a0..c476277736 100644 --- a/installer/PowerToysSetup/Settings.wxs +++ b/installer/PowerToysSetup/Settings.wxs @@ -4,7 +4,7 @@ - + diff --git a/installer/PowerToysSetup/TextExtractor.wxs b/installer/PowerToysSetup/TextExtractor.wxs index f392ad7d37..f4f4c725b0 100644 --- a/installer/PowerToysSetup/TextExtractor.wxs +++ b/installer/PowerToysSetup/TextExtractor.wxs @@ -4,7 +4,7 @@ - + diff --git a/installer/PowerToysSetupCustomActions/PowerToysSetupCustomActions.vcxproj b/installer/PowerToysSetupCustomActions/PowerToysSetupCustomActions.vcxproj index e4802e286a..1e5e6c2295 100644 --- a/installer/PowerToysSetupCustomActions/PowerToysSetupCustomActions.vcxproj +++ b/installer/PowerToysSetupCustomActions/PowerToysSetupCustomActions.vcxproj @@ -48,7 +48,7 @@ call cmd /C "copy ""$(ProjectDir)DepsFilesLists.h"" ""$(ProjectDir)DepsFilesLists.h.bk""" call cmd /C "copy ""$(ProjectDir)..\PowerToysSetup\Core.wxs"" ""$(ProjectDir)..\PowerToysSetup\Core.wxs.bk"""" - call powershell.exe -NonInteractive -executionpolicy Unrestricted -File parseRuntimes.ps1 -depsjsonpath "$(ProjectDir)..\..\$(Platform)\$(Configuration)\modules\ColorPicker\PowerToys.ColorPickerUI.deps.json" -depsfileslistspath "$(ProjectDir)DepsFilesLists.h" -productwxspath "$(ProjectDir)..\PowerToysSetup\Core.wxs" + call powershell.exe -NonInteractive -executionpolicy Unrestricted -File parseRuntimes.ps1 -runtimedepsjsonpath "$(ProjectDir)..\..\$(Platform)\$(Configuration)\Settings\PowerToys.Settings.deps.json" -wpfdepsjsonpath "$(ProjectDir)..\..\$(Platform)\$(Configuration)\modules\ColorPicker\PowerToys.ColorPickerUI.deps.json" -depsfileslistspath "$(ProjectDir)DepsFilesLists.h" -productwxspath "$(ProjectDir)..\PowerToysSetup\Core.wxs" Backing up original files and populating .NET and WPF Runtime dependencies diff --git a/installer/PowerToysSetupCustomActions/parseRuntimes.ps1 b/installer/PowerToysSetupCustomActions/parseRuntimes.ps1 index f031c4429d..1ea58c268c 100644 --- a/installer/PowerToysSetupCustomActions/parseRuntimes.ps1 +++ b/installer/PowerToysSetupCustomActions/parseRuntimes.ps1 @@ -1,13 +1,46 @@ [CmdletBinding()] Param( [Parameter(Mandatory = $True, Position = 1)] - [string]$depsjsonpath, + [string]$runtimedepsjsonpath, [Parameter(Mandatory = $True, Position = 2)] - [string]$depsfileslistspath, + [string]$wpfdepsjsonpath, [Parameter(Mandatory = $True, Position = 3)] + [string]$depsfileslistspath, + [Parameter(Mandatory = $True, Position = 4)] [string]$productwxspath ) +function Get-RuntimePack ($depsJsonFile, $runtimeName) { + Write-Host "Parsing $runtimeName Runtime" + $runtimePackList = ([array]$depsJsonFile.targets.PSObject.Properties)[-1].Value.PSObject.Properties | Where-Object { $_.Name -match "runtimepack.$runtimeName" }; + + if ($runtimePackList.Length -eq 0) { + Write-Host -ForegroundColor Red "$runtimeName has not been found" + exit 1 + } + + # Enumerate through array of custom objects and parse the names of the property values into a HashTable + $runtimePackList | ForEach-Object { + $runtimes += @{"$($_.Name -replace "runtimepack\.(\S+)\.\S+/\S+",'$1')" = $_.Value.PSObject.Properties.Value | ForEach-Object { + $_.PSObject.Properties.Name + } + } + } + Write-Output $runtimes; +} + +function Update-RuntimeHashTable () { + $runtimes = Get-RuntimePack $runtimeFile "Microsoft.NETCore.App.Runtime" + $runtimes = Get-RuntimePack $wpfRuntimeFile "Microsoft.WindowsDesktop.App.Runtime" + + # Find the dlls that exist in both the .NET Runtime and WPF Runtime deps list and filter out of WPF + $runtimeFileComparison = Compare-Object -ReferenceObject $runtimes["Microsoft.NETCore.App.Runtime"] -DifferenceObject $runtimes["Microsoft.WindowsDesktop.App.Runtime"] -IncludeEqual -ExcludeDifferent + + $runtimes["Microsoft.WindowsDesktop.App.Runtime"] = $runtimes["Microsoft.WindowsDesktop.App.Runtime"] | Where-Object { $_ -notin $runtimeFileComparison.InputObject } + + Write-Output $runtimes; +} + function Update-RuntimeFileList($runtimeToken, $runtimeKey) { $depsFilesLists -replace "($runtimeToken = )(.*);", "`$1 {`r`n$(($runtimes[$runtimeKey] | ForEach-Object {' L"'+$_+'"'} | Sort-Object) -join ",`r`n") };" } @@ -16,8 +49,7 @@ function Update-ProductWxsRuntimeFileList($runtimeToken, $runtimeKey) { $productWxs -replace "(define $runtimeToken=)(.*)?>", "`$1$($runtimes[$runtimeKey] -join ';')?>" } -function Update-DotnetFilesComponentGuid() -{ +function Update-DotnetFilesComponentGuid() { $productWxs -replace "Dlls_DotnetFiles_Component"" Guid=""([{]?[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}[}]?)""", "Dlls_DotnetFiles_Component"" Guid=""$((New-Guid).ToString().ToUpper())""" } @@ -28,26 +60,12 @@ $depsFilesLists = Get-Content $depsfileslistspath; $productWxs = Get-Content $productwxspath; # Read the deps.json file and convert it to a JSON object -$runtimeFile = Get-Content $depsjsonpath | ConvertFrom-Json; +$runtimeFile = Get-Content $runtimedepsjsonpath | ConvertFrom-Json; +$wpfRuntimeFile = Get-Content $wpfdepsjsonpath | ConvertFrom-Json; $runtimes = @{} -Write-Host "Parsing .NET Runtimes from $depsjsonpath `r`n" - -$runtimeList = ([array]$runtimeFile.targets.PSObject.Properties)[-1].Value.PSObject.Properties | Where-Object { $_.Name -match "runtimepack" }; - -if ($runtimeList.Length -eq 0) { - Write-Host -ForegroundColor Red "No runtimes have been detected" - exit 1 -} - -# Enumerate through array of custom objects and parse the names of the property values into a HashTable -$runtimeList | ForEach-Object { - $runtimes += @{"$($_.Name -replace "runtimepack\.(\S+)\.\S+/\S+",'$1')" = $_.Value.PSObject.Properties.Value | ForEach-Object { - $_.PSObject.Properties.Name - } - } -} +$runtimes = Update-RuntimeHashTable Write-Host "Writing Microsoft.NETCore.App.Runtime files" $depsFilesLists = Update-RuntimeFileList "dotnetRuntimeFiles" "Microsoft.NETCore.App.Runtime" @@ -64,6 +82,4 @@ Write-Host "Updating $depsfileslistspath" Set-Content -Path $depsfileslistspath -Value $depsFilesLists Write-Host "Updating $productwxspath" -Set-Content -Path $productwxspath -Value $productWxs - - +Set-Content -Path $productwxspath -Value $productWxs \ No newline at end of file