-
Notifications
You must be signed in to change notification settings - Fork 26
/
build.gradle
461 lines (364 loc) · 15 KB
/
build.gradle
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
import com.google.gson.GsonBuilder
import io.pry.gradle.offline_dependencies.OfflineDependenciesPlugin
import org.gradle.internal.os.OperatingSystem
buildscript {
dependencies {
classpath 'com.google.code.gson:gson:2.8.9'
}
}
plugins {
id 'java'
id 'cpp'
id "de.undercouch.download" version "4.1.2" apply false
id "com.github.johnrengelman.shadow" version "7.1.2" apply false
}
apply from: "automation/macos_notarization.gradle"
apply plugin: OfflineDependenciesPlugin
ext.pubVersion = ''
if (project.hasProperty("publishVersion")) {
pubVersion = project.publishVersion
} else {
pubVersion = gradleRioVersion
}
if (pubVersion == '') {
pubVersion = '0.0.1-unknown'
}
println pubVersion
project.ext.setProperty('toolchain-optional-roboRio', '')
if (OperatingSystem.current().isWindows()) {
project.ext.currentClassifier = 'windowsx86-64'
} else if (OperatingSystem.current().isMacOsX()) {
project.ext.currentClassifier = 'osxuniversal'
} else {
project.ext.currentClassifier = 'linuxx86-64'
}
if (project.hasProperty('linuxBuild')) {
project.ext.forcePlatform = 'linuxx86-64'
project.ext.forceNativeClassifier = 'linuxx86-64'
project.ext.forceToolsClassifier = 'linuxx64'
project.ext.forceCppToolsClassifier = 'linuxx86-64'
project.ext.buildClassifier = 'Linux'
offlineRepositoryRoot = "$buildDir/dependencies/linux"
project.ext.archiveType = Tar
project.ext.isUnix = true
project.ext.dotnetRuntime = 'linux-x64'
} else if (project.hasProperty('linuxBuildArm64')) {
project.ext.forcePlatform = 'linuxarm64'
project.ext.forceNativeClassifier = 'linuxarm64'
project.ext.forceToolsClassifier = 'linuxarm64'
project.ext.forceCppToolsClassifier = 'linuxarm64'
project.ext.buildClassifier = 'LinuxArm64'
offlineRepositoryRoot = "$buildDir/dependencies/linuxarm64"
project.ext.archiveType = Tar
project.ext.isUnix = true
project.ext.dotnetRuntime = 'linux-arm64'
} else if (project.hasProperty('macBuild')) {
project.ext.forcePlatform = 'osx'
project.ext.forceNativeClassifier = 'osxuniversal'
project.ext.forceToolsClassifier = 'macx64'
project.ext.forceCppToolsClassifier = 'osxuniversal'
project.ext.buildClassifier = 'Mac'
offlineRepositoryRoot = "$buildDir/dependencies/mac"
project.ext.archiveType = Tar
project.ext.isUnix = true
project.ext.dotnetRuntime = 'osx-x64'
} else if (project.hasProperty('macBuildArm')) {
project.ext.forcePlatform = 'osx'
project.ext.forceNativeClassifier = 'osxuniversal'
project.ext.forceToolsClassifier = 'macarm64'
project.ext.forceCppToolsClassifier = 'osxuniversal'
project.ext.buildClassifier = 'MacArm'
offlineRepositoryRoot = "$buildDir/dependencies/mac"
project.ext.archiveType = Tar
project.ext.isUnix = true
project.ext.dotnetRuntime = 'osx-arm64'
} else {
project.ext.forcePlatform = 'windows'
project.ext.forceNativeClassifier = 'windowsx86-64'
project.ext.forceToolsClassifier = 'winx64'
project.ext.forceCppToolsClassifier = 'windowsx86-64'
project.ext.buildClassifier = 'Windows'
offlineRepositoryRoot = "$buildDir/dependencies/windows"
project.ext.archiveType = Zip
project.ext.isUnix = false
project.ext.dotnetRuntime = 'win-x64'
}
apply from: 'scripts/versions.gradle'
apply from: 'scripts/gradlew.gradle'
apply from: 'scripts/installer.gradle'
apply from: 'scripts/toolchain.gradle'
apply from: 'scripts/jdk.gradle'
apply from: 'scripts/maven.gradle'
apply from: 'scripts/advantagescope.gradle'
apply from: 'scripts/elastic.gradle'
// Tools must happen after maven
apply from: 'scripts/tools.gradle'
apply from: 'scripts/vscode.gradle'
apply from: 'scripts/vars.gradle'
ext.getGsonBuilder = {
return new GsonBuilder()
}
def upgradeConfigFile = file("$buildDir/upgradeConfig.json")
def upgradeConfigFileTask = tasks.register('generateUpgradeConfigFile', Task) { Task task ->
task.outputs.file upgradeConfigFile
def configurations = []
configurations << toolsConfig()
configurations << mavenConfigSetup()
configurations << varConfigSetup()
configurations.each {
it.first(task)
}
doLast {
def config = [:]
config['FrcYear'] = frcYear
config['InstallerType'] = project.ext.buildClassifier
configurations.each {
it.second(config)
}
def gbuilder = getGsonBuilder()
gbuilder.setPrettyPrinting()
def json = gbuilder.create().toJson(config)
upgradeConfigFile.parentFile.mkdirs()
upgradeConfigFile.text = json
}
}
def commonResources = { AbstractArchiveTask zip ->
zip.dependsOn upgradeConfigFileTask
zip.inputs.file upgradeConfigFile
zip.from(upgradeConfigFile) {
into '/installUtils'
}
msBuildExtraSetup(zip)
toolsSetup(zip)
mavenZipSetup(zip)
vscodeZipSetup(zip)
varsZipSetup(zip)
}
def fullConfigFile = file("$buildDir/fullConfig.json")
def fullConfigFileTask = tasks.register('generateFullConfigFile', Task) { Task task ->
task.outputs.file fullConfigFile
def configurations = []
configurations << gradleConfigTaskSetup()
configurations << toolchainConfigTaskSetup()
configurations.each {
it.first(task)
}
doLast {
def config = [:]
configurations.each {
it.second(config)
}
def gbuilder = new GsonBuilder()
gbuilder.setPrettyPrinting()
def json = gbuilder.create().toJson(config)
fullConfigFile.parentFile.mkdirs()
fullConfigFile.text = json
}
}
def generateFullResourcesTask = tasks.register('generateFullResources', project.ext.archiveType) {
archiveBaseName = 'WPILib_' + buildClassifier + '-' + pubVersion + '-artifacts'
destinationDirectory = file("$buildDir/outputs")
duplicatesStrategy 'exclude'
if (project.ext.isUnix) {
archiveExtension = 'tar.gz'
compression = Compression.GZIP
}
dependsOn fullConfigFileTask
inputs.file fullConfigFile
it.from(fullConfigFile) {
into '/installUtils'
}
commonResources(it)
gradleZipTaskSetup(it)
toolchainZipSetup(it)
jdkZipSetup(it)
advantageScopeZipSetup(it)
elasticZipSetup(it)
if (OperatingSystem.current().isWindows()) {
def task = it
// Grab release shortcut creator
project(':WPILibShortcutCreator').application.binaries.whenElementFinalized { binary ->
if (binary.name == 'mainRelease') {
task.from(binary.executableFile) {
into '/installUtils'
}
task.dependsOn binary.executableFileProducer
}
}
}
}
// Creates the main installer application.
def dotnetInstallerTask = tasks.register('createInstaller', Exec) {
workingDir = "$projectDir/WPILibInstaller-Avalonia"
def macRuntimeId = "osx-x64"
if (project.hasProperty("macBuildArm")) {
macRuntimeId = "osx-arm64"
}
if (project.hasProperty("macBuild") || project.hasProperty("macBuildArm")) {
commandLine 'dotnet', 'publish', '-c', 'Release', '-r', dotnetRuntime, '--self-contained',
"/p:Version=$pubVersion", "/t:BundleApp", "-p:RuntimeIdentifier=${macRuntimeId}",
"-p:CFBundleShortVersionString=$pubVersion", "-p:CFBundleVersion=$pubVersion",
'/p:EnableCompressionInSingleFile=true'
} else {
commandLine 'dotnet', 'publish', '-c', 'Release', '-r', dotnetRuntime, '/p:PublishSingleFile=true',
"/p:Version=$pubVersion", '/p:EnableCompressionInSingleFile=true', '--self-contained'
}
}
// Creates the WPILib version file.
def versionFile = file("$buildDir/versionNumber/WPILibInstallerVersion.txt")
def versionFileTask = tasks.register('writeVersionNumber', Task) {
outputs.upToDateWhen { false }
outputs.dir file("$buildDir/versionNumber")
doLast {
// TODO make this a bit smarter
versionFile.text = pubVersion
}
}
def installerProj = new XmlParser().parse("$projectDir/WPILibInstaller-Avalonia/WPILibInstaller-Avalonia.csproj")
def dotnetVersion = installerProj.PropertyGroup.TargetFramework.text()
// Copies the main application to build/outputs.
def installDirectory = "$projectDir/WPILibInstaller-Avalonia/bin/Release/$dotnetVersion/$dotnetRuntime/publish"
def macIcon = "$projectDir/WPILibInstaller-Avalonia/wpilib.icns"
def copyInstallerFiles = tasks.register('copyInstallerFiles', Copy) {
if (!project.hasProperty("macBuild") && !project.hasProperty("macBuildArm")) {
from(installDirectory) {
exclude('WPILibInstaller', 'WPILibInstaller.app')
fileMode 0644
}
from(installDirectory) {
include('WPILibInstaller', 'WPILibInstaller.app/**')
}
from versionFile
} else {
// We only want to copy the application and its contents. Otherwise, a bunch of other dlls
// that we don't need also get copied on Mac.
from(installDirectory) { include 'WPILibInstaller.app/**' }
into("WPILibInstaller.app/Contents/MacOS") { with copySpec { from versionFile } }
into("WPILibInstaller.app/Contents/Resources") { with copySpec { from file(macIcon) } }
}
into "$buildDir/outputs"
dependsOn dotnetInstallerTask
dependsOn versionFileTask
}
// Generates common resources and config files.
def generateConfigFiles = tasks.register('generateCommonResources', Zip) {
archiveBaseName = 'WPILibInstaller_' + buildClassifier + '-' + pubVersion + '-resources'
if (!project.hasProperty("macBuild") && !project.hasProperty("macBuildArm")) {
destinationDirectory = file("$buildDir/outputs")
} else {
destinationDirectory = file("$buildDir/outputs/WPILibInstaller.app/Contents/MacOS")
}
dependsOn copyInstallerFiles
duplicatesStrategy 'exclude'
dependsOn fullConfigFileTask
inputs.file fullConfigFile
it.from(fullConfigFile)
def zip = it
zip.dependsOn upgradeConfigFileTask
zip.inputs.file upgradeConfigFile
zip.from(upgradeConfigFile)
jdkConfigFileSetup(zip)
advantageScopeConfigFileSetup(zip)
elasticConfigFileSetup(zip)
vscodeConfigZipSetup(zip)
}
// Generates the Info.plist file.
def infoPlistInput = file("automation/macos_plist.in")
def infoPlistOutput = file("$buildDir/outputs/WPILibInstaller.app/Contents/Info.plist")
def generateInfoPlist = tasks.register("generateInfoPlist", Task) {
outputs.upToDateWhen { false }
outputs.file infoPlistOutput
inputs.file infoPlistInput
doLast {
if (infoPlistOutput.exists())
infoPlistOutput.delete()
def read = infoPlistInput.text.replace('${wpilib_version}', pubVersion)
infoPlistOutput.write(read)
}
dependsOn copyInstallerFiles
}
// Signs the resources/artifacts tar and saves the signature inside the app (macOS only)
def signResourcesTask = tasks.register('signResources', Exec) {
dependsOn generateFullResourcesTask
dependsOn copyInstallerFiles
workingDir = "$buildDir/outputs"
def file = 'WPILib_' + buildClassifier + '-' + pubVersion + '-artifacts' + '.tar.gz'
commandLine 'sh', '-c', "shasum -a 256 $file | cut -d \" \" -f 1 > WPILibInstaller.app/Contents/MacOS/checksum.txt"
}
// Creates the Windows disk image.
def windowsCreateImageTask = tasks.register('createWindowsImage', Exec) {
dependsOn generateFullResourcesTask
dependsOn copyInstallerFiles
dependsOn generateConfigFiles
workingDir = "$projectDir/IsoCreator"
inputs.dir "$buildDir/outputs"
def file = "$buildDir/pubOutputs/WPILib_" + buildClassifier + '-' + pubVersion + '.iso'
outputs.file file
commandLine 'dotnet', 'run', '--input', "$buildDir/outputs", '--output', file, '--version', pubVersion
}
// Creates the Linux tarball.
def linuxCreateImageTask = tasks.register('createLinuxImage', Tar) {
dependsOn generateFullResourcesTask
dependsOn copyInstallerFiles
dependsOn generateConfigFiles
archiveExtension = 'tar.gz'
compression = Compression.GZIP
inputs.dir "$buildDir/outputs"
archiveBaseName = 'WPILib_' + buildClassifier + '-' + pubVersion + ''
into 'WPILib_' + buildClassifier + '-' + pubVersion + ''
destinationDirectory = file("$buildDir/pubOutputs")
duplicatesStrategy 'exclude'
from("$buildDir/outputs")
}
// Creates the macOS disk image. If the relevant parameters are provided, the app with also be signed and notarized.
def macCreateImageTask = tasks.register('createMacImage', Task) {
dependsOn generateFullResourcesTask
dependsOn copyInstallerFiles
dependsOn generateConfigFiles
dependsOn generateInfoPlist
dependsOn signResourcesTask
doLast {
// We can sign the app because we have a Developer ID.
if (project.hasProperty("developerID")) {
println "Received a Developer ID -- signing the application..."
String identity = project.property("developerID")
exec {
commandLine "sh", "-c", "automation/macos_codesign.sh ${identity} $buildDir/outputs/WPILibInstaller.app"
}
}
// Notarize the application.
if (project.hasProperty("notarization-username") && project.hasProperty("notarization-teamid") && project.hasProperty("notarization-password")) {
println "Received an App Store Connect username and password -- notarizing the application..."
notarize(file("$buildDir/outputs/WPILibInstaller.app"), "WPILibInstaller-${pubVersion}",
project.property("notarization-username") as String,
project.property("notarization-teamid") as String,
project.property("notarization-password") as String)
}
// Create disk image.
println "Creating disk image..."
def diskArch = "macOS-Intel"
if (project.hasProperty('macBuildArm')) {
diskArch = "macOS-Arm64"
}
exec { commandLine "mkdir", "-p", "$buildDir/pubOutputs" }
exec {
commandLine "hdiutil", "create", "-volname", "WPILibInstaller",
"-srcfolder", "$buildDir/outputs/", "-format", "UDRO",
"WPILib_${diskArch}-${pubVersion}.dmg"
workingDir "$buildDir/pubOutputs"
}
}
}
// Runs the entire pipeline and generates
tasks.register('generateInstallers', Task) {
if (OperatingSystem.current().isWindows()) {
dependsOn windowsCreateImageTask
} else if (project.hasProperty("macBuild") || project.hasProperty("macBuildArm")) {
dependsOn macCreateImageTask
} else {
dependsOn linuxCreateImageTask
}
}
wrapper {
gradleVersion = '8.11'
}