Skip to content

Commit dd822a7

Browse files
authored
Azure cadl ranch (Azure#47936)
* Initial alignment to support cadl ranch scripts * generate stubbed cadl ranch specs * autogen launch settings * add cadl ranch test project * regen with comments * add test cadl ranch ability * regen stubs in azure format * remove problematic specs * remove comments from stubs * pr fb * pr feedback * regen with scaffolding changes * pr feedback * use process tracker from testframework * update sparse checkout * pr fb
1 parent c6850c4 commit dd822a7

File tree

437 files changed

+36172
-494
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

437 files changed

+36172
-494
lines changed

eng/Microsoft.Build.CentralPackageVersions/2.0.46/Sdk/Sdk.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
</ItemGroup>
131131

132132
<Target Name="CheckPackageReferences"
133-
Condition=" '$(EnableCentralPackageVersions)' != 'false' And '$(DesignTimeBuild)' != 'true' And @(PackageReference->Count()) > 0 ">
133+
Condition=" '$(EnableCentralPackageVersions)' != 'false' And '$(DesignTimeBuild)' != 'true' And @(PackageReference->Count()) > 0">
134134

135135
<!--
136136
Get a list of duplicate <PackageReference /> and <GlobalPackageReference /> items. Users must be made aware

eng/Packages.Data.props

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@
258258
</ItemGroup>
259259

260260
<ItemGroup Condition="'$(IsGeneratorLibrary)' == 'true'">
261-
<PackageReference Update="Microsoft.Generator.CSharp.ClientModel" Version="1.0.0-alpha.20250117.1" />
261+
<PackageReference Update="Microsoft.Generator.CSharp.ClientModel" Version="1.0.0-alpha.20250123.2" />
262262
</ItemGroup>
263263

264264
<!--
@@ -267,6 +267,7 @@
267267
<ItemGroup Condition="('$(IsTestProject)' == 'true') OR ('$(IsTestSupportProject)' == 'true') OR ('$(IsPerfProject)' == 'true') OR ('$(IsStressProject)' == 'true') OR ('$(IsSamplesProject)' == 'true')">
268268
<PackageReference Update="ApprovalTests" Version="3.0.22" />
269269
<PackageReference Update="ApprovalUtilities" Version="3.0.22" />
270+
<PackageReference Update="Azure.Core" Version="1.44.1" />
270271
<PackageReference Update="Azure.Identity" Version="1.13.1" />
271272
<PackageReference Update="Azure.Messaging.EventGrid" Version="4.17.0" />
272273
<PackageReference Update="Azure.Messaging.EventHubs.Processor" Version="5.11.3" />
@@ -334,6 +335,7 @@
334335
<PackageReference Update="Microsoft.Azure.Test.HttpRecorder" Version="[1.13.3, 2.0.0)" />
335336
<PackageReference Update="Microsoft.Azure.WebJobs.Extensions" Version="5.0.0" />
336337
<PackageReference Update="Microsoft.Azure.WebJobs.Extensions.Http" Version="3.0.2" />
338+
<PackageReference Update="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.8.0" />
337339
<PackageReference Update="Microsoft.CSharp" Version="4.7.0" />
338340
<PackageReference Update="Microsoft.Data.SqlClient" Version="5.1.3" />
339341
<PackageReference Update="Microsoft.Extensions.Azure" Version="1.7.6" />
@@ -375,6 +377,7 @@
375377
<PackageReference Update="System.IO.Compression" Version="4.3.0" />
376378
<PackageReference Update="System.IO.Pipelines" Version="4.5.1" />
377379
<PackageReference Update="System.Linq.Async" Version="5.0.0" />
380+
<PackageReference Update="System.Memory.Data" Version="6.0.0" />
378381
<PackageReference Update="System.Net.WebSockets.Client" Version="4.3.2" />
379382
<PackageReference Update="System.Reflection.Emit" Version="4.7.0" />
380383
<PackageReference Update="System.Runtime.InteropServices" Version="4.3.0" />

eng/packages/http-client-csharp/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ extends:
4040
parameters:
4141
SparseCheckoutPaths:
4242
- /sdk/core/Azure.Core/src/Shared
43+
- /sdk/core/Azure.Core.TestFramework/src
4344
BuildPrereleaseVersion: ${{ parameters.BuildPrereleaseVersion }}
4445
UseTypeSpecNext: ${{ parameters.UseTypeSpecNext }}
4546
${{ if eq(variables['System.TeamProject'], 'internal') }}:

eng/packages/http-client-csharp/emitter/src/emitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import { azureSDKContextOptions } from "./sdk-context-options.js";
1212

1313
export async function $onEmit(context: EmitContext<NetEmitterOptions>) {
14-
context.options["plugin-name"] = "AzureClientPlugin";
14+
context.options["plugin-name"] ??= "AzureClientPlugin";
1515
context.options["emitter-extension-path"] = import.meta.url;
1616
setSDKContextOptions(azureSDKContextOptions);
1717
await $OnMGCEmit(context);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
$repoRoot = Resolve-Path (Join-Path $PSScriptRoot '..')
2+
3+
function IsGenerated {
4+
param (
5+
[string]$dir
6+
)
7+
8+
if (-not ($dir.EndsWith("Generated"))) {
9+
return $false
10+
}
11+
12+
$csFiles = Get-ChildItem -Path $dir -Filter *.cs -File
13+
return $csFiles.Count -gt 0
14+
}
15+
16+
function Capitalize-FirstLetter {
17+
param (
18+
[string]$inputString
19+
)
20+
21+
if ([string]::IsNullOrEmpty($inputString)) {
22+
return $inputString
23+
}
24+
25+
$firstChar = $inputString[0].ToString().ToUpper()
26+
$restOfString = $inputString.Substring(1)
27+
28+
return $firstChar + $restOfString
29+
}
30+
31+
function Get-Namespace {
32+
param (
33+
[string]$dir
34+
)
35+
36+
$words = $dir.Split('-')
37+
$namespace = ""
38+
foreach ($word in $words) {
39+
$namespace += Capitalize-FirstLetter $word
40+
}
41+
return $namespace
42+
}
43+
44+
Export-ModuleMember -Function "IsGenerated"
45+
Export-ModuleMember -Function "Get-Namespace"
Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
#Requires -Version 7.0
2+
param(
3+
$filter,
4+
[bool]$Stubbed = $true,
5+
[bool]$LaunchOnly = $false
6+
)
7+
8+
Import-Module "$PSScriptRoot\Generation.psm1" -DisableNameChecking -Force;
9+
10+
$packageRoot = Resolve-Path (Join-Path $PSScriptRoot '..' '..')
11+
$solutionDir = Join-Path $packageRoot 'generator'
12+
13+
if (-not $LaunchOnly) {
14+
Refresh-Build
15+
16+
if ($null -eq $filter -or $filter -eq "Basic-TypeSpec") {
17+
Write-Host "Generating BasicTypeSpec" -ForegroundColor Cyan
18+
$testProjectsLocalDir = Join-Path $packageRoot 'generator' 'TestProjects' 'Local'
19+
20+
$unbrandedTypespecTestProject = Join-Path $testProjectsLocalDir "Basic-TypeSpec"
21+
$unbrandedTypespecTestProject = $unbrandedTypespecTestProject
22+
23+
Invoke (Get-TspCommand "$unbrandedTypespecTestProject/Basic-TypeSpec.tsp" $unbrandedTypespecTestProject)
24+
25+
# exit if the generation failed
26+
if ($LASTEXITCODE -ne 0) {
27+
exit $LASTEXITCODE
28+
}
29+
30+
Write-Host "Building UnbrandedTypeSpec" -ForegroundColor Cyan
31+
Invoke "dotnet build $packageRoot/generator/TestProjects/Local/Basic-TypeSpec/src/BasicTypeSpec.csproj"
32+
33+
# exit if the generation failed
34+
if ($LASTEXITCODE -ne 0) {
35+
exit $LASTEXITCODE
36+
}
37+
}
38+
}
39+
40+
$specsDirectory = "$packageRoot/node_modules/@typespec/http-specs"
41+
$azureSpecsDirectory = "$packageRoot/node_modules/@azure-tools/azure-http-specs"
42+
$cadlRanchRoot = Join-Path $packageRoot 'generator' 'TestProjects' 'CadlRanch'
43+
44+
function IsSpecDir {
45+
param (
46+
[string]$dir
47+
)
48+
$subdirs = Get-ChildItem -Path $dir -Directory
49+
return -not ($subdirs) -and (Test-Path "$dir/main.tsp")
50+
}
51+
52+
$failingSpecs = @(
53+
Join-Path 'http' 'payload' 'pageable'
54+
Join-Path 'http' 'payload' 'xml'
55+
Join-Path 'http' 'type' 'model' 'flatten'
56+
Join-Path 'http' 'type' 'model' 'templated'
57+
Join-Path 'http' 'payload' 'multipart'
58+
Join-Path 'http' 'server' 'path' 'multiple'
59+
Join-Path 'http' 'server' 'versions' 'versioned'
60+
Join-Path 'http' 'type' 'union'
61+
Join-Path 'http' 'type' 'enum' 'extensible'
62+
Join-Path 'http' 'type' 'model' 'inheritance' 'enum-discriminator'
63+
Join-Path 'http' 'type' 'property' 'additional-properties'
64+
Join-Path 'http' 'type' 'property' 'optionality'
65+
Join-Path 'http' 'type' 'property' 'value-types'
66+
Join-Path 'http' 'versioning' 'added'
67+
Join-Path 'http' 'versioning' 'madeOptional'
68+
Join-Path 'http' 'versioning' 'removed'
69+
Join-Path 'http' 'versioning' 'renamedFrom'
70+
Join-Path 'http' 'versioning' 'returnTypeChangedFrom'
71+
Join-Path 'http' 'versioning' 'typeChangedFrom'
72+
Join-Path 'http' 'client' 'naming'
73+
Join-Path 'http' 'resiliency' 'srv-driven'
74+
Join-Path 'http' 'client' 'structure' 'client-operation-group'
75+
Join-Path 'http' 'client' 'structure' 'renamed-operation'
76+
Join-Path 'http' 'client' 'structure' 'multi-client'
77+
Join-Path 'http' 'client' 'structure' 'two-operation-group'
78+
Join-Path 'http' 'encode' 'bytes'
79+
Join-Path 'http' 'encode' 'datetime'
80+
Join-Path 'http' 'encode' 'duration'
81+
Join-Path 'http' 'parameters' 'collection-format'
82+
Join-Path 'http' 'routes'
83+
Join-Path 'http' 'type' 'array'
84+
Join-Path 'http' 'type' 'dictionary'
85+
Join-Path 'http' 'type' 'scalar'
86+
)
87+
88+
$azureAllowSpecs = @(
89+
Join-Path 'http' 'client' 'naming'
90+
Join-Path 'http' 'client' 'structure' 'client-operation-group'
91+
Join-Path 'http' 'client' 'structure' 'default'
92+
Join-Path 'http' 'client' 'structure' 'multi-client'
93+
Join-Path 'http' 'client' 'structure' 'renamed-operation'
94+
Join-Path 'http' 'client' 'structure' 'two-operation-group'
95+
Join-Path 'http' 'resiliency' 'srv-driven'
96+
)
97+
98+
$cadlRanchLaunchProjects = @{}
99+
100+
# Loop through all directories and subdirectories of the cadl ranch specs
101+
$directories = @(Get-ChildItem -Path "$specsDirectory/specs" -Directory -Recurse)
102+
$directories += @(Get-ChildItem -Path "$azureSpecsDirectory/specs" -Directory -Recurse)
103+
foreach ($directory in $directories) {
104+
if (-not (IsSpecDir $directory.FullName)) {
105+
continue
106+
}
107+
108+
$fromAzure = $directory.FullName.Contains("azure-http-specs")
109+
110+
$specFile = Join-Path $directory.FullName "client.tsp"
111+
if (-not (Test-Path $specFile)) {
112+
$specFile = Join-Path $directory.FullName "main.tsp"
113+
}
114+
$subPath = if ($fromAzure) {$directory.FullName.Substring($azureSpecsDirectory.Length + 1)} else {$directory.FullName.Substring($specsDirectory.Length + 1)}
115+
$subPath = $subPath -replace '^specs', 'http' # Keep consistent with the previous folder name because 'http' makes more sense then current 'specs'
116+
$folders = $subPath.Split([System.IO.Path]::DirectorySeparatorChar)
117+
118+
if (-not (Compare-Paths $subPath $filter)) {
119+
continue
120+
}
121+
122+
if ($fromAzure -eq $true -and !$azureAllowSpecs.Contains($subPath)) {
123+
continue
124+
}
125+
126+
if ($failingSpecs.Contains($subPath)) {
127+
Write-Host "Skipping $subPath" -ForegroundColor Yellow
128+
continue
129+
}
130+
131+
$generationDir = $cadlRanchRoot
132+
foreach ($folder in $folders) {
133+
$generationDir = Join-Path $generationDir $folder
134+
}
135+
136+
# create the directory if it doesn't exist
137+
if (-not (Test-Path $generationDir)) {
138+
New-Item -ItemType Directory -Path $generationDir | Out-Null
139+
}
140+
141+
if ($folders.Contains("versioning")) {
142+
Generate-Versioning $directory.FullName $generationDir -generateStub $stubbed
143+
$cadlRanchLaunchProjects.Add($($folders -join "-") + "-v1", $("TestProjects/CadlRanch/$($subPath.Replace([System.IO.Path]::DirectorySeparatorChar, '/'))") + "/v1")
144+
$cadlRanchLaunchProjects.Add($($folders -join "-") + "-v2", $("TestProjects/CadlRanch/$($subPath.Replace([System.IO.Path]::DirectorySeparatorChar, '/'))") + "/v2")
145+
continue
146+
}
147+
148+
# srv-driven contains two separate specs, for two separate clients. We need to generate both.
149+
if ($folders.Contains("srv-driven")) {
150+
Generate-Srv-Driven $directory.FullName $generationDir -generateStub $stubbed
151+
$cadlRanchLaunchProjects.Add($($folders -join "-") + "-v1", $("TestProjects/CadlRanch/$($subPath.Replace([System.IO.Path]::DirectorySeparatorChar, '/'))") + "/v1")
152+
$cadlRanchLaunchProjects.Add($($folders -join "-") + "-v2", $("TestProjects/CadlRanch/$($subPath.Replace([System.IO.Path]::DirectorySeparatorChar, '/'))") + "/v2")
153+
continue
154+
}
155+
156+
$cadlRanchLaunchProjects.Add(($folders -join "-"), ("TestProjects/CadlRanch/$($subPath.Replace([System.IO.Path]::DirectorySeparatorChar, '/'))"))
157+
if ($LaunchOnly) {
158+
continue
159+
}
160+
161+
Write-Host "Generating $subPath" -ForegroundColor Cyan
162+
Invoke (Get-TspCommand $specFile $generationDir $stubbed)
163+
164+
# exit if the generation failed
165+
if ($LASTEXITCODE -ne 0) {
166+
exit $LASTEXITCODE
167+
}
168+
}
169+
170+
# only write new launch settings if no filter was passed in
171+
if ($null -eq $filter) {
172+
Write-Host "Writing new launch settings" -ForegroundColor Cyan
173+
$mgcExe = "`$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.exe"
174+
$sampleExe = "`$(SolutionDir)/../generator/artifacts/bin/SamplePlugin/Debug/net8.0/Microsoft.Generator.CSharp.exe"
175+
$unbrandedSpec = "TestProjects/Local/Basic-TypeSpec"
176+
177+
$launchSettings = @{}
178+
$launchSettings.Add("profiles", @{})
179+
$launchSettings["profiles"].Add("Basic-TypeSpec", @{})
180+
$launchSettings["profiles"]["Basic-TypeSpec"].Add("commandLineArgs", "`$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.dll `$(SolutionDir)/$unbrandedSpec -p AzureClientPlugin")
181+
$launchSettings["profiles"]["Basic-TypeSpec"].Add("commandName", "Executable")
182+
$launchSettings["profiles"]["Basic-TypeSpec"].Add("executablePath", "dotnet")
183+
184+
foreach ($kvp in $cadlRanchLaunchProjects.GetEnumerator()) {
185+
$launchSettings["profiles"].Add($kvp.Key, @{})
186+
$launchSettings["profiles"][$kvp.Key].Add("commandLineArgs", "`$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.dll `$(SolutionDir)/$($kvp.Value) -p AzureStubPlugin")
187+
$launchSettings["profiles"][$kvp.Key].Add("commandName", "Executable")
188+
$launchSettings["profiles"][$kvp.Key].Add("executablePath", "dotnet")
189+
}
190+
191+
$sortedLaunchSettings = @{}
192+
$sortedLaunchSettings.Add("profiles", [ordered]@{})
193+
$launchSettings["profiles"].Keys | Sort-Object | ForEach-Object {
194+
$profileKey = $_
195+
$originalProfile = $launchSettings["profiles"][$profileKey]
196+
197+
# Sort the keys inside each profile
198+
# This is needed due to non deterministic ordering of json elements in powershell
199+
$sortedProfile = [ordered]@{}
200+
$originalProfile.GetEnumerator() | Sort-Object Key | ForEach-Object {
201+
$sortedProfile[$_.Key] = $_.Value
202+
}
203+
204+
$sortedLaunchSettings["profiles"][$profileKey] = $sortedProfile
205+
}
206+
207+
# Write the launch settings to the launchSettings.json file
208+
$launchSettingsPath = Join-Path $solutionDir "Azure.Generator" "src" "Properties" "launchSettings.json"
209+
# Write the settings to JSON and normalize line endings to Unix style (LF)
210+
$sortedLaunchSettings | ConvertTo-Json | ForEach-Object { $_ -replace "`r`n", "`n" } | Set-Content $launchSettingsPath
211+
}

0 commit comments

Comments
 (0)