Repository navigation
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
617 lines (555 loc) · 24.8 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
617 lines (555 loc) · 24.8 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
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
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
/*
* EduMIPS64 Gradle build configuration
*/
// detekt rules that don't add signal in a Gradle build script: helper
// functions need no KDoc, repeated literals are task/path names, and
// catching Exception around optional Xvfb startup is intentional.
@file:Suppress(
"UndocumentedPublicFunction",
"StringLiteralDuplication",
"LabeledExpression",
"TooGenericExceptionCaught",
)
import java.time.LocalDateTime
import java.util.concurrent.TimeUnit
import ru.vyarus.gradle.plugin.python.task.PythonTask
import ru.vyarus.gradle.plugin.python.PythonExtension.Scope.VIRTUALENV
plugins {
java
// The Eclipse plugin adds the "eclipse" task, which generates
// files needed for Visual Studio Code and other IDEs.
id ("eclipse")
id ("application")
id ("jacoco")
id ("com.dorongold.task-tree") version "4.0.2"
id ("us.ascendtech.gwt.classic") version "0.14.1"
id ("ru.vyarus.use-python") version "4.1.0"
}
// Consolidate all Gradle build outputs under a single "out/" directory in the
// project root, instead of the Gradle default "build/". This keeps generated
// artifacts (JARs, docs, GWT output, MSI, reports, ...) in one discoverable
// location.
layout.buildDirectory.set(layout.projectDirectory.dir("out"))
// The us.ascendtech.gwt.classic plugin hard-codes the resources output to
// "build/classes/java/main" (see GWTLibPlugin). Override it so resources are
// emitted under the custom build directory too, keeping everything in one place.
sourceSets.matching { it.name == "main" }.configureEach {
output.setResourcesDir(layout.buildDirectory.dir("classes/java/main"))
}
repositories {
mavenCentral()
}
dependencies {
compileOnly("org.gwtproject:gwt-user:2.13.1")
compileOnly("org.gwtproject:gwt-dev:2.13.1")
compileOnly("com.google.elemental2:elemental2-dom:1.3.2")
compileOnly("com.vertispan.rpc:workers:1.0-alpha-8")
implementation("com.formdev:flatlaf:3.7.2")
implementation("javax.help:javahelp:2.0.05")
implementation("info.picocli:picocli:4.7.7")
testImplementation(platform("org.junit:junit-bom:6.1.3"))
testImplementation("org.junit.jupiter:junit-jupiter")
// To run JUnit 4 tests.
testImplementation("junit:junit:4.13.2")
testImplementation("org.assertj:assertj-swing-junit:3.17.1")
testRuntimeOnly("org.junit.vintage:junit-vintage-engine")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
// GWT Testing
testImplementation("org.gwtproject:gwt-user:2.13.1")
testImplementation("org.gwtproject:gwt-dev:2.13.1")
testImplementation("com.google.elemental2:elemental2-dom:1.3.2")
testImplementation("com.vertispan.rpc:workers:1.0-alpha-8")
}
python {
// Allow overriding pythonPath via Gradle project property (e.g., -PpythonPath=... or
// ORG_GRADLE_PROJECT_pythonPath env var). Used in CI to point to the Python installed
// by actions/setup-python rather than the system Python.
val customPythonPath = findProperty("pythonPath") as String?
if (customPythonPath != null) {
pythonPath = customPythonPath
}
scope = VIRTUALENV
requirements.file = "docs/requirements.txt"
minPythonVersion = "3.12"
}
application {
mainClass.set("org.edumips64.Main")
}
val codename = project.property("codename") as String
val version = project.property("version") as String
// Use Java toolchain for consistent JDK version across all compilations.
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
// Exclude the GWT super-source directory from the main Java compilation. It provides
// alternative implementations of classes that aren't compatible with GWT's JRE emulation
// (see webclient.gwt.xml <super-source> directive) and would otherwise clash with the
// regular sources as duplicate classes.
sourceSets {
main {
java {
exclude("org/edumips64/supersource/**")
}
}
}
tasks.withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
}
// Bundle the English user-manual reStructuredText sources as JAR resources
// so the in-shell `help <topic>` browser can display them. Shipping the rst
// files verbatim (rather than hand-curated summaries) keeps the build
// hermetic: the chapters the CLI shows are exactly the chapters that
// Sphinx renders for the website / PDF, and they cannot drift apart.
tasks.processResources {
from("docs/user/en/src") {
include("*.rst")
into("org/edumips64/help/topics")
}
}
tasks.processTestResources {
from("docs/user/en") {
include("EduMIPS64.hs")
include("EduMIPS64Index.xml")
include("EduMIPS64TOC.xml")
include("Map.jhm")
include("JavaHelpSearch/**")
include("img/**")
into("docs/user/en")
}
}
/*
* Documentation tasks. To avoid dependency on GNU Make, these tasks duplicate the commands run by the Sphinx makefiles.
*
* The user manual is split (via Sphinx `.. only::` directives) in three
* flavors, all built from the same sources:
* - "full" (no Sphinx tag): includes both UI chapters. Used for the PDF
* and matches what Read the Docs publishes.
* - "swing" (-t swing): only the desktop (Swing) UI chapter. Used by the
* in-application help of the desktop JAR.
* - "web" (-t web): only the web UI chapter. Used by the in-application
* help of the web frontend.
*/
fun buildDocsCmd(language: String, type: String, flavor: String = "full") : String {
val outputSubdir = if (type == "html" && flavor != "full") "${type}-${flavor}" else type
val baseDir = "${layout.buildDirectory.get()}/docs/${language}"
val tagFlag = if (flavor == "full") "" else "-t ${flavor} "
return "-m sphinx -N -a -E ${tagFlag}. ${baseDir}/${outputSubdir} -b ${type} -d ${baseDir}/doctrees-${flavor}"
}
/*
* Jar tasks
*/
val docsDir = layout.buildDirectory.dir("resources/main/docs")
// Generate documentation tasks for all languages
val languages = listOf("en", "it", "zh")
val docTypes = listOf("html", "pdf")
// HTML flavors that filter the user-interface chapter via Sphinx `.. only::`
// directives. The "full" flavor (no tag) includes both UI chapters and
// matches the PDF and Read the Docs build.
val htmlFlavors = listOf("full", "swing", "web")
val allDocsTaskNames = mutableListOf<String>()
val copyHelpTaskNames = mutableListOf<String>()
val copyWebHelpTaskNames = mutableListOf<String>()
val htmlTaskNames = mutableListOf<String>()
fun langCap(l: String) = l.replaceFirstChar { it.uppercase() }
fun flavorCap(f: String) = f.replaceFirstChar { it.uppercase() }
for (language in languages) {
// PDF tasks (single flavor: "full"; the PDF always contains everything).
val pdfTaskName = "pdfDocs${langCap(language)}"
tasks.register<PythonTask>(pdfTaskName) {
workDir = "${projectDir}/docs/user/${language}/src"
command = buildDocsCmd(language, "pdf")
}
allDocsTaskNames.add(pdfTaskName)
// HTML tasks, one per flavor. The "full" flavor keeps the historical
// task name `htmlDocs<Lang>` so existing dependencies (e.g. on Read the
// Docs and CI) keep working unchanged.
for (flavor in htmlFlavors) {
val taskName = if (flavor == "full") "htmlDocs${langCap(language)}"
else "htmlDocs${flavorCap(flavor)}${langCap(language)}"
tasks.register<PythonTask>(taskName) {
workDir = "${projectDir}/docs/user/${language}/src"
command = buildDocsCmd(language, "html", flavor)
}
allDocsTaskNames.add(taskName)
if (flavor == "full") {
htmlTaskNames.add(taskName)
}
}
// copyHelp<Lang>: copies the Swing-flavored HTML into the JAR resources.
val copyTaskName = "copyHelp${langCap(language)}"
tasks.register<Copy>(copyTaskName) {
from("${layout.buildDirectory.get()}/docs/${language}") {
// Map the Swing-flavored HTML output to the standard "html/"
// path used at runtime (Map.jhm + HelpDialog.js both look for
// docs/<lang>/html/).
include("html-swing/**")
exclude("**/_sources/**")
eachFile { path = path.replaceFirst("html-swing", "html") }
includeEmptyDirs = false
}
into(docsDir.map { it.dir("user/$language") })
dependsOn("htmlDocsSwing${langCap(language)}")
mustRunAfter("compileJava")
}
copyHelpTaskNames.add(copyTaskName)
// copyWebHelp<Lang>: copies the Web-flavored HTML into the web bundle.
val copyWebTaskName = "copyWebHelp${langCap(language)}"
tasks.register<Copy>(copyWebTaskName) {
from("${layout.buildDirectory.get()}/docs/${language}") {
include("html-web/**")
exclude("**/.buildinfo", "**/objects.inv", "**/_sources/**")
eachFile { path = path.replaceFirst("html-web", "html") }
includeEmptyDirs = false
}
into(layout.buildDirectory.dir("web/docs/${language}"))
dependsOn("htmlDocsWeb${langCap(language)}")
}
copyWebHelpTaskNames.add(copyWebTaskName)
}
// Catch-all tasks for documentation
tasks.register("allDocs") {
dependsOn(allDocsTaskNames)
description = "Run all documentation tasks"
}
tasks.register("htmlDocs") {
dependsOn(htmlTaskNames)
description = "Run all HTML documentation tasks"
}
// Include the docs folder at the root of the jar, for JavaHelp
tasks.register<Copy>("copyHelp") {
from("docs/") {
exclude("**/src/**", "**/design/**", "**/*.py", "**/*.pyc",
"**/*.md", "**/.buildinfo", "**/objects.inv", "**/*.txt", "**/__pycache__/**",
// The MIPS64 ISA reference PDF is large (~5.6 MB) and is not referenced
// by JavaHelp or any in-app component; ship it via the project website
// instead of embedding it in every JAR.
"**/*.pdf")
}
into(docsDir)
copyHelpTaskNames.forEach { dependsOn(it) }
}
/*
* Source control metadata, using Gradle providers for configuration-cache compatibility.
* On CI (GitHub Actions), values come from environment variables.
* Locally, values are obtained by running git commands.
*/
val gitBranch: Provider<String> = providers.environmentVariable("GITHUB_REF")
.orElse(providers.exec {
commandLine("git", "rev-parse", "--abbrev-ref", "HEAD")
}.standardOutput.asText.map { it.trim() })
val gitCommitHash: Provider<String> = providers.environmentVariable("GITHUB_SHA")
.map { it.substring(0, 7) }
.orElse(providers.exec {
commandLine("git", "rev-parse", "--verify", "--short", "HEAD")
}.standardOutput.asText.map { it.trim() })
val gitDescribe: Provider<String> = providers.exec {
commandLine("git", "describe", "--tags", "--match", "v*", "--always", "--dirty")
}.standardOutput.asText.map { it.trim().removePrefix("v") }
.orElse(version as String)
val sharedManifest = Action<Manifest> {
attributes["Signature-Version"] = gitDescribe.get()
attributes["Codename"] = codename
attributes["Build-Date"] = LocalDateTime.now()
attributes["Full-Buildstring"] = "${gitBranch.get()}@${gitCommitHash.get()}"
attributes["Git-Revision"] = gitCommitHash.get()
}
// Main JAR — write directly under the build directory (out/) rather than
// the default out/libs/ subfolder, so JARs sit next to other top-level artifacts.
tasks.jar {
archiveVersion.set(gitDescribe)
destinationDirectory.set(layout.buildDirectory)
from(sourceSets.main.get().output)
from(docsDir) {
into("docs")
}
from({
configurations.runtimeClasspath.get().filter { (it.name.contains("picocli") || it.name.contains("javahelp") || it.name.contains("flatlaf")) && it.name.endsWith("jar") }.map { println("Adding dependency " + it.name); zipTree(it) }
})
manifest {
attributes["Main-Class"] = application.mainClass.get()
sharedManifest.execute(this)
}
dependsOn("copyHelp")
}
// NoHelp JAR — same destination as the main JAR (build directory root).
tasks.register<Jar>("noHelpJar"){
archiveVersion.set(gitDescribe)
destinationDirectory.set(layout.buildDirectory)
archiveClassifier.set("nohelp")
dependsOn(configurations.runtimeClasspath)
from(sourceSets.main.get().output)
from({
configurations.runtimeClasspath.get().filter { it.name.contains("picocli") && it.name.endsWith("jar") || it.name.contains("flatlaf") }.map { println("Adding dependency " + it.name); zipTree(it) }
})
manifest {
attributes["Main-Class"] = application.mainClass.get()
sharedManifest.execute(this)
}
}
/*
* Code coverage report tasks
*/
jacoco {
toolVersion = "0.8.15"
}
tasks.jacocoTestReport {
reports {
xml.required.set(true)
csv.required.set(false)
html.required.set(false)
}
}
// Add logging of all executed tests.
tasks {
withType<Test> {
useJUnitPlatform()
testLogging.events = setOf(
org.gradle.api.tasks.testing.logging.TestLogEvent.PASSED,
org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED,
org.gradle.api.tasks.testing.logging.TestLogEvent.SKIPPED
)
// GWTTestCase requires source files on the classpath to compile the module
classpath += files(project.sourceSets.main.get().java.srcDirs)
classpath += files(project.sourceSets.test.get().java.srcDirs)
// Increase memory for GWT compilation
maxHeapSize = "1024m"
// Pass system property to allow GWT to find the module
systemProperty("gwt.args", "-war " + layout.buildDirectory.dir("gwt-tests").get().asFile.absolutePath)
// Ensure UTF-8 encoding for tests
systemProperty("file.encoding", "UTF-8")
}
}
// The Swing UI tests drive a real AWT robot, which moves the mouse and types on
// whatever X display is currently active. On Linux we therefore run the whole
// test suite on a private Xvfb (virtual framebuffer) display, both in CI and
// locally, so the tests never interfere with the developer's X session (and
// never hang waiting for focus on a busy desktop). When Xvfb is not installed
// the suite falls back to headless mode, which makes the Swing tests skip
// themselves instead of grabbing the real display. Pass -PuseRealDisplay to opt
// out and run the tests against the current display instead.
//
// Windows and macOS have no Xvfb equivalent in the standard toolchain, so on
// those platforms the Swing tests are SKIPPED by default (we force headless
// mode) instead of grabbing the developer's real desktop. Pass -PuseRealDisplay
// to run them against the current display instead. CI only exercises the
// desktop UI on Linux (the build-desktop job), where Xvfb is available.
if (org.gradle.internal.os.OperatingSystem.current().isLinux && !project.hasProperty("useRealDisplay")) {
// How long to wait for Xvfb to create its lock file and start serving
// clients before we assume it came up successfully.
val xvfbStartupDelayMillis = 1000L
// How long to wait for Xvfb to exit gracefully before killing it forcibly.
val xvfbShutdownTimeoutSeconds = 5L
// Range of X display numbers to probe for a free one.
val xvfbDisplayRange = 99..199
// Shared state between the start/stop tasks and the test JVM configuration.
val xvfb = object {
var process: Process? = null
var display: String? = null
}
val startXvfb = tasks.register("startXvfb") {
description = "Starts a private Xvfb display for the Swing UI tests."
doLast {
// Pick a free X display number to avoid clashing with a running
// X server or a previous Xvfb instance.
val display = xvfbDisplayRange.firstOrNull { n -> !file("/tmp/.X$n-lock").exists() }?.let { ":$it" }
if (display == null) {
logger.warn(
"No free X display found in the range :${xvfbDisplayRange.first}-:${xvfbDisplayRange.last}; " +
"the Swing UI tests will be SKIPPED. Free up a display or pass " +
"-PuseRealDisplay to use your current one."
)
return@doLast
}
try {
val process = ProcessBuilder(
"Xvfb", display, "-screen", "0", "1280x1024x24", "-nolisten", "tcp"
)
.redirectOutput(ProcessBuilder.Redirect.DISCARD)
.redirectError(ProcessBuilder.Redirect.DISCARD)
.start()
// Give Xvfb a moment to create its lock file and start serving.
Thread.sleep(xvfbStartupDelayMillis)
if (!process.isAlive) {
throw GradleException("Xvfb exited immediately on display $display")
}
xvfb.process = process
xvfb.display = display
logger.lifecycle("Started Xvfb on display $display for the Swing UI tests.")
} catch (e: Exception) {
logger.warn(
"Could not start Xvfb ({}); the Swing UI tests will be SKIPPED. " +
"Install the 'xvfb' package to run them on Linux.", e.toString()
)
}
}
}
val stopXvfb = tasks.register("stopXvfb") {
description = "Stops the private Xvfb display used by the Swing UI tests."
doLast {
xvfb.process?.let { process ->
process.destroy()
if (!process.waitFor(xvfbShutdownTimeoutSeconds, TimeUnit.SECONDS)) {
process.destroyForcibly()
}
}
xvfb.process = null
xvfb.display = null
}
}
tasks.withType<Test>().configureEach {
dependsOn(startXvfb)
finalizedBy(stopXvfb)
doFirst {
val display = xvfb.display
if (display != null) {
environment("DISPLAY", display)
} else {
// No virtual framebuffer available: force headless so the Swing
// tests skip instead of taking over the developer's real display.
// Make the reason visible in the Gradle output, since the skipped
// tests on their own do not explain why.
systemProperty("java.awt.headless", "true")
logger.warn(
"No virtual framebuffer (Xvfb) is available: the Swing UI tests in " +
"this run will be SKIPPED. Install the 'xvfb' package to run them on " +
"Linux, or pass -PuseRealDisplay to use your current display."
)
}
}
}
} else if (!org.gradle.internal.os.OperatingSystem.current().isLinux && !project.hasProperty("useRealDisplay")) {
// On Windows and macOS there is no Xvfb equivalent in the standard toolchain,
// so by default we force headless mode, which makes the Swing UI tests skip
// themselves instead of grabbing the developer's real display. Pass
// -PuseRealDisplay to run them against the current display instead.
tasks.withType<Test>().configureEach {
doFirst {
systemProperty("java.awt.headless", "true")
logger.warn(
"The Swing UI tests are SKIPPED by default on non-Linux platforms. " +
"Pass -PuseRealDisplay to run them against your current display instead."
)
}
}
}
tasks.check{
dependsOn("jacocoTestReport")
}
tasks.register("release") {
group = "Release"
description = "Creates all artifacts for a given EduMIPS64 release"
dependsOn("allDocs")
dependsOn("jar")
dependsOn("msi")
doFirst {
println("Creating artifacts for version $version.")
}
}
tasks.register<Exec>("msi"){
group = "Distribution"
description = "Creates an installable MSI file"
workingDir = projectDir
doFirst{
var os = System.getProperty("os.name") as String;
if (!("Windows" in os)){
throw GradleException("MSI creation must be executed on Windows")
}
var majorVersion = System.getProperty("java.version").split(".")[0].toInt()
if (majorVersion < 14) {
throw GradleException("JDK 14+ is required to create the MSI package.")
}
// Find the actual main JAR (excludes nohelp variant) so the filename
// always matches regardless of the git-describe build suffix.
val jarFile = layout.buildDirectory.get().asFile.listFiles()
?.filter { it.name.startsWith("edumips64-") && it.name.endsWith(".jar") && !it.name.contains("nohelp") }
?.firstOrNull()
?: throw GradleException("Could not find edumips64-*.jar in ${layout.buildDirectory.get().asFile}. Please execute ./gradlew jar before trying to build the MSI.")
if (System.getenv("WIX") == null){
throw GradleException("Wix is required to create the MSI package.")
}
val buildDirName = layout.buildDirectory.get().asFile.name
// jpackage's --input directory is copied in its entirety into the installer,
// so we stage just the main JAR in a dedicated folder to avoid shipping the
// nohelp JAR, WAR, etc. The MSI itself is written to the build directory root.
val inputStaging = layout.buildDirectory.dir("tmp/msi-input").get().asFile
inputStaging.deleteRecursively()
inputStaging.mkdirs()
jarFile.copyTo(inputStaging.resolve(jarFile.name), overwrite = true)
val destDir = "./${buildDirName}"
println("Creating ${destDir}/EduMIPS64-${version}.msi.");
val cmd = "jpackage.exe --main-jar ${jarFile.name} --input ./${buildDirName}/tmp/msi-input/ --dest ${destDir} --app-version ${version} --name EduMIPS64 --description \"Educational MIPS64 CPU Simulator\" --vendor \"EduMIPS64 Development Team\" --copyright \"Copyright ${LocalDateTime.now().year}, EduMIPS64 development Team\" --license-file ./LICENSE --win-shortcut --win-dir-chooser --win-menu --type msi --icon ./src/main/resources/images/ico.ico --win-per-user-install --java-options -Dfile.encoding=utf-8"
commandLine(cmd.split(" "));
}
}
/*
* GWT tasks
*/
gwt {
modules.add("org.edumips64.webclient")
sourceLevel = "1.11"
}
// Redirect GWT outputs from the plugin's hard-coded "gwt/war", "gwt/extras" and
// "gwt/codeServer" subdirectories. GWT always writes its output into a
// subfolder named after the module's `rename-to` value (we use "web"), so we
// point it at a scratch staging directory and then copy the produced files
// into out/web/ via the assembleWebApp task below.
tasks.named("gwtCompile") {
setProperty("outputDir", layout.buildDirectory.dir("tmp/gwt-war").get().asFile)
setProperty("extraOutputDir", layout.buildDirectory.dir("tmp/gwt-extras").get().asFile)
}
tasks.withType<War>().configureEach {
destinationDirectory.set(layout.buildDirectory)
}
// Copy the files produced by gwtCompile (scripts, resources) into out/web/,
// which is the canonical location for the assembled web application. Webpack
// also writes its bundle here, and copyWebHelp copies the HTML docs into
// out/web/docs/.
val assembleWebApp = tasks.register<Copy>("assembleWebApp") {
group = "Web"
description = "Assembles GWT compiler output into out/web/"
dependsOn("gwtCompile")
from(layout.buildDirectory.dir("tmp/gwt-war/web"))
into(layout.buildDirectory.dir("web"))
}
val npmExecutable = if (System.getProperty("os.name").lowercase().contains("windows")) "npm.cmd" else "npm"
val npmBuild = tasks.register<Exec>("npmBuild") {
group = "Web"
description = "Builds the EduMIPS64 React frontend"
workingDir = projectDir
commandLine(npmExecutable, "run", "build")
inputs.files(
"package.json",
"package-lock.json",
"vite.config.mts"
)
inputs.dir("src/webapp")
outputs.dir(layout.buildDirectory.dir("web"))
mustRunAfter("war")
}
val copyWebHelp = tasks.register("copyWebHelp") {
group = "Web"
description = "Copies the Web-flavored HTML help into the web UI bundle"
// Aggregate per-language copyWebHelp<Lang> tasks; each of them copies the
// `html-web/` Sphinx build output for one language into out/web/docs/.
copyWebHelpTaskNames.forEach { dependsOn(it) }
mustRunAfter("war")
}
// Transitional CI compatibility: `pull_request_target` loads reusable
// workflows (including build-web.yml) from the base branch, so while this
// PR is open the master workflow is still uploading the web artifact from
// the legacy `build/gwt/war/edumips64/` path. Mirror the assembled
// out/web/ tree there so the artifact upload finds the files. Once this
// PR is merged and master's build-web.yml uploads from `out/web`, this
// shim can be removed.
val mirrorLegacyWebApp = tasks.register<Copy>("mirrorLegacyWebApp") {
from(layout.buildDirectory.dir("web"))
into(layout.projectDirectory.dir("build/gwt/war/edumips64"))
dependsOn(assembleWebApp, npmBuild, copyWebHelp)
}
tasks.register("webapp") {
group = "Web"
description = "Builds the EduMIPS64 web application with bundled documentation"
dependsOn("war", mirrorLegacyWebApp)
}