mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
Build the built-in modules as a pack module jar from a list of module classes and check it with IrisApi's pack class checks
builtinModulesJar packages the classes listed in builtin-modules.txt from Iris core's compiled output, writes the module entry points, runs ModuleJarCheck on the result and only then puts build/libs/iris-builtins.jar in place. Nothing is listed yet.
This commit is contained in:
1 parent
98562bf962
commit
5a99c2e70c
3 files changed
+138
-1
No files matched your search
@@ -37,3 +37,14 @@ core against the existing allowlist.
|
||||
From this directory, run `./gradlew check` to invoke the Iris host's joint compilation and purity
|
||||
check and build the module sources archive. Run `./gradlew builtinSourcesJar` to build just the
|
||||
archive. The host project also provides `:core:defaultModuleSourcesJar` for the same source tree.
|
||||
|
||||
## Built-in modules as a pack module jar
|
||||
|
||||
`./gradlew builtinModulesJar` builds `build/libs/iris-builtins.jar`, the built-in modules as an ordinary pack
|
||||
module jar for a pack's `modules/` folder. `builtin-modules.txt` lists what goes in: `module <class>` lines
|
||||
(the jar's entry points, written to `META-INF/services/com.volmit.IrisModule`) and `include <pattern>` lines
|
||||
for further classes. The classes come from Iris core's compiled output, which the task builds first.
|
||||
Before the jar lands in `build/libs`, `ModuleJarCheck` of IrisApi runs the class checks of a pack load on it,
|
||||
with `art.arcane.iris.builtin` as the only exposed Iris package; a listed class that uses Iris internals fails
|
||||
the task naming the class and what it uses. `check` runs the task. Nothing is ported yet, so the jar is empty
|
||||
and not loadable as a pack module (a pack module jar must name at least one module).
|
||||
+111
-1
@@ -1,7 +1,9 @@
|
||||
import org.gradle.jvm.tasks.Jar
|
||||
import java.io.ByteArrayOutputStream
|
||||
|
||||
plugins {
|
||||
base
|
||||
`java-base`
|
||||
}
|
||||
|
||||
group = "art.arcane"
|
||||
@@ -33,8 +35,116 @@ val checkBuiltins = tasks.register<Exec>("checkBuiltins") {
|
||||
)
|
||||
}
|
||||
|
||||
// The built-ins as a pack module jar, to put into a pack's modules/ folder. What goes in is listed in builtin-modules.txt.
|
||||
|
||||
/** What [builtinModulesFile] lists: module classes (the jar's entry points) and further class patterns. */
|
||||
data class BuiltinModuleList(val moduleClasses: List<String>, val classPatterns: List<String>) {
|
||||
/** Ant patterns, relative to the class root, of every class the jar takes from Iris's compiled classes. */
|
||||
fun packagedClassPatterns(): List<String> =
|
||||
moduleClasses.flatMap { listOf(it.replace('.', '/') + ".class", it.replace('.', '/') + "$*.class") } + classPatterns
|
||||
}
|
||||
|
||||
fun readBuiltinModuleList(file: File): BuiltinModuleList {
|
||||
val moduleClasses = mutableListOf<String>()
|
||||
val classPatterns = mutableListOf<String>()
|
||||
file.readLines().map { it.substringBefore('#').trim() }.filter { it.isNotEmpty() }.forEach { line ->
|
||||
val (keyword, value) = line.split(Regex("\\s+"), limit = 2).let { it[0] to it.getOrElse(1) { "" }.trim() }
|
||||
require(value.isNotEmpty()) { "${file.name}: '$line' needs a value after '$keyword'" }
|
||||
when (keyword) {
|
||||
"module" -> moduleClasses += value
|
||||
"include" -> classPatterns += value
|
||||
else -> throw GradleException("${file.name}: unknown line '$line'; start it with 'module' or 'include'")
|
||||
}
|
||||
}
|
||||
return BuiltinModuleList(moduleClasses, classPatterns)
|
||||
}
|
||||
|
||||
val builtinModulesFile = layout.projectDirectory.file("builtin-modules.txt").asFile
|
||||
val builtinModuleList = readBuiltinModuleList(builtinModulesFile)
|
||||
val builtinModulesJarName = "iris-builtins.jar"
|
||||
val builtinModuleEntryFile = "com.volmit.IrisModule"
|
||||
|
||||
/** Host packages pack modules may use besides the IrisApi. Keep in step with IrisModuleHost.BUILT_IN_API_PACKAGE in Iris. */
|
||||
val exposedHostPackages = listOf("art.arcane.iris.builtin")
|
||||
val irisClasses = irisRoot.resolve("core/build/classes/java/main")
|
||||
val builtinModulesBuild = layout.buildDirectory.dir("builtin-modules")
|
||||
val checkedJarsDirectory = layout.buildDirectory.dir("libs")
|
||||
|
||||
val irisApiForChecks by configurations.creating {
|
||||
isCanBeConsumed = false
|
||||
attributes.attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME))
|
||||
}
|
||||
|
||||
dependencies {
|
||||
irisApiForChecks("com.volmit:IrisApi")
|
||||
}
|
||||
|
||||
val compileBuiltins = tasks.register<Exec>("compileBuiltins") {
|
||||
description = "Compiles Iris core together with the built-in sources, which is where the jar's classes come from."
|
||||
workingDir(irisRoot)
|
||||
val offline = if (gradle.startParameter.isOffline) listOf("--offline") else emptyList()
|
||||
commandLine(listOf("./gradlew", ":core:compileJava", "-PincludeModdedAdapters=false", "--console=plain") + offline)
|
||||
}
|
||||
|
||||
val writeBuiltinModuleEntries = tasks.register("writeBuiltinModuleEntries") {
|
||||
description = "Writes the jar's META-INF/services/$builtinModuleEntryFile, one module class per line."
|
||||
val entries = builtinModulesBuild.map { it.file("services/$builtinModuleEntryFile") }
|
||||
inputs.file(builtinModulesFile)
|
||||
outputs.file(entries)
|
||||
doLast {
|
||||
entries.get().asFile.apply { parentFile.mkdirs() }.writeText(builtinModuleList.moduleClasses.joinToString("\n", postfix = "\n"))
|
||||
}
|
||||
}
|
||||
|
||||
val packageBuiltinModules = tasks.register<Jar>("packageBuiltinModules") {
|
||||
description = "Packages the listed built-in modules and classes before they are checked."
|
||||
dependsOn(compileBuiltins)
|
||||
archiveFileName.set(builtinModulesJarName)
|
||||
destinationDirectory.set(builtinModulesBuild.map { it.dir("unchecked") })
|
||||
inputs.file(builtinModulesFile)
|
||||
val patterns = builtinModuleList.packagedClassPatterns()
|
||||
// An empty include list would take every class of Iris.
|
||||
if (patterns.isNotEmpty()) {
|
||||
from(irisClasses) { include(patterns) }
|
||||
from(writeBuiltinModuleEntries) { into("META-INF/services") }
|
||||
}
|
||||
}
|
||||
|
||||
val checkBuiltinModulesJar = tasks.register<JavaExec>("checkBuiltinModulesJar") {
|
||||
description = "Runs IrisApi's pack class and reference checks on the packaged jar, as a pack load would."
|
||||
dependsOn(packageBuiltinModules)
|
||||
// A jar without module entries is not a loadable pack module; there is nothing to check until a module is listed.
|
||||
onlyIf { builtinModuleList.moduleClasses.isNotEmpty() }
|
||||
val packaged = packageBuiltinModules.flatMap { it.archiveFile }
|
||||
classpath = irisApiForChecks + files(irisClasses)
|
||||
mainClass.set("com.volmit.host.ModuleJarCheck")
|
||||
javaLauncher.set(javaToolchains.launcherFor { languageVersion.set(JavaLanguageVersion.of(25)) })
|
||||
argumentProviders.add(CommandLineArgumentProvider { listOf(packaged.get().asFile.absolutePath) + exposedHostPackages })
|
||||
isIgnoreExitValue = true
|
||||
val problems = ByteArrayOutputStream()
|
||||
errorOutput = problems
|
||||
doFirst {
|
||||
// A jar from an earlier run that passed must not survive a run that fails.
|
||||
checkedJarsDirectory.get().file(builtinModulesJarName).asFile.delete()
|
||||
}
|
||||
doLast {
|
||||
if (executionResult.get().exitValue == 0) return@doLast
|
||||
throw GradleException(
|
||||
"The built-in modules jar breaks the rules of a pack module jar:\n" + problems.toString().trim() +
|
||||
"\nFix the classes listed in ${builtinModulesFile.name}, or move what they use into the jar or into art.arcane.iris.builtin.")
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register<Copy>("builtinModulesJar") {
|
||||
group = "build"
|
||||
description = "Builds build/libs/$builtinModulesJarName, the built-in modules as a pack module jar for a pack's modules/ folder."
|
||||
dependsOn(checkBuiltinModulesJar)
|
||||
from(packageBuiltinModules.flatMap { it.archiveFile })
|
||||
into(checkedJarsDirectory)
|
||||
}
|
||||
|
||||
tasks.named("check") {
|
||||
dependsOn(checkBuiltins, "builtinSourcesJar")
|
||||
dependsOn(checkBuiltins, "builtinSourcesJar", "builtinModulesJar")
|
||||
}
|
||||
|
||||
tasks.named("assemble") {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
# What goes into build/libs/iris-builtins.jar, the built-in modules as a pack module jar.
|
||||
#
|
||||
# A line is one of (blank lines and # comments are ignored):
|
||||
#
|
||||
# module <binary class name> an IrisModule class. It is listed in META-INF/services/com.volmit.IrisModule,
|
||||
# and its nested classes are packaged with it.
|
||||
# include <class pattern> more classes for the jar, as an Ant pattern relative to the class root, such as
|
||||
# art/arcane/iris/engine/modifier/carve/** Settings types, helpers and stage
|
||||
# constants a listed module owns go here.
|
||||
#
|
||||
# A class here must be one a pack module may have: it may use only the IrisApi, the packages Iris exposes
|
||||
# (art.arcane.iris.builtin), the JDK and the other classes of the jar. `./gradlew builtinModulesJar` checks
|
||||
# that with IrisApi's pack class checks and fails naming the class and what it uses.
|
||||
#
|
||||
# Moving a module here means removing it from IrisModuleHost.generationModules() or PlacementModules.all() in Iris.
|
||||
# Nothing is ported yet.
|
||||
Reference in new issue
Block a user