Skip to content

Commit 8474ce8

Browse files
authored
For Ticket #11 (#12)
exe/dcu output directories and UnitSearchPath
1 parent 1d1de38 commit 8474ce8

4 files changed

Lines changed: 294 additions & 31 deletions

File tree

CHANGELOG.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,29 @@ All notable changes to this project will be documented in this file.
55
---
66
## [0.3.0] - Unreleased
77

8+
- Add `-ExeOutputDir` parameter to set the compiled executable output directory
9+
via `/p:DCC_ExeOutput`
10+
- Add `-DcuOutputDir` parameter to set the compiled DCU output directory
11+
via `/p:DCC_DcuOutput`
12+
- Add `-UnitSearchPath` parameter to append additional unit search paths
13+
via `/p:DCC_UnitSearchPath=$(DCC_UnitSearchPath);...`, preserving paths
14+
already set by the project's PropertyGroups
15+
[#11](https://github.com/continuous-delphi/delphi-msbuild/issues/11)
16+
817
- Add support for passing compiler defines to MSBUILD
9-
[#9](https://github.com/continuous-delphi/delphi-msbuild/issues/9)
18+
[#9](https://github.com/continuous-delphi/delphi-msbuild/issues/9)
1019

1120
## [0.2.0] - 2026-03-16
1221

1322
- Added `delphi-msbuild.ps1` to be a direct download on the release page
14-
[#5](https://github.com/continuous-delphi/delphi-msbuild/issues/5)
23+
[#5](https://github.com/continuous-delphi/delphi-msbuild/issues/5)
1524

1625
## [0.1.0] - 2026-03-16
1726

1827
- Initial release of `delphi-msbuild.ps1` -- build Delphi `.dproj` projects
1928
via MSBuild from the command line, with support for piped output from
2029
`delphi-inspect` and automatic `rsvars.bat` environment sourcing.
21-
[#1](https://github.com/continuous-delphi/delphi-msbuild/issues/1)
30+
[#1](https://github.com/continuous-delphi/delphi-msbuild/issues/1)
2231

2332

2433
<br />

README.md

Lines changed: 67 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,59 @@ The MSBuild verbosity level. Passed to MSBuild as `/v:<value>`.
115115

116116
Valid values: `quiet`, `minimal`, `normal`, `detailed`, `diagnostic`
117117

118+
## -ExeOutputDir
119+
120+
```text
121+
-ExeOutputDir <path>
122+
```
123+
124+
Output directory for the compiled executable or library. Passed to MSBuild as
125+
`/p:DCC_ExeOutput=<path>`.
126+
127+
When omitted, MSBuild uses the output location defined in the project's
128+
PropertyGroups. The result object's `.exeOutputDir` is `$null` when this
129+
parameter is not supplied.
130+
131+
## -DcuOutputDir
132+
133+
```text
134+
-DcuOutputDir <path>
135+
```
136+
137+
Output directory for compiled `.dcu` files. Passed to MSBuild as
138+
`/p:DCC_DcuOutput=<path>`.
139+
140+
When omitted, MSBuild uses the DCU location from the project's PropertyGroups.
141+
The result object's `.dcuOutputDir` is `$null` when this parameter is not
142+
supplied.
143+
144+
## -UnitSearchPath
145+
146+
```text
147+
-UnitSearchPath <path[]>
148+
```
149+
150+
Additional unit search paths appended to the project's existing unit path.
151+
Accepts an array of path strings. Multiple paths are joined with semicolons
152+
and passed as:
153+
154+
```text
155+
/p:DCC_UnitSearchPath="$(DCC_UnitSearchPath);path1;path2"
156+
```
157+
158+
The `$(DCC_UnitSearchPath)` prefix preserves the paths already set in the
159+
project's PropertyGroups. Without it, the assignment would replace them
160+
entirely.
161+
162+
When omitted (or an empty array), no `/p:DCC_UnitSearchPath` argument is added.
163+
The result object's `.unitSearchPath` is `$null` when no paths are supplied.
164+
165+
Example:
166+
167+
```powershell
168+
-UnitSearchPath @('C:\Libs\A', 'C:\Libs\B')
169+
```
170+
118171
## -Define
119172

120173
```text
@@ -191,17 +244,20 @@ On success or build failure (exit codes 0 and 5), a single
191244
`pscustomobject` is written to the pipeline before the script exits.
192245
This allows downstream pipeline steps to consume the build result.
193246

194-
| Property | Type | Description |
195-
|---------------|---------|------------------------------------------------------|
196-
| `projectFile` | string | Absolute path to the project file |
197-
| `platform` | string | Platform value used (e.g. `Win32`) |
198-
| `config` | string | Config value used (e.g. `Debug`) |
199-
| `target` | string | Target used (e.g. `Build`) |
200-
| `rootDir` | string | Resolved Delphi installation root |
201-
| `rsvarsPath` | string | Derived path to `rsvars.bat` |
202-
| `exitCode` | int | MSBuild process exit code |
203-
| `success` | bool | `$true` when `exitCode` is 0 |
204-
| `output` | string | Captured MSBuild output; `$null` when `-ShowOutput` |
247+
| Property | Type | Description |
248+
|------------------|----------|----------------------------------------------------------|
249+
| `projectFile` | string | Absolute path to the project file |
250+
| `platform` | string | Platform value used (e.g. `Win32`) |
251+
| `config` | string | Config value used (e.g. `Debug`) |
252+
| `target` | string | Target used (e.g. `Build`) |
253+
| `rootDir` | string | Resolved Delphi installation root |
254+
| `rsvarsPath` | string | Derived path to `rsvars.bat` |
255+
| `exeOutputDir` | string | Value of `-ExeOutputDir`; `$null` when not supplied |
256+
| `dcuOutputDir` | string | Value of `-DcuOutputDir`; `$null` when not supplied |
257+
| `unitSearchPath` | string[] | Value of `-UnitSearchPath`; `$null` when not supplied |
258+
| `exitCode` | int | MSBuild process exit code |
259+
| `success` | bool | `$true` when `exitCode` is 0 |
260+
| `output` | string | Captured MSBuild output; `$null` when `-ShowOutput` |
205261

206262
Note: On fata errors before MSBuild is invoked (exit codes 2, 3, 4) no result
207263
object is emitted.

source/delphi-msbuild.ps1

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ param(
7474
[ValidateSet('quiet','minimal','normal','detailed','diagnostic')]
7575
[string]$Verbosity = 'normal',
7676

77+
# Output directory for the compiled executable or DLL (/p:DCC_ExeOutput property).
78+
[string]$ExeOutputDir,
79+
80+
# Output directory for compiled DCU files (/p:DCC_DcuOutput property).
81+
[string]$DcuOutputDir,
82+
83+
# Additional unit search paths (/p:DCC_UnitSearchPath property). Multiple paths are
84+
# joined with semicolons and appended to the paths already set by the project's
85+
# PropertyGroups.
86+
[string[]]$UnitSearchPath = @(),
87+
7788
[string[]]$Define = @(),
7889

7990
[switch]$ShowOutput
@@ -179,7 +190,10 @@ function Invoke-MsbuildProject {
179190
[string]$Config,
180191
[string]$Target,
181192
[string]$Verbosity,
182-
[string[]]$Define = @(),
193+
[string]$ExeOutputDir,
194+
[string]$DcuOutputDir,
195+
[string[]]$UnitSearchPath = @(),
196+
[string[]]$Define = @(),
183197
[switch]$ShowOutput
184198
)
185199

@@ -191,6 +205,14 @@ function Invoke-MsbuildProject {
191205
"/v:$Verbosity"
192206
)
193207

208+
if (-not [string]::IsNullOrWhiteSpace($ExeOutputDir)) { $msbuildArgs += "/p:DCC_ExeOutput=$ExeOutputDir" }
209+
if (-not [string]::IsNullOrWhiteSpace($DcuOutputDir)) { $msbuildArgs += "/p:DCC_DcuOutput=$DcuOutputDir" }
210+
211+
if ($UnitSearchPath.Count -gt 0) {
212+
$unitSearchValue = '$(DCC_UnitSearchPath);' + ($UnitSearchPath -join ';')
213+
$msbuildArgs += "/p:DCC_UnitSearchPath=$unitSearchValue"
214+
}
215+
194216
if ($Define.Count -gt 0) {
195217
$defineValue = '$(DCC_Define);' + ($Define -join ';')
196218
$msbuildArgs += "/p:DCC_Define=$defineValue"
@@ -239,25 +261,31 @@ try {
239261
Invoke-RsvarsEnvironment -RsvarsPath $rsvarsPath
240262

241263
$buildResult = Invoke-MsbuildProject `
242-
-ProjectFile $resolvedProjectFile `
243-
-Platform $Platform `
244-
-Config $Config `
245-
-Target $Target `
246-
-Verbosity $Verbosity `
247-
-Define $Define `
264+
-ProjectFile $resolvedProjectFile `
265+
-Platform $Platform `
266+
-Config $Config `
267+
-Target $Target `
268+
-Verbosity $Verbosity `
269+
-ExeOutputDir $ExeOutputDir `
270+
-DcuOutputDir $DcuOutputDir `
271+
-UnitSearchPath $UnitSearchPath `
272+
-Define $Define `
248273
-ShowOutput:$ShowOutput
249274

250275
$resultObj = [pscustomobject]@{
251-
scriptVersion = $script:Version
252-
projectFile = $resolvedProjectFile
253-
platform = $Platform
254-
config = $Config
255-
target = $Target
256-
rootDir = $resolvedRootDir
257-
rsvarsPath = $rsvarsPath
258-
exitCode = $buildResult.ExitCode
259-
success = ($buildResult.ExitCode -eq 0)
260-
output = $buildResult.Output
276+
scriptVersion = $script:Version
277+
projectFile = $resolvedProjectFile
278+
platform = $Platform
279+
config = $Config
280+
target = $Target
281+
rootDir = $resolvedRootDir
282+
rsvarsPath = $rsvarsPath
283+
exeOutputDir = if ([string]::IsNullOrWhiteSpace($ExeOutputDir)) { $null } else { $ExeOutputDir }
284+
dcuOutputDir = if ([string]::IsNullOrWhiteSpace($DcuOutputDir)) { $null } else { $DcuOutputDir }
285+
unitSearchPath = if ($UnitSearchPath.Count -eq 0) { $null } else { $UnitSearchPath }
286+
exitCode = $buildResult.ExitCode
287+
success = ($buildResult.ExitCode -eq 0)
288+
output = $buildResult.Output
261289
}
262290

263291
Write-Output $resultObj

0 commit comments

Comments
 (0)