-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
structured_sources: Allow build_tgt to be added as source
In some cases, there is a need to use a built library as a "source" for another target. Specifically Java JAR might want to contain their own native JNI libraries in order to provide a single file "executable".
- Loading branch information
Showing
8 changed files
with
38 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,43 @@ | ||
package com.mesonbuild; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.InputStream; | ||
import java.io.IOException; | ||
|
||
public final class JniTest { | ||
private static String libname = "jnijava"; | ||
static { | ||
String fullname = System.mapLibraryName(libname); | ||
// this is somewhat hacky, but attempt to split off the extension | ||
int ext = fullname.indexOf("."); | ||
if (ext < 0) | ||
ext = fullname.length(); | ||
try { | ||
File fslib = File.createTempFile(fullname.substring(0, ext), fullname.substring(ext)); | ||
fslib.setReadable(true); | ||
fslib.setWritable(true, true); | ||
fslib.setExecutable(true); | ||
|
||
InputStream istream = JniTest.class.getResourceAsStream("/" + fullname); | ||
FileOutputStream ostream = new FileOutputStream(fslib); | ||
istream.transferTo(ostream); | ||
istream.close(); | ||
ostream.close(); | ||
|
||
System.load(fslib.getAbsolutePath()); | ||
|
||
fslib.deleteOnExit(); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private static native int jni_test(); | ||
|
||
public static void main(String[] args) { | ||
if (jni_test() != Configured.FINGERPRINT) { | ||
throw new RuntimeException("jdk_test() did not return 0"); | ||
} | ||
} | ||
|
||
static { | ||
System.loadLibrary("jnijava"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters