forked from ferronweb/ferron
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ps1
More file actions
192 lines (166 loc) · 5.12 KB
/
build.ps1
File metadata and controls
192 lines (166 loc) · 5.12 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# Get version from Cargo.toml
$ferronVersionCargo = Select-String -Path "ferron/Cargo.toml" -Pattern '^version' | ForEach-Object {
if ($_ -match '"([0-9a-zA-Z.+-]+)"')
{
$matches[1]
}
}
# Get version from latest git tag
$ferronVersionGit = git tag --sort=-committerdate | Select-Object -First 1 | ForEach-Object {
$_ -replace '[^0-9a-zA-Z.+-]', ''
}
# Use Cargo version if available, otherwise fallback to git version
$ferronVersion = if ($ferronVersionCargo)
{ $ferronVersionCargo
} else
{ $ferronVersionGit
}
# Get host target triple
$hostTargetTriple = rustc -vV | Where-Object { $_ -match '^host: ' } | ForEach-Object { $_ -replace 'host: ', '' }
# Check if $env:TARGET is set
if ($env:TARGET)
{
$cargoFinalExtraArgs = "--target $env:TARGET"
$cargoTargetRoot = "target/$env:TARGET"
$destTargetTriple = $env:TARGET
$buildRelease = "build/release-$env:TARGET"
} else
{
$cargoFinalExtraArgs = ""
$cargoTargetRoot = "target"
$destTargetTriple = $hostTargetTriple
$buildRelease = "build/release"
}
# Append extra arguments if set
if ($env:CARGO_FINAL_EXTRA_ARGS)
{
$cargoFinalExtraArgs = "$cargoFinalExtraArgs $env:CARGO_FINAL_EXTRA_ARGS"
}
if ($env:NO_MONOIO)
{
$cargoFinalExtraArgs = "--no-default-features -F ferron/runtime-tokio $cargoFinalExtraArgs"
}
# Split the arguments (to avoid being interpreted as one large argument)
$cargoFinalExtraArgs = $cargoFinalExtraArgs -Split ' '
# Set cargo executable if not set
if (-not $env:CARGO_FINAL)
{
$cargoFinal = "cargo"
} else
{
$cargoFinal = $env:CARGO_FINAL
}
function Run
{
Build
if (-not (Test-Path "ferron.kdl"))
{
Copy-Item "configs/ferron.test.kdl" "ferron.kdl" -ErrorAction SilentlyContinue -Force
}
& "$cargoTargetRoot/release/ferron"
}
function RunDev
{
BuildDev
if (-not (Test-Path "ferron.kdl"))
{
Copy-Item "configs/ferron.test.kdl" "ferron.kdl" -ErrorAction SilentlyContinue -Force
}
& "$cargoTargetRoot/debug/ferron"
}
function Smoketest
{
Build
$env:FERRON = $PWD.Path + '\' + $cargoTargetRoot + '\release\ferron'
& powershell.exe -ExecutionPolicy Bypass ".\smoketest\smoketest.ps1"
}
function SmoketestDev
{
BuildDev
$env:FERRON = $PWD.Path + '\' + $cargoTargetRoot + '\debug\ferron'
& powershell.exe -ExecutionPolicy Bypass ".\smoketest\smoketest.ps1"
}
function Build
{
PrepareBuild
FixConflicts
Push-Location build/workspace
& $cargoFinal build --target-dir ../../target -r $cargoFinalExtraArgs
Pop-Location
}
function BuildDev
{
PrepareBuild
FixConflicts
Push-Location build/workspace
& $cargoFinal build --target-dir ../../target $cargoFinalExtraArgs
Pop-Location
}
function PrepareBuild
{
& cargo run --manifest-path build/prepare/Cargo.toml
}
function FixConflicts
{
Push-Location build/workspace
while (($oldConflictingPackages -ne $conflictingPackages) -or (-not $oldConflictingPackages))
{
$oldConflictingPackages = $conflictingPackages
$conflictingPackages = (cargo update -w --dry-run 2>&1) | Select-String -Pattern '^error: failed to select a version for (?:the requirement )?`([^ `]+)' | ForEach-Object { $_.Matches.Groups[1].Value }
$conflictingPackages = $conflictingPackages -Split ' '
if (-not $conflictingPackages)
{ break
}
if ($oldConflictingPackages -eq $conflictingPackages)
{ throw "Couldn't resolve Cargo conflicts"
}
if ($conflictingPackages)
{ & cargo update $conflictingPackages
}
}
Pop-Location
}
function Package
{
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue $buildRelease
New-Item -ItemType Directory -Path $buildRelease | Out-Null
Get-ChildItem "$cargoTargetRoot/release" -File |
Where-Object { !$_.Name.Contains('.') -or $_.Extension -in ".exe", ".dll", ".dylib", ".so" } |
ForEach-Object {
Copy-Item -Path $_.FullName -Destination $buildRelease -Force
}
Copy-Item configs/ferron.release.kdl "$buildRelease/ferron.kdl" -Force
Copy-Item wwwroot -Destination $buildRelease -Recurse -Force
if (-not (Test-Path "dist"))
{ New-Item -ItemType Directory -Path "dist" | Out-Null
}
if (Test-Path "dist/ferron-$ferronVersion-$destTargetTriple.zip")
{ Remove-Item -Recurse -Force -ErrorAction SilentlyContinue "dist/ferron-$ferronVersion-$destTargetTriple.zip"
}
Compress-Archive -Path "$buildRelease\*" -DestinationPath "dist/ferron-$ferronVersion-$destTargetTriple.zip"
Remove-Item -Recurse -Force $buildRelease
}
function BuildWithPackage
{
Build
Package
}
function Installer
{
& cargo run --manifest-path build/installer/Cargo.toml
}
function Clean
{
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue build/workspace, build/release, dist, packaging/deb/ferron_* packaging/deb/md5sums.tmp
& cargo clean
Push-Location build/prepare
& cargo clean
Pop-Location
}
if ($args.Count -gt 0)
{
& $args[0]
} else
{
Write-Host "Available commands: Run, RunDev, Build, BuildDev, Smoketest, SmoketestDev, PrepareBuild, FixConflicts, Package, BuildWithPackage, Installer, Clean"
}