aboutsummaryrefslogtreecommitdiff
path: root/stage2
diff options
context:
space:
mode:
authorChristopher Vogt <oss.nsp@cvogt.org>2017-02-09 21:20:11 -0500
committerChristopher Vogt <oss.nsp@cvogt.org>2017-02-09 22:43:00 -0500
commite8673866b79f7473391dcee26243eee80d5d3cb6 (patch)
tree16146affeebdb58cd302a1f8527220c906818c96 /stage2
parentbee13ba7a4458482ce00a5c6bae4cd64328c4e5e (diff)
downloadcbt-e8673866b79f7473391dcee26243eee80d5d3cb6.tar.gz
cbt-e8673866b79f7473391dcee26243eee80d5d3cb6.tar.bz2
cbt-e8673866b79f7473391dcee26243eee80d5d3cb6.zip
idempotent change propagation
using lastModified instead of a non-idempotent needsUpdate flag this fixes a bug where dependees would not be rebuilt if cbt exited or was killed after dependencies were already rebuilt.
Diffstat (limited to 'stage2')
-rw-r--r--stage2/BasicBuild.scala21
-rw-r--r--stage2/BuildDependency.scala2
-rw-r--r--stage2/GitDependency.scala2
-rw-r--r--stage2/Lib.scala6
-rw-r--r--stage2/PackageJars.scala4
-rw-r--r--stage2/Stage2.scala4
-rw-r--r--stage2/ToolsStage2.scala2
-rw-r--r--stage2/ToolsTasks.scala26
-rw-r--r--stage2/plugins/Dotty.scala44
9 files changed, 56 insertions, 55 deletions
diff --git a/stage2/BasicBuild.scala b/stage2/BasicBuild.scala
index 2fd34c7..ef5411a 100644
--- a/stage2/BasicBuild.scala
+++ b/stage2/BasicBuild.scala
@@ -98,7 +98,7 @@ trait BaseBuild extends BuildInterface with DependencyImplementation with Trigge
}
logEmptySourceDirectories()
- def Resolver( urls: URL* ) = MavenResolver( context.cbtHasChanged, context.paths.mavenCache, urls: _* )
+ def Resolver( urls: URL* ) = MavenResolver( context.cbtLastModified, context.paths.mavenCache, urls: _* )
def ScalaDependency(
groupId: String, artifactId: String, version: String, classifier: Classifier = Classifier.none,
@@ -126,7 +126,7 @@ trait BaseBuild extends BuildInterface with DependencyImplementation with Trigge
val resourcesDirectory = projectDirectory ++ "/resources"
ClassPath( if(resourcesDirectory.exists) Seq(resourcesDirectory) else Nil )
}
- def exportedClasspath : ClassPath = ClassPath(compile.toSeq) ++ resourceClasspath
+ def exportedClasspath : ClassPath = ClassPath(compileFile.toSeq) ++ resourceClasspath
def targetClasspath = ClassPath(Seq(compileTarget))
// ========== compile, run, test ==========
@@ -137,23 +137,20 @@ trait BaseBuild extends BuildInterface with DependencyImplementation with Trigge
"-unchecked"
)
- def needsUpdate: Boolean = taskCache[BaseBuild]("needsUpdate").memoize[java.lang.Boolean](
- context.cbtHasChanged
- || lib.needsUpdate( sourceFiles, compileStatusFile )
- || transitiveDependencies.filterNot(_ == context.parentBuild).exists(_.needsUpdate)
- )
+ final def lastModified: Long = compile.getOrElse(0L)
+
+ final def compileFile: Option[File] = compile.map(_ => compileTarget)
- def compile: Option[File] = taskCache[BaseBuild]("compile").memoize{
+ def compile: Option[Long] = taskCache[BaseBuild]("_compile").memoize{
lib.compile(
- context.cbtHasChanged,
- needsUpdate || context.parentBuild.map(_.needsUpdate).getOrElse(false),
+ context.cbtLastModified,
sourceFiles, compileTarget, compileStatusFile, compileDependencies,
context.paths.mavenCache, scalacOptions, context.classLoaderCache,
zincVersion = zincVersion, scalaVersion = scalaVersion
)
}
- def mainClasses: Seq[Class[_]] = compile.toSeq.flatMap( lib.mainClasses( _, classLoader(classLoaderCache) ) )
+ def mainClasses: Seq[Class[_]] = compileFile.toSeq.flatMap( lib.mainClasses( _, classLoader(classLoaderCache) ) )
def runClass: Option[String] = lib.runClass( mainClasses ).map( _.getName )
@@ -181,7 +178,7 @@ trait BaseBuild extends BuildInterface with DependencyImplementation with Trigge
System.setProperty(colorized, "true")
}
- val scalac = new ScalaCompilerDependency(context.cbtHasChanged, context.paths.mavenCache, scalaVersion)
+ val scalac = new ScalaCompilerDependency(context.cbtLastModified, context.paths.mavenCache, scalaVersion)
lib.runMain(
"scala.tools.nsc.MainGenericRunner",
Seq(
diff --git a/stage2/BuildDependency.scala b/stage2/BuildDependency.scala
index 4b4fdc1..236f958 100644
--- a/stage2/BuildDependency.scala
+++ b/stage2/BuildDependency.scala
@@ -27,7 +27,7 @@ final case class DirectoryDependency(context: Context) extends TriggerLoop{
def exportedClasspath = ClassPath()
def dependencies = Seq(build)
def triggerLoopFiles = root.triggerLoopFiles
- def needsUpdate = build.needsUpdate
+ def lastModified = build.lastModified
def targetClasspath = ClassPath()
}
/*
diff --git a/stage2/GitDependency.scala b/stage2/GitDependency.scala
index e27eff9..059d650 100644
--- a/stage2/GitDependency.scala
+++ b/stage2/GitDependency.scala
@@ -76,5 +76,5 @@ case class GitDependency(
def exportedClasspath = ClassPath()
private[cbt] def targetClasspath = exportedClasspath
- def needsUpdate: Boolean = false
+ def lastModified: Long = dependency.lastModified
}
diff --git a/stage2/Lib.scala b/stage2/Lib.scala
index c570ca3..a76e281 100644
--- a/stage2/Lib.scala
+++ b/stage2/Lib.scala
@@ -15,7 +15,7 @@ import scala.util._
case class Developer(id: String, name: String, timezone: String, url: URL)
/** Don't extend. Create your own libs :). */
-final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{
+final class Lib(val logger: Logger) extends Stage1Lib(logger) with Scaffold{
lib =>
val buildClassName = "Build"
@@ -74,7 +74,7 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{
}
def docJar(
- cbtHasChanged: Boolean,
+ cbtLastModified: Long,
scalaVersion: String,
sourceFiles: Seq[File],
dependencyClasspath: ClassPath,
@@ -101,7 +101,7 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{
runMain(
"scala.tools.nsc.ScalaDoc",
args,
- new ScalaDependencies(cbtHasChanged,mavenCache,scalaVersion).classLoader(classLoaderCache)
+ new ScalaDependencies(cbtLastModified,mavenCache,scalaVersion).classLoader(classLoaderCache)
)
}
lib.jarFile(
diff --git a/stage2/PackageJars.scala b/stage2/PackageJars.scala
index 3ecceb2..7079786 100644
--- a/stage2/PackageJars.scala
+++ b/stage2/PackageJars.scala
@@ -11,7 +11,7 @@ trait PackageJars extends BaseBuild with ArtifactInfo{
)( _() ).flatten
def jar: Option[File] = taskCache[PackageJars]("jar").memoize{
- compile.flatMap( lib.jar( artifactId, scalaMajorVersion, version, _, jarTarget ) )
+ compileFile.flatMap( lib.jar( artifactId, scalaMajorVersion, version, _, jarTarget ) )
}
def srcJar: Option[File] = taskCache[PackageJars]("srcJar").memoize{
@@ -20,7 +20,7 @@ trait PackageJars extends BaseBuild with ArtifactInfo{
def docJar: Option[File] = taskCache[PackageJars]("docJar").memoize{
lib.docJar(
- context.cbtHasChanged,
+ context.cbtLastModified,
scalaVersion, sourceFiles, compileClasspath, docTarget,
jarTarget, artifactId, scalaMajorVersion, version,
scalacOptions, context.classLoaderCache, context.paths.mavenCache
diff --git a/stage2/Stage2.scala b/stage2/Stage2.scala
index 2884ddb..542a982 100644
--- a/stage2/Stage2.scala
+++ b/stage2/Stage2.scala
@@ -30,9 +30,9 @@ object Stage2 extends Stage2Base{
args.args.drop( taskIndex +1 ).toArray,
logger.enabledLoggers.toArray,
logger.start,
- args.cbtHasChanged,
+ args.stage2LastModified,
null,
- args.persistentCache,
+ args.classLoaderCache.hashMap,
args.transientCache,
args.cache,
args.cbtHome,
diff --git a/stage2/ToolsStage2.scala b/stage2/ToolsStage2.scala
index df615fc..2b5e092 100644
--- a/stage2/ToolsStage2.scala
+++ b/stage2/ToolsStage2.scala
@@ -4,7 +4,7 @@ object ToolsStage2 extends Stage2Base{
def run( _args: Stage2Args ): Unit = {
val args = _args.args.dropWhile(Seq("tools","direct") contains _)
val lib = new Lib(_args.logger)
- val toolsTasks = new ToolsTasks(lib, args, _args.cwd, _args.classLoaderCache, _args.cache, _args.cbtHome, _args.cbtHasChanged)
+ val toolsTasks = new ToolsTasks(lib, args, _args.cwd, _args.classLoaderCache, _args.cache, _args.cbtHome, _args.stage2LastModified)
new lib.ReflectObject(toolsTasks){
def usage: String = "Available methods: " ++ lib.taskNames(toolsTasks.getClass).mkString(" ")
}.callNullary(args.lift(0))
diff --git a/stage2/ToolsTasks.scala b/stage2/ToolsTasks.scala
index 839780a..6acf72c 100644
--- a/stage2/ToolsTasks.scala
+++ b/stage2/ToolsTasks.scala
@@ -9,11 +9,11 @@ class ToolsTasks(
classLoaderCache: ClassLoaderCache,
cache: File,
cbtHome: File,
- cbtHasChanged: Boolean
+ cbtLastModified: Long
){
private val paths = CbtPaths(cbtHome, cache)
import paths._
- private def Resolver( urls: URL* ) = MavenResolver(cbtHasChanged,mavenCache,urls: _*)
+ private def Resolver( urls: URL* ) = MavenResolver(cbtLastModified,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 )
@@ -56,7 +56,7 @@ class ToolsTasks(
}
def scala = {
val version = args.lift(1).getOrElse(constants.scalaVersion)
- val scalac = new ScalaCompilerDependency( cbtHasChanged, mavenCache, version )
+ val scalac = new ScalaCompilerDependency( cbtLastModified, mavenCache, version )
val _args = Seq("-cp", scalac.classpath.string) ++ args.drop(2)
lib.runMain(
"scala.tools.nsc.MainGenericRunner", _args, scalac.classLoader(classLoaderCache)
@@ -97,14 +97,15 @@ class ToolsTasks(
val n = valName(d)
s"""
// ${d.groupId}:${d.artifactId}:${d.version}
- download(new URL(mavenUrl + "${d.basePath(true)}.jar"), Paths.get(${n}File), "${d.jarSha1}");
-
String[] ${n}ClasspathArray = new String[]{${deps.sortBy(_.jar).map(valName(_)+"File").mkString(", ")}};
- String ${n}Classpath = classpath( ${n}ClasspathArray );
- ClassLoader $n =
- classLoaderCache.contains( ${n}Classpath )
- ? classLoaderCache.get( ${n}Classpath )
- : classLoaderCache.put( classLoader( ${n}File, $parentString ), ${n}Classpath );"""
+ ClassLoader $n = loadDependency(
+ mavenUrl + "${d.basePath(true)}.jar",
+ ${n}File,
+ "${d.jarSha1}",
+ classLoaderCache,
+ $parentString,
+ ${n}ClasspathArray
+ );"""
}
}
val assignments = codeEach(zinc) ++ codeEach(scalaXml)
@@ -116,6 +117,7 @@ import java.io.*;
import java.nio.file.*;
import java.net.*;
import java.security.*;
+import java.util.*;
import static cbt.Stage0Lib.*;
import static cbt.NailgunLauncher.*;
@@ -130,13 +132,13 @@ class EarlyDependencies{
${files.map(d => s""" String ${valName(d)}File;""").mkString("\n")}
public EarlyDependencies(
- String mavenCache, String mavenUrl, JavaCache<ClassLoader> classLoaderCache, ClassLoader rootClassLoader
+ String mavenCache, String mavenUrl, ClassLoaderCache classLoaderCache, ClassLoader rootClassLoader
) throws Throwable {
${files.map(d => s""" ${valName(d)}File = mavenCache + "${d.basePath(true)}.jar";""").mkString("\n")}
${scalaDeps.map(d => s""" download(new URL(mavenUrl + "${d.basePath(true)}.jar"), Paths.get(${valName(d)}File), "${d.jarSha1}");""").mkString("\n")}
${assignments.mkString("\n")}
-
+
classLoader = scalaXml_${scalaXmlVersion.replace(".","_")}_;
classpathArray = scalaXml_${scalaXmlVersion.replace(".","_")}_ClasspathArray;
diff --git a/stage2/plugins/Dotty.scala b/stage2/plugins/Dotty.scala
index fe949a3..6fe5dd3 100644
--- a/stage2/plugins/Dotty.scala
+++ b/stage2/plugins/Dotty.scala
@@ -8,17 +8,15 @@ trait Dotty extends BaseBuild{
def dottyVersion: String = "0.1-20160926-ec28ea1-NIGHTLY"
def dottyOptions: Seq[String] = Seq()
override def scalaTarget: File = target ++ s"/dotty-$dottyVersion"
-
+
private lazy val dottyLib = new DottyLib(
- logger, context.cbtHasChanged, context.paths.mavenCache,
+ logger, context.cbtLastModified, context.paths.mavenCache,
context.classLoaderCache, dottyVersion = dottyVersion
)
- override def compile: Option[File] = taskCache[Dotty]("compile").memoize{
+ override def compile: Option[Long] = taskCache[Dotty]("compile").memoize{
dottyLib.compile(
- needsUpdate || context.parentBuild.map(_.needsUpdate).getOrElse(false),
- sourceFiles, compileTarget, compileStatusFile, compileClasspath,
- dottyOptions
+ sourceFiles, compileTarget, compileStatusFile, compileDependencies, dottyOptions
)
}
@@ -36,7 +34,7 @@ trait Dotty extends BaseBuild{
class DottyLib(
logger: Logger,
- cbtHasChanged: Boolean,
+ cbtLastModified: Long,
mavenCache: File,
classLoaderCache: ClassLoaderCache,
dottyVersion: String
@@ -44,7 +42,7 @@ class DottyLib(
val lib = new Lib(logger)
import lib._
- private def Resolver(urls: URL*) = MavenResolver(cbtHasChanged, mavenCache, urls: _*)
+ private def Resolver(urls: URL*) = MavenResolver(cbtLastModified, mavenCache, urls: _*)
private lazy val dottyDependency = Resolver(mavenCentral).bindOne(
MavenDependency("ch.epfl.lamp","dotty_2.11",dottyVersion)
)
@@ -94,22 +92,24 @@ class DottyLib(
}
def compile(
- needsRecompile: Boolean,
- files: Seq[File],
+ sourceFiles: Seq[File],
compileTarget: File,
statusFile: File,
- classpath: ClassPath,
+ dependencies: Seq[Dependency],
dottyOptions: Seq[String]
- ): Option[File] = {
-
+ ): Option[Long] = {
+ val d = Dependencies(dependencies)
+ val classpath = d.classpath
+ val cp = classpath.string
if(classpath.files.isEmpty)
- throw new Exception("Trying to compile with empty classpath. Source files: " ++ files.toString)
+ throw new Exception("Trying to compile with empty classpath. Source files: " ++ sourceFiles.toString)
- if( files.isEmpty ){
+ if( sourceFiles.isEmpty ){
None
}else{
- if( needsRecompile ){
- val start = System.currentTimeMillis
+ val start = System.currentTimeMillis
+ val lastCompiled = statusFile.lastModified
+ if( d.lastModified > lastCompiled || sourceFiles.exists(_.lastModified > lastCompiled) ){
val _class = "dotty.tools.dotc.Main"
val dualArgs =
@@ -118,7 +118,7 @@ class DottyLib(
)
val singleArgs = dottyOptions.map( "-S" ++ _ )
- val code =
+ val code =
try{
System.err.println("Compiling with Dotty to " ++ compileTarget.toString)
compileTarget.mkdirs
@@ -128,7 +128,7 @@ class DottyLib(
dualArgs ++ singleArgs ++ Seq(
"-bootclasspath", dottyDependency.classpath.string, // let's put cp last. It so long
"-classpath", classpath.string // let's put cp last. It so long
- ) ++ files.map(_.toString),
+ ) ++ sourceFiles.map(_.toString),
dottyDependency.classLoader(classLoaderCache)
)
}
@@ -150,7 +150,7 @@ ${dottyDependency.classpath.strings.mkString(":\\\n")} \\
-classpath \\
${classpath.strings.mkString(":\\\n")} \\
\\
-${files.sorted.mkString(" \\\n")}
+${sourceFiles.sorted.mkString(" \\\n")}
"""
)
ExitCode.Failure
@@ -164,8 +164,10 @@ ${files.sorted.mkString(" \\\n")}
} else {
System.exit(code.integer) // FIXME: let's find a better solution for error handling. Maybe a monad after all.
}
+ Some( start )
+ } else {
+ Some( lastCompiled )
}
- Some( compileTarget )
}
}
}