Skip to content

Commit

Permalink
fix: Build for correct buildTarget
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonIT committed Jan 2, 2025
1 parent 3c4ae8f commit 0d23ee0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ private void checkForTasksToAdd (BuildTarget target) {
jnigenBuildTask.dependsOn(jnigenTask);

JnigenSignTask jnigenSignTask = project.getTasks().create("jnigenSign" + os.name() + "_" + architecture.getDisplayName() + bitness.name(), JnigenSignTask.class, this);
jnigenSignTask.setBuildTarget(target);
jnigenSignTask.dependsOn(jnigenBuildTask);

platformLevelTargetsSeen.get(platform).mustRunAfter(jnigenBuildTask);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.badlogic.gdx.jnigen.gradle;

import com.badlogic.gdx.jnigen.BuildConfig;
import com.badlogic.gdx.jnigen.BuildTarget;
import com.badlogic.gdx.jnigen.FileDescriptor;
import com.badlogic.gdx.jnigen.build.RuntimeEnv;
import com.badlogic.gdx.jnigen.build.ToolFinder;
Expand All @@ -24,6 +25,8 @@ public class JnigenSignTask extends DefaultTask {

private final JnigenExtension ext;

private BuildTarget buildTarget;

@Inject
public JnigenSignTask(JnigenExtension ext) {
this.ext = ext;
Expand All @@ -32,57 +35,29 @@ public JnigenSignTask(JnigenExtension ext) {
setDescription("Signs native libraries");
}

public void setBuildTarget (BuildTarget buildTarget) {
this.buildTarget = buildTarget;
}

@TaskAction
public void run() {
BuildConfig buildConfig = new BuildConfig(ext.sharedLibName, ext.subProjectDir + ext.temporaryDir, ext.subProjectDir + ext.libsDir, ext.subProjectDir + ext.jniDir, null, new FileDescriptor(ext.subProjectDir));
RuntimeEnv env = new RuntimeEnv();
List<String> args = new ArrayList<>();
ext.targets.forEach(target -> {
switch (target.os) {
switch (buildTarget.os) {
case Windows:
Map<String, String> params = ext.signing.getJsignParams();
params.put("file", target.getTargetBinaryFile(buildConfig).getPath());
params.put("file", buildTarget.getTargetBinaryFile(buildConfig).getPath());
Closure<?> jsign = (Closure<?>) ext.project.getExtensions().getByName("jsign");
jsign.call(params);
break;
case Linux:
File bsign = ToolFinder.getToolFile("bsign", env, true);
String secretKeyRingFile = (String) getProject().property("signing.secretKeyRingFile");
String keyId = (String) getProject().property("signing.keyId");
String password = (String) getProject().property("signing.password");
args.add("--sign");
args.add(target.getTargetBinaryFile(buildConfig).getPath());
args.add("-P");
args.add(String.format("\"--keyring %s --default-key %s --passphrase %s --batch\"", secretKeyRingFile, keyId, password));
ToolchainExecutor.execute(bsign, new File(""), args, new ToolchainExecutor.ToolchainCallback() {
@Override
public void onInfoMessage(String message) {
log.info(message);
}

@Override
public void onErrorMessage(String message) {
log.error(message);
}

@Override
public void onSuccess() {
log.info("Signing successful");
}

@Override
public void onFail(int statusCode) {
log.error("Signing failed with status code: {}", statusCode);
}
});
break;
case MacOsX:
case IOS:
File codesign = ToolFinder.getToolFile("codesign", env, true);
args.add("-s");
args.add(ext.signing.getIdentity());
args.add("-f");
args.add(target.getTargetBinaryFile(buildConfig).getPath());
args.add(buildTarget.getTargetBinaryFile(buildConfig).getPath());
ToolchainExecutor.execute(codesign, new File(""), args, new ToolchainExecutor.ToolchainCallback() {
@Override
public void onInfoMessage(String message) {
Expand All @@ -105,10 +80,10 @@ public void onFail(int statusCode) {
}
});
break;
case Linux:
case Android:
log.info("Signing not supported on Android");
log.warn("Signing not supported for {}", buildTarget.os);
break;
}
});
}
}
15 changes: 14 additions & 1 deletion gdx-jnigen-generator-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import com.badlogic.gdx.jnigen.commons.Os

plugins {
id "com.badlogicgames.jnigen.jnigen-gradle"
id 'net.jsign' version '6.0'
}

sourceCompatibility = 1.8
Expand Down Expand Up @@ -57,6 +58,18 @@ jnigen {
options = ["-I" + file("src/test/resources/").absolutePath]
}

signing {
jsignParams = [
name : 'My Application',
url : 'http://www.example.com',
keystore : 'keystore.p12',
alias : 'test',
storepass: 'secret',
tsaurl : 'http://timestamp.sectigo.com'
]
identity = '-'
}

addLinux(x32, ARM)
addLinux(x64, x86)
addLinux(x64, ARM)
Expand All @@ -83,4 +96,4 @@ eclipse {
project {
name = "gdx-jnigen-generator-test"
}
}
}
Binary file added gdx-jnigen-generator-test/keystore.p12
Binary file not shown.

0 comments on commit 0d23ee0

Please sign in to comment.