aboutsummaryrefslogtreecommitdiff
path: root/jni-plugin/src/main/scala/ch/jodersky/sbt/jni/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'jni-plugin/src/main/scala/ch/jodersky/sbt/jni/plugins')
-rw-r--r--jni-plugin/src/main/scala/ch/jodersky/sbt/jni/plugins/JniJavah.scala69
-rw-r--r--jni-plugin/src/main/scala/ch/jodersky/sbt/jni/plugins/JniLoading.scala28
-rw-r--r--jni-plugin/src/main/scala/ch/jodersky/sbt/jni/plugins/JniNative.scala100
-rw-r--r--jni-plugin/src/main/scala/ch/jodersky/sbt/jni/plugins/JniPackaging.scala119
4 files changed, 0 insertions, 316 deletions
diff --git a/jni-plugin/src/main/scala/ch/jodersky/sbt/jni/plugins/JniJavah.scala b/jni-plugin/src/main/scala/ch/jodersky/sbt/jni/plugins/JniJavah.scala
deleted file mode 100644
index 63e5b23..0000000
--- a/jni-plugin/src/main/scala/ch/jodersky/sbt/jni/plugins/JniJavah.scala
+++ /dev/null
@@ -1,69 +0,0 @@
-package ch.jodersky.sbt.jni
-package plugins
-
-import sbt._
-import sbt.Keys._
-import util.ByteCode
-
-/** Adds `javah` header-generation functionality to projects. */
-object JniJavah extends AutoPlugin {
-
- override def requires = plugins.JvmPlugin
- override def trigger = allRequirements
-
- object autoImport {
-
- val javahClasses = taskKey[Set[String]](
- "Fully qualified names of classes containing native declarations."
- )
-
- val javah = taskKey[File](
- "Generate JNI headers. Returns the directory containing generated headers."
- )
-
- }
- import autoImport._
-
- lazy val mainSettings: Seq[Setting[_]] = Seq(
-
- javahClasses in javah := {
- val compiled: inc.Analysis = (compile in Compile).value
- val classFiles: Set[File] = compiled.relations.allProducts.toSet
- val nativeClasses = classFiles flatMap { file =>
- ByteCode.natives(file)
- }
- nativeClasses
- },
-
- target in javah := target.value / "include",
-
- fullClasspath in javah := fullClasspath.value,
-
- javah := {
- val out = (target in javah).value
- val jcp: Seq[File] = (fullClasspath in javah).value.map(_.data)
- val cp = jcp.mkString(sys.props("path.separator"))
- val log = streams.value.log
-
- val classes = (javahClasses in javah).value
-
- log.info("Headers will be generated to " + out.getAbsolutePath)
- for (clazz <- classes) {
- log.info("Generating header for " + clazz + "...")
- val parts = Seq(
- "javah",
- "-d", out.getAbsolutePath,
- "-classpath", cp,
- clazz
- )
- val cmd = parts.mkString(" ")
- val ev = Process(cmd) ! streams.value.log
- if (ev != 0) sys.error(s"Error occured running javah. Exit code: ${ev}")
- }
- out
- }
- )
-
- override lazy val projectSettings = inConfig(Compile)(mainSettings)
-
-}
diff --git a/jni-plugin/src/main/scala/ch/jodersky/sbt/jni/plugins/JniLoading.scala b/jni-plugin/src/main/scala/ch/jodersky/sbt/jni/plugins/JniLoading.scala
deleted file mode 100644
index 599bfa1..0000000
--- a/jni-plugin/src/main/scala/ch/jodersky/sbt/jni/plugins/JniLoading.scala
+++ /dev/null
@@ -1,28 +0,0 @@
-package ch.jodersky.sbt.jni
-package plugins
-
-import sbt._
-import sbt.Keys._
-import util.ByteCode
-
-/**
- * Enables loading native libraries from the classpath, typically created
- * from a project using JniPackaging.
- */
-object JniLoading extends AutoPlugin {
-
- override def requires = plugins.JvmPlugin
-
- lazy val settings = Seq(
-
- //enable enhanced native library extraction
- libraryDependencies += "ch.jodersky" %% "jni-library" % Version.PluginVersion,
-
- //fork new JVM, since native libraries can only be loaded once
- fork in run := true
-
- )
-
- override lazy val projectSettings = settings
-
-}
diff --git a/jni-plugin/src/main/scala/ch/jodersky/sbt/jni/plugins/JniNative.scala b/jni-plugin/src/main/scala/ch/jodersky/sbt/jni/plugins/JniNative.scala
deleted file mode 100644
index 2ac179d..0000000
--- a/jni-plugin/src/main/scala/ch/jodersky/sbt/jni/plugins/JniNative.scala
+++ /dev/null
@@ -1,100 +0,0 @@
-package ch.jodersky.sbt.jni
-package plugins
-
-import build._
-import ch.jodersky.jni.{NativeLoader, Platform}
-import sbt._
-import sbt.Keys._
-
-/** Wraps a native build system in sbt tasks. */
-object JniNative extends AutoPlugin {
-
- object autoImport {
-
- //Main task, inspect this first
- val nativeCompile = taskKey[File]("Builds a native library (by calling the native build tool).")
-
- val nativePlatform = settingKey[Platform]("Platform of the system this build is running on.")
-
- val nativeBuildTools = taskKey[Seq[BuildTool]](
- "A collection of build tools that are tested to determine the current build environment"
- )
- val nativeBuildTool = taskKey[BuildTool](
- "The build tool to be used when building a native library."
- )
-
- }
- import autoImport._
-
- lazy val settings: Seq[Setting[_]] = Seq(
-
- nativePlatform := Platform.current.getOrElse {
- sLog.value.warn("Warning: cannot determine platform! It will be set to 'unknown'.")
- Platform.Unknown
- },
-
- sourceDirectory in nativeCompile := sourceDirectory.value / "native",
-
- target in nativeCompile := target.value / "native" / (nativePlatform).value.id,
-
- nativeBuildTools := Seq(CMake, Autotools),
-
- nativeBuildTool := {
- val tools = nativeBuildTools.value
-
- val src = (sourceDirectory in nativeCompile).value
-
- val tool = if (src.exists && src.isDirectory) {
- tools.find(t => t detect src)
- } else {
- None
- }
- tool.getOrElse(
- sys.error("No supported native build tool detected. " +
- s"Check that the setting 'sourceDirectory in nativeCompile' (currently $src) " +
- "points to a valid directory. Supported build tools are: " +
- tools.map(_.name).mkString(","))
- )
-
- },
-
- clean in nativeCompile := {
- val log = streams.value.log
-
- log.debug("Cleaning native build")
- try {
- val tool = nativeBuildTool.value
- tool.api.clean(
- (sourceDirectory in nativeCompile).value,
- log
- )
- } catch {
- case ex: Exception =>
- log.debug(s"Native cleaning failed: $ex")
- }
-
- },
-
- nativeCompile := {
- val tool = nativeBuildTool.value
- val src = (sourceDirectory in nativeCompile).value
- val buildDir = (target in nativeCompile).value / "build"
- val targetDir = (target in nativeCompile).value / "lib"
- val log = streams.value.log
-
- IO.createDirectory(buildDir)
- IO.createDirectory(targetDir)
-
- tool.api.library(src, buildDir, targetDir, log)
- },
-
- // change clean task to also clean native sources
- clean := {
- (clean in nativeCompile).value
- clean.value
- }
-
- )
-
- override lazy val projectSettings = inConfig(Compile)(settings)
-}
diff --git a/jni-plugin/src/main/scala/ch/jodersky/sbt/jni/plugins/JniPackaging.scala b/jni-plugin/src/main/scala/ch/jodersky/sbt/jni/plugins/JniPackaging.scala
deleted file mode 100644
index cc3a851..0000000
--- a/jni-plugin/src/main/scala/ch/jodersky/sbt/jni/plugins/JniPackaging.scala
+++ /dev/null
@@ -1,119 +0,0 @@
-package ch.jodersky.sbt.jni
-package plugins
-
-import ch.jodersky.jni._
-import sbt._
-import sbt.Keys._
-
-/** Packages libraries built with JniNative. */
-object JniPackaging extends AutoPlugin {
-
- //JvmPlugin is required or else resource generators will be overriden
- override def requires = JniNative && plugins.JvmPlugin
- override def trigger = allRequirements
-
- object autoImport {
-
- val nativeLibraryPath = settingKey[String](
- "String that is prepended to the path of a native library when packaged. This value should be " +
- "passed to `NativeLoader.load()`"
- )
-
- val enableNativeCompilation = settingKey[Boolean](
- "Determines if native compilation is enabled. If disabled, only pre-compiled libraries in " +
- "`unmanagedNativeDirectories` will be packaged."
- )
-
- val unmanagedNativeDirectories = settingKey[Seq[File]](
- "Unmanaged directories containing native libraries. The libraries must be regular files " +
- "contained in a subdirectory corresponding to a platform. For example " +
- "`<unamagedNativeDirectory>/x86_64-linux/libfoo.so` is an unmanaged library for machines having " +
- "the x86_64 architecture and running the Linux kernel."
- )
-
- val unmanagedNativeLibraries = taskKey[Map[Platform, File]](
- "Reads `unmanagedNativeDirectories` and maps platforms to library files specified theirin."
- )
-
- val managedNativeLibraries = taskKey[Map[Platform, File]](
- "Maps locally built, platform-dependant libraries."
- )
-
- val nativeLibraries = taskKey[Map[Platform, File]](
- "All native libraries, managed and unmanaged."
- )
-
- }
- import autoImport._
- import JniNative.autoImport._
-
- lazy val settings: Seq[Setting[_]] = Seq(
-
- nativeLibraryPath := {
- val orgPath = organization.value.replaceAll("\\.", "/")
- s"/${orgPath}/${name.value}/native"
- },
-
- enableNativeCompilation := true,
-
- unmanagedNativeDirectories := Seq(baseDirectory.value / "lib_native"),
-
- unmanagedNativeLibraries := {
- val dirs: Seq[File] = unmanagedNativeDirectories.value
- val seq: Seq[(Platform, File)] = for (
- dir <- dirs;
- if (dir.exists && dir.isDirectory);
- platformDir <- dir.listFiles();
- if platformDir.isDirectory;
- platform = Platform.fromId(platformDir.name);
- library <- platformDir.listFiles();
- if library.isFile
- ) yield {
- platform -> library.getCanonicalFile()
- }
-
- seq.toMap
- },
-
- managedNativeLibraries := Def.taskDyn[Map[Platform, File]] {
- val enableManaged = (enableNativeCompilation).value
- if (enableManaged) Def.task {
- val library: File = nativeCompile.value
- val platform = nativePlatform.value
- Map(platform -> library)
- }
- else Def.task {
- Map()
- }
- }.value,
-
- // managed native libraries take precedence
- nativeLibraries := unmanagedNativeLibraries.value ++ managedNativeLibraries.value,
-
- resourceGenerators += Def.task {
-
- val libraries: Seq[(Platform, File)] = nativeLibraries.value.toSeq
-
- val resources: Seq[File] = for ((plat, file) <- libraries) yield {
-
- //native library as a managed resource file
- val resource = resourceManaged.value /
- NativeLoader.fullLibraryPath(
- (nativeLibraryPath).value,
- plat
- )
-
- //copy native library to a managed resource (so it can also be loaded when not packaged as a jar)
- IO.copyFile(file, resource)
- resource
- }
- resources
- }.taskValue
-
- )
-
- override lazy val projectSettings = inConfig(Compile)(settings) ++
- Seq(crossPaths := false) //don't add scala version to native jars
-
-
-}