Skip to content

Commit

Permalink
[BUILD] Improved logging for when building the native libraries.
Browse files Browse the repository at this point in the history
  • Loading branch information
eaplatanios committed May 3, 2018
1 parent a3fcc06 commit 6a5b40c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
13 changes: 9 additions & 4 deletions project/BuildTool.scala
Expand Up @@ -47,7 +47,10 @@ object BuildTool {
val baseDirectory : File
val buildDirectory: File

def clean(): Unit = if (buildDirectory.list().contains("Makefile")) Process("make clean", buildDirectory) ! log
def clean(): Unit = {
if (buildDirectory.list().contains("Makefile"))
Process("make clean", buildDirectory) ! log
}

def configure(targetDirectory: File): ProcessBuilder

Expand All @@ -56,9 +59,11 @@ object BuildTool {
def install(): ProcessBuilder = Process("make install", buildDirectory)

def libraries(targetDirectory: File): Seq[File] = {
val exitCode: Int = (configure(targetDirectory) #&& make() #&& install()) ! log
if (exitCode != 0)
sys.error(s"Failed to build the native library. Exit code: $exitCode.")
try {
(configure(targetDirectory) #&& make() #&& install()).lineStream.foreach(log.info(_))
} catch {
case t: Throwable => sys.error(s"Failed to build the native library: $t.")
}
val products: List[File] = (targetDirectory ** ("*.so" | "*.dylib" | "*.dll")).get.filter(_.isFile).toList
if (products == Nil)
sys.error(s"No files were created during compilation, something went wrong with the $name configuration.")
Expand Down
14 changes: 9 additions & 5 deletions project/JniNative.scala
Expand Up @@ -99,14 +99,18 @@ object JniNative extends AutoPlugin {
},
clean in nativeCompile := nativeClean.value,
nativeCompile := {
val log = streams.value.log
val tool = nativeBuildTool.value
val toolInstance = nativeBuildToolInstance.value
val targetDir = (target in nativeCompile).value / "bin"
IO.createDirectory(targetDir)
streams.value.log.info(s"Building library with native build tool ${tool.name}.")
val libraries = toolInstance.libraries(targetDir)
streams.value.log.success(s"Libraries built in:\n\t- ${libraries.map(_.getAbsolutePath).mkString("\n\t- ")}")
libraries
val cachedFunction = FileFunction.cached(streams.value.cacheDirectory)(_ => {
IO.createDirectory(targetDir)
log.info(s"Building library with native build tool ${tool.name}.")
val libraries = toolInstance.libraries(targetDir)
log.success(s"Libraries built in:\n\t- ${libraries.map(_.getAbsolutePath).mkString("\n\t- ")}")
libraries.toSet
})
cachedFunction((sourceDirectory in nativeCompile).value.listFiles().toSet).toSeq
},
compile in Compile := (compile in Compile).dependsOn(nativeCompile).value,
// Make the SBT clean task also cleans the native sources.
Expand Down
3 changes: 2 additions & 1 deletion project/TensorFlowGenerateTensorOps.scala
Expand Up @@ -68,9 +68,10 @@ object TensorFlowGenerateTensorOps extends AutoPlugin {
.foreach(Files.deleteIfExists)
},
generateTensorOps := {
streams.value.log.info("Generating TensorFlow tensor op files.")
val log = streams.value.log
val opsPBFile = (target in generateTensorOps).value / "resources" / "ops.pbtxt"
val cachedFunction = FileFunction.cached(streams.value.cacheDirectory)(opsFiles => {
log.info("Generating TensorFlow tensor op files.")
generateFiles(
opsFiles.head,
(target in generateTensorOps).value.toPath,
Expand Down

0 comments on commit 6a5b40c

Please sign in to comment.