From 4b0cca3622e0c4272e14e5019f986c40cbbc4bf7 Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Fri, 12 Jul 2013 10:09:44 +0200 Subject: add warining in case no JDK is found --- project/Build.scala | 2 +- project/jni.scala | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) (limited to 'project') diff --git a/project/Build.scala b/project/Build.scala index bfadd37..bd31c1b 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -118,7 +118,7 @@ object FlowBuild extends Build { settings (unixNativeSettings: _*) settings ( target := baseDirectory.value / "target" / "linux", - includeDirectories in Native += jdkHome.value / "include" / "linux", + includeDirectories in Native ++= jdkHome.value.map(jdk => jdk / "include" / "linux").toSeq, linkFlags in Native ++= Seq("-shared", s"-Wl,-soname,libflow.so.${BinaryMajorVersion}"), binaryName in Native := s"libflow.so.${BinaryMajorVersion}.${UnixBinaryMinorVersion}" ) diff --git a/project/jni.scala b/project/jni.scala index 7cde93b..5e248f2 100644 --- a/project/jni.scala +++ b/project/jni.scala @@ -1,9 +1,11 @@ import sbt._ import Keys._ import NativeKeys._ +import scala.util.Try object JniKeys { - val jdkHome = settingKey[File]("Home of JDK.") + val jdkHome = settingKey[Option[File]]("Home of JDK.") + val jdkHomeNotFound = taskKey[Unit]("Utility task that informs user that no JDK was found.") 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.") @@ -14,12 +16,22 @@ object JniDefaults { import JniKeys._ val defaultSettings: Seq[Setting[_]] = Seq( - jdkHome := file(sys.env("JAVA_HOME")), + jdkHome := Try(file(sys.env("JAVA_HOME"))).toOption, + jdkHomeNotFound := jdkHomeNotFoundImpl.value, + nativeCompile in Native := ((nativeCompile in Native) dependsOn jdkHomeNotFound).value, javahHeaderDirectory := (sourceManaged in Native).value / "javah", - javah := javahImpl.value, + javah := javahImpl.value, sourceGenerators in Native <+= javah map { headers => headers}, includeDirectories in Native += javahHeaderDirectory.value, - includeDirectories in Native += jdkHome.value / "include") + includeDirectories in Native ++= jdkHome.value.map( jdk => jdk / "include").toSeq) + + def jdkHomeNotFoundImpl = Def.task { + if (jdkHome.value == None) { + streams.value.log.warn( + "No JDK home directory found, any native code using JNI may not compile. Please set JAVA_HOME environment variable.") + } + () + } def javahImpl = Def.task { val cps = javahClasspath.value -- cgit v1.2.3