aboutsummaryrefslogtreecommitdiff
path: root/stage1
diff options
context:
space:
mode:
authorChristopher Vogt <oss.nsp@cvogt.org>2017-03-12 01:47:57 -0500
committerChristopher Vogt <oss.nsp@cvogt.org>2017-03-12 11:56:25 -0400
commit244f86a9cdf19904169456c234a2752f125dd427 (patch)
tree51e1f79100cc3651dfce66d4a284584d6bef3997 /stage1
parent4eb753e4d4ef5be7443b99832892bac697b10b50 (diff)
downloadcbt-244f86a9cdf19904169456c234a2752f125dd427.tar.gz
cbt-244f86a9cdf19904169456c234a2752f125dd427.tar.bz2
cbt-244f86a9cdf19904169456c234a2752f125dd427.zip
revamp loop feature
now CBT and builds pass their file names to the current build via the context. The build then simply blocks until any file changes. Then it returns with a special exit code, which the bash script picks up and restarts CBT. Thats works well for looping over project files. It works less well for looping over builds and CBT itself. For this a build has to success once, so that the .cbt-loop.tmp file exists. Then looping works for cbt and builds, but the file list is not updated in case of compile errors, etc. Fixes - https://github.com/cvogt/cbt/issues/406 - https://github.com/cvogt/cbt/issues/405 - https://github.com/cvogt/cbt/issues/202 - https://github.com/cvogt/cbt/issues/50 - https://github.com/cvogt/cbt/issues/22 We should improve for 1.0 in https://github.com/cvogt/cbt/issues/419 to handle looping over build files and cbt itself smarter.
Diffstat (limited to 'stage1')
-rw-r--r--stage1/ContextImplementation.scala3
-rw-r--r--stage1/Stage1.scala18
-rw-r--r--stage1/Stage1Lib.scala8
-rw-r--r--stage1/cbt.scala13
4 files changed, 27 insertions, 15 deletions
diff --git a/stage1/ContextImplementation.scala b/stage1/ContextImplementation.scala
index b263ef4..90d9d5f 100644
--- a/stage1/ContextImplementation.scala
+++ b/stage1/ContextImplementation.scala
@@ -15,7 +15,8 @@ class ContextImplementation(
override val cbtHome: File,
override val cbtRootHome: File,
override val compatibilityTarget: File,
- override val parentBuildOrNull: BuildInterface
+ override val parentBuildOrNull: BuildInterface,
+ override val triggerLoopFilesArray: Array[File]
) extends Context{
@deprecated("this method is replaced by workingDirectory","")
def projectDirectory = workingDirectory
diff --git a/stage1/Stage1.scala b/stage1/Stage1.scala
index 714ed65..85ec0e9 100644
--- a/stage1/Stage1.scala
+++ b/stage1/Stage1.scala
@@ -42,7 +42,8 @@ class Stage2Args(
val stage2LastModified: Long,
val cache: File,
val cbtHome: File,
- val compatibilityTarget: File
+ val compatibilityTarget: File,
+ val stage2sourceFiles: Seq[File]
)(
implicit val transientCache: java.util.Map[AnyRef,AnyRef], val classLoaderCache: ClassLoaderCache, val logger: Logger
){
@@ -57,7 +58,7 @@ object Stage1{
def getBuild( _context: java.lang.Object, buildStage1: BuildStage1Result ) = {
val context = _context.asInstanceOf[Context]
val logger = new Logger( context.enabledLoggers, buildStage1.start )
- val (cbtLastModified, classLoader) = buildStage2(
+ val (_, cbtLastModified, classLoader) = buildStage2(
buildStage1,
context.cbtHome,
context.cache
@@ -76,7 +77,9 @@ object Stage1{
def buildStage2(
buildStage1: BuildStage1Result, cbtHome: File, cache: File
- )(implicit transientCache: java.util.Map[AnyRef,AnyRef], classLoaderCache: ClassLoaderCache, logger: Logger): (Long, ClassLoader) = {
+ )(
+ implicit transientCache: java.util.Map[AnyRef,AnyRef], classLoaderCache: ClassLoaderCache, logger: Logger
+ ): (Seq[File], Long, ClassLoader) = {
import buildStage1._
@@ -149,7 +152,7 @@ object Stage1{
)
}
- ( stage2LastModified, stage2ClassLoader )
+ ( stage2sourceFiles, stage2LastModified, stage2ClassLoader )
}
def run(
@@ -166,7 +169,7 @@ object Stage1{
implicit val transientCache: java.util.Map[AnyRef,AnyRef] = new java.util.HashMap
implicit val classLoaderCache = new ClassLoaderCache( persistentCache )
- val (stage2LastModified, classLoader) = buildStage2( buildStage1, cbtHome, cache )
+ val (stage2sourceFiles, stage2LastModified, classLoader) = buildStage2( buildStage1, cbtHome, cache )
val stage2Args = new Stage2Args(
new File( args.args(0) ),
@@ -175,7 +178,8 @@ object Stage1{
stage2LastModified = stage2LastModified,
cache,
cbtHome,
- new File(buildStage1.compatibilityClasspath)
+ new File(buildStage1.compatibilityClasspath),
+ stage2sourceFiles
)
logger.stage1(s"Run Stage2")
@@ -193,7 +197,7 @@ object Stage1{
case _ => ExitCode.Success
}
).integer
- logger.stage1(s"Stage1 end")
+ logger.stage1(s"Stage1 end with exit code " + exitCode)
return exitCode;
}
}
diff --git a/stage1/Stage1Lib.scala b/stage1/Stage1Lib.scala
index 01115d4..f701c72 100644
--- a/stage1/Stage1Lib.scala
+++ b/stage1/Stage1Lib.scala
@@ -349,20 +349,22 @@ ${sourceFiles.sorted.mkString(" \\\n")}
res
}
- def trapExitCode( code: => ExitCode ): ExitCode = {
+ def trapExitCodeOrValue[T]( result: => T ): Either[ExitCode,T] = {
val trapExitCodeBefore = TrapSecurityManager.trapExitCode().get
try{
TrapSecurityManager.trapExitCode().set(true)
- code
+ Right( result )
} catch {
case CatchTrappedExitCode(exitCode) =>
logger.stage1(s"caught exit code $exitCode")
- exitCode
+ Left( exitCode )
} finally {
TrapSecurityManager.trapExitCode().set(trapExitCodeBefore)
}
}
+ def trapExitCode( code: => ExitCode ): ExitCode = trapExitCodeOrValue(code).merge
+
def ScalaDependency(
groupId: String, artifactId: String, version: String, classifier: Classifier = Classifier.none,
scalaMajorVersion: String, verifyHash: Boolean = true
diff --git a/stage1/cbt.scala b/stage1/cbt.scala
index 062e11d..05737d0 100644
--- a/stage1/cbt.scala
+++ b/stage1/cbt.scala
@@ -87,9 +87,9 @@ object `package`{
implicit class BuildInterfaceExtensions(build: BuildInterface){
import build._
// TODO: if every build has a method triggers a callback if files change
- // then we wouldn't need this and could provide this method from a
+ // then we wouldn't need this and could provide this method from a
// plugin rather than hard-coding trigger files stuff in cbt
- def triggerLoopFiles: Seq[File] = triggerLoopFilesArray.to
+ def triggerLoopFiles: Set[File] = triggerLoopFilesArray.to
}
implicit class ArtifactInfoExtensions(subject: ArtifactInfo){
import subject._
@@ -121,6 +121,9 @@ object `package`{
def scalaVersion = Option(scalaVersionOrNull)
def parentBuild = Option(parentBuildOrNull)
def cbtLastModified: scala.Long = subject.cbtLastModified
+ def triggerLoopFiles: Set[File] = triggerLoopFilesArray.toSet[File]
+
+ private[cbt] def loopFile = cwd / "target/.cbt-loop.tmp"
def copy(
workingDirectory: File = workingDirectory,
@@ -129,7 +132,8 @@ object `package`{
cbtLastModified: Long = cbtLastModified,
scalaVersion: Option[String] = scalaVersion,
cbtHome: File = cbtHome,
- parentBuild: Option[BuildInterface] = None
+ parentBuild: Option[BuildInterface] = None,
+ triggerLoopFiles: Set[File] = Set()
): Context = new ContextImplementation(
workingDirectory,
cwd,
@@ -144,7 +148,8 @@ object `package`{
cbtHome,
cbtRootHome,
compatibilityTarget,
- parentBuild.getOrElse(null)
+ parentBuild.getOrElse(null),
+ (triggerLoopFiles ++ triggerLoopFilesArray.toSet[File]).toArray
)
}
}