-
Notifications
You must be signed in to change notification settings - Fork 14
/
build.gradle.kts
523 lines (443 loc) · 20.3 KB
/
build.gradle.kts
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
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
import de.itemis.mps.gradle.*
import de.itemis.mps.gradle.tasks.MpsCheck
import de.itemis.mps.gradle.tasks.MpsMigrate
import de.itemis.mps.gradle.tasks.Remigrate
import java.util.Date
plugins {
base
`maven-publish`
id("co.riiid.gradle") version "0.4.2"
val mpsGradlePluginVersion = "1.28.0.+"
id("download-jbr") version mpsGradlePluginVersion
id("de.itemis.mps.gradle.common") version mpsGradlePluginVersion
}
val jbrVers = "17.0.8.1-b1000.32"
downloadJbr {
jbrVersion = jbrVers
}
// detect if we are in a CI build
val ciBuild = (System.getenv("CI") != null && System.getenv("CI").toBoolean()) || project.hasProperty("forceCI") || project.hasProperty("teamcity")
var nexusUsername: String? by extra
var nexusPassword: String? by extra
// Default repository credentials
if (nexusUsername == null) {
nexusUsername = ""
nexusPassword = ""
}
logger.info("Repository username: {}", nexusUsername)
// Project versions
val major = "2023"
val minor = "2"
val bugfix = ""
fun appendOpt(str:String, pre:String) = if(!str.isEmpty()) "${pre}${str}" else ""
val mpsVersion = "$major.$minor" + appendOpt(bugfix, ".")
// Dependency versions
val platformVersion = "$major.$minor.+"
// We now publish only from GitHub but there are older releases from TeamCity with higher build numbers due to TeamCity
// build sequence being higher. In order for GitHub build to appear later, we bump the GitHub run number to be greater
// than the build number from TeamCity.
//
// We do it only on 2022.3 and 2023.2 so that the hack can be eventually removed for later versions.
val githubRunNumberBump = if ("$major.$minor" == "2022.3" || "$major.$minor" == "2023.2") 1000 else 0
if (ciBuild) {
val branch = GitBasedVersioning.getGitBranch()
val buildNumber = if (System.getenv("GITHUB_RUN_NUMBER") != null)
System.getenv("GITHUB_RUN_NUMBER").toInt() + githubRunNumberBump
else
System.getenv("BUILD_NUMBER")!!.toInt()
if (branch.startsWith("maintenance") || branch.startsWith("mps") || branch.startsWith("migration")) {
version = "$major.$minor.$buildNumber.${GitBasedVersioning.getGitShortCommitHash()}"
} else {
version = GitBasedVersioning.getVersionWithCount(major, minor, buildNumber)
}
println("##teamcity[buildNumber '${version}']")
} else {
println("Local build detected, version will be SNAPSHOT")
version = "$major.$minor-SNAPSHOT"
}
val publishingRepository = uri("https://artifacts.itemis.cloud/repository/maven-mps-releases")
configurations {
val mps by creating
val languageLibs by creating
// includes also junit tasks support
val antLib by creating
val jbrWin by creating
val jbrMac by creating
val jbrLinux by creating
dependencies {
mps("com.jetbrains:mps:$mpsVersion")
languageLibs("com.mbeddr:platform:$platformVersion")
languageLibs("org.mpsqa:all-in-one:$platformVersion")
antLib("org.apache.ant:ant-junit:1.10.6")
jbrWin("com.jetbrains.jdk:jbr_jcef:$jbrVers:windows-x64@tgz")
jbrMac("com.jetbrains.jdk:jbr_jcef:$jbrVers:osx-x64@tgz")
jbrLinux("com.jetbrains.jdk:jbr_jcef:$jbrVers:linux-x64@tgz")
}
}
dependencyLocking { lockAllConfigurations() }
repositories {
val dependencyRepositories = listOf("https://artifacts.itemis.cloud/repository/maven-mps",
"https://maven.pkg.github.com/mbeddr/*")
for (repoUrl in dependencyRepositories) {
maven {
url = uri(repoUrl)
if (repoUrl.startsWith("https://maven.pkg.github.com/")) {
credentials {
username = project.property("gpr.user") as String
password = project.property("gpr.token") as String
}
}
}
}
mavenCentral()
}
val skipResolveMps = project.hasProperty("mpsHomeDir")
val mpsHomeDir = rootProject.file(project.findProperty("mpsHomeDir")
?: layout.buildDirectory.dir("mps").get().asFile.path)
val resolveMps = if (skipResolveMps) {
tasks.register("resolveMps") {
doLast {
logger.info("MPS resolution skipped")
logger.info("MPS home: {}", mpsHomeDir.getAbsolutePath())
}
}
} else {
tasks.register("resolveMps", Copy::class) {
dependsOn(configurations["mps"])
from({
configurations["mps"].resolve().map(::zipTree)
})
into(mpsHomeDir)
}
}
// tools needed for compiler support in ant calls
val buildScriptClasspath = project.configurations["antLib"]
val artifactsDir = layout.buildDirectory.dir("artifacts").get()
val dependenciesDir = layout.buildDirectory.dir("dependencies").get()
val jdkDir = layout.buildDirectory.dir("jdkDir").get()
// ___________________ utilities ___________________
val defaultScriptArgs = mapOf(
"mps.home" to mpsHomeDir,
"mbeddr.formal.home" to rootDir,
"build.dir" to layout.buildDirectory.get(),
"version" to version,
"build.date" to Date(),
//incremental build support
"mps.generator.skipUnmodifiedModels" to true,
"jdk.nio.zipfs.allowDotZipEntry" to true,
"jdk.util.zip.disableZip64ExtraFieldValidation" to true
)
fun scriptFile(relativePath: String):File = File("$rootDir/build/scripts/patched/$relativePath")
tasks {
val configureJava by registering {
dependsOn(downloadJbr)
doLast {
project.extra["itemis.mps.gradle.ant.defaultScriptArgs"] = defaultScriptArgs.map { "-D${it.key}=${it.value}" }
project.extra["itemis.mps.gradle.ant.defaultScriptClasspath"] = buildScriptClasspath
project.extra["itemis.mps.gradle.ant.defaultJavaExecutable"] = downloadJbr.get().javaExecutable
}
}
val resolveLanguageLibs by registering(Copy::class) {
dependsOn(configureJava)
from({ configurations["languageLibs"].resolve().map(::zipTree) })
into(dependenciesDir)
}
// "com.fasten.safety.rcp.pluginSolution" makes use of the mbeddr actionsfilter plugin.
// The "actionsfilter" plugin and dependencies must be copied to "MPS\plugins" folder in order to load properly.
val copy_mbeddr_actionsfilter by registering {
dependsOn(resolveLanguageLibs, resolveMps)
description="Installs 'com.mbeddr.mpsutil.actionsfilter' plugin and its dependencies into 'MPS\\plugins' directory."
// Using `Project#copy` method instead of using Copy task type in order to keep Gradle happy about multiple
// tasks using the same output.
doLast {
copy {
from("$dependenciesDir/com.mbeddr.platform")
include("com.mbeddr.mpsutil.actionsfilter/",
"de.itemis.mps.editor.widgets/",
"de.slisson.mps.hacks/",
"de.itemis.mps.tooltips/")
into("$mpsHomeDir/plugins")
}
}
}
val setup by registering {
dependsOn(resolveMps, copy_mbeddr_actionsfilter)
description = "Set up MPS project libraries. Libraries are read in from projectlibraries.properties file."
}
fun scriptFile(name: String): Provider<RegularFile> = layout.buildDirectory.file("scripts/$name")
val build_allScripts_unpatched by registering(BuildLanguages::class) {
dependsOn(resolveMps, resolveLanguageLibs)
script = scriptFile("build_all_scripts.xml")
}
// Patch JNA path in generated build scripts until https://github.com/JetBrains/MPS/pull/71 is fixed
val patch_allScripts by registering(Copy::class) {
dependsOn(build_allScripts_unpatched)
from("build/scripts")
exclude("patched")
exclude("build")
into("build/scripts/patched")
val isAarch64 = System.getProperty("os.arch") == "aarch64"
val jnaArch = if (isAarch64) "aarch64" else "amd64"
filter { line: String ->
line.replace("\"-Djna.boot.library.path=${'$'}{artifacts.mps}/lib/jna\"",
"\"-Djna.boot.library.path=${'$'}{artifacts.mps}/lib/jna/" + jnaArch + "\"")
}
}
val build_allScripts by registering {
dependsOn(patch_allScripts, resolveLanguageLibs)
}
val build_formal_languages by registering(BuildLanguages::class) {
dependsOn(build_allScripts)
script = scriptFile("build-formal-languages.xml")
}
val build_fasten_safety_distribution by registering(BuildLanguages::class) {
dependsOn(build_formal_languages)
script = scriptFile("build-fasten-safe-distribution.xml")
}
val run_smv_tests by registering(TestLanguages::class) {
description = "Will execute all tests from command line"
script = scriptFile("build-nusmv-tests.xml")
doLast {
ant.withGroovyBuilder {
"taskdef"("name" to "junitreport",
"classname" to "org.apache.tools.ant.taskdefs.optional.junit.XMLResultAggregator",
"classpath" to configurations["antLib"].asPath)
val reportDir = layout.buildDirectory.dir("junitreport_smv").get()
"junitreport" {
"fileset"("dir" to layout.buildDirectory.get(), "includes" to "**/TEST*.xml")
"report"("format" to "frames", "todir" to reportDir)
}
"echo"("JUnit report placed into $reportDir/index.html")
}
}
}
val run_safety_tests by registering(TestLanguages::class) {
description = "Will execute all tests from command line"
script = scriptFile("build-safety-tests.xml")
doLast {
ant.withGroovyBuilder {
"taskdef"("name" to "junitreport",
"classname" to "org.apache.tools.ant.taskdefs.optional.junit.XMLResultAggregator",
"classpath" to configurations["antLib"].asPath)
val reportDir = layout.buildDirectory.dir("junitreport_safety").get()
"junitreport" {
"fileset"("dir" to layout.buildDirectory.get(), "includes" to "**/TEST*.xml")
"report"("format" to "frames", "todir" to reportDir)
}
"echo"("JUnit report placed into $reportDir/index.html")
}
}
}
val run_all_tests by registering(TestLanguages::class) {
dependsOn(configureJava)
description = "Will execute all tests from command line"
script = scriptFile("build-all-tests.xml")
doLast {
ant.withGroovyBuilder {
"taskdef"("name" to "junitreport",
"classname" to "org.apache.tools.ant.taskdefs.optional.junit.XMLResultAggregator",
"classpath" to configurations["antLib"].asPath)
val reportDir = layout.buildDirectory.dir("junitreport").get()
"junitreport" {
"fileset"("dir" to layout.buildDirectory.get(), "includes" to "**/TEST*.xml")
"report"("format" to "frames", "todir" to reportDir)
}
"echo"("JUnit report placed into $reportDir/index.html")
}
}
}
withType<MpsCheck>().configureEach {
dependsOn(downloadJbr, resolveMps, resolveLanguageLibs)
javaLauncher = downloadJbr.flatMap { it.javaLauncher }
mpsHome = mpsHomeDir
folderMacros.put("mbeddr.formal.home", layout.projectDirectory)
pluginRoots.addAll(
layout.buildDirectory.map { buildDir ->
listOf(
"dependencies/com.mbeddr.platform",
"dependencies/org.mpsqa.allInOne",
"artifacts/com.mbeddr.formal.languages").map { buildDir.dir(it) }
})
ignoreFailures = true
maxHeapSize = "3G"
}
val checkSafetyTutorial by registering(MpsCheck::class) {
projectLocation = file("code/tutorial-safety")
modules = listOf("com.mbeddr.formal.safety.tutorial")
}
val checkNusmvTutorial by registering(MpsCheck::class) {
projectLocation = file("code/tutorial")
modules = listOf("com.mbeddr.formal.nusmv.tutorial")
}
check {
dependsOn(run_all_tests)
dependsOn(withType<MpsCheck>())
}
val package_formal by registering(Zip::class) {
dependsOn(build_formal_languages)
archiveBaseName.set("com.mbeddr.formal")
from(artifactsDir)
include("com.mbeddr.formal.languages/**")
}
val build_assurance_languages by registering(BuildLanguages::class) {
dependsOn(build_allScripts)
script = scriptFile("build-assurance-languages.xml")
}
val package_assurance by registering(Zip::class) {
dependsOn(build_assurance_languages)
archiveBaseName.set("fasten.assurance")
from(artifactsDir)
include("fasten.assurance.languages/**")
}
val resolveJBR_Win by registering(Copy::class) {
from(configurations["jbrWin"])
into(jdkDir)
rename { filename ->
val resolvedArtifact = configurations["jbrWin"].resolvedConfiguration.resolvedArtifacts.find { ra -> ra.file.name == filename }!!
resolvedArtifact.name + "-" + resolvedArtifact.classifier + "." + resolvedArtifact.extension
}
}
val unpackDistribution by registering(Copy::class) {
from(zipTree("$artifactsDir/com.mbeddr.formal.safetyDistribution/fasten-${version}.zip"))
into("$artifactsDir/com.mbeddr.formal.safetyDistribution/tmp")
}
val deleteJBR by registering(Delete::class) {
dependsOn(unpackDistribution)
delete("$artifactsDir/com.mbeddr.formal.safetyDistribution/tmp/fasten-${version}/jbr")
}
val removeJBR by registering(Zip::class) {
dependsOn(deleteJBR)
from("$artifactsDir/com.mbeddr.formal.safetyDistribution/tmp/fasten-${version}")
archiveFileName.set("fasten-${version}_with_removed_JBR.zip")
destinationDirectory.set(file("$artifactsDir/com.mbeddr.formal.safetyDistribution"))
}
val package_fasten_safety_distribution_win by registering(Zip::class) {
dependsOn(resolveJBR_Win, build_fasten_safety_distribution, removeJBR)
archiveBaseName.set("fasten-${version}-Win")
from(zipTree("$artifactsDir/com.mbeddr.formal.safetyDistribution/fasten-${version}_with_removed_JBR.zip"))
from(tarTree("$jdkDir/jbr_jcef-windows-x64.tgz"))
}
val build_all_languages by registering {
dependsOn(build_assurance_languages, build_formal_languages)
}
assemble { dependsOn(package_formal, package_assurance) }
val cleanMps by registering(Delete::class) {
delete(fileTree(projectDir) { include("**/classes_gen/**", "**/source_gen/**", "**/source_gen.caches/**", "tmp/**") })
}
//clean { dependsOn(cleanMps) }
val rebuild by registering { dependsOn(clean, build_formal_languages) }
// Some projects are not migrated because they (or languages contained in them) are not built by Gradle:
// - com.fasten.symo
// - com.mbeddr.formal.smt
// - com.mbeddr.formal.prism
//
// Tutorials could be migrated but would need a slightly different setup.
val projectsToMigrate = listOf(
"com.mpsbasics",
"com.mbeddr.formal.nusmv",
"com.mbeddr.formal.cprover",
"com.mbeddr.formal.repo_admin",
"com.mbeddr.formal.req",
"com.mbeddr.formal.spin",
"com.mbeddr.formal.safety",
).map { layout.projectDirectory.dir("code/languages/$it") }
val pluginRootsForMigration = listOf(mpsHomeDir.resolve("plugins"), dependenciesDir.asFile)
val migrate by registering(MpsMigrate::class) {
dependsOn(resolveMps, downloadJbr, build_all_languages)
javaLauncher = downloadJbr.flatMap { it.javaLauncher }
mpsHome = mpsHomeDir
folderMacros.put("mbeddr.formal.home", layout.projectDirectory)
projectDirectories.from(projectsToMigrate)
pluginRoots.from(pluginRootsForMigration)
haltOnPrecheckFailure = true
haltOnDependencyError = true
maxHeapSize = "4G"
}
val remigrate by registering(Remigrate::class) {
dependsOn(resolveMps, downloadJbr)
mustRunAfter(migrate)
// Technically we don't need to _depend_ on build_all_languages because we can opt to rerun only migrations that
// come from MPS.
mustRunAfter(build_all_languages)
javaLauncher = downloadJbr.flatMap { it.javaLauncher }
mpsHome = mpsHomeDir
folderMacros.put("mbeddr.formal.home", layout.projectDirectory)
projectDirectories.from(projectsToMigrate)
pluginRoots.from(pluginRootsForMigration)
maxHeapSize = "4G"
excludeModuleMigration("de.itemis.mps.editor.diagram", 0)
excludeModuleMigration("jetbrains.mps.baseLanguage.javadoc", 0)
}
}
publishing {
repositories {
maven {
url = publishingRepository
if (project.hasProperty("artifacts.itemis.cloud.user") && project.hasProperty("artifacts.itemis.cloud.pw")) {
credentials {
username = project.findProperty("artifacts.itemis.cloud.user") as String
password = project.findProperty("artifacts.itemis.cloud.pw") as String
}
}
}
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/mbeddr/mbeddr.formal")
if (project.hasProperty("gpr.token")) {
credentials {
username = project.findProperty("gpr.user") as String
password = project.findProperty("gpr.token") as String
}
}
}
}
publications {
create<MavenPublication>("NuSMVLanguages") {
groupId = "com.mbeddr"
artifactId = "formal"
artifact(tasks.named("package_formal"))
pom.withXml {
val dependenciesNode = asNode().appendNode("dependencies")
configurations["languageLibs"].resolvedConfiguration.firstLevelModuleDependencies.forEach {
val dependencyNode = dependenciesNode.appendNode("dependency")
dependencyNode.appendNode("groupId", it.moduleGroup)
dependencyNode.appendNode("artifactId", it.moduleName)
dependencyNode.appendNode("version", it.moduleVersion)
dependencyNode.appendNode("type", it.moduleArtifacts.first().type)
}
configurations["mps"].resolvedConfiguration.firstLevelModuleDependencies.forEach {
val dependencyNode = dependenciesNode.appendNode("dependency")
dependencyNode.appendNode("groupId", it.moduleGroup)
dependencyNode.appendNode("artifactId", it.moduleName)
dependencyNode.appendNode("version", it.moduleVersion)
dependencyNode.appendNode("type", it.moduleArtifacts.first().type)
dependencyNode.appendNode("scope", "provided")
}
}
}
create<MavenPublication>("FASTENSafetyLanguages") {
groupId = "fasten"
artifactId = "assurance"
artifact(tasks.named("package_assurance"))
pom.withXml {
val dependenciesNode = asNode().appendNode("dependencies")
configurations["languageLibs"].resolvedConfiguration.firstLevelModuleDependencies.forEach {
val dependencyNode = dependenciesNode.appendNode("dependency")
dependencyNode.appendNode("groupId", it.moduleGroup)
dependencyNode.appendNode("artifactId", it.moduleName)
dependencyNode.appendNode("version", it.moduleVersion)
dependencyNode.appendNode("type", it.moduleArtifacts.first().type)
}
configurations["mps"].resolvedConfiguration.firstLevelModuleDependencies.forEach {
val dependencyNode = dependenciesNode.appendNode("dependency")
dependencyNode.appendNode("groupId", it.moduleGroup)
dependencyNode.appendNode("artifactId", it.moduleName)
dependencyNode.appendNode("version", it.moduleVersion)
dependencyNode.appendNode("type", it.moduleArtifacts.first().type)
dependencyNode.appendNode("scope", "provided")
}
}
}
}
}
defaultTasks("build_formal_languages")