mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-03-30 05:05:20 -05:00
Add option to configure datagen with the client. (#1224)
* Add option to configure datagen with the client. * Revert nightly upgrade
This commit is contained in:
@@ -55,6 +55,7 @@ import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftSourceSets;
|
||||
import net.fabricmc.loom.util.download.DownloadException;
|
||||
import net.fabricmc.loom.util.fmj.FabricModJson;
|
||||
import net.fabricmc.loom.util.fmj.FabricModJsonFactory;
|
||||
@@ -112,6 +113,7 @@ public abstract class FabricApiExtension {
|
||||
settings.getCreateSourceSet().convention(false);
|
||||
settings.getStrictValidation().convention(false);
|
||||
settings.getAddToResources().convention(true);
|
||||
settings.getClient().convention(false);
|
||||
|
||||
action.execute(settings);
|
||||
|
||||
@@ -139,22 +141,25 @@ public abstract class FabricApiExtension {
|
||||
});
|
||||
|
||||
if (settings.getCreateSourceSet().get()) {
|
||||
final boolean isClientAndSplit = extension.areEnvironmentSourceSetsSplit() && settings.getClient().get();
|
||||
final SourceSet targetSourceSet = isClientAndSplit ? SourceSetHelper.getSourceSetByName(MinecraftSourceSets.Split.CLIENT_ONLY_SOURCE_SET_NAME, getProject()) : mainSourceSet;
|
||||
|
||||
SourceSetContainer sourceSets = SourceSetHelper.getSourceSets(getProject());
|
||||
|
||||
// Create the new datagen sourceset, depend on the main sourceset.
|
||||
// Create the new datagen sourceset, depend on the main or client sourceset.
|
||||
SourceSet dataGenSourceSet = sourceSets.create(DATAGEN_SOURCESET_NAME, sourceSet -> {
|
||||
sourceSet.setCompileClasspath(
|
||||
sourceSet.getCompileClasspath()
|
||||
.plus(mainSourceSet.getOutput())
|
||||
.plus(targetSourceSet.getOutput())
|
||||
);
|
||||
|
||||
sourceSet.setRuntimeClasspath(
|
||||
sourceSet.getRuntimeClasspath()
|
||||
.plus(mainSourceSet.getOutput())
|
||||
.plus(targetSourceSet.getOutput())
|
||||
);
|
||||
|
||||
extendsFrom(getProject(), sourceSet.getCompileClasspathConfigurationName(), mainSourceSet.getCompileClasspathConfigurationName());
|
||||
extendsFrom(getProject(), sourceSet.getRuntimeClasspathConfigurationName(), mainSourceSet.getRuntimeClasspathConfigurationName());
|
||||
extendsFrom(getProject(), sourceSet.getCompileClasspathConfigurationName(), targetSourceSet.getCompileClasspathConfigurationName());
|
||||
extendsFrom(getProject(), sourceSet.getRuntimeClasspathConfigurationName(), targetSourceSet.getRuntimeClasspathConfigurationName());
|
||||
});
|
||||
|
||||
settings.getModId().convention(getProject().provider(() -> {
|
||||
@@ -181,7 +186,7 @@ public abstract class FabricApiExtension {
|
||||
|
||||
if (settings.getCreateRunConfiguration().get()) {
|
||||
extension.getRunConfigs().create("datagen", run -> {
|
||||
run.inherit(extension.getRunConfigs().getByName("server"));
|
||||
run.inherit(extension.getRunConfigs().getByName(settings.getClient().get() ? "client" : "server"));
|
||||
run.setConfigName("Data Generation");
|
||||
|
||||
run.property("fabric-api.datagen");
|
||||
@@ -235,6 +240,11 @@ public abstract class FabricApiExtension {
|
||||
* Contains a boolean property indicating whether the generated resources will be automatically added to the main sourceset.
|
||||
*/
|
||||
Property<Boolean> getAddToResources();
|
||||
|
||||
/**
|
||||
* Contains a boolean property indicating whether data generation will be compiled and ran with the client.
|
||||
*/
|
||||
Property<Boolean> getClient();
|
||||
}
|
||||
|
||||
private String getDependencyNotation(String moduleName, String fabricApiVersion) {
|
||||
|
||||
@@ -29,10 +29,20 @@ import spock.lang.Unroll
|
||||
|
||||
import net.fabricmc.loom.test.util.GradleProjectTestTrait
|
||||
|
||||
import static net.fabricmc.loom.test.LoomTestConstants.PRE_RELEASE_GRADLE
|
||||
import static net.fabricmc.loom.test.LoomTestConstants.STANDARD_TEST_VERSIONS
|
||||
import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
|
||||
|
||||
class DataGenerationTest extends Specification implements GradleProjectTestTrait {
|
||||
private static String DEPENDENCIES = """
|
||||
dependencies {
|
||||
minecraft "com.mojang:minecraft:1.20.2"
|
||||
mappings "net.fabricmc:yarn:1.20.2+build.4:v2"
|
||||
modImplementation "net.fabricmc:fabric-loader:0.14.23"
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:0.90.0+1.20.2"
|
||||
}
|
||||
"""
|
||||
|
||||
@Unroll
|
||||
def "dataGeneration (gradle #version)"() {
|
||||
setup:
|
||||
@@ -41,14 +51,7 @@ class DataGenerationTest extends Specification implements GradleProjectTestTrait
|
||||
fabricApi {
|
||||
configureDataGeneration()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
minecraft "com.mojang:minecraft:1.20.2"
|
||||
mappings "net.fabricmc:yarn:1.20.2+build.4:v2"
|
||||
modImplementation "net.fabricmc:fabric-loader:0.14.23"
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:0.90.0+1.20.2"
|
||||
}
|
||||
'''
|
||||
''' + DEPENDENCIES
|
||||
when:
|
||||
def result = gradle.run(task: "runDatagen")
|
||||
|
||||
@@ -80,17 +83,8 @@ class DataGenerationTest extends Specification implements GradleProjectTestTrait
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
minecraft "com.mojang:minecraft:1.20.2"
|
||||
mappings "net.fabricmc:yarn:1.20.2+build.4:v2"
|
||||
modImplementation "net.fabricmc:fabric-loader:0.14.23"
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:0.90.0+1.20.2"
|
||||
|
||||
modDatagenImplementation fabricApi.module("fabric-data-generation-api-v1", "0.90.0+1.20.2")
|
||||
}
|
||||
|
||||
println("%%" + loom.runs.datagen.configName + "%%")
|
||||
'''
|
||||
''' + DEPENDENCIES
|
||||
when:
|
||||
def result = gradle.run(task: "runDatagen")
|
||||
|
||||
@@ -101,4 +95,111 @@ class DataGenerationTest extends Specification implements GradleProjectTestTrait
|
||||
where:
|
||||
version << STANDARD_TEST_VERSIONS
|
||||
}
|
||||
|
||||
@Unroll
|
||||
def "client dataGeneration (gradle #version)"() {
|
||||
setup:
|
||||
def gradle = gradleProject(project: "minimalBase", version: PRE_RELEASE_GRADLE)
|
||||
gradle.buildGradle << '''
|
||||
fabricApi {
|
||||
configureDataGeneration {
|
||||
client = true
|
||||
}
|
||||
}
|
||||
''' + DEPENDENCIES
|
||||
when:
|
||||
def result = gradle.run(task: "runDatagen")
|
||||
|
||||
then:
|
||||
result.task(":runDatagen").outcome == SUCCESS
|
||||
}
|
||||
|
||||
@Unroll
|
||||
def "client dataGeneration sourceset (gradle #version)"() {
|
||||
setup:
|
||||
def gradle = gradleProject(project: "minimalBase", version: PRE_RELEASE_GRADLE)
|
||||
gradle.buildGradle << '''
|
||||
// Must configure the main mod
|
||||
loom.mods {
|
||||
"example" {
|
||||
sourceSet sourceSets.main
|
||||
}
|
||||
}
|
||||
|
||||
fabricApi {
|
||||
configureDataGeneration {
|
||||
createSourceSet = true
|
||||
createRunConfiguration = true
|
||||
modId = "example-datagen"
|
||||
strictValidation = true
|
||||
client = true
|
||||
}
|
||||
}
|
||||
''' + DEPENDENCIES
|
||||
when:
|
||||
def result = gradle.run(task: "runDatagen")
|
||||
|
||||
then:
|
||||
result.task(":runDatagen").outcome == SUCCESS
|
||||
}
|
||||
|
||||
@Unroll
|
||||
def "split client dataGeneration (gradle #version)"() {
|
||||
setup:
|
||||
def gradle = gradleProject(project: "minimalBase", version: PRE_RELEASE_GRADLE)
|
||||
gradle.buildGradle << '''
|
||||
loom {
|
||||
splitEnvironmentSourceSets()
|
||||
mods {
|
||||
"example" {
|
||||
sourceSet sourceSets.main
|
||||
sourceSet sourceSets.client
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fabricApi {
|
||||
configureDataGeneration {
|
||||
client = true
|
||||
}
|
||||
}
|
||||
''' + DEPENDENCIES
|
||||
when:
|
||||
def result = gradle.run(task: "runDatagen")
|
||||
|
||||
then:
|
||||
result.task(":runDatagen").outcome == SUCCESS
|
||||
}
|
||||
|
||||
@Unroll
|
||||
def "split client dataGeneration sourceset (gradle #version)"() {
|
||||
setup:
|
||||
def gradle = gradleProject(project: "minimalBase", version: PRE_RELEASE_GRADLE)
|
||||
gradle.buildGradle << '''
|
||||
loom {
|
||||
splitEnvironmentSourceSets()
|
||||
mods {
|
||||
"example" {
|
||||
sourceSet sourceSets.main
|
||||
sourceSet sourceSets.client
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fabricApi {
|
||||
configureDataGeneration {
|
||||
createSourceSet = true
|
||||
createRunConfiguration = true
|
||||
modId = "example-datagen"
|
||||
strictValidation = true
|
||||
client = true
|
||||
}
|
||||
}
|
||||
''' + DEPENDENCIES
|
||||
when:
|
||||
def result = gradle.run(task: "runDatagen")
|
||||
|
||||
then:
|
||||
result.task(":runDatagen").outcome == SUCCESS
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user