aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--stage1/Stage1.scala2
-rw-r--r--stage1/logger.scala23
-rw-r--r--stage2/Stage2.scala39
3 files changed, 42 insertions, 22 deletions
diff --git a/stage1/Stage1.scala b/stage1/Stage1.scala
index 6c05f00..5391e2d 100644
--- a/stage1/Stage1.scala
+++ b/stage1/Stage1.scala
@@ -14,7 +14,7 @@ object CheckAlive{
}
}
-class Init(args: Array[String]) {
+private[cbt] class Init(args: Array[String]) {
/**
* Raw parameters including their `-D` flag.
**/
diff --git a/stage1/logger.scala b/stage1/logger.scala
index 16bd940..eaf64db 100644
--- a/stage1/logger.scala
+++ b/stage1/logger.scala
@@ -1,15 +1,24 @@
package cbt
+
import java.time._
-// We can replace this with something more sophisticated eventually
-case class Logger(enabledLoggers: Set[String]){
- val start = LocalTime.now()
- //System.err.println("Created Logger("+enabledLoggers+")")
+
+/**
+ * This represents a logger with namespaces that can be enabled or disabled as needed. The
+ * namespaces are defined using {{enabledLoggers}}. Possible values are defined in the subobject
+ * "names".
+ *
+ * We can replace this with something more sophisticated eventually.
+ */
+case class Logger(enabledLoggers: Set[String]) {
def this(enabledLoggers: Option[String]) = this( enabledLoggers.toVector.flatMap( _.split(",") ).toSet )
+
+ val start = LocalTime.now()
+
def log(name: String, msg: => String) = {
val timeTaken = (Duration.between(start, LocalTime.now()).toMillis.toDouble / 1000).toString
- System.err.println( s"[${" "*(6-timeTaken.size)}$timeTaken]["+name+"] " + msg )
+ System.err.println( s"[${" "*(6-timeTaken.size)}$timeTaken][$name] $msg" )
}
-
+
def showInvocation(method: String, args: Any) = method + "( " + args + " )"
final def stage1(msg: => String) = logGuarded(names.stage1, msg)
@@ -38,4 +47,4 @@ case class Logger(enabledLoggers: Set[String]){
log(name, msg)
}
}
-} \ No newline at end of file
+}
diff --git a/stage2/Stage2.scala b/stage2/Stage2.scala
index 44db3ae..f3e833f 100644
--- a/stage2/Stage2.scala
+++ b/stage2/Stage2.scala
@@ -1,30 +1,37 @@
package cbt
-import cbt.paths._
+
import java.io._
+import java.time._
+import java.time.LocalTime.now
+
import scala.collection.immutable.Seq
+import cbt.paths._
+
+
object Stage2{
def main(args: Array[String]) = {
- import java.time.LocalTime.now
val init = new Init(args)
- import java.time._
- val start = LocalTime.now()
- def timeTaken = Duration.between(start, LocalTime.now()).toMillis
- init.logger.stage2(s"[$now] Stage2 start")
-
import init._
+
+ val lib = new Lib(init.logger)
+
+ init.logger.stage2(s"[$now] Stage2 start")
val loop = argsV.lift(1) == Some("loop")
val direct = argsV.lift(1) == Some("direct")
- val taskIndex = if(loop || direct) 2 else 1
- val task = argsV.lift( taskIndex )
- val lib = new Lib(new Init(args).logger)
+ val taskIndex = if (loop || direct) {
+ 2
+ } else {
+ 1
+ }
+ val task = argsV.lift( taskIndex )
val context = Context( cwd, argsV.drop( taskIndex + 1 ), logger )
val first = lib.loadRoot( context )
val build = first.finalBuild
- val res = if( loop ){
+ val res = if (loop) {
// TODO: this should allow looping over task specific files, like test files as well
val triggerFiles = first.triggerLoopFiles.map(lib.realpath)
val triggerCbtFiles = Seq( nailgun, stage1, stage2 ).map(lib.realpath _)
@@ -32,15 +39,19 @@ object Stage2{
logger.loop("Looping change detection over:\n - "+allTriggerFiles.mkString("\n - "))
- lib.watch(allTriggerFiles){
+ lib.watch(allTriggerFiles) {
case file if triggerCbtFiles.exists(file.toString startsWith _.toString) =>
- logger.loop("Change is in CBT' own source code.")
+ logger.loop("Change is in CBT's own source code.")
logger.loop("Restarting CBT.")
scala.util.control.Breaks.break
+
case file if triggerFiles.exists(file.toString startsWith _.toString) =>
new lib.ReflectBuild( lib.loadDynamic(context) ).callNullary(task)
}
- } else new lib.ReflectBuild(build).callNullary(task)
+ } else {
+ new lib.ReflectBuild(build).callNullary(task)
+ }
+
init.logger.stage2(s"[$now] Stage2 end")
res
}