diff options
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/build_llvm_mc.ps1 | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/scripts/build_llvm_mc.ps1 b/scripts/build_llvm_mc.ps1 index e028fd9de..3d4d8044a 100644 --- a/scripts/build_llvm_mc.ps1 +++ b/scripts/build_llvm_mc.ps1 | |||
| @@ -49,8 +49,29 @@ if (-not ((Test-Path $cmake) -and (Test-Path $ninja))) { | |||
| 49 | 49 | ||
| 50 | $src = Join-Path $Temp "src" | 50 | $src = Join-Path $Temp "src" |
| 51 | $out = Join-Path $Temp "build" | 51 | $out = Join-Path $Temp "build" |
| 52 | function Remove-DirectoryRobust([string]$path) { | ||
| 53 | if (-not (Test-Path -LiteralPath $path)) { return } | ||
| 54 | # Strip read-only attributes on nested files and folders so Windows allows deletion | ||
| 55 | Get-ChildItem -LiteralPath $path -Recurse -Force -ErrorAction SilentlyContinue | ForEach-Object { | ||
| 56 | try { | ||
| 57 | if ($_.Attributes -band [System.IO.FileAttributes]::ReadOnly) { | ||
| 58 | $_.Attributes = $_.Attributes -bxor [System.IO.FileAttributes]::ReadOnly | ||
| 59 | } | ||
| 60 | } catch {} | ||
| 61 | } | ||
| 62 | for ($attempt = 1; $attempt -le 3; $attempt++) { | ||
| 63 | try { | ||
| 64 | Remove-Item -LiteralPath $path -Recurse -Force -ErrorAction Stop | ||
| 65 | return | ||
| 66 | } catch { | ||
| 67 | Start-Sleep -Milliseconds (100 * $attempt) | ||
| 68 | } | ||
| 69 | } | ||
| 70 | cmd.exe /c "rmdir /s /q `"$path`"" 2>$null | ||
| 71 | } | ||
| 72 | |||
| 52 | if (-not (Test-Path (Join-Path $src "llvm\CMakeLists.txt"))) { | 73 | if (-not (Test-Path (Join-Path $src "llvm\CMakeLists.txt"))) { |
| 53 | if (Test-Path $src) { Remove-Item -Recurse -Force $src } | 74 | if (Test-Path -LiteralPath $src) { Remove-DirectoryRobust $src } |
| 54 | New-Item -ItemType Directory -Force $Temp | Out-Null | 75 | New-Item -ItemType Directory -Force $Temp | Out-Null |
| 55 | # core.longpaths: some llvm/docs paths are about 150 characters, so with a -Temp of about 100 characters the | 76 | # core.longpaths: some llvm/docs paths are about 150 characters, so with a -Temp of about 100 characters the |
| 56 | # sparse checkout fails with "Filename too long" (Windows' 260-character limit). Set in the clone's config only. | 77 | # sparse checkout fails with "Filename too long" (Windows' 260-character limit). Set in the clone's config only. |
| @@ -125,10 +146,9 @@ New-Item -ItemType Directory -Force $Dest | Out-Null | |||
| 125 | $final = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath((Join-Path $Dest "llvm-mc.exe")) | 146 | $final = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath((Join-Path $Dest "llvm-mc.exe")) |
| 126 | Copy-Item -Force $exe $final | 147 | Copy-Item -Force $exe $final |
| 127 | if (-not $Keep) { | 148 | if (-not $Keep) { |
| 128 | try { | 149 | Remove-DirectoryRobust $Temp |
| 129 | Remove-Item -LiteralPath $Temp -Recurse -Force | 150 | if (Test-Path -LiteralPath $Temp) { |
| 130 | } catch { | 151 | Write-Warning "Installed $final, but cleanup of '$Temp' failed." |
| 131 | Write-Warning "Installed $final, but cleanup of '$Temp' failed: $($_.Exception.Message)" | ||
| 132 | } | 152 | } |
| 133 | } | 153 | } |
| 134 | if (-not $NoEnv) { | 154 | if (-not $NoEnv) { |