Skip to content

Commit 7ea711c

Browse files
authored
Add ability to set namespace (PR #5)
For Ticket #4 All 76 tests pass
1 parent c464894 commit 7ea711c

4 files changed

Lines changed: 121 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ All notable changes to this project will be documented in this file.
66

77
## [0.3.0] - Unreleased
88

9-
- Add support for passing compiler defines to DCC
10-
[#2](https://github.com/continuous-delphi/delphi-dccbuild/issues/2)
9+
- Add `-Namespace` parameter to specify unit scope names for unqualified unit
10+
resolution via the `-NS` flag; required for modern Delphi projects using
11+
namespaced RTL units (e.g. `System.SysUtils`, `Vcl.Forms`) when building
12+
outside the IDE without a project `.cfg` file
13+
[#4](https://github.com/continuous-delphi/delphi-dccbuild/issues/4)
1114

15+
- Add support for passing compiler defines to DCC
16+
[#2](https://github.com/continuous-delphi/delphi-dccbuild/issues/2)
1217

1318
## [0.1.0] - 2026-03-16
1419

README.md

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

220+
## -Namespace
221+
222+
```text
223+
-Namespace <string[]>
224+
```
225+
226+
Unit scope names (namespace prefixes) the compiler searches when resolving
227+
unqualified unit names. Accepts an array of scope name strings. Multiple
228+
names are joined with semicolons and passed as a single `-NS` argument:
229+
230+
```text
231+
-NSSystem;Vcl;Vcl.Imaging
232+
```
233+
234+
This is important for modern Delphi (XE2+) projects that use namespaced RTL
235+
units such as `System.SysUtils` or `Vcl.Forms`. When building outside the IDE
236+
without the project's `.cfg` file, the compiler cannot resolve `uses Forms`
237+
unless the `Vcl` scope is listed here.
238+
239+
When omitted (or an empty array), no `-NS` argument is added. The result
240+
object's `.namespace` is `$null` when no names are supplied.
241+
242+
Example:
243+
244+
```powershell
245+
-Namespace @('System', 'Vcl', 'Vcl.Imaging', 'Data')
246+
```
247+
220248
## -Define
221249

222250
```text

source/delphi-dccbuild.ps1

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

111+
# Unit scope names searched when resolving unqualified unit names (-NS flag).
112+
# Multiple names are joined with semicolons and passed as a single -NS argument.
113+
# Required for modern Delphi projects that use namespaced RTL units (e.g. System.SysUtils)
114+
# when building outside the IDE without a project .cfg file.
115+
[string[]]$Namespace = @(),
116+
111117
# Additional conditional defines (-D flag). Multiple defines are joined
112118
# with semicolons and passed as a single -D argument.
113119
[string[]]$Define = @(),
@@ -262,6 +268,7 @@ function Invoke-DccProject {
262268
[string]$DcuOutputDir,
263269
[string[]]$UnitSearchPath = @(),
264270
[string[]]$IncludePath = @(),
271+
[string[]]$Namespace = @(),
265272
[string[]]$Define = @(),
266273
[switch]$ShowOutput
267274
)
@@ -286,6 +293,9 @@ function Invoke-DccProject {
286293
if ($UnitSearchPath.Count -gt 0) { $dccArgs += "-U$($UnitSearchPath -join ';')" }
287294
if ($IncludePath.Count -gt 0) { $dccArgs += "-I$($IncludePath -join ';')" }
288295

296+
# Unit scope names: multiple entries joined with semicolons into a single -NS flag
297+
if ($Namespace.Count -gt 0) { $dccArgs += "-NS$($Namespace -join ';')" }
298+
289299
# Additional defines: multiple entries joined with semicolons into a single -D flag
290300
if ($Define.Count -gt 0) { $dccArgs += "-D$($Define -join ';')" }
291301

@@ -343,6 +353,7 @@ try {
343353
-DcuOutputDir $DcuOutputDir `
344354
-UnitSearchPath $UnitSearchPath `
345355
-IncludePath $IncludePath `
356+
-Namespace $Namespace `
346357
-Define $Define `
347358
-ShowOutput:$ShowOutput
348359

@@ -359,6 +370,7 @@ try {
359370
dcuOutputDir = if ([string]::IsNullOrWhiteSpace($DcuOutputDir)) { $null } else { $DcuOutputDir }
360371
unitSearchPath = if ($UnitSearchPath.Count -eq 0) { $null } else { $UnitSearchPath }
361372
includePath = if ($IncludePath.Count -eq 0) { $null } else { $IncludePath }
373+
namespace = if ($Namespace.Count -eq 0) { $null } else { $Namespace }
362374
exitCode = $buildResult.ExitCode
363375
success = ($buildResult.ExitCode -eq 0)
364376
output = $buildResult.Output

tests/pwsh/delphi-dccbuild.Tests.ps1

Lines changed: 74 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+
Namespace single entry adds a -NS flag with that value.
49+
Namespace multiple entries are joined with semicolons into a single -NS flag.
50+
Namespace omitted adds no -NS argument.
4851
Define omitted adds no extra -D argument beyond the config define.
4952
Define single entry adds a -D flag with that value.
5053
Define multiple entries are joined with semicolons into a single -D flag.
@@ -670,6 +673,77 @@ Describe 'Invoke-DccProject' {
670673

671674
}
672675

676+
Context 'Namespace single entry adds a -NS flag with that value' {
677+
678+
BeforeAll {
679+
$script:capturedArgs = $null
680+
Mock Invoke-DccExe {
681+
$script:capturedArgs = $Arguments
682+
return [pscustomobject]@{ ExitCode = 0; Output = '' }
683+
}
684+
685+
Invoke-DccProject `
686+
-CompilerPath 'C:\RAD\Studio\23.0\bin\dcc32.exe' `
687+
-ProjectFile 'C:\Projects\MyApp.dpr' `
688+
-Config 'Debug' `
689+
-Target 'Build' `
690+
-Verbosity 'normal' `
691+
-Namespace @('System')
692+
}
693+
694+
It 'includes -NSSystem' {
695+
$script:capturedArgs | Should -Contain '-NSSystem'
696+
}
697+
698+
}
699+
700+
Context 'Namespace multiple entries are joined with semicolons into a single -NS flag' {
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+
-Namespace @('System', 'Vcl', 'Vcl.Imaging')
716+
}
717+
718+
It 'includes -NSSystem;Vcl;Vcl.Imaging as a single argument' {
719+
$script:capturedArgs | Should -Contain '-NSSystem;Vcl;Vcl.Imaging'
720+
}
721+
722+
}
723+
724+
Context 'Namespace omitted adds no -NS argument' {
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+
}
740+
741+
It 'no argument starts with -NS' {
742+
($script:capturedArgs | Where-Object { $_ -like '-NS*' }) | Should -BeNullOrEmpty
743+
}
744+
745+
}
746+
673747
Context 'Define omitted adds no extra -D argument beyond the config define' {
674748

675749
BeforeAll {

0 commit comments

Comments
 (0)