Skip to content

Commit da3763a

Browse files
authored
Use projectListOverrideFile for preview generation (Azure#39614)
1 parent f8de740 commit da3763a

File tree

1 file changed

+62
-24
lines changed

1 file changed

+62
-24
lines changed

eng/scripts/Language-Settings.ps1

Lines changed: 62 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -588,42 +588,80 @@ function Get-dotnet-EmitterAdditionalOptions([string]$projectDirectory) {
588588
}
589589

590590
function Update-dotnet-GeneratedSdks([string]$PackageDirectoriesFile) {
591-
$showSummary = ($env:SYSTEM_DEBUG -eq 'true') -or ($VerbosePreference -ne 'SilentlyContinue')
592-
$summaryArgs = $showSummary ? "/v:n /ds" : ""
593-
594-
$packageDirectories = Get-Content $PackageDirectoriesFile | ConvertFrom-Json
591+
Push-Location $RepoRoot
592+
try {
593+
Write-Host "`n`n======================================================================"
594+
Write-Host "Generating projects" -ForegroundColor Yellow
595+
Write-Host "======================================================================`n"
595596

596-
$directoriesWithErrors = @()
597+
$packageDirectories = Get-Content $PackageDirectoriesFile | ConvertFrom-Json
597598

598-
Invoke-LoggedCommand "npm install -g autorest"
599+
# Build the project list override file
599600

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

607-
Invoke-LoggedCommand "dotnet msbuild /restore /t:GenerateCode /p:Scope=`"$directory`" $summaryArgs eng\service.proj" -GroupOutput
603+
foreach ($directory in $packageDirectories) {
604+
$projects = Get-ChildItem -Path "$RepoRoot/sdk/$directory" -Filter "*.csproj" -Recurse
605+
foreach ($project in $projects) {
606+
$lines += " <ProjectReference Include=`"$($project.FullName)`" />"
607+
}
608608
}
609-
catch {
610-
Write-Host "##[error]Error generating project under directory $directory"
611-
Write-Host $_.Exception.Message
612-
$directoriesWithErrors += $directory
609+
610+
$lines += ' </ItemGroup>', '</Project>'
611+
$artifactsPath = Join-Path $RepoRoot "artifacts"
612+
$projectListOverrideFile = Join-Path $artifactsPath "GeneratedSdks.proj"
613+
614+
Write-Host "Creating project list override file $projectListOverrideFile`:"
615+
$lines | ForEach-Object { " $_" } | Out-Host
616+
617+
New-Item $artifactsPath -ItemType Directory -Force | Out-Null
618+
$lines | Out-File $projectListOverrideFile -Encoding UTF8
619+
Write-Host "`n"
620+
621+
# Initialize npm and npx cache
622+
Write-Host "##[group]Initializing npm and npx cache"
623+
624+
## Generate code in sdk/template to prime the npx and npm cache
625+
Push-Location "$RepoRoot/sdk/template/Azure.Template/src"
626+
try {
627+
Write-Host "Building then resetting sdk/template/Azure.Template/src"
628+
Invoke-LoggedCommand "dotnet build /t:GenerateCode"
629+
Invoke-LoggedCommand "git restore ."
630+
Invoke-LoggedCommand "git clean . --force"
613631
}
614632
finally {
615633
Pop-Location
616634
}
617-
}
618635

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

622-
foreach ($directory in $directoriesWithErrors) {
623-
Write-Host " $directory"
641+
Push-Location $tempFolder
642+
try {
643+
Copy-Item "$RepoRoot/eng/emitter-package.json" "package.json"
644+
if(Test-Path "$RepoRoot/eng/emitter-package-lock.json") {
645+
Copy-Item "$RepoRoot/eng/emitter-package-lock.json" "package-lock.json"
646+
Invoke-LoggedCommand "npm ci"
647+
} else {
648+
Invoke-LoggedCommand "npm install"
649+
}
650+
}
651+
finally {
652+
Pop-Location
653+
$tempFolder | Remove-Item -Force -Recurse
624654
}
625655

626-
exit 1
627-
}
656+
Write-Host "##[endgroup]"
657+
658+
# Generate projects
659+
$showSummary = ($env:SYSTEM_DEBUG -eq 'true') -or ($VerbosePreference -ne 'SilentlyContinue')
660+
$summaryArgs = $showSummary ? "/v:n /ds" : ""
628661

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

0 commit comments

Comments
 (0)