feat(runtime): prepare safe context checkpoints
This commit is contained in:
@@ -183,6 +183,91 @@ function Assert-TemporaryChildWithoutReparsePoint {
|
||||
return $target
|
||||
}
|
||||
|
||||
function Import-VisualStudioBuildEnvironment {
|
||||
$originalPath = $env:Path
|
||||
$programFilesX86 = [Environment]::GetFolderPath(
|
||||
[Environment+SpecialFolder]::ProgramFilesX86
|
||||
)
|
||||
$vswherePath = Join-Path `
|
||||
-Path $programFilesX86 `
|
||||
-ChildPath "Microsoft Visual Studio\Installer\vswhere.exe"
|
||||
if (-not (Test-Path -LiteralPath $vswherePath -PathType Leaf)) {
|
||||
throw "Visual Studio Installer's vswhere.exe was not found. Install Microsoft C++ Build Tools."
|
||||
}
|
||||
|
||||
$installationPath = (
|
||||
& $vswherePath `
|
||||
-latest `
|
||||
-products "*" `
|
||||
-requires "Microsoft.VisualStudio.Component.VC.Tools.x86.x64" `
|
||||
-property installationPath
|
||||
).Trim()
|
||||
if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($installationPath)) {
|
||||
throw "Microsoft C++ Build Tools were not found."
|
||||
}
|
||||
|
||||
$devCommandPath = Join-Path `
|
||||
-Path $installationPath `
|
||||
-ChildPath "Common7\Tools\VsDevCmd.bat"
|
||||
if (-not (Test-Path -LiteralPath $devCommandPath -PathType Leaf)) {
|
||||
throw "VsDevCmd.bat was not found in the selected Visual Studio installation."
|
||||
}
|
||||
|
||||
$commandLine = 'call "' + $devCommandPath + '" -arch=x64 -host_arch=x64 >nul && set'
|
||||
$environmentLines = @(& $env:ComSpec /d /c $commandLine)
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "Visual Studio x64 developer environment initialization failed."
|
||||
}
|
||||
|
||||
$developerPath = $null
|
||||
foreach ($line in $environmentLines) {
|
||||
$separator = $line.IndexOf("=")
|
||||
if ($separator -le 0) {
|
||||
continue
|
||||
}
|
||||
if ($line.StartsWith("PATH=", [System.StringComparison]::Ordinal)) {
|
||||
$developerPath = $line.Substring($separator + 1)
|
||||
continue
|
||||
}
|
||||
[Environment]::SetEnvironmentVariable(
|
||||
$line.Substring(0, $separator),
|
||||
$line.Substring($separator + 1),
|
||||
"Process"
|
||||
)
|
||||
}
|
||||
if ([string]::IsNullOrWhiteSpace($developerPath)) {
|
||||
throw "Visual Studio did not publish a developer PATH."
|
||||
}
|
||||
$pathSegments = @($developerPath)
|
||||
$userProfilePath = $env:USERPROFILE
|
||||
if ([string]::IsNullOrWhiteSpace($userProfilePath)) {
|
||||
$userProfilePath = [Environment]::GetFolderPath(
|
||||
[Environment+SpecialFolder]::UserProfile
|
||||
)
|
||||
}
|
||||
$cargoBinPath = Join-Path `
|
||||
-Path $userProfilePath `
|
||||
-ChildPath ".cargo\bin"
|
||||
if (Test-Path -LiteralPath (Join-Path -Path $cargoBinPath -ChildPath "rustup.exe") -PathType Leaf) {
|
||||
$pathSegments += $cargoBinPath
|
||||
}
|
||||
$pathSegments += $originalPath
|
||||
$env:Path = $pathSegments -join [System.IO.Path]::PathSeparator
|
||||
|
||||
foreach ($requiredTool in @("cl.exe", "link.exe", "rc.exe")) {
|
||||
$tool = Get-Command `
|
||||
-Name $requiredTool `
|
||||
-CommandType Application `
|
||||
-ErrorAction SilentlyContinue |
|
||||
Select-Object -First 1
|
||||
if ($null -eq $tool) {
|
||||
throw "$requiredTool was not found after loading Visual Studio Build Tools and the Windows SDK."
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host ("[ok] Visual Studio x64 C++ Build Tools and Windows SDK from {0}" -f $installationPath)
|
||||
}
|
||||
|
||||
if ($Demo -and -not $Launch) {
|
||||
throw "-Demo is only valid together with -Launch."
|
||||
}
|
||||
@@ -193,6 +278,8 @@ if (-not $Launch -and -not [string]::IsNullOrWhiteSpace($SmokeDataPath)) {
|
||||
throw "-SmokeDataPath is only valid together with -Launch."
|
||||
}
|
||||
|
||||
Import-VisualStudioBuildEnvironment
|
||||
|
||||
$projectRoot = [System.IO.Path]::GetFullPath((Join-Path -Path $PSScriptRoot -ChildPath ".."))
|
||||
$packageJsonPath = Join-Path -Path $projectRoot -ChildPath "package.json"
|
||||
$lappLockPath = Join-Path -Path $projectRoot -ChildPath "lapp-rs.lock"
|
||||
@@ -372,8 +459,9 @@ if (-not [string]::IsNullOrWhiteSpace($lappWorkTreeStatus)) {
|
||||
}
|
||||
Write-Host ("[ok] lapp-rs matches {0}" -f $expectedLappCommit.Substring(0, 12))
|
||||
|
||||
# Keep all automated gates deterministic and noninteractive. No environment
|
||||
# variables are enumerated or printed.
|
||||
# Keep all automated gates deterministic and noninteractive. Visual Studio's
|
||||
# developer shell is imported into this process; environment values are never
|
||||
# printed or persisted by this script.
|
||||
$env:CI = "true"
|
||||
$env:NO_COLOR = "1"
|
||||
$env:CARGO_TERM_COLOR = "never"
|
||||
|
||||
Reference in New Issue
Block a user