|
| 1 | +if ($args.Count -lt 1) { |
| 2 | + Write-Output "Usage: <premake>" |
| 3 | + exit 1 |
| 4 | +} |
| 5 | + |
| 6 | +$premakeVersion = $args[0] |
| 7 | + |
| 8 | +if ($PSVersionTable.PSVersion.Major -lt 6.0) { |
| 9 | + switch ($([System.Environment]::OSVersion.Platform)) { |
| 10 | + "Win32NT" { |
| 11 | + New-Variable -Option Constant -Name IsWindows -Value $True -ErrorAction SilentlyContinue |
| 12 | + New-Variable -Option Constant -Name IsLinux -Value $false -ErrorAction SilentlyContinue |
| 13 | + New-Variable -Option Constant -Name IsMacOs -Value $false -ErrorAction SilentlyContinue |
| 14 | + } |
| 15 | + } |
| 16 | +} |
| 17 | + |
| 18 | +$destination = "premake.zip" |
| 19 | +$premakeBinPath = "premake/premake5.exe" |
| 20 | +$premakePath = "premake" |
| 21 | + |
| 22 | +$currentPremakeVersion = "" |
| 23 | +if (Test-Path $premakeBinPath) { |
| 24 | + $currentPremakeVersion = ((& $premakeBinPath --version) -join "`n").Replace("premake5 (Premake Build Script Generator) ", "").Trim() |
| 25 | + if ($premakeVersionOutput -eq $premakeVersion) { |
| 26 | + exit |
| 27 | + } |
| 28 | + Write-Output "Premake dependency outdated: $currentPremakeVersion, expected: $premakeVersion" |
| 29 | + |
| 30 | + #------------------------------------------------- |
| 31 | + Write-Output "Deleting old Premake binary..." |
| 32 | + #------------------------------------------------- |
| 33 | + |
| 34 | + Remove-Item $premakeBinPath -ErrorAction Ignore |
| 35 | +} |
| 36 | + |
| 37 | +#------------------------------------------------- |
| 38 | +Write-Output "Locating 7-Zip" |
| 39 | +#------------------------------------------------- |
| 40 | + |
| 41 | +. $PSScriptRoot\7zip.ps1 |
| 42 | + |
| 43 | +#------------------------------------------------- |
| 44 | +Write-Output "Downloading Premake..." |
| 45 | +#------------------------------------------------- |
| 46 | + |
| 47 | +Add-Type -AssemblyName System.Web |
| 48 | +$premakeURLVersion = [uri]::EscapeUriString($premakeVersion) |
| 49 | + |
| 50 | +$source = "https://github.com/premake/premake-core/releases/download/v$premakeURLVersion/premake-$premakeURLVersion-windows.zip" |
| 51 | + |
| 52 | +# Net.WebClient is much faster than Invoke-WebRequest/Invoke-RestMethod |
| 53 | +(New-Object Net.WebClient).DownloadFile($source, $destination) |
| 54 | + |
| 55 | +#------------------------------------------------- |
| 56 | +Write-Output "Unpacking Premake..." |
| 57 | +#------------------------------------------------- |
| 58 | + |
| 59 | +# Only unpack the files we need |
| 60 | +& "$7z" x $destination premake5.exe -aoa -o"$premakePath" |
| 61 | + |
| 62 | +#------------------------------------------------- |
| 63 | +Write-Output "Doing cleanup..." |
| 64 | +#------------------------------------------------- |
| 65 | + |
| 66 | +Remove-Item $destination |
| 67 | + |
| 68 | +#------------------------------------------------- |
| 69 | +Write-Output "Premake download done!" |
0 commit comments