aboutsummaryrefslogtreecommitdiff
path: root/stage2
diff options
context:
space:
mode:
Diffstat (limited to 'stage2')
-rw-r--r--stage2/BasicBuild.scala29
-rw-r--r--stage2/BuildBuild.scala3
-rw-r--r--stage2/BuildDependency.scala3
-rw-r--r--stage2/GitDependency.scala10
-rw-r--r--stage2/Lib.scala4
-rw-r--r--stage2/PackageJars.scala9
-rw-r--r--stage2/Stage2.scala4
-rw-r--r--stage2/ToolsTasks.scala1
-rw-r--r--stage2/plugins/Dotty.scala5
9 files changed, 23 insertions, 45 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` = ()
}
diff --git a/stage2/BuildBuild.scala b/stage2/BuildBuild.scala
index cf515bb..1b05214 100644
--- a/stage2/BuildBuild.scala
+++ b/stage2/BuildBuild.scala
@@ -32,8 +32,7 @@ trait BuildBuildWithoutEssentials extends BaseBuild{
override def dependencies =
super.dependencies :+ context.cbtDependency
def managedBuildDirectory: java.io.File = lib.realpath( projectDirectory.parent )
- private object managedBuildCache extends Cache[BuildInterface]
- def managedBuild = managedBuildCache{
+ def managedBuild = taskCache[BuildBuildWithoutEssentials]("managedBuild").memoize{
val managedBuildFile = projectDirectory++"/build.scala"
logger.composition("Loading build at " ++ managedBuildDirectory.toString)
val build = (
diff --git a/stage2/BuildDependency.scala b/stage2/BuildDependency.scala
index 197a7a1..4b4fdc1 100644
--- a/stage2/BuildDependency.scala
+++ b/stage2/BuildDependency.scala
@@ -16,9 +16,12 @@ trait TriggerLoop extends DependencyImplementation{
}
/** You likely want to use the factory method in the BasicBuild class instead of this. */
final case class DirectoryDependency(context: Context) extends TriggerLoop{
+ override def toString = show
override def show = this.getClass.getSimpleName ++ "(" ++ context.projectDirectory.string ++ ")"
+ def moduleKey = this.getClass.getName ++ "("+context.projectDirectory.string+")"
lazy val logger = context.logger
override lazy val lib: Lib = new Lib(logger)
+ def transientCache = context.transientCache
private lazy val root = lib.loadRoot( context.copy(args=Seq()) )
lazy val build = root.finalBuild
def exportedClasspath = ClassPath()
diff --git a/stage2/GitDependency.scala b/stage2/GitDependency.scala
index 650fd09..e27eff9 100644
--- a/stage2/GitDependency.scala
+++ b/stage2/GitDependency.scala
@@ -15,15 +15,14 @@ case class GitDependency(
)(implicit val logger: Logger, classLoaderCache: ClassLoaderCache, context: Context ) extends DependencyImplementation{
import GitDependency._
override def lib = new Lib(logger)
-
+ def moduleKey = this.getClass.getName ++ "(" ++ url ++ subDirectory.map("/" ++ _).getOrElse("") ++ "#" ++ ref ++ ")"
+ def transientCache = context.transientCache
// TODO: add support for authentication via ssh and/or https
// See http://www.codeaffine.com/2014/12/09/jgit-authentication/
private val GitUrl( _, domain, path ) = url
private val credentialsFile = context.projectDirectory ++ "/git.login"
- private object checkoutCache extends Cache[File]
-
private def authenticate(_git: CloneCommand) =
if(!credentialsFile.exists){
_git
@@ -36,7 +35,7 @@ case class GitDependency(
_git.setCredentialsProvider( new UsernamePasswordCredentialsProvider(user, password) )
}
- def checkout: File = checkoutCache{
+ def checkout: File = taskCache[GitDependency]("checkout").memoize{
val checkoutDirectory = context.cache ++ s"/git/$domain/$path/$ref"
val _git = if(checkoutDirectory.exists){
logger.git(s"Found existing checkout of $url#$ref in $checkoutDirectory")
@@ -65,8 +64,7 @@ case class GitDependency(
assert( actualRef == ref, s"actual ref '$actualRef' does not match expected ref '$ref'")
checkoutDirectory
}
- private object dependencyCache extends Cache[DependencyImplementation]
- def dependency = dependencyCache{
+ def dependency = taskCache[GitDependency]("dependency").memoize{
DirectoryDependency(
context.copy(
projectDirectory = checkout ++ subDirectory.map("/" ++ _).getOrElse("")
diff --git a/stage2/Lib.scala b/stage2/Lib.scala
index 769cd97..c570ca3 100644
--- a/stage2/Lib.scala
+++ b/stage2/Lib.scala
@@ -86,7 +86,7 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{
compileArgs: Seq[String],
classLoaderCache: ClassLoaderCache,
mavenCache: File
- ): Option[File] = {
+ )(implicit transientCache: java.util.Map[AnyRef,AnyRef]): Option[File] = {
if(sourceFiles.isEmpty){
None
} else {
@@ -101,7 +101,7 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{
runMain(
"scala.tools.nsc.ScalaDoc",
args,
- ScalaDependencies(cbtHasChanged,mavenCache,scalaVersion)(logger).classLoader(classLoaderCache)
+ new ScalaDependencies(cbtHasChanged,mavenCache,scalaVersion).classLoader(classLoaderCache)
)
}
lib.jarFile(
diff --git a/stage2/PackageJars.scala b/stage2/PackageJars.scala
index ff89284..3ecceb2 100644
--- a/stage2/PackageJars.scala
+++ b/stage2/PackageJars.scala
@@ -10,18 +10,15 @@ trait PackageJars extends BaseBuild with ArtifactInfo{
Seq(() => jar, () => docJar, () => srcJar)
)( _() ).flatten
- private object cacheJarBasicBuild extends Cache[Option[File]]
- def jar: Option[File] = cacheJarBasicBuild{
+ def jar: Option[File] = taskCache[PackageJars]("jar").memoize{
compile.flatMap( lib.jar( artifactId, scalaMajorVersion, version, _, jarTarget ) )
}
- private object cacheSrcJarBasicBuild extends Cache[Option[File]]
- def srcJar: Option[File] = cacheSrcJarBasicBuild{
+ def srcJar: Option[File] = taskCache[PackageJars]("srcJar").memoize{
lib.srcJar( sourceFiles, artifactId, scalaMajorVersion, version, scalaTarget )
}
- private object cacheDocBasicBuild extends Cache[Option[File]]
- def docJar: Option[File] = cacheDocBasicBuild{
+ def docJar: Option[File] = taskCache[PackageJars]("docJar").memoize{
lib.docJar(
context.cbtHasChanged,
scalaVersion, sourceFiles, compileClasspath, docTarget,
diff --git a/stage2/Stage2.scala b/stage2/Stage2.scala
index ab7b4fe..2884ddb 100644
--- a/stage2/Stage2.scala
+++ b/stage2/Stage2.scala
@@ -24,7 +24,7 @@ object Stage2 extends Stage2Base{
}
val task = args.args.lift( taskIndex )
- val context: Context = ContextImplementation(
+ val context: Context = new ContextImplementation(
args.cwd,
args.cwd,
args.args.drop( taskIndex +1 ).toArray,
@@ -33,7 +33,7 @@ object Stage2 extends Stage2Base{
args.cbtHasChanged,
null,
args.persistentCache,
- new HashMap,
+ args.transientCache,
args.cache,
args.cbtHome,
args.cbtHome,
diff --git a/stage2/ToolsTasks.scala b/stage2/ToolsTasks.scala
index b92cb7a..839780a 100644
--- a/stage2/ToolsTasks.scala
+++ b/stage2/ToolsTasks.scala
@@ -15,6 +15,7 @@ class ToolsTasks(
import paths._
private def Resolver( urls: URL* ) = MavenResolver(cbtHasChanged,mavenCache,urls: _*)
implicit val logger: Logger = lib.logger
+ implicit val transientCache: java.util.Map[AnyRef,AnyRef] = new java.util.HashMap
def createMain: Unit = lib.createMain( cwd )
def createBuild: Unit = lib.createBuild( cwd )
def gui = NailgunLauncher.main(Array(
diff --git a/stage2/plugins/Dotty.scala b/stage2/plugins/Dotty.scala
index 8671fb6..fe949a3 100644
--- a/stage2/plugins/Dotty.scala
+++ b/stage2/plugins/Dotty.scala
@@ -14,8 +14,7 @@ trait Dotty extends BaseBuild{
context.classLoaderCache, dottyVersion = dottyVersion
)
- private object compileCache extends Cache[Option[File]]
- override def compile: Option[File] = compileCache{
+ override def compile: Option[File] = taskCache[Dotty]("compile").memoize{
dottyLib.compile(
needsUpdate || context.parentBuild.map(_.needsUpdate).getOrElse(false),
sourceFiles, compileTarget, compileStatusFile, compileClasspath,
@@ -41,7 +40,7 @@ class DottyLib(
mavenCache: File,
classLoaderCache: ClassLoaderCache,
dottyVersion: String
-){
+)(implicit transientCache: java.util.Map[AnyRef,AnyRef]){
val lib = new Lib(logger)
import lib._