-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[8.0.4xx] Use dotnetup preview for SDK acquisition #55644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nagilson
wants to merge
1
commit into
dotnet:release/8.0.4xx
Choose a base branch
from
nagilson:nagilson/dotnetup-preview-release-8.0.4xx
base: release/8.0.4xx
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| # Shared helpers for acquiring dotnetup, dot-sourced by both | ||
| # eng/configure-toolset.ps1 (bootstrap SDK install) and eng/restore-toolset.ps1 | ||
| # (test runtime install). This file only defines functions; it has no top-level | ||
| # side effects so it is safe to dot-source multiple times. | ||
|
|
||
| # General SDK build helpers (Get-NativeMachineArchitecture, etc.). | ||
| . (Join-Path $PSScriptRoot 'sdk-tools.ps1') | ||
|
|
||
| # Returns $true when an already-downloaded dotnetup binary at $DotnetupExe is | ||
| # recent enough (<24h old) and its architecture matches the native machine, so the | ||
| # download can be skipped. Returns $false when dotnetup should be (re)downloaded. | ||
| function Test-ShouldUseCachedDotnetup([string]$DotnetupExe) { | ||
| if (-not (Test-Path $DotnetupExe)) { | ||
| return $false | ||
| } | ||
|
|
||
| # Re-download dotnetup at most once every 24 hours to avoid unnecessary network calls. | ||
| $age = (Get-Date) - (Get-Item $DotnetupExe).LastWriteTime | ||
| if ($age.TotalHours -ge 24) { | ||
| return $false | ||
| } | ||
| Write-Host "dotnetup binary is less than 24 hours old; skipping re-download." -ForegroundColor DarkGray | ||
|
|
||
| # dotnetup installs runtimes for its own process architecture, so a cached | ||
| # binary downloaded under emulation (process arch != native arch) would install | ||
| # the wrong runtimes. Re-download when the architectures differ. | ||
| if ((Get-NativeMachineArchitecture) -ne (Get-ProcessMachineArchitecture)) { | ||
| Write-Host "Native architecture differs from process architecture; re-downloading dotnetup for the native architecture." -ForegroundColor DarkGray | ||
| return $false | ||
| } | ||
|
|
||
| return $true | ||
| } | ||
|
|
||
| # Runs a PowerShell script in a SEPARATE PowerShell process so that an 'exit' | ||
| # inside it cannot terminate this build host and bypass the caller's try/catch. | ||
| # Uses the current host's own executable to keep pwsh / Windows PowerShell 5.1 | ||
| # parity. Throws on non-zero exit code. | ||
| function Invoke-GetDotnetupScript([string]$ScriptPath, [string]$InstallDir, [string]$ErrorLabel) { | ||
| $psExe = (Get-Process -Id $PID).Path | ||
| if (-not $psExe) { | ||
| $psExeName = if ($PSVersionTable.PSEdition -eq 'Core') { 'pwsh' } else { 'powershell' } | ||
| $psExe = Join-Path $PSHOME $psExeName | ||
| } | ||
| if (-not (Test-Path Variable:LASTEXITCODE)) { $global:LASTEXITCODE = 0 } | ||
|
|
||
| # Temporarily set ErrorActionPreference to Continue so that stderr output | ||
| # from the child process does not become a terminating error (the parent | ||
| # shell inherits 'Stop' from eng/common/tools.ps1). We rely on | ||
| # $LASTEXITCODE for error detection instead. | ||
| $prevEAP = $ErrorActionPreference | ||
| try { | ||
| $ErrorActionPreference = 'Continue' | ||
| & $psExe -NoProfile -ExecutionPolicy Bypass -File $ScriptPath -InstallDir $InstallDir | ||
| } | ||
| finally { | ||
| $ErrorActionPreference = $prevEAP | ||
| } | ||
|
|
||
| if ($LASTEXITCODE -ne 0) { throw "$ErrorLabel exited with code $LASTEXITCODE." } | ||
| } | ||
|
|
||
| # Invokes a native command (e.g. the dotnetup executable) | ||
| # Returns that process exit code WITHOUT letting a non-zero exit become a terminating error. | ||
| # (This covers against $ErrorActionPreference and $PSNativeCommandUseErrorActionPreference) | ||
| function Invoke-DotnetupNativeCommand([scriptblock]$Command) { | ||
| if (-not (Test-Path Variable:LASTEXITCODE)) { $global:LASTEXITCODE = 0 } | ||
| $ErrorActionPreference = 'Continue' | ||
| $PSNativeCommandUseErrorActionPreference = $false | ||
| try { | ||
| # Write command output to the host and prevent it from being returned alongside the exit code | ||
| & $Command | Out-Host | ||
| return $LASTEXITCODE | ||
| } | ||
| catch { | ||
| Write-Host "dotnetup command failed: $($_.Exception.Message)" -ForegroundColor Yellow | ||
| if ($LASTEXITCODE -ne 0) { return $LASTEXITCODE } | ||
| return 1 | ||
| } | ||
| } | ||
|
|
||
| # Downloads the public dotnetup installer from aka.ms | ||
| # (https://aka.ms/dotnet/dotnetup/daily/get-dotnetup.ps1) and runs it to install dotnetup into | ||
| # $DotnetupDir. Throws on failure so callers can choose how to react. | ||
| # | ||
| # If a local get-dotnetup.ps1 script exists in the repo (scripts/get-dotnetup.ps1), | ||
| # it is used directly instead of downloading from aka.ms. This supports branches | ||
| # (e.g. release/dnup) that carry the script locally and avoids merge conflicts | ||
| # when code flows between branches with and without the local script. | ||
| function Install-DotnetupFromAkaMs([string]$DotnetupDir) { | ||
| $repoRoot = (Get-Item $PSScriptRoot).Parent.FullName | ||
| $localGetter = Join-Path (Join-Path $repoRoot 'scripts') 'get-dotnetup.ps1' | ||
|
|
||
| # Prefer the repo-local script when available (e.g. on release/dnup). | ||
| if (Test-Path $localGetter) { | ||
| Write-Host "Using local get-dotnetup.ps1 from '$localGetter'." -ForegroundColor DarkGray | ||
| Invoke-GetDotnetupScript -ScriptPath $localGetter -InstallDir $DotnetupDir -ErrorLabel "Local get-dotnetup.ps1" | ||
| return | ||
| } | ||
|
|
||
| $getterUrl = 'https://aka.ms/dotnet/dotnetup/daily/get-dotnetup.ps1' | ||
| $getterScript = Join-Path ([System.IO.Path]::GetTempPath()) ("get-dotnetup-{0}.ps1" -f [System.IO.Path]::GetRandomFileName()) | ||
|
|
||
| # Download the installer with retry/backoff. Invoke-WebRequest's built-in | ||
| # -MaximumRetryCount is unavailable on Windows PowerShell 5.1, so retry manually. | ||
| $maxAttempts = 3 | ||
| for ($attempt = 1; $true; $attempt++) { | ||
| try { | ||
| Invoke-WebRequest -Uri $getterUrl -OutFile $getterScript -UseBasicParsing | ||
| break | ||
| } | ||
| catch { | ||
| if ($attempt -ge $maxAttempts) { | ||
| throw "Failed to download dotnetup installer from $getterUrl after $maxAttempts attempts: $($_.Exception.Message)" | ||
| } | ||
| $delaySeconds = [Math]::Pow(2, $attempt) | ||
| Write-Host "Download of dotnetup installer failed (attempt $attempt of $maxAttempts): $($_.Exception.Message). Retrying in $delaySeconds seconds..." -ForegroundColor Yellow | ||
| Start-Sleep -Seconds $delaySeconds | ||
| } | ||
| } | ||
|
|
||
| try { | ||
| Invoke-GetDotnetupScript -ScriptPath $getterScript -InstallDir $DotnetupDir -ErrorLabel "get-dotnetup.ps1" | ||
| } | ||
| finally { | ||
| Remove-Item $getterScript -Force -ErrorAction SilentlyContinue | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.