Updated to use a Gradle 1.11 nightly

This commit is contained in:
Adam Murdoch
2013-12-06 18:42:13 +11:00
parent 09bbd0f3ed
commit dfc7fa2f53
6 changed files with 187 additions and 196 deletions

View File

@@ -64,143 +64,84 @@ task nativeHeaders {
} }
} }
cpp { model {
sourceSets { platforms {
main { create("osx_i386") {
source.exclude 'curses.cpp' architecture "i386"
operatingSystem "osx"
} }
curses { create("osx_amd64") {
source.srcDirs = ['src/main/cpp'] architecture "amd64"
source.include 'curses.cpp' operatingSystem "osx"
source.include 'generic.cpp' }
source.include 'generic_posix.cpp' create("linux_i386") {
architecture "i386"
operatingSystem "linux"
}
create("linux_amd64") {
architecture "amd64"
operatingSystem "linux"
}
create("windows_i386") {
architecture "i386"
operatingSystem "windows"
}
create("windows_amd64") {
architecture "amd64"
operatingSystem "windows"
} }
} }
} }
def variants = [:]
libraries { libraries {
if (org.gradle.internal.os.OperatingSystem.current().macOsX) { nativePlatform {
all { baseName 'native-platform'
spec {
includes(files('/System/Library/Frameworks/JavaVM.framework/Versions/Current/Headers/'))
args("-arch", "x86_64", "-arch", "i386")
}
}
universal {
sourceSets << cpp.sourceSets.main
spec {
baseName = 'native-platform-osx-universal'
args("-o", outputFile)
}
}
cursesUniversal {
sourceSets << cpp.sourceSets.curses
spec {
baseName = 'native-platform-curses-osx-universal'
args("-lcurses")
args("-o", outputFile)
}
}
variants['osx-universal'] = [universal, cursesUniversal]
} else if (org.gradle.internal.os.OperatingSystem.current().windows) {
all {
spec {
includes(files("${org.gradle.internal.jvm.Jvm.current().javaHome}/include"))
includes(files("${org.gradle.internal.jvm.Jvm.current().javaHome}/include/win32"))
args("/DWIN32")
}
}
def out = new ByteArrayOutputStream()
exec {
commandLine "cl.exe", "/?"
errorOutput = out
standardOutput = new ByteArrayOutputStream()
}
def header = out.toString().readLines().head()
if (header.endsWith("for 80x86") || header.endsWith("for x86")) {
i386 {
sourceSets << cpp.sourceSets.main
spec {
baseName = 'native-platform-windows-i386'
}
}
variants['windows-i386'] = [i386]
} else if (header.endsWith("for x64")) {
amd64 {
sourceSets << cpp.sourceSets.main
spec {
baseName = 'native-platform-windows-amd64'
}
}
variants['windows-amd64'] = [amd64]
} else {
throw new RuntimeException("Cannot determine compiler's target architecture")
}
} else if (org.gradle.internal.os.OperatingSystem.current().linux) {
all {
spec {
includes(files("${org.gradle.internal.jvm.Jvm.current().javaHome}/include"))
includes(files("${org.gradle.internal.jvm.Jvm.current().javaHome}/include/linux"))
}
}
if (System.getProperty('os.arch') == 'i386' || project.hasProperty('multiarch')) {
i386 {
sourceSets << cpp.sourceSets.main
spec {
baseName = 'native-platform-linux-i386'
args("-m32")
}
}
cursesI386 {
sourceSets << cpp.sourceSets.curses
spec {
baseName = 'native-platform-curses-linux-i386'
args("-m32", "-lcurses")
}
}
variants['linux-i386'] = [i386, cursesI386]
}
if (System.getProperty('os.arch') == 'amd64' || project.hasProperty('multiarch')) {
amd64 {
sourceSets << cpp.sourceSets.main
spec {
baseName = 'native-platform-linux-amd64'
args("-m64")
}
}
cursesAmd64 {
sourceSets << cpp.sourceSets.curses
spec {
baseName = 'native-platform-curses-linux-amd64'
args("-m64", "-lcurses")
}
}
variants['linux-amd64'] = [amd64, cursesAmd64]
}
} else {
baseName = "native-platform-solaris"
main {
sourceSets << cpp.sourceSets.main
sourceSets << cpp.sourceSets.curses
spec {
includes(files("${org.gradle.internal.jvm.Jvm.current().javaHome}/include"))
includes(files("${org.gradle.internal.jvm.Jvm.current().javaHome}/include/solaris"))
args("-DSOLARIS", "-lcurses")
}
}
variants['solaris'] = [main]
} }
all { nativePlatformCurses {
spec { baseName 'native-platform-curses'
includes(files(nativeHeadersDir, 'src/main/headers')) targetPlatforms "osx_i386", "osx_amd64", "linux_i386", "linux_amd64"
binaries.all {
linker.args "-lcurses"
}
}
all {
binaries.all {
if (targetPlatform.operatingSystem.name == "osx") {
cppCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include"
cppCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include/darwin"
} else if (targetPlatform.operatingSystem.name == "linux") {
cppCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include"
cppCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include/linux"
} else if (targetPlatform.operatingSystem.name == "windows") {
cppCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include"
cppCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include/win32"
cppCompiler.define("WIN32")
}
cppCompiler.args '-I', nativeHeadersDir.absolutePath
tasks.withType(CppCompile) { task ->
task.dependsOn nativeHeaders
}
}
}
}
sources {
nativePlatform {
cpp {
source.srcDirs = ['src/main/cpp']
exportedHeaders.srcDirs = ['src/main/headers']
source.exclude 'curses.cpp'
}
}
nativePlatformCurses {
cpp {
source.srcDirs = ['src/main/cpp']
exportedHeaders.srcDirs = ['src/main/headers']
source.include 'curses.cpp'
source.include 'generic.cpp'
source.include 'generic_posix.cpp'
} }
def task = tasks["compile${spec.binary.name.capitalize()}"]
task.dependsOn nativeHeaders
test.dependsOn spec
} }
} }
@@ -210,23 +151,34 @@ configurations {
def deployer = uploadJni.repositories.mavenDeployer def deployer = uploadJni.repositories.mavenDeployer
variants.each { variant, libs -> binaries.withType(SharedLibraryBinary) { binary ->
def variantName = GUtil.toCamelCase(variant) if (!buildable) {
def nativeJar = task("nativeJar${variantName}", type: Jar) { return
from libs.collect { tasks["compile${it.name.capitalize()}"] }
baseName = "native-platform-$variant"
} }
artifacts {
jni nativeJar def variantName = "${targetPlatform.operatingSystem.name}-${targetPlatform.architecture.name}"
runtime nativeJar def taskName = "jar-${variantName}"
def nativeJar = project.tasks.findByName(taskName)
if (nativeJar == null) {
nativeJar = project.task(taskName, type: Jar) {
baseName = "native-platform-$variantName"
}
artifacts {
jni nativeJar
runtime nativeJar
}
def jniPom = deployer.addFilter(variantName) { artifact, file ->
return file == nativeJar.archivePath
}
jniPom.groupId = project.group
jniPom.artifactId = nativeJar.baseName
jniPom.version = project.version
jniPom.scopeMappings.mappings.clear()
} }
def jniPom = deployer.addFilter(variant) { artifact, file ->
return file == nativeJar.archivePath def builderTask = binary.tasks.builder
} nativeJar.into("net/rubygrapefruit/platform/$variantName") { from builderTask.outputFile }
jniPom.groupId = project.group nativeJar.dependsOn builderTask
jniPom.artifactId = nativeJar.baseName
jniPom.version = project.version
jniPom.scopeMappings.mappings.clear()
} }
javadoc { javadoc {
@@ -258,14 +210,10 @@ mainPom.scopeMappings.mappings.clear()
mainPom.withXml { provider -> mainPom.withXml { provider ->
def node = provider.asNode() def node = provider.asNode()
def deps = node.appendNode('dependencies') def deps = node.appendNode('dependencies')
['osx-universal', 'linux-amd64', 'linux-i386', 'windows-amd64', 'windows-i386'].each { platform -> ['osx-i386', 'osx-amd64', 'linux-amd64', 'linux-i386', 'windows-amd64', 'windows-i386'].each { platform ->
def dep = deps.appendNode('dependency') def dep = deps.appendNode('dependency')
dep.appendNode('groupId', project.group) dep.appendNode('groupId', project.group)
dep.appendNode('artifactId', "native-platform-${platform}") dep.appendNode('artifactId', "native-platform-${platform}")
dep.appendNode('version', project.version) dep.appendNode('version', project.version)
} }
} }
task wrapper(type: Wrapper) {
gradleVersion = "1.3-20120907220018+0000"
}

View File

@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.4-rc-1-bin.zip distributionUrl=http\://services.gradle.org/distributions-snapshots/gradle-1.11-20131205031946+0000-bin.zip

View File

@@ -0,0 +1,28 @@
package net.rubygrapefruit.platform.internal;
public class LibraryDef {
final String name;
final String platform;
public LibraryDef(String name, String platform) {
this.name = name;
this.platform = platform;
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj == null || obj.getClass() != getClass()) {
return false;
}
LibraryDef other = (LibraryDef) obj;
return name.equals(other.name) && platform.equals(other.platform);
}
@Override
public int hashCode() {
return name.hashCode() ^ platform.hashCode();
}
}

View File

@@ -38,9 +38,9 @@ public class NativeLibraryLoader {
return; return;
} }
try { try {
File libFile = nativeLibraryLocator.find(libraryFileName); File libFile = nativeLibraryLocator.find(new LibraryDef(libraryFileName, platform.getId()));
if (libFile == null) { if (libFile == null) {
throw new NativeIntegrationUnavailableException(String.format("Native library is not available for %s.", platform)); throw new NativeIntegrationUnavailableException(String.format("Native library '%s' is not available for %s.", libraryFileName, platform));
} }
System.load(libFile.getCanonicalPath()); System.load(libFile.getCanonicalPath());
} catch (NativeException e) { } catch (NativeException e) {

View File

@@ -30,9 +30,10 @@ public class NativeLibraryLocator {
this.extractDir = extractDir; this.extractDir = extractDir;
} }
public File find(String libraryFileName) throws IOException { public File find(LibraryDef libraryDef) throws IOException {
String resourceName = String.format("net/rubygrapefruit/platform/%s/%s", libraryDef.platform, libraryDef.name);
if (extractDir != null) { if (extractDir != null) {
File libFile = new File(extractDir, String.format("%s/%s", NativeLibraryFunctions.VERSION, libraryFileName)); File libFile = new File(extractDir, String.format("%s/%s", NativeLibraryFunctions.VERSION, libraryDef.name));
File lockFile = new File(libFile.getParentFile(), libFile.getName() + ".lock"); File lockFile = new File(libFile.getParentFile(), libFile.getName() + ".lock");
lockFile.getParentFile().mkdirs(); lockFile.getParentFile().mkdirs();
lockFile.createNewFile(); lockFile.createNewFile();
@@ -44,7 +45,7 @@ public class NativeLibraryLocator {
// Library has been extracted // Library has been extracted
return libFile; return libFile;
} }
URL resource = getClass().getClassLoader().getResource(libraryFileName); URL resource = getClass().getClassLoader().getResource(resourceName);
if (resource != null) { if (resource != null) {
// Extract library and write marker to lock file // Extract library and write marker to lock file
libFile.getParentFile().mkdirs(); libFile.getParentFile().mkdirs();
@@ -58,20 +59,20 @@ public class NativeLibraryLocator {
lockFileAccess.close(); lockFileAccess.close();
} }
} else { } else {
URL resource = getClass().getClassLoader().getResource(libraryFileName); URL resource = getClass().getClassLoader().getResource(resourceName);
if (resource != null) { if (resource != null) {
File libFile; File libFile;
File libDir = File.createTempFile("native-platform", "dir"); File libDir = File.createTempFile("native-platform", "dir");
libDir.delete(); libDir.delete();
libDir.mkdirs(); libDir.mkdirs();
libFile = new File(libDir, libraryFileName); libFile = new File(libDir, libraryDef.name);
libFile.deleteOnExit(); libFile.deleteOnExit();
copy(resource, libFile); copy(resource, libFile);
return libFile; return libFile;
} }
} }
File libFile = new File("build/binaries/" + libraryFileName); File libFile = new File(String.format("build/binaries/%s/%s", libraryDef.platform, libraryDef.name));
if (libFile.isFile()) { if (libFile.isFile()) {
return libFile; return libFile;
} }

View File

@@ -44,12 +44,14 @@ public abstract class Platform {
platform = new Linux32Bit(); platform = new Linux32Bit();
} }
} else if (osName.contains("os x")) { } else if (osName.contains("os x")) {
if (arch.equals("i386") || arch.equals("x86_64") || arch.equals("amd64")) { if (arch.equals("i386")) {
platform = new OsX(); platform = new OsX32Bit();
} }
} else if (osName.contains("sunos")) { else if (arch.equals("x86_64") || arch.equals("amd64")) {
platform = new Solaris(); platform = new OsX64Bit();
} else { }
}
if (platform == null) {
platform = new Unsupported(); platform = new Unsupported();
} }
} }
@@ -74,6 +76,8 @@ public abstract class Platform {
throw new NativeIntegrationUnavailableException(String.format("Native integration is not available for %s.", toString())); throw new NativeIntegrationUnavailableException(String.format("Native integration is not available for %s.", toString()));
} }
public abstract String getId();
private static String getOperatingSystem() { private static String getOperatingSystem() {
return System.getProperty("os.name"); return System.getProperty("os.name");
} }
@@ -88,6 +92,11 @@ public abstract class Platform {
return true; return true;
} }
@Override
public String getLibraryName() {
return "native-platform.dll";
}
@Override @Override
public <T extends NativeIntegration> T get(Class<T> type, NativeLibraryLoader nativeLibraryLoader) { public <T extends NativeIntegration> T get(Class<T> type, NativeLibraryLoader nativeLibraryLoader) {
if (type.equals(Process.class)) { if (type.equals(Process.class)) {
@@ -111,15 +120,15 @@ public abstract class Platform {
private static class Window32Bit extends Windows { private static class Window32Bit extends Windows {
@Override @Override
public String getLibraryName() { public String getId() {
return "native-platform-windows-i386.dll"; return "windows-i386";
} }
} }
private static class Window64Bit extends Windows { private static class Window64Bit extends Windows {
@Override @Override
public String getLibraryName() { public String getId() {
return "native-platform-windows-amd64.dll"; return "windows-amd64";
} }
} }
@@ -153,6 +162,15 @@ public abstract class Platform {
} }
private abstract static class Unix extends Posix { private abstract static class Unix extends Posix {
@Override
public String getLibraryName() {
return "libnative-platform.so";
}
@Override
String getCursesLibraryName() {
return "libnative-platform-curses.so";
}
} }
private abstract static class Linux extends Unix { private abstract static class Linux extends Unix {
@@ -167,41 +185,19 @@ public abstract class Platform {
private static class Linux32Bit extends Linux { private static class Linux32Bit extends Linux {
@Override @Override
public String getLibraryName() { public String getId() {
return "libnative-platform-linux-i386.so"; return "linux-i386";
}
@Override
String getCursesLibraryName() {
return "libnative-platform-curses-linux-i386.so";
} }
} }
private static class Linux64Bit extends Linux { private static class Linux64Bit extends Linux {
@Override @Override
public String getLibraryName() { public String getId() {
return "libnative-platform-linux-amd64.so"; return "linux-amd64";
}
@Override
String getCursesLibraryName() {
return "libnative-platform-curses-linux-amd64.so";
} }
} }
private static class Solaris extends Unix { private static abstract class OsX extends Posix {
@Override
public String getLibraryName() {
return "libnative-platform-solaris.so";
}
@Override
String getCursesLibraryName() {
return "libnative-platform-curses-solaris.so";
}
}
private static class OsX extends Posix {
@Override @Override
public <T extends NativeIntegration> T get(Class<T> type, NativeLibraryLoader nativeLibraryLoader) { public <T extends NativeIntegration> T get(Class<T> type, NativeLibraryLoader nativeLibraryLoader) {
if (type.equals(FileSystems.class)) { if (type.equals(FileSystems.class)) {
@@ -212,16 +208,34 @@ public abstract class Platform {
@Override @Override
public String getLibraryName() { public String getLibraryName() {
return "libnative-platform-osx-universal.dylib"; return "libnative-platform.dylib";
} }
@Override @Override
String getCursesLibraryName() { String getCursesLibraryName() {
return "libnative-platform-curses-osx-universal.dylib"; return "libnative-platform-curses.dylib";
}
}
private static class OsX32Bit extends OsX {
@Override
public String getId() {
return "osx-i386";
}
}
private static class OsX64Bit extends OsX {
@Override
public String getId() {
return "osx-amd64";
} }
} }
private static class Unsupported extends Platform { private static class Unsupported extends Platform {
@Override
public String getId() {
throw new UnsupportedOperationException();
}
} }
} }