@@ -114,98 +114,7 @@ $ExitRootDirError = 3
114114$ExitProjectNotFound = 4
115115$ExitBuildFailed = 5
116116
117- $script :Version = ' 1.0.0'
118- $ToolVersion = $script :Version
119-
120- # BEGIN-CD-HOSTLOG
121- # -----------------------------------------------------------------------------
122- # Write-CDHostLog v0.1.0
123- # Source: https://github.com/continuous-delphi/delphi-logger
124- #
125- # Universal output function for Continuous-Delphi PowerShell tooling.
126- # Opt-in structured logging via ContinuousDelphi.Logger module.
127- # See: https://github.com/continuous-delphi/delphi-logger/docs/output-modes.md
128- # -----------------------------------------------------------------------------
129-
130- # Logger detection -- check once at load time whether the caller has loaded
131- # ContinuousDelphi.Logger. If so, structured events are emitted alongside
132- # native PowerShell stream output. If not, Write-CDHostLog routes to native
133- # Write-Output / Write-Verbose / Write-Host / Write-Warning / Write-Error only.
134- $script :LoggerAvailable = [bool ](Get-Module - Name ' ContinuousDelphi.Logger' )
135- $script :LoggerCaptureOutput = if ($script :LoggerAvailable ) {
136- $script :CDLoggerState = (Get-Module - Name ' ContinuousDelphi.Logger' ).SessionState.PSVariable.GetValue(' CDLoggerState' )
137- if ($null -ne $script :CDLoggerState ) { $script :CDLoggerState.CaptureOutput } else { $false }
138- } else { $false }
139-
140- function Write-CDHostLog {
141- [Diagnostics.CodeAnalysis.SuppressMessageAttribute (' PSAvoidUsingWriteHost' , ' ' ,
142- Justification= ' Write-Host is used intentionally for Info/Success level output to stream 6 without polluting the pipeline' )]
143- param (
144- [Parameter (Mandatory )]
145- $Message ,
146-
147- [ValidateSet (' Output' , ' Trace' , ' Debug' , ' Verbose' , ' Info' , ' Success' , ' Warning' , ' Error' , ' Fatal' )]
148- [string ]$Level = ' Info' ,
149-
150- [string ]$EventId ,
151- [hashtable ]$Data ,
152-
153- [switch ]$LogOnly
154- )
155-
156- # Write to native PowerShell stream (unless LogOnly)
157- if (-not $LogOnly ) {
158- switch ($Level ) {
159- ' Output' {
160- Write-Output $Message
161- }
162- { $_ -in ' Trace' , ' Debug' , ' Verbose' } {
163- Write-Verbose $Message
164- }
165- { $_ -in ' Info' , ' Success' } {
166- Write-Host $Message
167- }
168- ' Warning' {
169- Write-Warning $Message
170- }
171- { $_ -in ' Error' , ' Fatal' } {
172- Write-Error $Message - ErrorAction Continue
173- }
174- }
175- }
176-
177- # Also emit structured log event if logger available
178- if ($script :LoggerAvailable ) {
179- $msgStr = [string ]$Message
180- if ([string ]::IsNullOrWhiteSpace($msgStr )) { return }
181- if ($Level -eq ' Output' ) {
182- if (-not $script :LoggerCaptureOutput ) { return }
183- $logLevel = ' Info'
184- } else {
185- $logLevel = $Level
186- }
187- $params = @ { Level = $logLevel ; Message = $msgStr }
188- if ($EventId ) { $params.EventId = $EventId }
189- if ($Data ) { $params.Data = $Data }
190- Write-CDLogEvent @params
191- }
192- }
193-
194- function Complete-CDActivity {
195- param (
196- [int ]$ExitCode ,
197- [string ]$Command ,
198- [string ]$Message
199- )
200- if (-not $script :LoggerAvailable ) { return }
201- $result = New-CDActivityResult `
202- - ToolVersion $ToolVersion `
203- - Activity $Command `
204- - ExitCode $ExitCode `
205- - Message $Message
206- Write-Information - MessageData $result - Tags @ (' CDLog' , ' ActivityResult' )
207- }
208- # END-CD-HOSTLOG
117+ $script :Version = ' 1.1.0'
209118
210119# Resolve the Delphi root dir from the explicit -RootDir parameter or from a
211120# piped delphi-inspect result object (.rootDir property).
@@ -282,7 +191,7 @@ function Invoke-MsbuildExe {
282191 & msbuild.exe @Arguments 2>&1 | ForEach-Object {
283192 $line = [string ]$_
284193 [void ]$outputLines.Add ($line )
285- if ($ShowOutput ) { Write-CDHostLog - Level Info - Message $line }
194+ if ($ShowOutput ) { Write-Host $line }
286195 }
287196 $exitCode = $LASTEXITCODE
288197 $output = $outputLines -join [Environment ]::NewLine
@@ -388,45 +297,35 @@ if ($MyInvocation.InvocationName -eq '.') { return }
388297
389298try {
390299 if ([string ]::IsNullOrWhiteSpace($ProjectFile )) {
391- Write-CDHostLog - Level Error - Message ' -ProjectFile is required.' - EventId ' INVALID-ARGS'
392- Complete-CDActivity - ExitCode $ExitInvalidArguments - Command ' build' - Message ' ProjectFile is required'
300+ Write-Error ' -ProjectFile is required.' - ErrorAction Continue
393301 exit $ExitInvalidArguments
394302 }
395303
396304 $resolvedRootDir = Resolve-RootDir - ExplicitRootDir $RootDir - Installation $DelphiInstallation
397- Write-CDHostLog - Level Verbose - Message " Project: $ProjectFile , Platform: $Platform , Config: $Config , Target: $Target "
398305
399306 if ([string ]::IsNullOrWhiteSpace($resolvedRootDir )) {
400307 $msg = ' No Delphi root dir supplied. Provide -RootDir or pipe a delphi-inspect result object.'
401- Write-CDHostLog - Level Error - Message $msg - EventId ' ROOTDIR-MISSING'
402- Complete-CDActivity - ExitCode $ExitRootDirError - Command ' build' - Message $msg
308+ if ($ShowOutput ) { Write-Error $msg - ErrorAction Continue } else { Write-Error $msg - ErrorAction Continue }
403309 exit $ExitRootDirError
404310 }
405311
406- Write-CDHostLog - Level Verbose - Message " RootDir: $resolvedRootDir "
407-
408312 if (-not (Test-Path - LiteralPath $resolvedRootDir )) {
409313 $msg = " Delphi root dir not found on disk: $resolvedRootDir "
410- Write-CDHostLog - Level Error - Message $msg - EventId ' ROOTDIR-NOT-FOUND'
411- Complete-CDActivity - ExitCode $ExitRootDirError - Command ' build' - Message $msg
314+ Write-Error $msg - ErrorAction Continue
412315 exit $ExitRootDirError
413316 }
414317
415318 $rsvarsPath = Get-RsvarsPath - RootDir $resolvedRootDir
416319 if (-not (Test-Path - LiteralPath $rsvarsPath )) {
417320 $msg = " rsvars.bat not found: $rsvarsPath "
418- Write-CDHostLog - Level Error - Message $msg - EventId ' RSVARS-NOT-FOUND'
419- Complete-CDActivity - ExitCode $ExitRootDirError - Command ' build' - Message $msg
321+ Write-Error $msg - ErrorAction Continue
420322 exit $ExitRootDirError
421323 }
422324
423- Write-CDHostLog - Level Verbose - Message " rsvars.bat: $rsvarsPath "
424-
425325 $resolvedProjectFile = [System.IO.Path ]::GetFullPath($ProjectFile )
426326 if (-not (Test-Path - LiteralPath $resolvedProjectFile )) {
427327 $msg = " Project file not found: $resolvedProjectFile "
428- Write-CDHostLog - Level Error - Message $msg - EventId ' PROJECT-NOT-FOUND'
429- Complete-CDActivity - ExitCode $ExitProjectNotFound - Command ' build' - Message $msg
328+ Write-Error $msg - ErrorAction Continue
430329 exit $ExitProjectNotFound
431330 }
432331
@@ -473,26 +372,21 @@ try {
473372 }
474373
475374 if ($Format -eq ' json' ) {
476- Write-CDHostLog - Level Output - Message ($resultObj | ConvertTo-Json - Depth 5 - Compress)
375+ Write-Output ($resultObj | ConvertTo-Json - Depth 5 - Compress)
477376 } else {
478- Write-CDHostLog - Level Output - Message $resultObj
377+ Write-Output $resultObj
479378 }
480379
481380 if ($buildResult.ExitCode -ne 0 ) {
482- Write-CDHostLog - Level Error - Message " MSBuild failed with exit code $ ( $buildResult .ExitCode ) " - EventId ' BUILD-FAILED ' `
483- - Data @ { exitCode = $buildResult .ExitCode ; warnings = $counts .Warnings ; errors = $counts .Errors }
484- Complete-CDActivity - ExitCode $ExitBuildFailed - Command ' build ' - Message " MSBuild failed with exit code $ ( $buildResult .ExitCode ) "
381+ if ( $ShowOutput ) {
382+ Write-Error " MSBuild failed with exit code $ ( $buildResult .ExitCode ) " - ErrorAction Continue
383+ }
485384 exit $ExitBuildFailed
486385 }
487386
488- Write-CDHostLog - Level Verbose - Message " Build succeeded: $ ( $counts.Warnings ) warning(s), $ ( $counts.Errors ) error(s)"
489- Complete-CDActivity - ExitCode $ExitSuccess - Command ' build'
490387 exit $ExitSuccess
491388
492389} catch {
493- $errMsg = if ([string ]::IsNullOrWhiteSpace($_.Exception.Message )) { $_.ToString () } else { $_.Exception.Message }
494- if ([string ]::IsNullOrWhiteSpace($errMsg )) { $errMsg = ' Unknown error' }
495- Write-CDHostLog - Level Fatal - Message $errMsg - EventId ' UNEXPECTED-ERROR'
496- Complete-CDActivity - ExitCode $ExitUnexpectedError - Command ' build' - Message $errMsg
390+ Write-Error $_.Exception.Message - ErrorAction Continue
497391 exit $ExitUnexpectedError
498392}
0 commit comments