From eab2e148c7605ca0fd836bbe9230734895cce7d0 Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Tue, 8 Dec 2015 21:44:31 -0800 Subject: Use sbt-jni plugin --- project/Build.scala | 96 ------------------------------------------------- project/FlowBuild.scala | 75 ++++++++++++++++++++++++++++++++++++++ project/jni.scala | 38 -------------------- project/native.scala | 83 ------------------------------------------ project/plugins.sbt | 1 + 5 files changed, 76 insertions(+), 217 deletions(-) delete mode 100644 project/Build.scala create mode 100644 project/FlowBuild.scala delete mode 100644 project/jni.scala delete mode 100644 project/native.scala create mode 100644 project/plugins.sbt (limited to 'project') diff --git a/project/Build.scala b/project/Build.scala deleted file mode 100644 index 1ef55eb..0000000 --- a/project/Build.scala +++ /dev/null @@ -1,96 +0,0 @@ -import sbt._ -import Keys._ -import JniKeys._ -import NativeKeys._ - - -object FlowBuild extends Build { - - val scalaVersions = List("2.11.7", "2.12.0-M3") - - lazy val commonSettings: Seq[Setting[_]] = Seq( - version := "2.3.2-SNAPSHOT", - scalaVersion in ThisBuild := scalaVersions.head, - crossScalaVersions in ThisBuild := scalaVersions.reverse, - scalacOptions ++= Seq("-deprecation", "-unchecked", "-feature", "-target:jvm-1.8"), - organization := "com.github.jodersky", - licenses := Seq(("BSD New", url("http://opensource.org/licenses/BSD-3-Clause"))), - homepage := Some(url("https://github.com/jodersky/flow")), - pomIncludeRepository := { _ => false }, - pomExtra := { - - git@github.com:jodersky/flow.git - scm:git:git@github.com:jodersky/flow.git - - - - jodersky - Jakob Odersky - - - } - ) - - lazy val runSettings: Seq[Setting[_]] = Seq( - fork := true, - connectInput in run := true, - outputStrategy := Some(StdoutOutput) - ) - - lazy val root: Project = ( - Project("root", file(".")) - aggregate(main, native) - settings(commonSettings: _*) - settings( - publishArtifact := false, - publish := (), - publishLocal := (), - publishTo := Some(Resolver.file("Unused transient repository", target.value / "unusedrepo")) // make sbt-pgp happy - ) - ) - - lazy val main: Project = ( - Project("flow-main", file("flow-main")) - settings(commonSettings: _*) - settings(JniDefaults.settings: _*) - settings( - name := "flow", - javahHeaderDirectory := (baseDirectory in ThisBuild).value / "flow-native" / "src", - javahClasses := Seq("com.github.jodersky.flow.internal.NativeSerial"), - compileOrder in Compile := CompileOrder.Mixed, - libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.4.1" - ) - ) - - lazy val native: Project = ( - Project("flow-native", file("flow-native-sbt")) - settings(commonSettings: _*) - settings(NativeDefaults.settings: _*) - settings( - name := "flow-native", - crossPaths := false, - nativeBuildDirectory := (baseDirectory in ThisBuild).value / "flow-native" - ) - ) - - lazy val samplesTerminal = ( - Project("flow-samples-terminal", file("flow-samples") / "terminal") - settings(commonSettings: _*) - settings(runSettings: _*) - dependsOn(main) - - //kind of dirty, but it gets the sample to run without installing native libraries - settings( - (run in Compile) <<= (run in Compile).dependsOn(nativeBuild in native), - javaOptions += "-Djava.library.path=" + (nativeOutputDirectory in native).value.getAbsolutePath() - ) - ) - - lazy val samplesWatcher = ( - Project("flow-samples-watcher", file("flow-samples") / "watcher") - settings(commonSettings: _*) - settings(runSettings: _*) - dependsOn(main) - ) - -} diff --git a/project/FlowBuild.scala b/project/FlowBuild.scala new file mode 100644 index 0000000..15a3fe4 --- /dev/null +++ b/project/FlowBuild.scala @@ -0,0 +1,75 @@ +import sbt._ +import Keys._ + +object FlowBuild extends Build { + + val scalaVersions = List("2.11.7", "2.12.0-M3") + + lazy val commonSettings: Seq[Setting[_]] = Seq( + version := "2.4.0-SNAPSHOT", + scalaVersion in ThisBuild := scalaVersions.head, + crossScalaVersions in ThisBuild := scalaVersions.reverse, + scalacOptions ++= Seq("-deprecation", "-unchecked", "-feature", "-target:jvm-1.8"), + organization := "com.github.jodersky", + licenses := Seq(("BSD New", url("http://opensource.org/licenses/BSD-3-Clause"))), + homepage := Some(url("https://github.com/jodersky/flow")), + pomIncludeRepository := { _ => false }, + pomExtra := { + + git@github.com:jodersky/flow.git + scm:git:git@github.com:jodersky/flow.git + + + + jodersky + Jakob Odersky + + + } + ) + + lazy val runSettings: Seq[Setting[_]] = Seq( + fork := true, + connectInput in run := true, + outputStrategy := Some(StdoutOutput) + ) + + lazy val root: Project = ( + Project("root", file(".")) + aggregate(main, native) + settings(commonSettings: _*) + settings( + publishArtifact := false, + publish := (), + publishLocal := (), + publishTo := Some(Resolver.file("Unused transient repository", target.value / "unusedrepo")) // make sbt-pgp happy + ) + ) + + lazy val main = Project( + id = "flow-main", + base = file("flow-main"), + settings = commonSettings + ) + + lazy val native = Project( + id = "flow-native", + base = file("flow-native"), + settings = commonSettings + ) + + lazy val samplesTerminal = Project( + id = "flow-samples-terminal", + base = file("flow-samples") / "terminal", + settings = commonSettings, + dependencies = Seq(main, native % Runtime) + ) + + lazy val samplesWatcher = Project( + id = "flow-samples-watcher", + base = file("flow-samples"), + settings = commonSettings, + dependencies = Seq(main, native % Runtime) + ) + +} diff --git a/project/jni.scala b/project/jni.scala deleted file mode 100644 index 07d8406..0000000 --- a/project/jni.scala +++ /dev/null @@ -1,38 +0,0 @@ -import sbt._ -import Keys._ -import scala.util.Try - -object JniKeys { - val javahHeaderDirectory = settingKey[File]("Directory where generated javah header files are placed.") - val javahClasses = settingKey[Seq[String]]("Fully qualified names of classes containing native declarations.") - val javahClasspath = taskKey[Seq[File]]("Classpath to use in javah.") - val javah = taskKey[Seq[File]]("Generate JNI headers.") -} - -object JniDefaults { - import JniKeys._ - - val settings: Seq[Setting[_]] = Seq( - javahHeaderDirectory := baseDirectory.value, - javahClasspath := Seq((classDirectory in Compile).value), - javah := javahImpl.value - ) - - def javahImpl = Def.task { - val jcp = javahClasspath.value - val cp = jcp.mkString(sys.props("path.separator")) - for (clazz <- javahClasses.value) { - val parts = Seq( - "javah", - "-d", javahHeaderDirectory.value, - "-classpath", cp, - clazz) - val cmd = parts.mkString(" ") - val ev = Process(cmd) ! streams.value.log - if (ev != 0) throw new RuntimeException(s"Error occured running javah. Exit code: ${ev}") - } - IO.listFiles(javahHeaderDirectory.value) - } - -} - diff --git a/project/native.scala b/project/native.scala deleted file mode 100644 index 342a863..0000000 --- a/project/native.scala +++ /dev/null @@ -1,83 +0,0 @@ -import sbt._ -import Keys._ -import java.io.File -import java.util.jar.Manifest - -object NativeKeys { - - val nativeBuildDirectory = settingKey[File]("Directory containing native build scripts.") - val nativeTargetDirectory = settingKey[File]("Base directory to store native products.") - val nativeOutputDirectory = settingKey[File]("Actual directory where native products are stored.") - val nativePackageUnmanagedDirectory = settingKey[File]("Directory containing external products that will be copied to the native jar.") - - val nativeClean = taskKey[Unit]("Clean native build.") - val nativeBuild = taskKey[File]("Invoke native build.") -} - -object NativeDefaults { - import NativeKeys._ - - val autoClean = Def.task { - val log = streams.value.log - val build = nativeBuildDirectory.value - - Process("make distclean", build) #|| Process("make clean", build) ! log - } - - val autoLib = Def.task { - val log = streams.value.log - val build = nativeBuildDirectory.value - val out = nativeOutputDirectory.value - - val configure = Process( - "./configure " + - "--prefix=" + out.getAbsolutePath + " " + - "--libdir=" + out.getAbsolutePath + " " + - "--disable-versioned-lib", //Disable producing versioned library files, not needed for fat jars. - build) - - val make = Process("make", build) - - val makeInstall = Process("make install", build) - - val ev = configure #&& make #&& makeInstall ! log - if (ev != 0) - throw new RuntimeException(s"Building native library failed. Exit code: ${ev}") - - (out ** ("*.la")).get.foreach(_.delete()) - - out - } - - val nativePackageMappings = Def.task { - val managedDir = nativeTargetDirectory.value - val unmanagedDir = nativePackageUnmanagedDirectory.value - - val managed = (nativeBuild.value ** "*").get - val unmanaged = (unmanagedDir ** "*").get - - val managedMappings: Seq[(File, String)] = for (file <- managed; if file.isFile) yield { - file -> ("native/" + (file relativeTo managedDir).get.getPath) - } - - val unmanagedMappings: Seq[(File, String)] = for (file <- unmanaged; if file.isFile) yield { - file -> ("native/" + (file relativeTo unmanagedDir).get.getPath) - } - - managedMappings ++ unmanagedMappings - } - - def os = System.getProperty("os.name").toLowerCase.filter(c => !c.isWhitespace) - def arch = System.getProperty("os.arch").toLowerCase - - val settings: Seq[Setting[_]] = Seq( - nativeTargetDirectory := target.value / "native", - nativeOutputDirectory := nativeTargetDirectory.value / (os + "-" + arch), - nativeClean := autoClean.value, - nativeBuild := autoLib.value, - nativePackageUnmanagedDirectory := baseDirectory.value / "lib_native", - mappings in (Compile, packageBin) ++= nativePackageMappings.value - ) - -} - diff --git a/project/plugins.sbt b/project/plugins.sbt new file mode 100644 index 0000000..489fdbc --- /dev/null +++ b/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("ch.jodersky" %% "sbt-jni" % "0.2-SNAPSHOT") -- cgit v1.2.3