diff options
author | Jan Christopher Vogt <oss.nsp@cvogt.org> | 2016-04-02 16:06:40 -0400 |
---|---|---|
committer | Jan Christopher Vogt <oss.nsp@cvogt.org> | 2016-04-02 16:06:40 -0400 |
commit | 63b54f79c10854e38b2a4a43ee39f508458e280f (patch) | |
tree | 6a5791efedc2d297cfac1ad8bbaac0b090105149 /stage2/BasicBuild.scala | |
parent | 16b02cf34078113c833225297b686752aa26b407 (diff) | |
parent | efe68c7e710aa8c54144715408b7faca36f52c27 (diff) | |
download | cbt-63b54f79c10854e38b2a4a43ee39f508458e280f.tar.gz cbt-63b54f79c10854e38b2a4a43ee39f508458e280f.tar.bz2 cbt-63b54f79c10854e38b2a4a43ee39f508458e280f.zip |
Rewrite CBT's classloading and dependency classloaders, fetch zinc early and various smaller changes
Rewrite CBT's classloading and dependency classloaders, fetch zinc early and various smaller changes
Diffstat (limited to 'stage2/BasicBuild.scala')
-rw-r--r-- | stage2/BasicBuild.scala | 52 |
1 files changed, 21 insertions, 31 deletions
diff --git a/stage2/BasicBuild.scala b/stage2/BasicBuild.scala index 2f90197..9ed8c26 100644 --- a/stage2/BasicBuild.scala +++ b/stage2/BasicBuild.scala @@ -2,7 +2,6 @@ package cbt import cbt.paths._ import java.io._ -import java.lang.reflect.InvocationTargetException import java.net._ import java.nio.file.{Path =>_,_} import java.nio.file.Files.readAllBytes @@ -10,15 +9,13 @@ import java.security.MessageDigest import java.util.jar._ import scala.collection.immutable.Seq -import scala.reflect.runtime.{universe => ru} import scala.util._ -import ammonite.ops.{cwd => _,_} - class BasicBuild( context: Context ) extends Build( context ) class Build(val context: Context) extends Dependency with TriggerLoop{ // library available to builds implicit final val logger: Logger = context.logger + implicit final val classLoaderCache: ClassLoaderCache = context.classLoaderCache override final protected val lib: Lib = new Lib(logger) // ========== general stuff ========== @@ -26,7 +23,7 @@ class Build(val context: Context) extends Dependency with TriggerLoop{ def enableConcurrency = false final def projectDirectory: File = lib.realpath(context.cwd) assert( projectDirectory.exists, "projectDirectory does not exist: " ++ projectDirectory.string ) - final def usage: Unit = new lib.ReflectBuild(this).usage + final def usage: String = lib.usage(this.getClass, context) // ========== meta data ========== @@ -51,6 +48,12 @@ class Build(val context: Context) extends Dependency with TriggerLoop{ def apiTarget: File = scalaTarget ++ "/api" /** directory where the class files should be put (in package directories) */ def compileTarget: File = scalaTarget ++ "/classes" + /** + File which cbt uses to determine if it needs to trigger an incremental re-compile. + Last modified date is the time when the last successful compilation started. + Contents is the cbt version git hash. + */ + def compileStatusFile: File = compileTarget ++ ".last-success" /** Source directories and files. Defaults to .scala and .java files in src/ and top-level. */ def sources: Seq[File] = Seq(defaultSourceDirectory) ++ projectDirectory.listFiles.toVector.filter(sourceFileFilter) @@ -113,7 +116,7 @@ class Build(val context: Context) extends Dependency with TriggerLoop{ override def dependencyClasspath : ClassPath = ClassPath(localJars) ++ super.dependencyClasspath override def dependencyJars : Seq[File] = localJars ++ super.dependencyJars - def exportedClasspath : ClassPath = ClassPath(Seq(compile)) + def exportedClasspath : ClassPath = ClassPath(compile.toSeq:_*) def targetClasspath = ClassPath(Seq(compileTarget)) def exportedJars: Seq[File] = Seq() // ========== compile, run, test ========== @@ -121,38 +124,25 @@ class Build(val context: Context) extends Dependency with TriggerLoop{ /** scalac options used for zinc and scaladoc */ def scalacOptions: Seq[String] = Seq( "-feature", "-deprecation", "-unchecked" ) - val updated: Boolean = { - val existingClassFiles = lib.listFilesRecursive(compileTarget) - val sourcesChanged = existingClassFiles.nonEmpty && { - val oldestClassFile = existingClassFiles.sortBy(_.lastModified).head - val oldestClassFileAge = oldestClassFile.lastModified - val changedSourceFiles = sourceFiles.filter(_.lastModified > oldestClassFileAge) - if(changedSourceFiles.nonEmpty){ - /* - println(changedSourceFiles) - println(changedSourceFiles.map(_.lastModified)) - println(changedSourceFiles.map(_.lastModified > oldestClassFileAge)) - println(oldestClassFile) - println(oldestClassFileAge) - println("-"*80) - */ - } - changedSourceFiles.nonEmpty - } - sourcesChanged || transitiveDependencies.map(_.updated).fold(false)(_ || _) + private object needsUpdateCache extends Cache[Boolean] + def needsUpdate: Boolean = { + needsUpdateCache( + lib.needsUpdate( sourceFiles, compileStatusFile ) + || transitiveDependencies.exists(_.needsUpdate) + ) } - private object compileCache extends Cache[File] - def compile: File = compileCache{ + private object compileCache extends Cache[Option[File]] + def compile: Option[File] = compileCache{ lib.compile( - updated, - sourceFiles, compileTarget, dependencyClasspath, scalacOptions, - zincVersion = zincVersion, scalaVersion = scalaVersion + needsUpdate, + sourceFiles, compileTarget, compileStatusFile, dependencyClasspath, scalacOptions, + context.classLoaderCache, zincVersion = zincVersion, scalaVersion = scalaVersion ) } def runClass: String = "Main" - def run: ExitCode = lib.runMainIfFound( runClass, context.args, classLoader ) + def run: ExitCode = lib.runMainIfFound( runClass, context.args, classLoader(context.classLoaderCache) ) def test: ExitCode = lib.test(context) |