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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions eng/scripts/automation/GenerateAndBuildLib.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -917,8 +917,15 @@ function GetSDKProjectFolder()
if ($yml["parameters"] -And $yml["parameters"]["service-dir"]) {
$service = $yml["parameters"]["service-dir"]["default"];
}
# Support both old and new C# emitters
$csharpOpts = $null
if ($yml["options"] -And $yml["options"]["@azure-tools/typespec-csharp"]) {
$csharpOpts = $yml["options"]["@azure-tools/typespec-csharp"]
} elseif ($yml["options"] -And $yml["options"]["@azure-typespec/http-client-csharp"]) {
$csharpOpts = $yml["options"]["@azure-typespec/http-client-csharp"]
}

if ($csharpOpts) {
if ($csharpOpts["package-dir"]) {
$packageDir = $csharpOpts["package-dir"]
} elseif ($csharpOpts["namespace"]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,78 @@ options:

{GetSDKProjectFolder -typespecConfigurationFile $testTspConfigFile2 -sdkRepoRoot "/test"} | Should -Throw "*namespace*"
}

it("should work with new @azure-typespec/http-client-csharp emitter") {
$testTspConfigFileNew = Join-Path $testTspConfigDir "tspconfig-new-emitter.yaml"
$testConfigNewEmitter = @"
parameters:
service-dir:
default: testservice
options:
"@azure-typespec/http-client-csharp":
namespace: Azure.TestService.NewEmitter
service-dir: testservice
"@
$testConfigNewEmitter | Out-File -FilePath $testTspConfigFileNew -Encoding UTF8

$testSdkRoot = "/test/sdk/root"
$result = GetSDKProjectFolder -typespecConfigurationFile $testTspConfigFileNew -sdkRepoRoot $testSdkRoot
$expected = Join-Path $testSdkRoot "testservice" "Azure.TestService.NewEmitter"
$result | Should -Be $expected
}

it("should prioritize package-dir over namespace with new emitter") {
$testTspConfigFileNewPackageDir = Join-Path $testTspConfigDir "tspconfig-new-emitter-package-dir.yaml"
$testConfigNewEmitterPackageDir = @"
parameters:
service-dir:
default: testservice
options:
"@azure-typespec/http-client-csharp":
package-dir: Azure.TestService.NewEmitter.PackageDir
namespace: Azure.TestService.NewEmitter
service-dir: testservice
"@
$testConfigNewEmitterPackageDir | Out-File -FilePath $testTspConfigFileNewPackageDir -Encoding UTF8

$testSdkRoot = "/test/sdk/root"
$result = GetSDKProjectFolder -typespecConfigurationFile $testTspConfigFileNewPackageDir -sdkRepoRoot $testSdkRoot
$expected = Join-Path $testSdkRoot "testservice" "Azure.TestService.NewEmitter.PackageDir"
$result | Should -Be $expected
}

it("should prefer old emitter when both are present") {
$testTspConfigFileBoth = Join-Path $testTspConfigDir "tspconfig-both-emitters.yaml"
$testConfigBothEmitters = @"
parameters:
service-dir:
default: testservice
options:
"@azure-tools/typespec-csharp":
namespace: Azure.TestService.OldEmitter
service-dir: testservice
"@azure-typespec/http-client-csharp":
namespace: Azure.TestService.NewEmitter
service-dir: testservice
"@
$testConfigBothEmitters | Out-File -FilePath $testTspConfigFileBoth -Encoding UTF8

$testSdkRoot = "/test/sdk/root"
$result = GetSDKProjectFolder -typespecConfigurationFile $testTspConfigFileBoth -sdkRepoRoot $testSdkRoot
$expected = Join-Path $testSdkRoot "testservice" "Azure.TestService.OldEmitter"
$result | Should -Be $expected
}

it("should throw error when neither emitter has namespace") {
$testTspConfigFileNoEmitter = Join-Path $testTspConfigDir "tspconfig-no-emitter.yaml"
$testConfigNoEmitter = @"
parameters:
service-dir:
default: testservice
options: {}
"@
$testConfigNoEmitter | Out-File -FilePath $testTspConfigFileNoEmitter -Encoding UTF8

{GetSDKProjectFolder -typespecConfigurationFile $testTspConfigFileNoEmitter -sdkRepoRoot "/test"} | Should -Throw "*namespace*"
}
}