forked from DSharpPlus/DSharpPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrebuild-linux.ps1
279 lines (244 loc) · 7.77 KB
/
rebuild-linux.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
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#!/usr/bin/env pwsh
# Rebuild-Linux
#
# A sub-script of Rebuild-Lib, which handles building the library under Linux.
#
# Author: Emzi0767
# Version: 2018-08-30 13:39
#
# Arguments:
# .\rebuild-linux.ps1 <output path> [version suffix] [-configuration Debug/Release] [-mono /path/to/mono]
#
# Run as:
# .\rebuild-linux.ps1 "..\dsp-artifacts"
#
# Or:
# .\rebuild-linux.ps1 "..\dsp-artifacts" ci 00420
#
# Or:
# .\rebuild-linux.ps1 "..\dsp-artifacts" -configuration Debug
#
# Or:
# .\rebuild-linux.ps1 "..\dsp-artifacts" -mono /usr/local/bin/mono
param
(
[parameter(Mandatory = $true)]
[string] $ArtifactLocation,
[parameter(Mandatory = $true)]
[string] $Configuration,
[parameter(Mandatory = $false)]
[string] $VersionSuffix,
[parameter(Mandatory = $false)]
[string] $BuildNumber,
[parameter(Mandatory = $false)]
[string] $Mono
)
# Projects excluded from FX build
$fx_excluded = @("DSharpPlus.WebSocket.WebSocket4NetCore")
$fc_excluded = "DSharpPlus.WebSocket.WebSocket4Net","DSharpPlus.WebSocket.WebSocketSharp"
$al_excluded = @("DSharpPlus.Test")
# Check if configuration is valid
if ($Configuration -ne "Debug" -and $Configuration -ne "Release")
{
Write-Host "Invalid configuration specified. Must be Release or Debug."
Exit 1
}
# Gets framework base path
function Get-FxBasePath([string] $mono_location)
{
# Check if mono location was passed
$mono = $mono_location
if ("$mono" -eq "")
{
Write-Host "Mono location not specified, attempting autodetection"
try
{
$mono = Get-Command "mono"
$mono = $mono.Source
}
catch
{
Write-Host "Mono autodetection failed"
Return 1
}
}
# Check if we found anything
if ("$mono" -eq "")
{
Write-Host "Mono was not found on this system. Ensure you have mono installed, and that it's in your path. If the path was supplied manually, ensure that it is correct."
Return 1
}
# Check if it's indeed mono, and which version
try
{
$mono_out = & $mono -V
if ("$mono_out" -eq "")
{
Write-Host "Your installation of mono failed to produce any output. Ensure that your mono is installed properly."
return 1
}
$mono_out = ($mono_out -split "\n")[0]
$mono_out = ($mono_out -split " ")
if ($mono_out[0] -ne "Mono")
{
Write-Host "Your installation of mono failed to produce expected output. Ensure that your mono installation is indeed a mono installation."
Return 1
}
$mono_v = New-Object System.Version($mono_out[4])
$targ_v = New-Object System.Version("5.0.0")
if ($mono_v.CompareTo($targ_v) -lt 0)
{
Write-Host "Your installation of mono is older than required (5.0.0). Please upgrade your mono to a newer version, then re-try this script."
Return 1
}
}
catch
{
Write-Host "Your installation of mono failed to run ($($_.Exception.Message)). Ensure that your mono is installed properly."
Return 1
}
$mono_pfix = $mono.Substring(0, $mono.IndexOf("/bin/mono"))
$mono_fxpf = "$mono_pfix/lib/mono"
Write-Host "Detected FX base: $mono_fxpf"
return $mono_fxpf
}
# Build project for specified framework
function Build-Project([string] $project, [string] $framework, [string] $configuration, [string] $mono, [string] $version_suffix, [string] $build_number)
{
# base arguments for dotnet
$dotnet_args = ""
# check if FX target
if ($framework.StartsWith("net4"))
{
# yes, check if the project qualifies
if ($fx_excluded.Contains($project) -or $al_excluded.Contains($project))
{
Write-Host "Skipping building $project for framework $framework"
Return 0
}
# yes, add the mono override
# construct the version string
$fxv = (($framework.Substring(3) -split "") -join ".")
$fxv = $fxv.Substring(1, $fxv.Length - 2)
# construct the args
$dotnet_args = "-p:FrameworkPathOverride=`"$mono/$fxv-api`""
}
elseif ($framework.StartsWith("netstandard"))
{
# no, check if the project qualifies for core build
if ($fc_excluded.Contains($project) -or $al_excluded.Contains($project))
{
Write-Host "Skipping building $project for framework $framework"
Return 0
}
# check if websocket project
if ($framework -eq "netstandard1.1" -and $project.StartsWith("DSharpPlus.WebSocket"))
{
Write-Host "Skipping building $project for framework $framework"
Return 0
}
}
else
{
# netcoreapp project
if (-not $al_excluded.Contains($project))
{
Write-Host "Skipping building $project for framework $framework"
Return 0
}
}
# invoke dotnet
if (-not $version_suffix -or -not $build_number)
{
& dotnet build -v minimal -c $configuration -f $framework $dotnet_args | Out-Host
}
else
{
& dotnet build -v minimal -c $configuration -f $framework --version-suffix "$version_suffix" -p:BuildNumber="$build_number" $dotnet_args | Out-Host
}
if ($LastExitCode -ne 0)
{
Write-Host "Build failed"
Return $LastExitCode
}
Return 0
}
# detect mono
$mono_path = Get-FxBasePath $Mono
if ($mono_path -eq 1)
{
Write-Host "Detecting mono installation failed. Ensure that mono is installed, and is in your PATH, or pass the location of your mono binary via -Mono argument."
Exit 1
}
# find projects
$projects = Get-ChildItem | ? { $_.Name.StartsWith("DSharpPlus") -and ($_.Attributes -band [System.IO.FileAttributes]::Directory) -eq [System.IO.FileAttributes]::Directory } | Sort-Object
$frameworks = "net45","net46","net47","netstandard1.1","netstandard1.3","netstandard2.0","netcoreapp2.0"
$cloc = Get-Location
foreach ($project in $projects)
{
$pname = $project.Name
Set-Location $project
Write-Host "Building project: $pname"
foreach ($fx in $frameworks)
{
$build_result = Build-Project "$pname" "$fx" "$Configuration" "$mono_path" "$VersionSuffix"
if ($build_result -ne 0)
{
Set-Location $cloc
Write-Host "Building $pname for $fx failed"
Exit $build_result
}
}
Set-Location $cloc
Write-Host "Building $pname completed"
}
Write-Host "Build succeeded"
# check if debug
if ($Configuration -eq "Debug")
{
# exit, we don't package in debug
Exit 0
}
# construct the framework string array
$pack_fxs = @()
foreach ($fx in $frameworks)
{
if (-not $fx.StartsWith("net4"))
{
# not an FX
continue
}
$fxv = (($fx.Substring(3) -split "") -join ".")
$fxv = $fxv.Substring(1, $fxv.Length - 2)
$pack_fxs += "-p:FrameworkPathOverride=`"$mono_path/$fxv-api`""
}
Write-Host "Packaging"
# package all projects
foreach ($project in $projects)
{
$pname = $project.Name
if ($al_excluded.Contains($pname))
{
# we do not package all-excluded projects
continue
}
Set-Location $project
Write-Host "Packaging project: $pname"
if (-not $VersionSuffix -or -not $BuildNumber)
{
& dotnet pack -v minimal -c "$bcfg" --no-build -o "$ArtifactLocation" --include-symbols $pack_fxs | Out-Host
}
else
{
& dotnet pack -v minimal -c "$bcfg" --version-suffix "$VersionSuffix" -p:BuildNumber="$BuildNumber" --no-build -o "$ArtifactLocations" --include-symbols $pack_fxs | Out-Host
}
if ($LastExitCode -ne 0)
{
Set-Location $cloc
Write-Host "Packaging failed"
Return $LastExitCode
}
Set-Location $cloc
Write-Host "Packaging $pname completed"
}
Exit