aboutsummaryrefslogtreecommitdiff
path: root/stage1/Stage1Lib.scala
diff options
context:
space:
mode:
authorChristopher Vogt <oss.nsp@cvogt.org>2016-03-30 23:39:14 -0400
committerChristopher Vogt <oss.nsp@cvogt.org>2016-03-30 23:39:14 -0400
commit57de43907e05d4cd3986e2994e0e3bff93e09b4e (patch)
tree9e07a28943ffe0d9c2ace7f06315d8034f1dd6f8 /stage1/Stage1Lib.scala
parent8a4578311e4d11c06bfb4fe04e5bf414b94d24e8 (diff)
downloadcbt-57de43907e05d4cd3986e2994e0e3bff93e09b4e.tar.gz
cbt-57de43907e05d4cd3986e2994e0e3bff93e09b4e.tar.bz2
cbt-57de43907e05d4cd3986e2994e0e3bff93e09b4e.zip
Makes zinc usage smarter, so we do not need to call it when no files changed (and safe up to 0.1s for each call)
There still seem to be 2 bugs related to CBT development in the code. One if you simpy save a stage1 file unchanged and re-run cbt, it fails to call Stage2.run reflectively. Also in case of compile errors in stage1, a TrappedExitCode exception is thrown and not caught.
Diffstat (limited to 'stage1/Stage1Lib.scala')
-rw-r--r--stage1/Stage1Lib.scala39
1 files changed, 23 insertions, 16 deletions
diff --git a/stage1/Stage1Lib.scala b/stage1/Stage1Lib.scala
index 69b828b..e4fe15e 100644
--- a/stage1/Stage1Lib.scala
+++ b/stage1/Stage1Lib.scala
@@ -6,6 +6,7 @@ import java.io._
import java.lang.reflect.InvocationTargetException
import java.net._
import java.nio.file._
+import java.nio.file.attribute.FileTime
import javax.tools._
import java.security._
import java.util._
@@ -111,14 +112,22 @@ class Stage1Lib( val logger: Logger ) extends BaseLib{
}
}
- def zinc(
+ def needsUpdate( sourceFiles: Seq[File], statusFile: File ) = {
+ val lastCompile = statusFile.lastModified
+ sourceFiles.filter(_.lastModified > lastCompile).nonEmpty
+ }
+
+ def compile(
needsRecompile: Boolean,
files: Seq[File],
compileTarget: File,
+ statusFile: File,
classpath: ClassPath,
+ scalacOptions: Seq[String] = Seq(),
classLoaderCache: ClassLoaderCache,
- extraArgs: Seq[String] = Seq()
- )( zincVersion: String, scalaVersion: String ): Unit = {
+ zincVersion: String,
+ scalaVersion: String
+ ): File = {
val cp = classpath.string
if(classpath.files.isEmpty)
@@ -126,9 +135,6 @@ class Stage1Lib( val logger: Logger ) extends BaseLib{
if(files.isEmpty)
throw new Exception("Trying to compile no files. ClassPath: " ++ cp)
-
- // only run zinc if files changed, for performance reasons
- // FIXME: this is broken, need invalidate on changes in dependencies as well
if( needsRecompile ){
val zinc = JavaDependency("com.typesafe.zinc","zinc", zincVersion)
val zincDeps = zinc.transitiveDependencies
@@ -151,6 +157,8 @@ class Stage1Lib( val logger: Logger ) extends BaseLib{
val scalaReflect = JavaDependency("org.scala-lang","scala-reflect",scalaVersion).jar
val scalaCompiler = JavaDependency("org.scala-lang","scala-compiler",scalaVersion).jar
+ val start = System.currentTimeMillis
+
val code = redirectOutToErr{
lib.runMain(
"com.typesafe.zinc.Main",
@@ -162,22 +170,21 @@ class Stage1Lib( val logger: Logger ) extends BaseLib{
"-scala-extra", scalaReflect.toString,
"-cp", cp,
"-d", compileTarget.toString
- ) ++ extraArgs.map("-S"++_) ++ files.map(_.toString),
+ ) ++ scalacOptions.map("-S"++_) ++ files.map(_.toString),
zinc.classLoader(classLoaderCache)
)
}
- if(code != ExitCode.Success){
- // Ensure we trigger recompilation next time. This is currently required because we
- // don't record the time of the last successful build elsewhere. But hopefully that will
- // change soon.
- val now = System.currentTimeMillis()
- files.foreach(_.setLastModified(now))
-
- // Tell the caller that things went wrong.
- System.exit(code.integer)
+ if(code == ExitCode.Success){
+ // write version and when last compilation started so we can trigger
+ // recompile if cbt version changed or newer source files are seen
+ Files.write(statusFile.toPath, "".getBytes)//cbtVersion.getBytes)
+ Files.setLastModifiedTime(statusFile.toPath, FileTime.fromMillis(start) )
+ } else {
+ System.exit(code.integer) // FIXME: let's find a better solution for error handling. Maybe a monad after all.
}
}
+ compileTarget
}
def redirectOutToErr[T](code: => T): T = {
val oldOut = System.out