[Windows] Remove RustJunction.ps1 post-generation script (#4635)

* Remove RustJunction.ps1 post-generation script
* update rust tests
This commit is contained in:
Aleksandr Chebotov
2021-12-14 18:08:46 +03:00
committed by GitHub
parent 573c5aa999
commit 44d41e873b
3 changed files with 20 additions and 53 deletions

View File

@@ -1,12 +0,0 @@
# Create Rust junction points to cargo and rustup folder
$cargoTarget = "$env:USERPROFILE\.cargo"
if (-not (Test-Path $cargoTarget))
{
New-Item -ItemType Junction -Path $cargoTarget -Target "C:\Rust\.cargo"
}
$rustupTarget = "$env:USERPROFILE\.rustup"
if (-not (Test-Path $rustupTarget))
{
New-Item -ItemType Junction -Path $rustupTarget -Target "C:\Rust\.rustup"
}

View File

@@ -4,8 +4,8 @@
################################################################################ ################################################################################
# Rust Env # Rust Env
$env:RUSTUP_HOME = "C:\Rust\.rustup" $env:RUSTUP_HOME = "C:\Users\Default\.rustup"
$env:CARGO_HOME = "C:\Rust\.cargo" $env:CARGO_HOME = "C:\Users\Default\.cargo"
# Download the latest rustup-init.exe for Windows x64 # Download the latest rustup-init.exe for Windows x64
# See https://rustup.rs/# # See https://rustup.rs/#
@@ -14,43 +14,16 @@ $rustupPath = Start-DownloadWithRetry -Url "https://win.rustup.rs/x86_64" -Name
# Install Rust by running rustup-init.exe (disabling the confirmation prompt with -y) # Install Rust by running rustup-init.exe (disabling the confirmation prompt with -y)
& $rustupPath -y --default-toolchain=stable --profile=minimal & $rustupPath -y --default-toolchain=stable --profile=minimal
# Add %USERPROFILE%\.cargo\bin to USER PATH
Add-DefaultPathItem "%USERPROFILE%\.cargo\bin"
# Add Rust binaries to the path # Add Rust binaries to the path
Add-MachinePathItem "$env:CARGO_HOME\bin" $env:Path += ";$env:CARGO_HOME\bin"
$env:Path = Get-MachinePath
# Install common tools # Install common tools
rustup component add rustfmt clippy rustup component add rustfmt clippy
cargo install --locked bindgen cbindgen cargo-audit cargo-outdated cargo install --locked bindgen cbindgen cargo-audit cargo-outdated
# Run script at startup for all users
$cmdRustSymScript = @"
@echo off
if exist $env:CARGO_HOME (
if not exist %USERPROFILE%\.cargo (
mklink /J %USERPROFILE%\.cargo $env:CARGO_HOME
)
)
if exist $env:RUSTUP_HOME (
if not exist %USERPROFILE%\.rustup (
mklink /J %USERPROFILE%\.rustup $env:RUSTUP_HOME
)
)
"@
$cmdPath = "C:\Rust\rustsym.bat"
$cmdRustSymScript | Out-File -Encoding ascii -FilePath $cmdPath
# Cleanup Cargo crates cache # Cleanup Cargo crates cache
Remove-Item "${env:CARGO_HOME}\registry\*" -Recurse -Force Remove-Item "${env:CARGO_HOME}\registry\*" -Recurse -Force
# Update Run key to run a script at logon Invoke-PesterTests -TestFile "Rust"
Set-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Run" -Name "RUSTSYM" -Value $cmdPath
# Create temporary symlinks to properly validate tools version
Set-Location -Path $env:UserProfile
$null = New-Item -Name ".rustup" -Value $env:RUSTUP_HOME -ItemType Junction
$null = New-Item -Name ".cargo" -Value $env:CARGO_HOME -ItemType Junction
Invoke-PesterTests -TestFile "Rust"

View File

@@ -1,10 +1,16 @@
Describe "Rust" { Describe "Rust" {
BeforeAll {
$env:RUSTUP_HOME = "C:\Users\Default\.rustup"
$env:CARGO_HOME = "C:\Users\Default\.cargo"
$env:Path += ";$env:CARGO_HOME\bin"
}
$rustTools = @( $rustTools = @(
@{ToolName = "rustup"; binPath = "C:\Rust\.cargo\bin\rustup.exe"} @{ToolName = "rustup"; binPath = "C:\Users\Default\.cargo\bin\rustup.exe"}
@{ToolName = "rustc"; binPath = "C:\Rust\.cargo\bin\rustc.exe"} @{ToolName = "rustc"; binPath = "C:\Users\Default\.cargo\bin\rustc.exe"}
@{ToolName = "cargo"; binPath = "C:\Rust\.cargo\bin\cargo.exe"} @{ToolName = "cargo"; binPath = "C:\Users\Default\.cargo\bin\cargo.exe"}
@{ToolName = "cargo audit"; binPath = "C:\Rust\.cargo\bin\cargo-audit.exe"} @{ToolName = "cargo audit"; binPath = "C:\Users\Default\.cargo\bin\cargo-audit.exe"}
@{ToolName = "cargo outdated"; binPath = "C:\Rust\.cargo\bin\cargo-outdated.exe"} @{ToolName = "cargo outdated"; binPath = "C:\Users\Default\.cargo\bin\cargo-outdated.exe"}
) )
$rustEnvNotExists = @( $rustEnvNotExists = @(
@@ -12,8 +18,8 @@ Describe "Rust" {
@{envVar = "CARGO_HOME"} @{envVar = "CARGO_HOME"}
) )
It "C:\Rust\.rustup and C:\Rust\.cargo folders exist" { It "C:\Users\Default\.rustup and C:\Users\Default\.cargo folders exist" {
"C:\Rust\.rustup", "C:\Rust\.cargo" | Should -Exist "C:\Users\Default\.rustup", "C:\Users\Default\.cargo" | Should -Exist
} }
It "<envVar> environment variable does not exist" -TestCases $rustEnvNotExists { It "<envVar> environment variable does not exist" -TestCases $rustEnvNotExists {
@@ -24,4 +30,4 @@ Describe "Rust" {
"$ToolName --version" | Should -ReturnZeroExitCode "$ToolName --version" | Should -ReturnZeroExitCode
$binPath | Should -Exist $binPath | Should -Exist
} }
} }