aboutsummaryrefslogtreecommitdiff
path: root/stage2/BasicBuild.scala
diff options
context:
space:
mode:
authorChristopher Vogt <oss.nsp@cvogt.org>2017-02-09 02:29:44 +0000
committerChristopher Vogt <oss.nsp@cvogt.org>2017-02-09 21:44:23 -0500
commitbee13ba7a4458482ce00a5c6bae4cd64328c4e5e (patch)
tree3eac3a3dee9fe2645673a7df09915d2f77f0b781 /stage2/BasicBuild.scala
parent00157c927255a9c885287a7e16670561e8e6391e (diff)
downloadcbt-bee13ba7a4458482ce00a5c6bae4cd64328c4e5e.tar.gz
cbt-bee13ba7a4458482ce00a5c6bae4cd64328c4e5e.tar.bz2
cbt-bee13ba7a4458482ce00a5c6bae4cd64328c4e5e.zip
memoize task results across classes within a single run
Diffstat (limited to 'stage2/BasicBuild.scala')
-rw-r--r--stage2/BasicBuild.scala29
1 files changed, 5 insertions, 24 deletions
diff --git a/stage2/BasicBuild.scala b/stage2/BasicBuild.scala
index 8b4a3a5..2fd34c7 100644
--- a/stage2/BasicBuild.scala
+++ b/stage2/BasicBuild.scala
@@ -9,6 +9,8 @@ trait BaseBuild extends BuildInterface with DependencyImplementation with Trigge
// will create new instances given the context, which means operations in the
// overrides will happen multiple times and if they are not idempotent stuff likely breaks
def context: Context
+ def moduleKey: String = "BaseBuild("+projectDirectory.string+")"
+ implicit def transientCache: java.util.Map[AnyRef,AnyRef] = context.transientCache
// library available to builds
implicit protected final val logger: Logger = context.logger
@@ -59,7 +61,7 @@ trait BaseBuild extends BuildInterface with DependencyImplementation with Trigge
// FIXME: this should probably be removed
Resolver( mavenCentral ).bind(
"org.scala-lang" % "scala-library" % scalaVersion
- ) :+ BinaryDependency(localJars, Nil)
+ ) ++ ( if(localJars.nonEmpty) Seq( BinaryDependency(localJars, Nil) ) else Nil )
// ========== paths ==========
final private val defaultSourceDirectory = projectDirectory ++ "/src"
@@ -135,15 +137,13 @@ trait BaseBuild extends BuildInterface with DependencyImplementation with Trigge
"-unchecked"
)
- private object needsUpdateCache extends Cache[Boolean]
- def needsUpdate: Boolean = needsUpdateCache(
+ def needsUpdate: Boolean = taskCache[BaseBuild]("needsUpdate").memoize[java.lang.Boolean](
context.cbtHasChanged
|| lib.needsUpdate( sourceFiles, compileStatusFile )
|| transitiveDependencies.filterNot(_ == context.parentBuild).exists(_.needsUpdate)
)
- private object compileCache extends Cache[Option[File]]
- def compile: Option[File] = compileCache{
+ def compile: Option[File] = taskCache[BaseBuild]("compile").memoize{
lib.compile(
context.cbtHasChanged,
needsUpdate || context.parentBuild.map(_.needsUpdate).getOrElse(false),
@@ -153,7 +153,6 @@ trait BaseBuild extends BuildInterface with DependencyImplementation with Trigge
)
}
-
def mainClasses: Seq[Class[_]] = compile.toSeq.flatMap( lib.mainClasses( _, classLoader(classLoaderCache) ) )
def runClass: Option[String] = lib.runClass( mainClasses ).map( _.getName )
@@ -264,24 +263,6 @@ trait BaseBuild extends BuildInterface with DependencyImplementation with Trigge
def finalBuild: BuildInterface = this
override def show = this.getClass.getSimpleName ++ "(" ++ projectDirectory.string ++ ")"
- // TODO: allow people not provide the method name, maybe via macro
- // TODO: pull this out into lib
- /**
- caches given value in context keyed with given key and projectDirectory
- the context is fresh on every complete run of cbt
- */
- def cached[T <: AnyRef](name: String)(task: => T): T = {
- val cache = context.transientCache
- val key = (projectDirectory,name)
- if( cache.containsKey(key) ){
- cache.get(key).asInstanceOf[T]
- } else{
- val value = task
- cache.put( key, value )
- value
- }
- }
-
// a method that can be called only to trigger any side-effects
final def `void` = ()
}