diff --git a/eng/Packages.Data.props b/eng/Packages.Data.props index 8666d50fed2e5..3c378fee745c4 100644 --- a/eng/Packages.Data.props +++ b/eng/Packages.Data.props @@ -160,7 +160,7 @@ All should have PrivateAssets="All" set so they don't become package dependencies --> - + diff --git a/eng/csharp-emitter-package.json b/eng/emitter-package.json similarity index 100% rename from eng/csharp-emitter-package.json rename to eng/emitter-package.json diff --git a/eng/scripts/Cadl-Project-Generate.ps1 b/eng/scripts/Cadl-Project-Generate.ps1 deleted file mode 100644 index 953847886c861..0000000000000 --- a/eng/scripts/Cadl-Project-Generate.ps1 +++ /dev/null @@ -1,75 +0,0 @@ -[CmdletBinding()] -param ( - [Parameter(Position=0)] - [ValidateNotNullOrEmpty()] - [string] $ProjectDirectory -) - -$ErrorActionPreference = "Stop" -. $PSScriptRoot/../common/scripts/Helpers/PSModule-Helpers.ps1 -Install-ModuleIfNotInstalled "powershell-yaml" "0.4.1" | Import-Module - -function NpmInstallForProject([string]$workingDirectory) { - Push-Location $workingDirectory - try { - $currentDur = Resolve-Path "." - Write-Host "Generating from $currentDur" - if (Test-Path "package.json") { - Remove-Item -Path "package.json" -Force - } - if (Test-Path ".npmrc") { - Remove-Item -Path ".npmrc" -Force - } - Copy-Item -Path "$PSScriptRoot/../csharp-emitter-package.json" -Destination "package.json" -Force - npm install - if ($LASTEXITCODE) { exit $LASTEXITCODE } - } - finally { - Pop-Location - } -} - -$cadlConfigurationFile = Resolve-Path "$ProjectDirectory/src/cadl-location.yaml" - -Write-Host "Reading configuration from $cadlConfigurationFile" -$configuration = Get-Content -Path $cadlConfigurationFile -Raw | ConvertFrom-Yaml - -$specSubDirectory = $configuration["directory"] -$innerFolder = Split-Path $specSubDirectory -Leaf - -$tempFolder = "$ProjectDirectory/TempCadlFiles" -$npmWorkingDir = Resolve-Path $tempFolder/$innerFolder -$mainCadlFile = If (Test-Path "$npmWorkingDir/client.cadl") { Resolve-Path "$npmWorkingDir/client.cadl" } Else { Resolve-Path "$npmWorkingDir/main.cadl"} -$resolvedProjectDirectory = Resolve-Path "$ProjectDirectory/src" - -$HasEmitterOutputDir = $false; -if (Test-Path "$npmWorkingDir/cadl-project.yaml") { - $cadlProjectYaml = Get-Content -Path "$npmWorkingDir/cadl-project.yaml" -Raw - $yml = ConvertFrom-YAML $cadlProjectYaml - if ($yml -And $yml["options"] -And $yml["options"]["@azure-tools/cadl-csharp"] -And $yml["options"]["@azure-tools/cadl-csharp"]["emitter-output-dir"]) { - $HasEmitterOutputDir = $true - } -} - -try { - Push-Location $npmWorkingDir - NpmInstallForProject $npmWorkingDir - if ($HasEmitterOutputDir) { - $csharpSdkFolder = (Join-Path $ProjectDirectory ".." ".." "..") - $csharpSdkFolder = Resolve-Path $csharpSdkFolder - Write-Host("npx cadl compile $mainCadlFile --emit `"`@azure-tools/cadl-csharp`" --arg `"csharp-sdk-folder=$csharpSdkFolder`"") - npx cadl compile $mainCadlFile --emit "@azure-tools/cadl-csharp" --arg "csharp-sdk-folder=$csharpSdkFolder" - } else { - Write-Host("npx cadl compile $mainCadlFile --emit `"`@azure-tools/cadl-csharp`" --option `"@azure-tools/cadl-csharp.emitter-output-dir=$resolvedProjectDirectory`"") - npx cadl compile $mainCadlFile --emit "@azure-tools/cadl-csharp" --option @azure-tools/cadl-csharp.emitter-output-dir=$resolvedProjectDirectory - } - if ($LASTEXITCODE) { exit $LASTEXITCODE } -} -finally { - Pop-Location -} - -$shouldCleanUp = $configuration["cleanup"] ?? $true -if ($shouldCleanUp) { - Remove-Item $tempFolder -Recurse -Force -} \ No newline at end of file diff --git a/eng/scripts/Cadl-Project-Sync.ps1 b/eng/scripts/Cadl-Project-Sync.ps1 deleted file mode 100644 index 797b7996bed49..0000000000000 --- a/eng/scripts/Cadl-Project-Sync.ps1 +++ /dev/null @@ -1,138 +0,0 @@ -[CmdletBinding()] -param ( - [Parameter(Position=0)] - [ValidateNotNullOrEmpty()] - [string] $ProjectDirectory -) - -$ErrorActionPreference = "Stop" -. $PSScriptRoot/../common/scripts/Helpers/PSModule-Helpers.ps1 -Install-ModuleIfNotInstalled "powershell-yaml" "0.4.1" | Import-Module -$sparseCheckoutFile = ".git/info/sparse-checkout" - -function AddSparseCheckoutPath([string]$subDirectory) { - if (!(Test-Path $sparseCheckoutFile) -or !((Get-Content $sparseCheckoutFile).Contains($subDirectory))) { - Write-Output $subDirectory >> .git/info/sparse-checkout - } -} - -function CopySpecToProjectIfNeeded([string]$specCloneRoot, [string]$mainSpecDir, [string]$dest, [string[]]$specAdditionalSubDirectories) { - $source = "$specCloneRoot/$mainSpecDir" - Write-Host "Copying spec from $source" - # $mainSpecDir is the PR folder, we just need to copy its subfolders which include the cadl project folder - Get-ChildItem –Path "$source" -Exclude @("data-plane", "resource-manager")| - Foreach-Object { - Copy-Item -Path $_.FullName -Destination $dest -Recurse -Force - } - foreach($additionalDir in $specAdditionalSubDirectories) - { - $source = "$specCloneRoot/$additionalDir" - Write-Host "Copying spec from $source" - Copy-Item -Path $source -Destination $dest -Recurse -Force - } -} - -function UpdateSparseCheckoutFile([string]$mainSpecDir, [string[]]$specAdditionalSubDirectories) { - AddSparseCheckoutPath $mainSpecDir - foreach($subDir in $specAdditionalSubDirectories) - { - AddSparseCheckoutPath $subDir - } -} - -function GetGitRemoteValue([string]$repo) { - Push-Location $ProjectDirectory - $result = "" - try { - $gitRemotes = (git remote -v) - foreach ($remote in $gitRemotes) - { - if ($remote.StartsWith("origin")) { - if ($remote -match 'https://github.com/\S+[\.git]') { - $result = "https://github.com/$repo.git" - break - } elseif ($remote -match "git@github.com:\S+[\.git]"){ - $result = "git@github.com:$repo.git" - break - } else { - throw "Unknown git remote format found: $remote" - } - } - } - } - finally { - Pop-Location - } - - return $result -} - -function InitializeSparseGitClone([string]$repo) { - git clone --no-checkout --filter=tree:0 $repo . - if ($LASTEXITCODE) { exit $LASTEXITCODE } - git sparse-checkout init - if ($LASTEXITCODE) { exit $LASTEXITCODE } - Remove-Item $sparseCheckoutFile -Force -} - -function GetSpecCloneDir([string]$projectName) { - Push-Location $ProjectDirectory - try { - $root = git rev-parse --show-toplevel - } - finally { - Pop-Location - } - - $sparseSpecCloneDir = "$root/../sparse-spec/$projectName" - New-Item $sparseSpecCloneDir -Type Directory -Force | Out-Null - $createResult = Resolve-Path $sparseSpecCloneDir - return $createResult -} - -$cadlConfigurationFile = Resolve-Path "$ProjectDirectory/src/cadl-location.yaml" -Write-Host "Reading configuration from $cadlConfigurationFile" -$configuration = Get-Content -Path $cadlConfigurationFile -Raw | ConvertFrom-Yaml - -$pieces = $cadlConfigurationFile.Path.Replace("\","/").Split("/") -$projectName = $pieces[$pieces.Count - 3] - -# clone the whole RP directory which is the parent of $configuration["directory"] -if ($configuration["directory"] -match "^[^/\\]+[\\/]+[^/\\]+") -{ - $specSubDirectory = $Matches[0] -} -else -{ - throw "The directory in $cadlConfigurationFile is not expected" -} -if ( $configuration["repo"] -and $configuration["commit"]) { - $specCloneDir = GetSpecCloneDir $projectName - $gitRemoteValue = GetGitRemoteValue $configuration["repo"] - - Write-Host "Setting up sparse clone for $projectName at $specCloneDir" - - Push-Location $specCloneDir.Path - try { - if (!(Test-Path ".git")) { - InitializeSparseGitClone $gitRemoteValue - UpdateSparseCheckoutFile $specSubDirectory $configuration["additionalDirectories"] - } - git checkout $configuration["commit"] - if ($LASTEXITCODE) { exit $LASTEXITCODE } - } - finally { - Pop-Location - } -} elseif ( $configuration["spec-root-dir"] ) { - $specCloneDir = $configuration["spec-root-dir"] -} - - -$tempCadlDir = "$ProjectDirectory/TempCadlFiles" -New-Item $tempCadlDir -Type Directory -Force | Out-Null -CopySpecToProjectIfNeeded ` - -specCloneRoot $specCloneDir ` - -mainSpecDir $specSubDirectory ` - -dest $tempCadlDir ` - -specAdditionalSubDirectories $configuration["additionalDirectories"] diff --git a/eng/scripts/Language-Settings.ps1 b/eng/scripts/Language-Settings.ps1 index ac2ceccf5efd0..066bfa4a6f51d 100644 --- a/eng/scripts/Language-Settings.ps1 +++ b/eng/scripts/Language-Settings.ps1 @@ -13,7 +13,7 @@ $PackageRepositoryUri = "https://www.nuget.org/packages" function Get-AllPackageInfoFromRepo($serviceDirectory) { $allPackageProps = @() - # $addDevVersion is a global variable set by a parameter in + # $addDevVersion is a global variable set by a parameter in # Save-Package-Properties.ps1 $shouldAddDevVersion = Get-Variable -Name 'addDevVersion' -ValueOnly -ErrorAction 'Ignore' $msbuildOutput = dotnet msbuild ` @@ -271,7 +271,7 @@ function GetExistingPackageVersions ($PackageName, $GroupId=$null) return $existingVersion.versions } catch { - if ($_.Exception.Response.StatusCode -ne 404) + if ($_.Exception.Response.StatusCode -ne 404) { LogError "Failed to retrieve package versions for ${PackageName}. $($_.Exception.Message)" } @@ -283,10 +283,10 @@ function Get-dotnet-DocsMsMetadataForPackage($PackageInfo) { $readmeName = $PackageInfo.Name.ToLower() # Readme names (which are used in the URL) should not include redundant terms - # when viewed in URL form. For example: + # when viewed in URL form. For example: # https://docs.microsoft.com/en-us/dotnet/api/overview/azure/storage.blobs-readme # Note how the end of the URL doesn't look like: - # ".../azure/azure.storage.blobs-readme" + # ".../azure/azure.storage.blobs-readme" # This logic eliminates a preceeding "azure." in the readme filename. # "azure.storage.blobs" -> "storage.blobs" @@ -304,16 +304,16 @@ function Get-dotnet-DocsMsMetadataForPackage($PackageInfo) { # Details on CSV schema: # https://review.docs.microsoft.com/en-us/help/onboard/admin/reference/dotnet/documenting-nuget?branch=master#set-up-the-ci-job -# -# PowerShell's included Import-Csv cmdlet is not sufficient for parsing this -# format because it does not easily handle rows whose number of columns is +# +# PowerShell's included Import-Csv cmdlet is not sufficient for parsing this +# format because it does not easily handle rows whose number of columns is # greater than the number of columns in the first row. We must manually parse # this CSV file. function Get-DocsCiConfig($configPath) { Write-Host "Loading csv from $configPath" $output = @() foreach ($row in Get-Content $configPath) { - # CSV format: + # CSV format: # {package_moniker_base_string},{package_ID},{version_1},{version_2},...,{version_N} # # The {package_ID} field can contain optional properties denoted by square @@ -327,12 +327,12 @@ function Get-DocsCiConfig($configPath) { LogError "Do include the package name for each of the csv entry." } # If the {package_ID} field contains optional properties inside square - # brackets, parse those properties into key value pairs. In the case of + # brackets, parse those properties into key value pairs. In the case of # duplicate keys, the last one wins. $rawProperties = '' $packageProperties = [ordered]@{} - if ($fields[1] -match '\[(.*)\]') { - $rawProperties = $Matches[1] + if ($fields[1] -match '\[(.*)\]') { + $rawProperties = $Matches[1] foreach ($propertyExpression in $rawProperties.Split(';')) { $propertyParts = $propertyExpression.Split('=') $packageProperties[$propertyParts[0]] = $propertyParts[1] @@ -344,20 +344,20 @@ function Get-DocsCiConfig($configPath) { # [key=value;key=value]Package.Name # Package.Name $packageName = '' - if ($fields[1] -match '(\[.*\])?(.*)') { - $packageName = $Matches[2] - } else { - Write-Error "Could not find package id in row: $row" + if ($fields[1] -match '(\[.*\])?(.*)') { + $packageName = $Matches[2] + } else { + Write-Error "Could not find package id in row: $row" } - # Remaining entries in the row are versions, add them to the package + # Remaining entries in the row are versions, add them to the package # properties $outputVersions = @() if ($fields.Count -gt 2 -and $fields[2]) { $outputVersions = $fields[2..($fields.Count - 1)] } - # Example row: + # Example row: # packagemoniker,[key1=value1;key2=value2]Package.Name,1.0.0,1.2.3-beta.1 $output += [PSCustomObject]@{ Id = $fields[0]; # packagemoniker @@ -370,17 +370,17 @@ function Get-DocsCiConfig($configPath) { return $output } -function Get-DocsCiLine ($item) { +function Get-DocsCiLine ($item) { $line = '' if ($item.Properties.Count) { $propertyPairs = @() - foreach ($key in $item.Properties.Keys) { + foreach ($key in $item.Properties.Keys) { $propertyPairs += "$key=$($item.Properties[$key])" } $packageProperties = $propertyPairs -join ';' $line = "$($item.Id),[$packageProperties]$($item.Name)" - } else { + } else { $line = "$($item.Id),$($item.Name)" } @@ -422,12 +422,12 @@ function EnsureCustomSource($package) { Write-Error $_ -ErrorAction Continue return $package } - - # Matches package version against output: + + # Matches package version against output: # "Azure.Security.KeyVault.Secrets 4.3.0-alpha.20210915.3" $matchedVersion = $existingVersions.Where({$_.Version -eq $package.Versions}) - if (!$matchedVersion) { + if (!$matchedVersion) { return $package } @@ -439,7 +439,7 @@ function Update-dotnet-DocsMsPackages($DocsRepoLocation, $DocsMetadata) { UpdateDocsMsPackages ` (Join-Path $DocsRepoLocation 'bundlepackages/azure-dotnet-preview.csv') ` 'preview' ` - $DocsMetadata + $DocsMetadata UpdateDocsMsPackages ` (Join-Path $DocsRepoLocation 'bundlepackages/azure-dotnet.csv') ` @@ -466,14 +466,14 @@ function UpdateDocsMsPackages($DocConfigFile, $Mode, $DocsMetadata) { continue } - if ($matchingPublishedPackageArray.Count -gt 1) { + if ($matchingPublishedPackageArray.Count -gt 1) { LogWarning "Found more than one matching published package in metadata for $($package.Name); only updating first entry" } $matchingPublishedPackage = $matchingPublishedPackageArray[0] - if ($Mode -eq 'preview' -and !$matchingPublishedPackage.VersionPreview.Trim()) { + if ($Mode -eq 'preview' -and !$matchingPublishedPackage.VersionPreview.Trim()) { # If we are in preview mode and the package does not have a superseding - # preview version, remove the package from the list. + # preview version, remove the package from the list. Write-Host "Remove superseded preview package: $($package.Name)" continue } @@ -499,13 +499,13 @@ function UpdateDocsMsPackages($DocConfigFile, $Mode, $DocsMetadata) { $outputPackagesHash[$package.Name] = $true } - $remainingPackages = @() - if ($Mode -eq 'preview') { - $remainingPackages = $DocsMetadata.Where({ + $remainingPackages = @() + if ($Mode -eq 'preview') { + $remainingPackages = $DocsMetadata.Where({ $_.VersionPreview.Trim() -and !$outputPackagesHash.ContainsKey($_.Package) }) - } else { - $remainingPackages = $DocsMetadata.Where({ + } else { + $remainingPackages = $DocsMetadata.Where({ $_.VersionGA.Trim() -and !$outputPackagesHash.ContainsKey($_.Package) }) } @@ -530,15 +530,23 @@ function UpdateDocsMsPackages($DocConfigFile, $Mode, $DocsMetadata) { Name = $package.Package; Properties = $newPackageProperties; Versions = $versions - } - $newPackage = EnsureCustomSource $newPackage + } + $newPackage = EnsureCustomSource $newPackage $outputPackages += $newPackage } - $outputLines = @() - foreach ($package in $outputPackages) { + $outputLines = @() + foreach ($package in $outputPackages) { $outputLines += Get-DocsCiLine $package } Set-Content -Path $DocConfigFile -Value $outputLines } + +function Get-dotnet-EmitterName() { + return "@azure-tools/cadl-csharp" +} + +function Get-dotnet-EmitterAdditionalOptions([string]$projectDirectory) { + return "--option @azure-tools/cadl-csharp.emitter-output-dir=$projectDirectory/src" +} diff --git a/sdk/anomalydetector/Azure.AI.AnomalyDetector/src/cadl-location.yaml b/sdk/anomalydetector/Azure.AI.AnomalyDetector/cadl-location.yaml similarity index 100% rename from sdk/anomalydetector/Azure.AI.AnomalyDetector/src/cadl-location.yaml rename to sdk/anomalydetector/Azure.AI.AnomalyDetector/cadl-location.yaml diff --git a/sdk/openai/Azure.AI.OpenAI/src/cadl-location.yaml b/sdk/openai/Azure.AI.OpenAI/cadl-location.yaml similarity index 100% rename from sdk/openai/Azure.AI.OpenAI/src/cadl-location.yaml rename to sdk/openai/Azure.AI.OpenAI/cadl-location.yaml