diff options
Diffstat (limited to 'jni-plugin/src/main/scala/ch/jodersky/sbt/jni/build')
4 files changed, 106 insertions, 0 deletions
diff --git a/jni-plugin/src/main/scala/ch/jodersky/sbt/jni/build/BuildTool.scala b/jni-plugin/src/main/scala/ch/jodersky/sbt/jni/build/BuildTool.scala new file mode 100644 index 0000000..23df2b2 --- /dev/null +++ b/jni-plugin/src/main/scala/ch/jodersky/sbt/jni/build/BuildTool.scala @@ -0,0 +1,14 @@ +package ch.jodersky.sbt.jni +package build + +import java.io.File + +trait BuildTool { + + def name: String + + def detect(baseDirectory: File): Boolean + + def api: BuildToolApi + +} diff --git a/jni-plugin/src/main/scala/ch/jodersky/sbt/jni/build/BuildToolApi.scala b/jni-plugin/src/main/scala/ch/jodersky/sbt/jni/build/BuildToolApi.scala new file mode 100644 index 0000000..47d9a90 --- /dev/null +++ b/jni-plugin/src/main/scala/ch/jodersky/sbt/jni/build/BuildToolApi.scala @@ -0,0 +1,23 @@ +package ch.jodersky.sbt.jni +package build + +import java.io.File +import sbt.Logger + + +trait BuildToolApi { + + /** Invokes the native build tool's clean task */ + def clean(baseDirectory: File, log: Logger): Unit + + /** + * Invokes the native build tool's main task, resulting in a single shared + * library file. + */ + def library( + baseDirectory: File, + targetDirectory: File, + log: Logger + ): File + +} diff --git a/jni-plugin/src/main/scala/ch/jodersky/sbt/jni/build/CMake.scala b/jni-plugin/src/main/scala/ch/jodersky/sbt/jni/build/CMake.scala new file mode 100644 index 0000000..cd0b363 --- /dev/null +++ b/jni-plugin/src/main/scala/ch/jodersky/sbt/jni/build/CMake.scala @@ -0,0 +1,60 @@ +package ch.jodersky.sbt.jni +package build + +import Keys._ +import sbt._ +import sbt.Keys._ +import sbt.Logger +import java.io.File + + +object CMake extends BuildTool { + + val name = "CMake" + + def detect(baseDirectory: File) = baseDirectory.list().contains("CMakeLists.txt") + + object api extends BuildToolApi { + + def clean(baseDirectory: File, log: Logger) = Process("make clean", baseDirectory) ! log + + def library( + baseDirectory: File, + targetDirectory: File, + log: Logger + ): File = { + val out = targetDirectory + val outPath = out.getAbsolutePath + + val configure = Process( + //Disable producing versioned library files, not needed for fat jars. + s"cmake -DCMAKE_INSTALL_PREFIX:PATH=$outPath -DLIB_INSTALL_DIR:PATH=$outPath -DENABLE_VERSIONED_LIB:BOOLEAN=OFF", + baseDirectory + ) + + val make = Process("make", baseDirectory) + + val makeInstall = Process("make install", baseDirectory) + + val ev = configure #&& make #&& makeInstall ! log + if (ev != 0) sys.error(s"Building native library failed. Exit code: ${ev}") + + val products: List[File] = (out ** ("*" -- "*.la")).get.filter(_.isFile).toList + + //only one produced library is expected + products match { + case Nil => + sys.error("No files were created during compilation, " + + "something went wrong with the autotools configuration.") + case head :: Nil => + head + case head :: tail => + log.warn("More than one file was created during compilation, " + + s"only the first one (${head.getAbsolutePath}) will be used.") + head + } + } + } + +} + diff --git a/jni-plugin/src/main/scala/ch/jodersky/sbt/jni/build/NoTool.scala b/jni-plugin/src/main/scala/ch/jodersky/sbt/jni/build/NoTool.scala new file mode 100644 index 0000000..96dd85f --- /dev/null +++ b/jni-plugin/src/main/scala/ch/jodersky/sbt/jni/build/NoTool.scala @@ -0,0 +1,9 @@ +package ch.jodersky.sbt.jni +package build + + +object NoTool { + + + +} |