From 673cfda515bb4484a251a1dc86d8ce296a07a813 Mon Sep 17 00:00:00 2001 From: peterbarancek <62284244+peterbarancek@users.noreply.github.com> Date: Fri, 30 Oct 2026 10:06:23 +0100 Subject: [PATCH 1/2] Make local build resumable per component and stop tsproj encoding corruption MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Record completed build steps in _Vortex/build.state.json; with resume=$true a failed build continues from the failed step. Vortex builder runs per component (dependency order from csproj/plcproj references), PLC compile per tsproj and tests per test project, each checkpointed separately. - Run Visual Studio for the builder headless (headlessVs) with a COM message filter, and add incremental mode (no clean, /Build instead of /Rebuild). - Load/save tsproj XML as UTF-8 and save only on change. Get-Content read the BOM-less files as ANSI, so every build re-encoded the 'µs' of the EL1819 terminal in XAETcoIo.tsproj; the file grew to ~600 MB and stopped loading. - Repair the corrupted EL1819 terminal names in XAETcoIo.tsproj. Co-Authored-By: Claude Opus 5.5 --- README.md | 6 +- pipelines/build.ps1 | 192 +++++++++++++------ pipelines/tcobuildutils.psm1 | 264 +++++++++++++++++++++++++- src/TcoIo/src/XAE/XAE/XAETcoIo.tsproj | 4 +- 4 files changed, 392 insertions(+), 74 deletions(-) diff --git a/README.md b/README.md index 4ce552d2..49885132 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,11 @@ You should set up Windows environment variable ```Tc3Target``` with the value of **Build project to restore necessary tooling and packages** -### BEFORE RUNNING THE SCRIPT MAKE SURE ALL INSTANCES OF VISUAL STUDIO ARE CLOSED. THE SCRIPT WILL OPEN VS TO COMPLETE THE BUILD OF THE PROJECT. +The script runs Visual Studio in the background without opening the IDE window (Vortex builder and the TwinCAT compile still need the VS 2019 engine). It closes only the VS instance it started, so your own VS sessions stay open. Set `"headlessVs" = $false` to open the IDE window as before. + +For local development add `"incremental" = $true`. This skips the clean step (generated twins, `_meta`, `obj/bin`, TwinCAT compile info are kept) and uses `/Build` instead of `/Rebuild` for the PLC projects. + +Every build records its successfully completed steps in `_Vortex\build.state.json`. When a build fails, run it again with `"resume" = $true` and it continues from the failed step. The Vortex builder runs and is checkpointed per component (dependencies first), the PLC compile per tsproj and the tests per test project, so only the failed one and the rest are built. Combine with `"incremental" = $true` so the PLC projects are not rebuilt. The state is removed after a successful build, and it is ignored when `buildConfig` differs. _VS 2019 Community edition_ ~~~ PowerShell diff --git a/pipelines/build.ps1 b/pipelines/build.ps1 index b8effc96..5475bb56 100644 --- a/pipelines/build.ps1 +++ b/pipelines/build.ps1 @@ -16,21 +16,34 @@ $testTargetAmsId = ([System.Environment]::GetEnvironmentVariable('Tc3Target')) $testingStrength = 0 $doesNeedVs = $true + # starts VS for Vortex builder without UI (no IDE window); $false opens the IDE as before + $headlessVs = $true + # local dev: keeps generated/compiled outputs and builds PLC projects instead of rebuilding them + $incremental = $false + # continues after the last successfully completed step of the previous run (state in _Vortex\build.state.json) + $resume = $false + $buildStateFile = "$baseDir\_Vortex\build.state.json" } -task default -depends Init, BuildScripts, Start, Clean, Check-Target-License, NugetRestore, CopyInxton, RemovePinnedVersion, DisableDevices, SetPlcCpuCores, GitVersion, ` +task default -depends Init, BuildScripts, Start, Clean, Check-Target-License, NugetRestore, CopyInxton, FindTsProjects, RemovePinnedVersion, DisableDevices, SetPlcCpuCores, GitVersion, ` OpenVisualStudio, BuildWithInxtonBuilder, Build, CloseVs, CopyPlcLibs, Tests, ClearPackages, CreatePackages, PublishPackages, Finish FormatTaskName (("="*25) + " [ {0} ] " + ("="*25)) +# only reached when the task action succeeded +TaskTearDown { + Complete-BuildStep $buildStateFile $psake.context.Peek().currentTaskName +} + task Init { Write-Host "Setting location to $baseDir" Set-Location $baseDir $psake.context.Peek().properties $properties + Initialize-BuildState $buildStateFile $resume $buildConfig } @@ -45,17 +58,24 @@ task Start { #Assert $gitOK "[📩] Please commit your changes before running build" } -task Clean { - Write-Host "Clean obj bin" - CleanObjBin - RemoveTcBins - RemoveTcProjBins - RemoveGenerated - - if($doesNeedVs) +task Clean -precondition { Test-BuildStepPending $buildStateFile "Clean" } { + if($incremental) { - RemoveMeta - } + Write-Host "Incremental build: skipping clean" + } + else + { + Write-Host "Clean obj bin" + CleanObjBin + RemoveTcBins + RemoveTcProjBins + RemoveGenerated + + if($doesNeedVs) + { + RemoveMeta + } + } mkdir .\_Vortex\builder -ErrorAction SilentlyContinue mkdir .\.nuget -ErrorAction SilentlyContinue @@ -78,15 +98,12 @@ task Check-Target-License ` } -task NugetRestore { +task NugetRestore -precondition { Test-BuildStepPending $buildStateFile "NugetRestore" } { + # packages are restored by msbuild -restore in Build task EnsureNuget +} - exec{ - & $dotnet restore TcOpen.build.slnf - } -} - -task CopyInxton -continueOnError { +task CopyInxton -continueOnError -precondition { Test-BuildStepPending $buildStateFile "CopyInxton" } { exec { & $dotnet build ` .\src\TcoCore\tests\TcoDummyTest\TcoDummyTest.csproj ` @@ -96,21 +113,27 @@ task CopyInxton -continueOnError { } } +task FindTsProjects ` + -description "Scan repository for tsproj files once for following tasks" ` +{ + $script:tsProjects = (Get-ChildItem .\ -recurse "*.tsproj" | % { $_.FullName }) +} + task RemovePinnedVersion ` + -precondition { Test-BuildStepPending $buildStateFile "RemovePinnedVersion" } ` -description "Remove pinned to version if found in any tsproj" ` { - $tsProjects = (Get-ChildItem .\ -recurse "*.tsproj" | % { $_.FullName }) - foreach ($tsProject in $tsProjects) + foreach ($tsProject in $script:tsProjects) { RemovePinVersion($tsProject) } } task DisableDevices ` + -precondition { Test-BuildStepPending $buildStateFile "DisableDevices" } ` -description "Disable any device if found in any tsproj" ` { - $tsProjects = (Get-ChildItem .\ -recurse "*.tsproj" | % { $_.FullName }) - foreach ($tsProject in $tsProjects) + foreach ($tsProject in $script:tsProjects) { DisableDevices($tsProject) } @@ -118,10 +141,9 @@ task DisableDevices ` task SetPlcCpuCores ` -description "Will set 1 shared 1 isolated core to every tsproj" ` - -precondition { Is-AMS-Id-Local $testTargetAmsId } ` + -precondition { (Is-AMS-Id-Local $testTargetAmsId) -and (Test-BuildStepPending $buildStateFile "SetPlcCpuCores") } ` { - $tsProjects = (Get-ChildItem .\ -recurse "*.tsproj" | % { $_.FullName }) - foreach ($tsProject in $tsProjects) + foreach ($tsProject in $script:tsProjects) { Remove-TargetNetId($tsProject) if (Has-RT-Isolated-Core $tsProject -or $tsProject.Contains("XAEVortexBase")) @@ -179,55 +201,92 @@ task OpenVisualStudio { } -task BuildWithInxtonBuilder { +task BuildWithInxtonBuilder -precondition { Test-BuildStepPending $buildStateFile "BuildWithInxtonBuilder" } { - if($doesNeedVs) + # one builder run per component (dependencies first), each completed component is checkpointed + $components = Get-SlnfComponents .\TcOpen.plc.slnf | Where-Object { $_.Projects -like '*.tsproj' } + foreach($component in $components) { - $command = ".\_Vortex\builder\vortex.compiler.console.exe -s .\TcOpen.plc.slnf" + $step = "BuildWithInxtonBuilder:$($component.Name)" + if(-not (Test-BuildStepPending $buildStateFile $step)) { continue } + + $slnf = New-PartialSlnf .\TcOpen.plc.slnf $component.Projects $component.Name .\_Vortex\slnf + $command = ".\_Vortex\builder\vortex.compiler.console.exe -s `"$slnf`"" + Write-Host $command -ForegroundColor Cyan + exec { + $hiddenVs = $null + try + { + if($doesNeedVs) + { + if($headlessVs) + { + $hiddenVs = Start-HiddenVs $slnf + } + else + { + Stop-AllVs + Start-Process $slnf + } + } + cmd /c $command + } + finally + { + if($hiddenVs) { Stop-HiddenVs $hiddenVs } + elseif($doesNeedVs) { Stop-AllVs } + } + } -maxRetries 3 + + Complete-BuildStep $buildStateFile $step } - else +} + +task Build -precondition { Test-BuildStepPending $buildStateFile "Build" } { + #/consoleloggerparameters:ErrorsOnly + if(Test-BuildStepPending $buildStateFile "Build:DotNet") { - $command = ".\_Vortex\builder\vortex.compiler.console.exe -s .\TcOpen.plc.slnf -n false" + exec{ + & $msbuild .\TcOpen.build.slnf ` + -restore ` + /m ` + /nr:false ` + /p:Configuration=$buildConfig ` + -noWarn:"CS1591;CS0067;CS0108;CS1570" ` + /consoleloggerparameters:ErrorsOnly ` + -v:$msbuildVerbosity + } -maxRetries 3 + Complete-BuildStep $buildStateFile "Build:DotNet" } - Write-Host $command - exec { - try{Get-Process devenv | Stop-Process -ErrorAction SilentlyContinue} catch{} - if($doesNeedVs) - { - Start-Process .\TcOpen.plc.slnf - } - cmd /c $command - try{Get-Process devenv | Stop-Process -ErrorAction SilentlyContinue}catch{} - } -maxRetries 3 -} -task Build { - #/consoleloggerparameters:ErrorsOnly - Write-Host $command - exec{ - & $msbuild .\TcOpen.build.slnf ` - /p:Configuration=$buildConfig ` - -noWarn:"CS1591;CS0067;CS0108;CS1570" ` - /consoleloggerparameters:ErrorsOnly ` - -v:$msbuildVerbosity - } -maxRetries 3 + $plcBuildAction = if($incremental) { "/Build" } else { "/Rebuild" } - $command = "`"$devenv`" .\TcOpen.test.build.plc.slnf /Rebuild " + "`"$buildConfig|TwinCAT RT (x64)`"" + # one devenv run per plc project, each completed project is checkpointed + $tsProjects = (Get-Content .\TcOpen.test.build.plc.slnf -Raw | ConvertFrom-Json).solution.projects + foreach($tsProject in $tsProjects) + { + $name = [System.IO.Path]::GetFileNameWithoutExtension($tsProject) + $step = "Build:Plc:$name" + if(-not (Test-BuildStepPending $buildStateFile $step)) { continue } + $slnf = New-PartialSlnf .\TcOpen.test.build.plc.slnf @($tsProject) "plc.$name" .\_Vortex\slnf + Write-Host "$plcBuildAction $tsProject" -ForegroundColor Cyan exec{ - & $devenv .\TcOpen.test.build.plc.slnf /Rebuild "$buildConfig|TwinCAT RT (x64)" - #cmd /c $command - } -maxRetries 2 + & $devenv $slnf $plcBuildAction "$buildConfig|TwinCAT RT (x64)" + } -maxRetries 2 + + Complete-BuildStep $buildStateFile $step + } } -task CloseVs { +task CloseVs -precondition { -not $headlessVs -and (Test-BuildStepPending $buildStateFile "CloseVs") } { exec{ - try{Get-Process devenv | Stop-Process -ErrorAction SilentlyContinue} catch{} + Stop-AllVs } } -task CopyPlcLibs { +task CopyPlcLibs -precondition { Test-BuildStepPending $buildStateFile "CopyPlcLibs" } { $slnfPath = ".\TcOpen.plc.slnf" $slnf = Get-Content $slnfPath | ConvertFrom-Json $slnfDir = [System.IO.Path]::GetDirectoryName($slnfPath) @@ -287,7 +346,10 @@ task Tests -precondition { return $isTestingEnabled } { if($tier -le $testingStrength) - { + { + # tests are checkpointed per project, a resumed run continues with the failed one + if(-not (Test-BuildStepPending $buildStateFile "Tests:$projName")) { continue } + Write-Host '--------------------------------------------' -ForegroundColor Cyan Write-Host "Running test for $testProjectOrSolution | plc: $xaeProjectFolder" -ForegroundColor Cyan Write-Host '--------------------------------------------' -ForegroundColor Cyan @@ -315,7 +377,9 @@ task Tests -precondition { return $isTestingEnabled } { -l:"trx;LogFileName=$LogFileName" ` --no-build ` --no-restore - } -maxRetries 2 + } -maxRetries 2 + + Complete-BuildStep $buildStateFile "Tests:$projName" } @@ -329,7 +393,7 @@ task Tests -precondition { return $isTestingEnabled } { task ClearPackages ` - -precondition { $publishNugets } ` + -precondition { $publishNugets -and (Test-BuildStepPending $buildStateFile "ClearPackages") } ` { mkdir nugets -ErrorAction SilentlyContinue mkdir nugets\dependants -ErrorAction SilentlyContinue @@ -337,7 +401,7 @@ task ClearPackages ` } task CreatePackages ` - -precondition { $packNugets } ` + -precondition { $packNugets -and (Test-BuildStepPending $buildStateFile "CreatePackages") } ` { $semVer = $script:gitVersion.SemVer exec { @@ -353,12 +417,14 @@ task CreatePackages ` } } -task PublishPackages -precondition {return $publishNugets} { +task PublishPackages -precondition { $publishNugets -and (Test-BuildStepPending $buildStateFile "PublishPackages") } { Write-Host "About to" PushNugets -folderWithNugets .\nugets -token $nugetToken -source $nugetSource } task Finish { + # whole build succeeded, next run starts from the beginning + Clear-BuildState $buildStateFile Write-Host "Done" } diff --git a/pipelines/tcobuildutils.psm1 b/pipelines/tcobuildutils.psm1 index 062cc6eb..224250a1 100644 --- a/pipelines/tcobuildutils.psm1 +++ b/pipelines/tcobuildutils.psm1 @@ -242,6 +242,24 @@ function GitVersionToPlcVersion{ # [END] clean.ps1 +# tsproj files are UTF-8 without BOM. Get-Content would read them with the ANSI code page and each save +# would encode non-ASCII characters (e.g. 'µs' in EtherCAT terminal names) once more, growing the file on every build. +function Read-XmlFile($path) +{ + $xml = New-Object System.Xml.XmlDocument + $xml.PreserveWhitespace = $true + $xml.Load((Resolve-Path $path).Path) + return ,$xml +} + +function Save-XmlFile([System.Xml.XmlDocument] $xml, $path) +{ + $settings = New-Object System.Xml.XmlWriterSettings + $settings.Encoding = New-Object System.Text.UTF8Encoding($false) + $writer = [System.Xml.XmlWriter]::Create((Resolve-Path $path).Path, $settings) + try { $xml.Save($writer) } finally { $writer.Dispose() } +} + # Isolated core functions function Has-Isolated-Core($tcproj) @@ -274,7 +292,7 @@ function Has-RT-Isolated-Core($tcproj) function Set-CPU-Cores($tcproj, $shared, $isolated) { - $xml = [System.Xml.XmlDocument](Get-Content $tcproj); + $xml = Read-XmlFile $tcproj $settingsNode = $xml.SelectSingleNode("TcSmProject/Project/System/Settings") if($settingsNode -eq $null) { @@ -301,7 +319,7 @@ function Set-CPU-Cores($tcproj, $shared, $isolated) $settingsNode.AppendChild($isolatedCoreXmlNode) - $xml.Save($tcproj) + Save-XmlFile $xml $tcproj } function Is-AMS-Id-Local($TargetAmsId) @@ -315,12 +333,12 @@ function Is-AMS-Id-Local($TargetAmsId) function Remove-TargetNetId($tcproj) { - $xml = [System.Xml.XmlDocument](Get-Content $tcproj); + $xml = Read-XmlFile $tcproj $projectNode = $xml.SelectSingleNode("TcSmProject/Project") if($projectNode.HasAttribute("TargetNetId")) { $projectNode.RemoveAttribute("TargetNetId") - $xml.save($tcproj) + Save-XmlFile $xml $tcproj } } @@ -414,12 +432,12 @@ function GetInstalledTwincatVersion{ function RemovePinVersion($tsproj) { - $xml = [System.Xml.XmlDocument](Get-Content $tsproj); + $xml = Read-XmlFile $tsproj $TcSmProjectNode = $xml.SelectSingleNode("TcSmProject") if($TcSmProjectNode.HasAttribute("TcVersionFixed")) { $TcSmProjectNode.RemoveAttribute("TcVersionFixed") - $xml.save($tsproj) + Save-XmlFile $xml $tsproj Write-Host "Pin version removed in`t" $tsproj } } @@ -427,10 +445,11 @@ function RemovePinVersion($tsproj) function DisableDevices($tsproj) { - $xml = [System.Xml.XmlDocument](Get-Content $tsproj); + $xml = Read-XmlFile $tsproj $ioNode = $xml.SelectSingleNode("TcSmProject/Project/Io") if($ioNode -ne $null) { + $changed = $false $devicesNodes= $xml.SelectNodes("TcSmProject/Project/Io/Device") foreach($deviceNode in $devicesNodes) { @@ -438,8 +457,237 @@ function DisableDevices($tsproj) { $deviceNode.SetAttribute("Disabled","true") Write-Host "Disabled device`t" $deviceNode.RemoteName " in`t" $tsproj + $changed = $true + } + } + if($changed) { Save-XmlFile $xml $tsproj } + } +} + + +# COM message filter: retries calls rejected by a busy Visual Studio (RPC_E_CALL_REJECTED) +function Register-ComMessageFilter +{ + if (-not ("TcoBuild.MessageFilter" -as [type])) + { + Add-Type -TypeDefinition @" +using System; +using System.Runtime.InteropServices; + +namespace TcoBuild +{ + [ComImport, Guid("00000016-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface IOleMessageFilter + { + [PreserveSig] int HandleInComingCall(int dwCallType, IntPtr hTaskCaller, int dwTickCount, IntPtr lpInterfaceInfo); + [PreserveSig] int RetryRejectedCall(IntPtr hTaskCallee, int dwTickCount, int dwRejectType); + [PreserveSig] int MessagePending(IntPtr hTaskCallee, int dwTickCount, int dwPendingType); + } + + public class MessageFilter : IOleMessageFilter + { + [DllImport("Ole32.dll")] + private static extern int CoRegisterMessageFilter(IOleMessageFilter newFilter, out IOleMessageFilter oldFilter); + + public static void Register() { IOleMessageFilter old; CoRegisterMessageFilter(new MessageFilter(), out old); } + public static void Revoke() { IOleMessageFilter old; CoRegisterMessageFilter(null, out old); } + + int IOleMessageFilter.HandleInComingCall(int dwCallType, IntPtr hTaskCaller, int dwTickCount, IntPtr lpInterfaceInfo) { return 0; } + // SERVERCALL_RETRYLATER -> retry after 200 ms + int IOleMessageFilter.RetryRejectedCall(IntPtr hTaskCallee, int dwTickCount, int dwRejectType) { return dwRejectType == 2 ? 200 : -1; } + int IOleMessageFilter.MessagePending(IntPtr hTaskCallee, int dwTickCount, int dwPendingType) { return 2; } + } +} +"@ + } + [TcoBuild.MessageFilter]::Register() +} + +function Unregister-ComMessageFilter +{ + if ("TcoBuild.MessageFilter" -as [type]) + { + [TcoBuild.MessageFilter]::Revoke() + } +} + +# Starts Visual Studio without UI and opens the solution, so tools attaching over EnvDTE (Vortex builder) can use it. +# Returns handle for Stop-HiddenVs. +function Start-HiddenVs +{ + param( + [string] $solutionPath, + [string] $progId = "VisualStudio.DTE.16.0" + ) + + Register-ComMessageFilter + + $before = @(Get-Process devenv -ErrorAction SilentlyContinue | ForEach-Object { $_.Id }) + $dte = New-Object -ComObject $progId + $vsProcessIds = @(Get-Process devenv -ErrorAction SilentlyContinue | Where-Object { $before -notcontains $_.Id } | ForEach-Object { $_.Id }) + + $dte.SuppressUI = $true + $dte.UserControl = $false + try { $dte.MainWindow.Visible = $false } catch {} + + Write-Host "Opening $solutionPath in hidden $progId (pid $vsProcessIds)" + $dte.Solution.Open($solutionPath) + + return [PSCustomObject]@{ Dte = $dte; ProcessIds = $vsProcessIds } +} + +function Stop-HiddenVs($hiddenVs) +{ + if ($hiddenVs -eq $null) { return } + + try { $hiddenVs.Dte.Quit() } catch { Write-Host "DTE.Quit failed: $_" } + Unregister-ComMessageFilter + + foreach ($id in $hiddenVs.ProcessIds) + { + try { Wait-Process -Id $id -Timeout 60 -ErrorAction Stop } catch { Stop-Process -Id $id -Force -ErrorAction SilentlyContinue } + } +} + +function Stop-AllVs +{ + try { Get-Process devenv -ErrorAction SilentlyContinue | Stop-Process -ErrorAction SilentlyContinue } catch {} +} + +# Build checkpoints: successfully completed steps are recorded in a state file, so a build started with resume skips them. +function Read-BuildState($stateFile) +{ + if (Test-Path $stateFile) + { + try { return Get-Content $stateFile -Raw | ConvertFrom-Json } catch { Write-Host "Unreadable build state '$stateFile', ignoring: $_" } + } + return $null +} + +function Save-BuildState($stateFile, $state) +{ + New-Item -ItemType Directory -Force (Split-Path $stateFile) | Out-Null + ConvertTo-Json -InputObject $state | Set-Content $stateFile -Encoding UTF8 +} + +# Keeps the previous state when resuming the same configuration, otherwise starts a new one. +function Initialize-BuildState($stateFile, [bool] $resume, [string] $buildConfig) +{ + $state = Read-BuildState $stateFile + if ($resume -and $state -ne $null -and $state.buildConfig -eq $buildConfig) + { + Write-Host "Resuming build, completed steps will be skipped: $(@($state.completed) -join ', ')" -ForegroundColor Yellow + return + } + + if ($resume) + { + Write-Host "Nothing to resume (no previous state or different buildConfig), running full build" -ForegroundColor Yellow + } + Save-BuildState $stateFile ([PSCustomObject]@{ buildConfig = $buildConfig; completed = @() }) +} + +function Test-BuildStepPending($stateFile, [string] $step) +{ + $state = Read-BuildState $stateFile + if ($state -ne $null -and @($state.completed) -contains $step) + { + Write-Host "Skipping '$step', completed in previous run" -ForegroundColor DarkGray + return $false + } + return $true +} + +function Complete-BuildStep($stateFile, [string] $step) +{ + $state = Read-BuildState $stateFile + if ($state -eq $null) { return } + if (@($state.completed) -notcontains $step) + { + $state.completed = @($state.completed) + $step + Save-BuildState $stateFile $state + } +} + +function Clear-BuildState($stateFile) +{ + Remove-Item $stateFile -ErrorAction SilentlyContinue +} + +# Splits solution filter projects into components (src\), ordered so that referenced components come first. +# Dependencies come from csproj project references and plcproj library references. +function Get-SlnfComponents($slnfPath) +{ + $slnf = Get-Content $slnfPath -Raw | ConvertFrom-Json + $solutionDir = Split-Path (Join-Path (Split-Path (Resolve-Path $slnfPath).Path) $slnf.solution.path) + + $components = [ordered]@{} + foreach ($project in $slnf.solution.projects) + { + $name = ($project -split '\\')[0..1] -join '\' + if (-not $components.Contains($name)) + { + $components[$name] = [PSCustomObject]@{ Name = ($project -split '\\')[1]; Key = $name; Projects = @(); DependsOn = @() } + } + $components[$name].Projects += $project + } + + # plc library name -> component + $libraryOwners = @{} + foreach ($component in $components.Values) + { + Get-ChildItem (Join-Path $solutionDir $component.Key) -Recurse -Filter *.plcproj -ErrorAction SilentlyContinue | + ForEach-Object { $libraryOwners[$_.BaseName] = $component.Key } + } + + foreach ($component in $components.Values) + { + $references = @() + foreach ($project in $component.Projects | Where-Object { $_ -like '*.csproj' }) + { + $projectPath = Join-Path $solutionDir $project + $references += ([xml](Get-Content $projectPath)).Project.ItemGroup.ProjectReference.Include | Where-Object { $_ } | ForEach-Object { + $full = [System.IO.Path]::GetFullPath((Join-Path (Split-Path $projectPath) $_)) + ($full.Substring($solutionDir.TrimEnd('\').Length + 1) -split '\\')[0..1] -join '\' } } - $xml.Save($tsproj) + Get-ChildItem (Join-Path $solutionDir $component.Key) -Recurse -Filter *.plcproj -ErrorAction SilentlyContinue | ForEach-Object { + $plcproj = [xml](Get-Content $_.FullName) + $references += @($plcproj.Project.ItemGroup.PlaceholderReference.Include) + @($plcproj.Project.ItemGroup.LibraryReference.Include) | + Where-Object { $_ } | ForEach-Object { $libraryOwners[($_ -split ',')[0].Trim()] } + } + $component.DependsOn = @($references | Where-Object { $_ -and $_ -ne $component.Key -and $components.Contains($_) } | Sort-Object -Unique) } + + # depth-first ordering, keeps the slnf order where there is no dependency + $ordered = New-Object System.Collections.ArrayList + $visiting = @{} + function Visit($component) + { + if ($ordered -contains $component) { return } + if ($visiting[$component.Key]) { throw "Circular dependency between components at '$($component.Key)'" } + $visiting[$component.Key] = $true + foreach ($dependency in $component.DependsOn) { Visit $components[$dependency] } + $visiting[$component.Key] = $false + [void]$ordered.Add($component) + } + foreach ($component in $components.Values) { Visit $component } + + return $ordered } + +# Writes solution filter with given projects into $outputDir and returns its path. +function New-PartialSlnf($sourceSlnfPath, [string[]] $projects, [string] $name, [string] $outputDir) +{ + $slnf = Get-Content $sourceSlnfPath -Raw | ConvertFrom-Json + $solutionPath = (Resolve-Path (Join-Path (Split-Path (Resolve-Path $sourceSlnfPath).Path) $slnf.solution.path)).Path + + New-Item -ItemType Directory -Force $outputDir | Out-Null + $outputDir = (Resolve-Path $outputDir).Path + $relativeSolutionPath = (New-Object System.Uri("$outputDir\")).MakeRelativeUri((New-Object System.Uri($solutionPath))).ToString().Replace('/', '\') + + $partial = @{ solution = @{ path = $relativeSolutionPath; projects = @($projects) } } + $path = Join-Path $outputDir "$name.slnf" + ConvertTo-Json -InputObject $partial -Depth 5 | Set-Content $path -Encoding UTF8 + return $path +} \ No newline at end of file diff --git a/src/TcoIo/src/XAE/XAE/XAETcoIo.tsproj b/src/TcoIo/src/XAE/XAE/XAETcoIo.tsproj index 84e8827b..31e1a6d8 100644 --- a/src/TcoIo/src/XAE/XAE/XAETcoIo.tsproj +++ b/src/TcoIo/src/XAE/XAE/XAETcoIo.tsproj @@ -9167,7 +9167,7 @@ Bit1: Value bigger/equal Limit2]]> Term 26 (EL1819) 7 - + 001002000000010004000000000000000200001000010000 0000000000000000001000010100000002000000000000000000000000000000 Row_3 @@ -9256,7 +9256,7 @@ Bit1: Value bigger/equal Limit2]]> Term 27 (EL1819) 7 - + 001002000000010004000000000000000200001000010000 0000000000000000001000010100000002000000000000000000000000000000 Row_3 From e006ffb1e5eb50f9da010df85918eef990c44b8b Mon Sep 17 00:00:00 2001 From: peterbarancek <62284244+peterbarancek@users.noreply.github.com> Date: Fri, 30 Oct 2026 10:21:14 +0100 Subject: [PATCH 2/2] Fix EL1819 terminal names in XAETcoIo.tsproj MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous repair wrote a 0x01 control character instead of the terminal name, so XmlDocument.Load fails on CI: "'\x01', hexadecimal value 0x01, is an invalid character". Restore 'EL1819 16Ch. Dig. Input 24V, 10µs'. Co-Authored-By: Claude Opus 5.5 --- src/TcoIo/src/XAE/XAE/XAETcoIo.tsproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TcoIo/src/XAE/XAE/XAETcoIo.tsproj b/src/TcoIo/src/XAE/XAE/XAETcoIo.tsproj index 31e1a6d8..3530b525 100644 --- a/src/TcoIo/src/XAE/XAE/XAETcoIo.tsproj +++ b/src/TcoIo/src/XAE/XAE/XAETcoIo.tsproj @@ -9167,7 +9167,7 @@ Bit1: Value bigger/equal Limit2]]> Term 26 (EL1819) 7 - + 001002000000010004000000000000000200001000010000 0000000000000000001000010100000002000000000000000000000000000000 Row_3 @@ -9256,7 +9256,7 @@ Bit1: Value bigger/equal Limit2]]> Term 27 (EL1819) 7 - + 001002000000010004000000000000000200001000010000 0000000000000000001000010100000002000000000000000000000000000000 Row_3