mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
Iris packages and bundles the built-ins jar; this build copies it
The built-ins jar is now packaged and checked by Iris's :core:builtinModulesJar from core's own compiled classes and bundled into the plugin, so it always fits the Iris it ships with. builtinModulesJar here runs that task and copies the jar to build/libs; the packaging, entry file and check tasks moved to Iris, with the VolmLib include build they needed. SurfaceFitting (structure fitting, still Iris's) has its own outset instead of calling IrisObjectVacuum, which lives in the jar only: the plugin no longer carries the jar's classes outside the jar.
This commit is contained in:
1 parent
f06908a20f
commit
242ca3e323
4 files changed
+38
-140
No files matched your search
@@ -160,16 +160,19 @@ archive. The host project also provides `:core:defaultModuleSourcesJar` for the
|
||||
|
||||
## 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 the packages Iris exposes (`art.arcane.iris.builtin`, VolmLib's `art.arcane.volmlib` and Gson's
|
||||
`com.google.gson`, all three on the check's classpath); a listed class that uses Iris internals fails the task
|
||||
naming the class and what it uses. A VolmLib class that Iris's Bukkit jar strips (the list is Iris's
|
||||
`core/volmlib-left-out-of-bukkit-jar.txt`, which its shadowJar reads too) is on that classpath but missing on a
|
||||
server, so the check treats it as missing and fails the task naming it. `check` runs the task.
|
||||
Iris builds the built-in modules as an ordinary pack module jar, `iris-builtins.jar`, and bundles it into the plugin:
|
||||
Iris's `:core:builtinModulesJar` packages it from core's compiled classes, so it always fits the Iris it ships with, and
|
||||
every pack loads it as if it were in its `modules/` folder (IrisApi's `ModuleHost.bundlingJars`). A pack's own
|
||||
`modules/iris-builtins.jar`, such as an old copy, is left out, and Iris warns once with its path. `./gradlew builtinModulesJar`
|
||||
here runs that task and copies the jar to `build/libs/iris-builtins.jar`. `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 plugin's own classes leave those classes out; Iris's Bukkit artifact check fails the build if
|
||||
core still uses one of them.
|
||||
Before the jar is used, `ModuleJarCheck` of IrisApi runs the class checks of a pack load on it, with the packages Iris
|
||||
exposes (`art.arcane.iris.builtin`, VolmLib's `art.arcane.volmlib` and Gson's `com.google.gson`, all three on the check's
|
||||
classpath); a listed class that uses Iris internals fails the task naming the class and what it uses. A VolmLib class that
|
||||
Iris's Bukkit jar strips (the list is Iris's `core/volmlib-left-out-of-bukkit-jar.txt`, which its shadowJar reads too) is on
|
||||
that classpath but missing on a server, so the check treats it as missing and fails the task naming it. `check` runs the task.
|
||||
|
||||
The jar holds `iris:post`, `iris:perfection`, `iris:matter`, `iris:loot`, `iris:spawn`, `iris:vanilla-features` and
|
||||
`iris:carve`, and the object placement stages `iris:prepare`, `iris:anchor`, `iris:validate`, `iris:bore`, `iris:blocks`, `iris:stilt`, `iris:vacuum` and `iris:snow`. They are
|
||||
@@ -179,10 +182,9 @@ mantle's planned blocks; the placement stages read the placement being run throu
|
||||
spawn services, which have no chunk to ask, ask `LiveWorld` (both below). Without the jar a pack's world has no caves, vanilla
|
||||
placed features, loot, block drops, entity spawns or ambient effects, and its biomes' `loot`, `blockDrops`, `entitySpawners` and
|
||||
`effects` are not read.
|
||||
Iris no longer compiles them in (`IrisModuleHost.generationModules()`), so a pack gets them by putting
|
||||
`iris-builtins.jar` into its `modules` folder; the built-ins that order after their stages (`iris:floating`,
|
||||
`iris:objects`, `iris:decorant`, `iris:custom`) only order, so a pack without the jar still loads. Iris warns once per pack folder
|
||||
when a pack loads none of the jar's modules (`IrisModuleHost.JAR_MODULE_IDS`, which a test keeps equal to
|
||||
Iris no longer compiles them in (`IrisModuleHost.generationModules()`); every pack gets them from the bundled jar. A pack
|
||||
still loads without them, as with an Iris build that bundles no jar, and Iris warns once per pack folder when a pack loads
|
||||
none of the jar's modules (`IrisModuleHost.JAR_MODULE_IDS`, which a test keeps equal to
|
||||
`builtin-modules.txt`): add a module to the jar and to that list together.
|
||||
|
||||
`art.arcane.iris.builtin` also holds what the compiled-in built-ins and the jar must share, because each sees its own copy of
|
||||
|
||||
+9
-116
@@ -1,5 +1,4 @@
|
||||
import org.gradle.jvm.tasks.Jar
|
||||
import java.io.ByteArrayOutputStream
|
||||
|
||||
plugins {
|
||||
base
|
||||
@@ -35,129 +34,23 @@ 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)
|
||||
// The built-ins as a pack module jar. Iris packages and checks it from its own compiled classes (core's builtinModulesJar,
|
||||
// which reads builtin-modules.txt) and bundles it into the plugin; this copies it to build/libs for other hosts and tools.
|
||||
val builtinModulesJarName = "iris-builtins.jar"
|
||||
val builtinModuleEntryFile = "com.volmit.IrisModule"
|
||||
|
||||
/**
|
||||
* Host packages pack modules may use besides the IrisApi: the built-in module API, VolmLib and Gson. Keep in step with
|
||||
* IrisModuleHost.EXPOSED_PACKAGES in Iris.
|
||||
*/
|
||||
val exposedHostPackages = listOf("art.arcane.iris.builtin", "art.arcane.volmlib", "com.google.gson")
|
||||
val irisClasses = irisRoot.resolve("core/build/classes/java/main")
|
||||
/** The VolmLib classes Iris's Bukkit jar strips; Iris's shadowJar reads the same file. A module may not use them. */
|
||||
val volmLibLeftOutFile = irisRoot.resolve("core/volmlib-left-out-of-bukkit-jar.txt")
|
||||
val builtinModulesBuild = layout.buildDirectory.dir("builtin-modules")
|
||||
val checkedJarsDirectory = layout.buildDirectory.dir("libs")
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
/** What the jar check sees besides Iris's classes: the IrisApi and the libraries Iris shares with pack modules. */
|
||||
val irisApiForChecks by configurations.creating {
|
||||
isCanBeConsumed = false
|
||||
isTransitive = false
|
||||
attributes.attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME))
|
||||
}
|
||||
|
||||
dependencies {
|
||||
irisApiForChecks("com.volmit:IrisApi")
|
||||
irisApiForChecks("com.github.VolmitSoftware:VolmLib")
|
||||
// The Gson Iris compiles against (Iris/gradle/libs.versions.toml); at runtime modules get the platform's copy.
|
||||
irisApiForChecks("com.google.code.gson:gson:2.14.0")
|
||||
}
|
||||
|
||||
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."
|
||||
val packageBuiltinModulesInIris = tasks.register<Exec>("packageBuiltinModulesInIris") {
|
||||
description = "Runs Iris's :core:builtinModulesJar, which compiles Iris with the built-ins, packages and checks the jar."
|
||||
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)) })
|
||||
inputs.file(volmLibLeftOutFile)
|
||||
argumentProviders.add(CommandLineArgumentProvider {
|
||||
listOf(packaged.get().asFile.absolutePath, "--left-out=${volmLibLeftOutFile.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.")
|
||||
}
|
||||
commandLine(listOf("./gradlew", ":core:builtinModulesJar", "-PincludeModdedAdapters=false", "--console=plain") + offline)
|
||||
}
|
||||
|
||||
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)
|
||||
description = "Copies the checked jar Iris built to build/libs/$builtinModulesJarName, the built-in modules as a pack module jar."
|
||||
dependsOn(packageBuiltinModulesInIris)
|
||||
from(irisRoot.resolve("core/build/builtin-modules/$builtinModulesJarName"))
|
||||
into(layout.buildDirectory.dir("libs"))
|
||||
}
|
||||
|
||||
tasks.named("check") {
|
||||
|
||||
@@ -2,10 +2,3 @@ rootProject.name = "IrisModule"
|
||||
|
||||
// Keep the public API discoverable when importing the default module.
|
||||
includeBuild("../IrisApi")
|
||||
|
||||
// The built-ins jar check sees the libraries Iris shares with pack modules; VolmLib comes from the sibling checkout, as for Iris.
|
||||
includeBuild("../VolmLib") {
|
||||
dependencySubstitution {
|
||||
substitute(module("com.github.VolmitSoftware:VolmLib")).using(project(":shared"))
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,6 @@
|
||||
package art.arcane.iris.engine.framework.structure.fit;
|
||||
|
||||
import art.arcane.iris.builtin.structure.StructureTerrainMode;
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectVacuum;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.vanilla.DecorationStep;
|
||||
@@ -123,6 +122,17 @@ final class SurfaceFitting {
|
||||
return resolveSurface(anchors, worldX, worldZ, originalY).targetY();
|
||||
}
|
||||
|
||||
/** How far {@code value} lies outside {@code [low, high]}; 0 inside. Iris's vacuum measures footprints the same way. */
|
||||
private static int outset(int value, int low, int high) {
|
||||
if (value < low) {
|
||||
return low - value;
|
||||
}
|
||||
if (value > high) {
|
||||
return value - high;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static SurfaceResolution resolveSurface(List<SurfaceAnchor> anchors, int worldX, int worldZ, int originalY) {
|
||||
int localTargetY = originalY;
|
||||
SurfaceAnchor selectedLocal = null;
|
||||
@@ -130,8 +140,8 @@ final class SurfaceFitting {
|
||||
long weightedTargetY = 0L;
|
||||
long maximumInfluence = 0L;
|
||||
for (SurfaceAnchor anchor : anchors) {
|
||||
int outX = IrisObjectVacuum.outset(worldX, anchor.minX(), anchor.maxX());
|
||||
int outZ = IrisObjectVacuum.outset(worldZ, anchor.minZ(), anchor.maxZ());
|
||||
int outX = outset(worldX, anchor.minX(), anchor.maxX());
|
||||
int outZ = outset(worldZ, anchor.minZ(), anchor.maxZ());
|
||||
boolean containsColumn = outX == 0 && outZ == 0;
|
||||
long distanceSquared = (long) outX * outX + (long) outZ * outZ;
|
||||
long radiusSquared = (long) SURFACE_TERRAIN_RADIUS * SURFACE_TERRAIN_RADIUS;
|
||||
|
||||
Reference in new issue
Block a user