-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-libs.ps1
More file actions
129 lines (106 loc) · 3.87 KB
/
get-libs.ps1
File metadata and controls
129 lines (106 loc) · 3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
param(
[Parameter(Position = 0)]
[string]$SmeDepsVersion = "skip",
[Parameter(Position = 1)]
[string]$SmeDepsCommonVersion = "skip",
[Parameter(Position = 2)]
[string]$SmeDepsQtVersion = "skip",
[Parameter(Position = 3)]
[string]$SmeDepsLlvmVersion = "skip",
[Parameter(Position = 4)]
[string]$BuildTag = ""
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$ProgressPreference = "SilentlyContinue"
if ($env:RUNNER_OS -ne "Windows") {
throw "Unsupported runner combination: $($env:RUNNER_OS)/$($env:RUNNER_ARCH)"
}
switch ($env:RUNNER_ARCH) {
"X64" {
$os = "win64"
}
"ARM64" {
$os = "win64-arm64"
}
default {
throw "Unsupported runner combination: $($env:RUNNER_OS)/$($env:RUNNER_ARCH)"
}
}
$installPrefix = if ($env:INSTALL_PREFIX) { $env:INSTALL_PREFIX } else { "c:\smelibs" }
$installPrefix = $installPrefix.Replace("\", "/")
$haveFilesToInstall = $false
function Get-ReleaseUrl {
param(
[string]$Dep,
[string]$Version
)
if ($Version -eq "latest") {
return "https://github.com/spatial-model-editor/$Dep/releases/latest/download/${Dep}_${os}${BuildTag}.tgz"
}
return "https://github.com/spatial-model-editor/$Dep/releases/download/$Version/${Dep}_${os}${BuildTag}.tgz"
}
function Install-Dependency {
param(
[string]$Dep,
[string]$Version
)
if ($Version -eq "skip") {
Write-Host "Skipping $Dep download"
return
}
$archiveName = "${Dep}_${os}${BuildTag}.tgz"
$url = Get-ReleaseUrl -Dep $Dep -Version $Version
Write-Host "Downloading $Version $Dep$BuildTag for $os"
Invoke-WebRequest -Uri $url -OutFile $archiveName
tar -xf $archiveName
Remove-Item -Path $archiveName -Force
$script:haveFilesToInstall = $true
}
function Resolve-StagedInstallPath {
param(
[string]$InstallPrefix
)
$installPrefixWindows = $InstallPrefix.Replace("/", "\")
$candidates = [System.Collections.Generic.List[string]]::new()
if ($InstallPrefix -match "^[A-Za-z]:/") {
$driveLetter = $InstallPrefix.Substring(0, 1).ToLowerInvariant()
$rest = $InstallPrefix.Substring(3).Replace("/", "\")
if ($rest.Length -gt 0) {
$candidates.Add((Join-Path $PWD.Path (Join-Path $driveLetter $rest)))
}
}
$leaf = Split-Path -Leaf $installPrefixWindows
if ($leaf) {
$candidates.Add((Join-Path $PWD.Path $leaf))
}
$candidates.Add($installPrefixWindows)
foreach ($candidate in ($candidates | Select-Object -Unique)) {
if (Test-Path $candidate) {
return $candidate
}
}
throw "Could not find extracted install tree for $InstallPrefix after unpacking dependency archives"
}
Install-Dependency -Dep "sme_deps" -Version $SmeDepsVersion
Install-Dependency -Dep "sme_deps_common" -Version $SmeDepsCommonVersion
Install-Dependency -Dep "sme_deps_qt" -Version $SmeDepsQtVersion
Install-Dependency -Dep "sme_deps_llvm" -Version $SmeDepsLlvmVersion
if ($haveFilesToInstall) {
$installPrefixWindows = $installPrefix.Replace("/", "\")
$stagedInstallPath = Resolve-StagedInstallPath -InstallPrefix $installPrefix
$resolvedStagedInstallPath = (Resolve-Path $stagedInstallPath).Path
$installParent = Split-Path -Parent $installPrefixWindows
if ($installParent) {
New-Item -ItemType Directory -Force -Path $installParent | Out-Null
}
if (Test-Path $installPrefixWindows) {
$resolvedInstallPrefix = (Resolve-Path $installPrefixWindows).Path
if (-not [string]::Equals($resolvedInstallPrefix, $resolvedStagedInstallPath, [System.StringComparison]::OrdinalIgnoreCase)) {
Remove-Item -Path $installPrefixWindows -Recurse -Force
}
}
if (-not (Test-Path $installPrefixWindows)) {
Move-Item -Path $stagedInstallPath -Destination $installPrefixWindows
}
}