Skip to content

Commit

Permalink
Add Build Host task (#77)
Browse files Browse the repository at this point in the history
* feat(gradle): Add convinience task to build for host architecture

* chore: Try to make test build a bit better in recompile guarentee

* fix(gradle): Ensure task ordering of package and build tasks
  • Loading branch information
Berstanio authored Oct 18, 2024
1 parent fdc4ba5 commit 0606d1f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.badlogic.gdx.jnigen.RobovmBuildConfig;
import com.badlogic.gdx.jnigen.commons.*;
import org.gradle.api.Action;
import org.gradle.api.DefaultTask;
import org.gradle.api.Project;
import org.gradle.api.plugins.JavaPluginConvention;
import org.gradle.api.tasks.SourceSet;
Expand Down Expand Up @@ -205,7 +206,7 @@ public void add (Os targetOs, Architecture.Bitness bitness, Architecture archite
}

private Set<Os> osLevelTargetsSeen = new HashSet<>();
private Set<Platform> platformLevelTargetsSeen = new HashSet<>();
private Map<Platform, JnigenPackageTask> platformLevelTargetsSeen = new HashMap<>();

private void checkForTasksToAdd (BuildTarget target) {

Expand All @@ -216,11 +217,20 @@ private void checkForTasksToAdd (BuildTarget target) {

JnigenTask jnigenTask = (JnigenTask) project.getTasks().getByName("jnigen");

if (!platformLevelTargetsSeen.containsKey(platform)) {
JnigenPackageTask jnigenPackageTask = project.getTasks().create("jnigenPackageAll" + platform.name(), JnigenPackageTask.class, this);
jnigenPackageTask.configure(null, platform);

platformLevelTargetsSeen.put(platform, jnigenPackageTask);
}

if (!osLevelTargetsSeen.contains(os)) {
osLevelTargetsSeen.add(os);
JnigenBuildTask jnigenBuildTask = project.getTasks().create("jnigenBuildAll" + os.name(), JnigenBuildTask.class, this);
jnigenBuildTask.setOsToBuild(os);
jnigenBuildTask.dependsOn(jnigenTask);

platformLevelTargetsSeen.get(platform).mustRunAfter(jnigenBuildTask);
}

if (target.os == Android) {
Expand All @@ -233,22 +243,24 @@ private void checkForTasksToAdd (BuildTarget target) {
JnigenPackageTask jnigenPackageTask = project.getTasks().create("jnigenPackage" + platform.name() + "_" + target.getTargetAndroidABI().getAbiString(), JnigenPackageTask.class, this);
jnigenPackageTask.configure(target.getTargetAndroidABI(), platform);

jnigenPackageTask.mustRunAfter(jnigenBuildTask);
platformLevelTargetsSeen.get(platform).mustRunAfter(jnigenBuildTask);
} else if (target.os == Os.IOS) {
//Nope! No platform specific builds for ios, because theyend up in framework.
//Don't want to have to do a separate task after for combining the framework
} else {
JnigenBuildTask jnigenBuildTask = project.getTasks().create("jnigenBuild" + os.name() + "_" + architecture.getDisplayName() + bitness.name(), JnigenBuildTask.class, this);
jnigenBuildTask.setBuildTarget(target);
jnigenBuildTask.dependsOn(jnigenTask);
}

if (!platformLevelTargetsSeen.contains(platform)) {
platformLevelTargetsSeen.add(platform);

JnigenPackageTask jnigenPackageTask = project.getTasks().create("jnigenPackageAll" + platform.name(), JnigenPackageTask.class, this);
jnigenPackageTask.configure(null, platform);
platformLevelTargetsSeen.get(platform).mustRunAfter(jnigenBuildTask);
if (HostDetection.os == os && HostDetection.architecture == architecture && HostDetection.bitness == bitness) {
DefaultTask hostTask = project.getTasks().create("jnigenBuildHost", DefaultTask.class);
hostTask.dependsOn(jnigenBuildTask);
hostTask.setGroup("jnigen");
hostTask.setDescription("Builds only the host architecture");
}
}

}

public BuildTarget get (Os type, Architecture.Bitness bitness, Architecture architecture, AndroidABI androidABI, TargetType targetType, Action<BuildTarget> container) {
Expand Down
14 changes: 3 additions & 11 deletions gdx-jnigen-generator-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies {


test {
dependsOn "jnigenSequence"
dependsOn "jnigenSequence", "jnigenPackageAllDesktop"
useJUnitPlatform()
outputs.upToDateWhen {false}
}
Expand Down Expand Up @@ -74,16 +74,8 @@ jnigen {
}

tasks.register("jnigenSequence") {
dependsOn "compileTestJava"
dependsOn "jnigen"
if (HostDetection.os === Os.Windows) {
dependsOn "jnigenBuildAllWindows"
} else if (HostDetection.os === Os.Linux) {
dependsOn "jnigenBuildAllLinux"
} else if (HostDetection.os === Os.MacOsX) {
dependsOn "jnigenBuildAllMacOsX"
}
dependsOn "jnigenPackageAllDesktop"
dependsOn "jnigenBuildHost"
dependsOn(":jnigen-runtime:jnigenBuildHost")
}


Expand Down

0 comments on commit 0606d1f

Please sign in to comment.