Skip to content

Commit

Permalink
Use projectListOverrideFile for preview generation (#39614)
Browse files Browse the repository at this point in the history
  • Loading branch information
hallipr authored Oct 31, 2023
1 parent f8de740 commit da3763a
Showing 1 changed file with 62 additions and 24 deletions.
86 changes: 62 additions & 24 deletions eng/scripts/Language-Settings.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -588,42 +588,80 @@ function Get-dotnet-EmitterAdditionalOptions([string]$projectDirectory) {
}

function Update-dotnet-GeneratedSdks([string]$PackageDirectoriesFile) {
$showSummary = ($env:SYSTEM_DEBUG -eq 'true') -or ($VerbosePreference -ne 'SilentlyContinue')
$summaryArgs = $showSummary ? "/v:n /ds" : ""

$packageDirectories = Get-Content $PackageDirectoriesFile | ConvertFrom-Json
Push-Location $RepoRoot
try {
Write-Host "`n`n======================================================================"
Write-Host "Generating projects" -ForegroundColor Yellow
Write-Host "======================================================================`n"

$directoriesWithErrors = @()
$packageDirectories = Get-Content $PackageDirectoriesFile | ConvertFrom-Json

Invoke-LoggedCommand "npm install -g autorest"
# Build the project list override file

foreach ($directory in $packageDirectories) {
Push-Location $RepoRoot
try {
Write-Host "`n`n======================================================================"
Write-Host "Generating projects under directory '$directory'" -ForegroundColor Yellow
Write-Host "======================================================================`n"
$lines = @('<Project>', ' <ItemGroup>')

Invoke-LoggedCommand "dotnet msbuild /restore /t:GenerateCode /p:Scope=`"$directory`" $summaryArgs eng\service.proj" -GroupOutput
foreach ($directory in $packageDirectories) {
$projects = Get-ChildItem -Path "$RepoRoot/sdk/$directory" -Filter "*.csproj" -Recurse
foreach ($project in $projects) {
$lines += " <ProjectReference Include=`"$($project.FullName)`" />"
}
}
catch {
Write-Host "##[error]Error generating project under directory $directory"
Write-Host $_.Exception.Message
$directoriesWithErrors += $directory

$lines += ' </ItemGroup>', '</Project>'
$artifactsPath = Join-Path $RepoRoot "artifacts"
$projectListOverrideFile = Join-Path $artifactsPath "GeneratedSdks.proj"

Write-Host "Creating project list override file $projectListOverrideFile`:"
$lines | ForEach-Object { " $_" } | Out-Host

New-Item $artifactsPath -ItemType Directory -Force | Out-Null
$lines | Out-File $projectListOverrideFile -Encoding UTF8
Write-Host "`n"

# Initialize npm and npx cache
Write-Host "##[group]Initializing npm and npx cache"

## Generate code in sdk/template to prime the npx and npm cache
Push-Location "$RepoRoot/sdk/template/Azure.Template/src"
try {
Write-Host "Building then resetting sdk/template/Azure.Template/src"
Invoke-LoggedCommand "dotnet build /t:GenerateCode"
Invoke-LoggedCommand "git restore ."
Invoke-LoggedCommand "git clean . --force"
}
finally {
Pop-Location
}
}

if($directoriesWithErrors.Count -gt 0) {
Write-Host "##[error]Generation errors found in $($directoriesWithErrors.Count) directories:"
## Run npm install over emitter-package.json in a temp folder to prime the npm cache
$tempFolder = New-TemporaryFile
$tempFolder | Remove-Item -Force
New-Item $tempFolder -ItemType Directory -Force | Out-Null

foreach ($directory in $directoriesWithErrors) {
Write-Host " $directory"
Push-Location $tempFolder
try {
Copy-Item "$RepoRoot/eng/emitter-package.json" "package.json"
if(Test-Path "$RepoRoot/eng/emitter-package-lock.json") {
Copy-Item "$RepoRoot/eng/emitter-package-lock.json" "package-lock.json"
Invoke-LoggedCommand "npm ci"
} else {
Invoke-LoggedCommand "npm install"
}
}
finally {
Pop-Location
$tempFolder | Remove-Item -Force -Recurse
}

exit 1
}
Write-Host "##[endgroup]"

# Generate projects
$showSummary = ($env:SYSTEM_DEBUG -eq 'true') -or ($VerbosePreference -ne 'SilentlyContinue')
$summaryArgs = $showSummary ? "/v:n /ds" : ""

Invoke-LoggedCommand "dotnet msbuild /restore /t:GenerateCode /p:ProjectListOverrideFile=$(Resolve-Path $projectListOverrideFile -Relative) $summaryArgs eng\service.proj" -GroupOutput
}
finally {
Pop-Location
}
}

0 comments on commit da3763a

Please sign in to comment.