Skip to content

Commit b6bea85

Browse files
authored
* Add ability to set compiler defines (PR #3)
For Ticket #2 All 73 tests pass
1 parent 1dba957 commit b6bea85

3 files changed

Lines changed: 122 additions & 0 deletions

File tree

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,41 @@ Example:
217217
-IncludePath @('C:\Inc\Headers')
218218
```
219219

220+
## -Define
221+
222+
```text
223+
-Define <string[]>
224+
```
225+
226+
One or more additional conditional defines to pass to the DCC compiler. When
227+
at least one value is supplied, the defines are joined with semicolons and
228+
passed as a single `-D` argument:
229+
230+
```text
231+
-DMYFLAG;USE_JEDI_JCL
232+
```
233+
234+
This is appended to the existing config define (e.g. `-DDEBUG`) that the script
235+
always adds for the `-Config` value; it does not replace it.
236+
237+
When no `-Define` values are supplied (the default), no extra `-D` argument is
238+
added beyond the config define.
239+
240+
Examples:
241+
242+
```powershell
243+
# Single define
244+
delphi-dccbuild.ps1 -ProjectFile .\src\MyApp.dpr -RootDir $root -Define CI
245+
246+
# Multiple defines
247+
delphi-dccbuild.ps1 -ProjectFile .\src\MyApp.dpr -RootDir $root `
248+
-Define MYFLAG, USE_JEDI_JCL
249+
250+
# Via pipeline with defines
251+
delphi-inspect.ps1 -DetectLatest -Platform Win32 -BuildSystem DCC |
252+
delphi-dccbuild.ps1 -ProjectFile .\src\MyApp.dpr -Define CI, MYFLAG
253+
```
254+
220255
## -ShowOutput (switch)
221256

222257
```text

source/delphi-dccbuild.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ param(
108108
# joined with semicolons.
109109
[string[]]$IncludePath = @(),
110110

111+
# Additional conditional defines (-D flag). Multiple defines are joined
112+
# with semicolons and passed as a single -D argument.
113+
[string[]]$Define = @(),
114+
111115
[switch]$ShowOutput
112116
)
113117

@@ -258,6 +262,7 @@ function Invoke-DccProject {
258262
[string]$DcuOutputDir,
259263
[string[]]$UnitSearchPath = @(),
260264
[string[]]$IncludePath = @(),
265+
[string[]]$Define = @(),
261266
[switch]$ShowOutput
262267
)
263268

@@ -281,6 +286,9 @@ function Invoke-DccProject {
281286
if ($UnitSearchPath.Count -gt 0) { $dccArgs += "-U$($UnitSearchPath -join ';')" }
282287
if ($IncludePath.Count -gt 0) { $dccArgs += "-I$($IncludePath -join ';')" }
283288

289+
# Additional defines: multiple entries joined with semicolons into a single -D flag
290+
if ($Define.Count -gt 0) { $dccArgs += "-D$($Define -join ';')" }
291+
284292
return Invoke-DccExe -CompilerPath $CompilerPath -Arguments $dccArgs -ShowOutput:$ShowOutput
285293
}
286294

@@ -335,6 +343,7 @@ try {
335343
-DcuOutputDir $DcuOutputDir `
336344
-UnitSearchPath $UnitSearchPath `
337345
-IncludePath $IncludePath `
346+
-Define $Define `
338347
-ShowOutput:$ShowOutput
339348

340349
$resultObj = [pscustomobject]@{

tests/pwsh/delphi-dccbuild.Tests.ps1

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
DcuOutputDir adds -N0 flag.
4646
UnitSearchPath single entry adds -U flag; multiple joined with semicolons.
4747
IncludePath single entry adds -I flag; multiple joined with semicolons.
48+
Define omitted adds no extra -D argument beyond the config define.
49+
Define single entry adds a -D flag with that value.
50+
Define multiple entries are joined with semicolons into a single -D flag.
4851
4952
Describe 8 - Main flow (via Invoke-ToolProcess, no DCC calls):
5053
Exits 3 when no rootDir is provided (no pipeline, no -RootDir).
@@ -667,6 +670,81 @@ Describe 'Invoke-DccProject' {
667670

668671
}
669672

673+
Context 'Define omitted adds no extra -D argument beyond the config define' {
674+
675+
BeforeAll {
676+
$script:capturedArgs = $null
677+
Mock Invoke-DccExe {
678+
$script:capturedArgs = $Arguments
679+
return [pscustomobject]@{ ExitCode = 0; Output = '' }
680+
}
681+
682+
Invoke-DccProject `
683+
-CompilerPath 'C:\RAD\Studio\23.0\bin\dcc32.exe' `
684+
-ProjectFile 'C:\Projects\MyApp.dpr' `
685+
-Config 'Debug' `
686+
-Target 'Build' `
687+
-Verbosity 'normal'
688+
}
689+
690+
It 'contains exactly one -D argument (the config define)' {
691+
@($script:capturedArgs | Where-Object { $_ -like '-D*' }).Count | Should -Be 1
692+
}
693+
694+
It 'the only -D argument is -DDEBUG' {
695+
$script:capturedArgs | Should -Contain '-DDEBUG'
696+
}
697+
698+
}
699+
700+
Context 'Define single entry adds a -D flag with that value' {
701+
702+
BeforeAll {
703+
$script:capturedArgs = $null
704+
Mock Invoke-DccExe {
705+
$script:capturedArgs = $Arguments
706+
return [pscustomobject]@{ ExitCode = 0; Output = '' }
707+
}
708+
709+
Invoke-DccProject `
710+
-CompilerPath 'C:\RAD\Studio\23.0\bin\dcc32.exe' `
711+
-ProjectFile 'C:\Projects\MyApp.dpr' `
712+
-Config 'Debug' `
713+
-Target 'Build' `
714+
-Verbosity 'normal' `
715+
-Define @('MYFLAG')
716+
}
717+
718+
It 'includes -DMYFLAG' {
719+
$script:capturedArgs | Should -Contain '-DMYFLAG'
720+
}
721+
722+
}
723+
724+
Context 'Define multiple entries are joined with semicolons into a single -D flag' {
725+
726+
BeforeAll {
727+
$script:capturedArgs = $null
728+
Mock Invoke-DccExe {
729+
$script:capturedArgs = $Arguments
730+
return [pscustomobject]@{ ExitCode = 0; Output = '' }
731+
}
732+
733+
Invoke-DccProject `
734+
-CompilerPath 'C:\RAD\Studio\23.0\bin\dcc32.exe' `
735+
-ProjectFile 'C:\Projects\MyApp.dpr' `
736+
-Config 'Debug' `
737+
-Target 'Build' `
738+
-Verbosity 'normal' `
739+
-Define @('MYFLAG', 'USE_JEDI_JCL')
740+
}
741+
742+
It 'includes -DMYFLAG;USE_JEDI_JCL as a single argument' {
743+
$script:capturedArgs | Should -Contain '-DMYFLAG;USE_JEDI_JCL'
744+
}
745+
746+
}
747+
670748
}
671749

672750
Describe 'Main flow -- pre-compiler validation (no DCC invoked)' {

0 commit comments

Comments
 (0)