-
Notifications
You must be signed in to change notification settings - Fork 69
/
build.ps1
60 lines (51 loc) · 1.77 KB
/
build.ps1
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
param (
[Parameter(Mandatory = $false)]
[switch] $with_logging = $false,
[ValidateSet("x86", "x64")]
[string[]]
$Arch = @("x86", "x64"),
[Parameter(Position = 0, Mandatory = $false, ValueFromRemainingArguments = $true)]
[string[]]
$ScriptArgs
)
$VERSION = "2.6.1"
function writeErrorTip($msg) {
Write-Host $msg -BackgroundColor Red -ForegroundColor White
}
[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"
$TOOLS_DIR = Join-Path $PSScriptRoot "tools"
$XMAKE_DIR = Join-Path $TOOLS_DIR "xmake"
if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) {
Write-Verbose -Message "Creating tools dir..."
New-Item -Path $TOOLS_DIR -ItemType "directory" | Out-Null
}
if (!(Test-Path $XMAKE_DIR)) {
$outfile = Join-Path $TOOLS_DIR "$pid-xmake.zip"
$x64arch = @('AMD64', 'IA64', 'ARM64')
$os_arch = if ($env:PROCESSOR_ARCHITECTURE -in $x64arch -or $env:PROCESSOR_ARCHITEW6432 -in $x64arch) { 'win64' } else { 'win32' }
$url = "https://github.com/xmake-io/xmake/releases/download/v$VERSION/xmake-v$VERSION.$os_arch.zip"
Write-Host "Downloading xmake ($os_arch) from $url..."
try {
Invoke-WebRequest $url -OutFile $outfile -UseBasicParsing
}
catch {
writeErrorTip "Download failed!"
throw
}
try {
Expand-Archive -Path $outfile -DestinationPath $TOOLS_DIR
}
catch {
writeErrorTip "Failed to extract!"
throw
}
finally {
Remove-Item -Path $outfile
}
}
$XMAKE_EXE = Join-Path $XMAKE_DIR "xmake.exe"
foreach ($a in $Arch) {
$verbose_opt = if ($with_logging) { "--include_logging=y" } else { "--include_logging=n" }
Invoke-Expression "& $XMAKE_EXE f -a $a $verbose_opt"
Invoke-Expression "& $XMAKE_EXE $($ScriptArgs -join " ")"
}