diff options
Diffstat (limited to 'jni-plugin/src/main/scala/ch/jodersky/sbt/jni/build')
4 files changed, 70 insertions, 55 deletions
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 index 47d9a90..43dd17a 100644 --- 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 @@ -4,19 +4,23 @@ 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 + def clean(baseDirectory: File, log: Logger): Unit /** - * Invokes the native build tool's main task, resulting in a single shared - * library file. - */ + * Invokes the native build tool's main task, resulting in a single shared + * library file. + * @param baseDirectory the directory where the native project is located + * @param buildDirectory a directory from where the build is called, it may be used to store temporary files + * @param targetDirectory the directory into which the native library is copied + * @return the native library file + */ def library( baseDirectory: File, targetDirectory: File, + buildDirectory: 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 index cd0b363..3f75585 100644 --- 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 @@ -1,12 +1,8 @@ package ch.jodersky.sbt.jni package build -import Keys._ -import sbt._ -import sbt.Keys._ -import sbt.Logger import java.io.File - +import sbt._ object CMake extends BuildTool { @@ -14,46 +10,21 @@ object CMake extends BuildTool { def detect(baseDirectory: File) = baseDirectory.list().contains("CMakeLists.txt") - object api extends BuildToolApi { + object api extends ConfigureMakeInstall { - 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( + override def configure(base: File, build: File, target: File) = { + val targetPath = target.getAbsolutePath + 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 + "cmake " + + s"-DCMAKE_INSTALL_PREFIX:PATH=$targetPath " + + s"-DLIB_INSTALL_DIR:PATH=$targetPath " + + "-DENABLE_VERSIONED_LIB:BOOLEAN=OFF " + + base.getAbsolutePath, + build ) - - 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/ConfigureMakeInstall.scala b/jni-plugin/src/main/scala/ch/jodersky/sbt/jni/build/ConfigureMakeInstall.scala new file mode 100644 index 0000000..97011ed --- /dev/null +++ b/jni-plugin/src/main/scala/ch/jodersky/sbt/jni/build/ConfigureMakeInstall.scala @@ -0,0 +1,49 @@ +package ch.jodersky.sbt.jni +package build + +import java.io.File +import sbt._ + +/** Native build tools relying on a standard 'configure && make && make install' process */ +trait ConfigureMakeInstall extends BuildToolApi { + + override def clean(baseDirectory: File, log: Logger) = Process("make clean", baseDirectory) ! log + + def configure(baseDirectory: File, buildDirectory: File, targetDirectory: File): ProcessBuilder + + def make(baseDirectory: File, buildDirectory: File, targetDirectory: File): ProcessBuilder = Process("make", buildDirectory) + + def install(baseDirectory: File, buildDirectory: File, targetDirectory: File): ProcessBuilder = Process("make install", buildDirectory) + + override def library( + baseDirectory: File, + buildDirectory: File, + targetDirectory: File, + log: Logger + ): File = { + + val ev = ( + configure(baseDirectory, buildDirectory, targetDirectory) #&& + make(baseDirectory, buildDirectory, targetDirectory) #&& + install(baseDirectory, buildDirectory, targetDirectory) + ) ! log + + if (ev != 0) sys.error(s"Building native library failed. Exit code: ${ev}") + + val products: List[File] = (targetDirectory ** ("*" -- "*.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 deleted file mode 100644 index 96dd85f..0000000 --- a/jni-plugin/src/main/scala/ch/jodersky/sbt/jni/build/NoTool.scala +++ /dev/null @@ -1,9 +0,0 @@ -package ch.jodersky.sbt.jni -package build - - -object NoTool { - - - -} |