Skip to content

Commit 8c177dd

Browse files
authored
TerminalVelocity: if -Output is a directory the filename is derived from the input filename in -Path. Updated docs stating TV code file basenames MUST match source (.xml) filenames e.g. Foo\Bar.xml should only produce Bar.cpp (or Bar.cs). (#5111)
1 parent 4c2647f commit 8c177dd

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

docs/Coding-Guidelines/TerminalVelocity.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Run the TerminalVelocity generator to create a header file for your feature defi
8282
For example:
8383

8484
```
85-
tools\TerminalVelocity\Generate-TerminalVelocityFeatures.cmd -Path dev\common\TerminalVelocityFeatures-DeploymentAPI.xml -Namespace Microsoft.Windows.DeploymentAPI -Output dev\common\TerminalVelocityFeatures-DeploymentAPI.h
85+
tools\TerminalVelocity\Generate-TerminalVelocityFeatures.cmd -Channel Experimental -Language C++ -Namespace Microsoft.Windows.ApplicationModel.WindowsAppRuntime -Path dev\common\TerminalVelocityFeatures-DeploymentAPI.xml -Output dev\common
8686
```
8787

8888
Generate-TerminalVelocityFeatures.cmd runs the generator. The following parameters are supported:
@@ -91,7 +91,9 @@ Generate-TerminalVelocityFeatures.cmd runs the generator. The following paramete
9191
* **-Channel <channel>** -- channel being built. Allowed values: [`Experimental`, `Preview`, `Stable`, `WindowsInbox`]. Optional, default=`Experimental`.
9292
* **-Language <language>** -- language for generated code. Allowed values: [`C++`, `C#`]. Optional, default=`C++`.
9393
* **-Namespace <namespace>** -- namespace for generated symbols. The parameter can specify multiple namespaces delimited by `.` or `::` (the generator emits the right syntax for the target language regardless of the parameter's notation). Optional.
94-
* **-Output <filename>** -- file to write the generated output. Optional, default=stdout.
94+
* **-Output <filename>** -- file to write the generated output. Optional, default=stdout. If `filename` is a directory the filename is generated from the input filename (-Path) in the specified directory.
95+
96+
WARNING: As a matter of policy output files MUST have the same base name as the input file (-Path).
9597

9698
For help run
9799

@@ -109,7 +111,7 @@ Add a build task to run the TerminalVelocity with the build's properties. For ex
109111
inputs:
110112
targetType: filePath
111113
filePath: tools\TerminalVelocity\Generate-TerminalVelocityFeatures.ps1
112-
arguments: -Path $(Build.SourcesDirectory)\dev\common\TerminalVelocityFeatures-DeploymentAPI.xml -Channel ${{ parameters.channel }} -Language C++ -Namespace Microsoft.Windows.ApplicationModel.WindowsAppSDK -Output $(Build.SourcesDirectory)\dev\common\TerminalVelocityFeatures-DeploymentAPI.h
114+
arguments: -Path $(Build.SourcesDirectory)\dev\common\TerminalVelocityFeatures-DeploymentAPI.xml -Channel ${{ parameters.channel }} -Language C++ -Namespace Microsoft.Windows.ApplicationModel.WindowsAppSDK -Output $(Build.SourcesDirectory)\dev\common
113115
workingDirectory: '$(Build.SourcesDirectory)'
114116
```
115117

tools/TerminalVelocity/Generate-TerminalVelocityFeatures.ps1

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
The target channel for Feature checks (default=Experimental).
1616
1717
.PARAMETER Output
18-
File to create (default=stdout).
18+
File to create (default=stdout). If a directory the filename is derived from the input filename (-Path) and the language.
1919
2020
.PARAMETER Language
2121
Programming language to generate (default=C++).
@@ -67,6 +67,17 @@ if ([String]::IsNullOrEmpty($Namespace))
6767
}
6868
}
6969

70+
# Generate the output base name derived from input base name and language if the input filename (-Path) is a directory
71+
$Output_Original = $Output
72+
if (Test-Path -Path $Output -PathType Container)
73+
{
74+
$path_filename = Split-Path -Path $Path -Leaf
75+
$path_basename = $path_filename -replace '\.[^.]*$', ''
76+
$extension = @{ 'C++'='.h'; 'C#'='.cs' }[$Language]
77+
$filename = $path_basename + $extension
78+
$Output = Join-Path $Output $filename
79+
}
80+
7081
Enum State
7182
{
7283
AlwaysDisabled;
@@ -96,7 +107,7 @@ Class Feature
96107
$this.Name = $entry.name
97108
$this.State = ConvertTo-FeatureState $entry.state
98109

99-
# TODO: Remove the temp workaround of downgrading to StrictModel 1.0 once b#52128443 is fixed.
110+
# TODO: Remove the temp workaround of downgrading to StrictModel 1.0 once b#52128443 is fixed.
100111
Set-StrictMode -Version 1.0
101112
$this.Id = $entry.id
102113
$this.ChannelTokenStates = [System.Collections.Generic.Dictionary[string, State]]::new()
@@ -206,7 +217,7 @@ $comment_line_prefix Licensed under the MIT License.
206217
$comment_line_prefix THIS FILE IS AUTOMATICALLY GENERATED; DO NOT EDIT IT
207218
208219
$comment_line_prefix INPUT FILE: $Path
209-
$comment_line_prefix OPTIONS: -Channel $Channel -Language $Language$(if (-not ([String]::IsNullOrEmpty($Namespace))) { " -Namespace $Namespace" }) -Path $Path$(if (-not ([String]::IsNullOrEmpty($Output))) { " -Output $Output" })
220+
$comment_line_prefix OPTIONS: -Channel $Channel -Language $Language$(if (-not ([String]::IsNullOrEmpty($Namespace))) { " -Namespace $Namespace" }) -Path $Path$(if (-not ([String]::IsNullOrEmpty($Output))) { " -Output $Output_Original" })
210221
211222
212223
"@

0 commit comments

Comments
 (0)