Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ $ErrorActionPreference = 'Stop'
Set-StrictMode -Version 1

Write-Host 'Generating test CADL json...'
& (Join-Path $PSScriptRoot 'CadlGenerate.ps1')
& (Join-Path $PSScriptRoot 'TypespecGenerate.ps1')

Write-Host 'Checking generated file differences...'
git -c core.safecrlf=false diff --ignore-space-at-eol --exit-code
if ($LastExitCode -ne 0)
{
Write-Error 'Generated code is not up to date, please run CadlGenerate.ps1'
Write-Error 'Generated code is not up to date, please run TypespecGenerate.ps1'
}
38 changes: 19 additions & 19 deletions eng/Generate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ $sharedSource = Join-Path $repoRoot 'src' 'assets'
$configurationPath = Join-Path $repoRoot 'readme.md'
$testServerSwaggerPath = Join-Path $repoRoot 'node_modules' '@microsoft.azure' 'autorest.testserver' 'swagger'
$cadlRanchFilePath = Join-Path $repoRoot 'node_modules' '@azure-tools' 'cadl-ranch-specs' 'http'
$cadlEmitOptions = '--option @azure-tools/cadl-csharp.save-inputs=true --option @azure-tools/cadl-csharp.clear-output-folder=true'
$cadlEmitOptions = '--option @azure-tools/typespec-csharp.save-inputs=true --option @azure-tools/typespec-csharp.clear-output-folder=true'

function Add-Swagger ([string]$name, [string]$output, [string]$arguments) {
$swaggerDefinitions[$name] = @{
Expand All @@ -37,7 +37,7 @@ function Add-Swagger-Test ([string]$name, [string]$output, [string]$arguments) {
}
}

function Add-Cadl([string]$name, [string]$output, [string]$mainFile="", [string]$arguments="") {
function Add-Typespec([string]$name, [string]$output, [string]$mainFile="", [string]$arguments="") {
$cadlDefinitions[$name] = @{
'projectName'=$name;
'output'=$output;
Expand All @@ -53,11 +53,11 @@ function Add-TestServer-Swagger ([string]$testName, [string]$projectSuffix, [str
Add-Swagger "$testName$projectSuffix" $projectDirectory "--require=$configurationPath --try-require=$inputReadme --input-file=$inputFile $additionalArgs"
}

function Add-CadlRanch-Cadl([string]$testName, [string]$projectPrefix, [string]$cadlRanchProjectsDirectory, [boolean]$generateConvenience) {
function Add-CadlRanch-Typespec([string]$testName, [string]$projectPrefix, [string]$cadlRanchProjectsDirectory, [boolean]$generateConvenience) {
$projectDirectory = Join-Path $cadlRanchProjectsDirectory $testName
$cadlMain = Join-Path $cadlRanchFilePath $testName "main.cadl"
$convenienceOption = If ($generateConvenience) {""} Else {" --option @azure-tools/cadl-csharp.generate-convenience-methods=false"}
Add-Cadl "$projectPrefix$testName" $projectDirectory $cadlMain "--option @azure-tools/cadl-csharp.unreferenced-types-handling=keepAll$convenienceOption"
$convenienceOption = If ($generateConvenience) {""} Else {" --option @azure-tools/typespec-csharp.generate-convenience-methods=false"}
Add-Typespec "$projectPrefix$testName" $projectDirectory $cadlMain "--option @azure-tools/typespec-csharp.unreferenced-types-handling=keepAll$convenienceOption"
}

$testNames =
Expand Down Expand Up @@ -168,8 +168,8 @@ function Add-Directory ([string]$testName, [string]$directory, [boolean]$forTest
Add-Swagger-Test $testName $directory $testArguments
}
else {
if ($testName.EndsWith("Cadl")) {
Add-Cadl $testName $directory
if ($testName.EndsWith("Typespec")) {
Add-Typespec $testName $directory
} else {
Add-Swagger $testName $directory $testArguments
}
Expand All @@ -194,8 +194,8 @@ if (!($Exclude -contains "TestProjects"))
Add-Directory $testName $testsFolder $TRUE
continue
}
if ($testName.EndsWith("Cadl")) {
Add-Cadl $testName $directory "" "--option @azure-tools/cadl-csharp.generate-convenience-methods=false"
if ($testName.EndsWith("Typespec")) {
Add-Typespec $testName $directory "" "--option @azure-tools/typespec-csharp.generate-convenience-methods=false"
} else {
if (Test-Path $readmeConfigurationPath)
{
Expand Down Expand Up @@ -244,14 +244,14 @@ if (!($Exclude -contains "Samples"))
foreach ($projectName in $cadlSampleProjectName)
{
$projectDirectory = Join-Path $repoRoot 'samples' $projectName
$cadlMain = Join-Path $projectDirectory "main.cadl"
$cadlClient = Join-Path $projectDirectory "client.cadl"
$mainCadlFile = If (Test-Path "$cadlClient") { Resolve-Path "$cadlClient" } Else { Resolve-Path "$cadlMain"}
Add-Cadl $projectName $projectDirectory $mainCadlFile
$tspMain = Join-Path $projectDirectory "main.tsp"
$tspClient = Join-Path $projectDirectory "client.tsp"
$mainTspFile = If (Test-Path "$tspClient") { Resolve-Path "$tspClient" } Else { Resolve-Path "$tspMain"}
Add-Typespec $projectName $projectDirectory $mainTspFile
}
}

# Cadl projects
# Typespec projects
$cadlRanchProjectDirectory = Join-Path $repoRoot 'test' 'CadlRanchProjects'
$cadlRanchProjectPathsWithoutConvenience = # Needs justification to add item
'enums/extensible', # https://github.com/Azure/autorest.csharp/issues/3079
Expand All @@ -271,17 +271,17 @@ if (!($Exclude -contains "CadlRanchProjects"))
{
foreach ($testPath in $cadlRanchProjectPaths)
{
Add-CadlRanch-Cadl $testPath "cadl-" $cadlRanchProjectDirectory $TRUE
Add-CadlRanch-Typespec $testPath "typespec-" $cadlRanchProjectDirectory $TRUE
}

foreach ($testPath in $cadlRanchProjectPathsWithoutConvenience)
{
Add-CadlRanch-Cadl $testPath "cadl-" $cadlRanchProjectDirectory $FALSE
Add-CadlRanch-Typespec $testPath "typespec-" $cadlRanchProjectDirectory $FALSE
}
}

# TODO: remove later after cadl-ranch fixes the discriminator tests
Add-Cadl "inheritance-cadl" (Join-Path $cadlRanchProjectDirectory "inheritance")
Add-Typespec "inheritance-typespec" (Join-Path $cadlRanchProjectDirectory "inheritance")

# Smoke tests
if (!($Exclude -contains "SmokeTests"))
Expand Down Expand Up @@ -380,7 +380,7 @@ if ($reset -or $env:TF_BUILD)

if ($cadlCount -gt 0)
{
Invoke-CadlSetup
Invoke-TypespecSetup
}
}

Expand Down Expand Up @@ -411,6 +411,6 @@ $keys | %{ $swaggerTestDefinitions[$_] } | ForEach-Object -Parallel {
$keys | %{ $cadlDefinitions[$_] } | ForEach-Object -Parallel {
if ($_.output -ne $null) {
Import-Module "$using:PSScriptRoot\Generation.psm1" -DisableNameChecking;
Invoke-Cadl $_.output $_.projectName $_.mainFile $_.arguments $using:sharedSource $using:fast $using:debug;
Invoke-Typespec $_.output $_.projectName $_.mainFile $_.arguments $using:sharedSource $using:fast $using:debug;
}
} -ThrottleLimit $parallel
12 changes: 6 additions & 6 deletions eng/Generation.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function AutoRest-Reset()
Invoke "$script:autoRestBinary --reset"
}

function Invoke-Cadl($baseOutput, $projectName, $mainFile, $arguments="", $sharedSource="", $fast="", $debug="")
function Invoke-Typespec($baseOutput, $projectName, $mainFile, $arguments="", $sharedSource="", $fast="", $debug="")
{
if (!(Test-Path $baseOutput)) {
New-Item $baseOutput -ItemType Directory
Expand Down Expand Up @@ -81,8 +81,8 @@ function Invoke-Cadl($baseOutput, $projectName, $mainFile, $arguments="", $share
$autorestCsharpBinPath = Join-Path $repoRootPath "artifacts/bin/AutoRest.CSharp/Debug/net6.0/AutoRest.CSharp.dll"
Try
{
$cadlFileName = $mainFile ? $mainFile : "$baseOutput/$projectName.cadl"
$emitCommand = "npx cadl compile $cadlFileName --emit @azure-tools/cadl-csharp --option @azure-tools/cadl-csharp.emitter-output-dir=$outputPath --option @azure-tools/cadl-csharp.csharpGeneratorPath=$autorestCsharpBinPath $arguments"
$cadlFileName = $mainFile ? $mainFile : "$baseOutput/$projectName.tsp"
$emitCommand = "npx tsp compile $cadlFileName --emit @azure-tools/typespec-csharp --option @azure-tools/typespec-csharp.emitter-output-dir=$outputPath --option @azure-tools/typespec-csharp.csharpGeneratorPath=$autorestCsharpBinPath $arguments"
Invoke $emitCommand $outputPath
}
Finally
Expand All @@ -94,7 +94,7 @@ function Invoke-Cadl($baseOutput, $projectName, $mainFile, $arguments="", $share
Invoke "dotnet build $baseOutput --verbosity quiet /nologo"
}

function Invoke-CadlSetup()
function Invoke-TypespecSetup()
{
# build emitter
$emitterPath = Join-Path $PSScriptRoot ".." "src" "CADL.Extension" "Emitter.Csharp"
Expand Down Expand Up @@ -133,5 +133,5 @@ Export-ModuleMember -Function "Invoke"
Export-ModuleMember -Function "Invoke-AutoRest"
Export-ModuleMember -Function "AutoRest-Reset"
Export-ModuleMember -Function "Get-AutoRestProject"
Export-ModuleMember -Function "Invoke-Cadl"
Export-ModuleMember -Function "Invoke-CadlSetup"
Export-ModuleMember -Function "Invoke-Typespec"
Export-ModuleMember -Function "Invoke-TypespecSetup"
6 changes: 3 additions & 3 deletions eng/CadlGenerate.ps1 → eng/TypespecGenerate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ foreach ($directory in Get-ChildItem $testEmitterPath -Directory)
{
Remove-Item $projectPath/Generated -Force -Recurse
}
node node_modules/@cadl-lang/compiler/dist/core/cli.js compile $projectPath/$testName.cadl --emit @azure-tools/cadl-csharp --option @azure-tools/cadl-csharp.emitter-output-dir=$projectPath --option @azure-tools/cadl-csharp.skipSDKGeneration=true --option @azure-tools/cadl-csharp.save-inputs=true
node node_modules/@typespec/compiler/dist/core/cli/cli.js compile $projectPath/$testName.tsp --emit @azure-tools/typespec-csharp --option @azure-tools/typespec-csharp.emitter-output-dir=$projectPath --option @azure-tools/typespec-csharp.skipSDKGeneration=true --option @azure-tools/typespec-csharp.save-inputs=true
if (!$?) {
Pop-Location
throw "Failed to emit cadl model for $testName."
Expand All @@ -47,10 +47,10 @@ foreach ($directory in Get-ChildItem $samplePath -Directory)
{
Remove-Item $projectPath/Generated -Force -Recurse
}
node node_modules/@cadl-lang/compiler/dist/core/cli.js compile $projectPath/$testName.cadl --emit @azure-tools/cadl-csharp --option @azure-tools/cadl-csharp.emitter-output-dir=$projectPath --option @azure-tools/cadl-csharp.skipSDKGeneration=true --option @azure-tools/cadl-csharp.save-inputs=true
node node_modules/@typespec/compiler/dist/core/cli/cli.js compile $projectPath/$testName.tsp --emit @azure-tools/typespec-csharp --option @azure-tools/typespec-csharp.emitter-output-dir=$projectPath --option @azure-tools/typespec-csharp.skipSDKGeneration=true --option @azure-tools/typespec-csharp.save-inputs=true
if (!$?) {
Pop-Location
throw "Failed to emit cadl model for $testName."
throw "Failed to emit typespec model for $testName."
}
}

Expand Down
4 changes: 2 additions & 2 deletions eng/UpdateGeneratorMetadata.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ $PackagesProps = "$SdkRepoRoot\eng\Packages.Data.props"

$CadlEmitterProps = "$SdkRepoRoot\eng\emitter-package.json"
(Get-Content -Raw $CadlEmitterProps) -replace `
'"@azure-tools/cadl-csharp": ".*?"',
"`"@azure-tools/cadl-csharp`": `"$CadlEmitterVersion`"" | `
'"@azure-tools/typespec-csharp": ".*?"',
"`"@azure-tools/typespec-csharp`": `"$CadlEmitterVersion`"" | `
Set-Content $CadlEmitterProps -NoNewline
2 changes: 1 addition & 1 deletion eng/pipelines/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ stages:
command: custom
customCommand: run build
workingDir: $(Build.SourcesDirectory)/autorest.csharp/src/CADL.Extension/Emitter.Csharp
- pwsh: ./eng/ExecuteCadlEmitterUnitTests.ps1
- pwsh: ./eng/ExecuteTypespecEmitterUnitTests.ps1
displayName: 'E2E Test for CADL emitter'
workingDirectory: $(Build.SourcesDirectory)/autorest.csharp
- script: |
Expand Down
6 changes: 3 additions & 3 deletions eng/pipelines/cadl-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@ stages:
command: custom
customCommand: pack
workingDir: $(Build.SourcesDirectory)/src/CADL.Extension/Emitter.Csharp
- pwsh: ./eng/ExecuteCadlEmitterUnitTests.ps1
displayName: 'E2E_Test for CADL emitter'
- pwsh: ./eng/ExecuteTypespecEmitterUnitTests.ps1
displayName: 'E2E_Test for TypeSpec emitter'
workingDirectory: $(Build.SourcesDirectory)
- script: |
npm run test --prefix src/CADL.Extension/Emitter.Csharp
displayName: 'Unit Test'
workingDirectory: $(Build.SourcesDirectory)
- script: |
mkdir -p $(VAR_BUILD_ARTIFACT_STAGING_DIRECTORY)/packages
cp azure-tools-cadl-csharp-*.tgz $(VAR_BUILD_ARTIFACT_STAGING_DIRECTORY)/packages/
cp azure-tools-typespec-csharp-*.tgz $(VAR_BUILD_ARTIFACT_STAGING_DIRECTORY)/packages/
displayName: 'Copy CADL Csharp emitter library to staging dir'
workingDirectory: $(Build.SourcesDirectory)/src/CADL.Extension/Emitter.Csharp
- task: PublishBuildArtifacts@1
Expand Down
Loading