diff options
author | Christopher Vogt <oss.nsp@cvogt.org> | 2016-11-07 02:21:50 -0500 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2016-11-07 02:21:50 -0500 |
commit | c6b9a480879c101028b20b9cc8716b8ffa773630 (patch) | |
tree | fff15c1d6595455f6994f5793b63b08c5bf24d4a /stage2/Stage2.scala | |
parent | c89f87c9c9a0c7b256f225e37c55cb34f060aa6c (diff) | |
parent | fd849d293448d55c6bcb6f8440f44838b51fc860 (diff) | |
download | cbt-c6b9a480879c101028b20b9cc8716b8ffa773630.tar.gz cbt-c6b9a480879c101028b20b9cc8716b8ffa773630.tar.bz2 cbt-c6b9a480879c101028b20b9cc8716b8ffa773630.zip |
Merge remote-tracking branch 'origin/master' into integrate-eval
Diffstat (limited to 'stage2/Stage2.scala')
-rw-r--r-- | stage2/Stage2.scala | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/stage2/Stage2.scala b/stage2/Stage2.scala new file mode 100644 index 0000000..3d5c244 --- /dev/null +++ b/stage2/Stage2.scala @@ -0,0 +1,90 @@ +package cbt +import java.io._ + +object Stage2 extends Stage2Base{ + def getBuild(__context: java.lang.Object, _cbtChanged: java.lang.Boolean) = { + val _context = __context.asInstanceOf[Context] + val context = _context.copy( + cbtHasChanged = _context.cbtHasChanged || _cbtChanged + ) + val first = new Lib(context.logger).loadRoot( context ) + first.finalBuild + } + + def run( args: Stage2Args ): Unit = { + import args.logger + val paths = CbtPaths(args.cbtHome,args.cache) + import paths._ + val lib = new Lib(args.logger) + + logger.stage2(s"Stage2 start") + val loop = args.args.lift(0) == Some("loop") + val direct = args.args.lift(0) == Some("direct") + val cross = args.args.lift(0) == Some("cross") + + val taskIndex = if (loop || direct || cross) { + 1 + } else { + 0 + } + val task = args.args.lift( taskIndex ) + + val context: Context = ContextImplementation( + args.cwd, + args.cwd, + args.args.drop( taskIndex +1 ).toArray, + logger.enabledLoggers.toArray, + logger.start, + args.cbtHasChanged, + null, + null, + args.permanentKeys, + args.permanentClassLoaders, + args.cache, + args.cbtHome, + args.cbtHome, + args.compatibilityTarget, + null + ) + val first = lib.loadRoot( context ) + val build = first.finalBuild + + def call(build: BuildInterface): ExitCode = { + if(cross){ + build.crossScalaVersions.map{ + v => new lib.ReflectBuild( + build.copy(context.copy(scalaVersion = Some(v))) + ).callNullary(task) + }.filter(_ != ExitCode.Success).headOption getOrElse ExitCode.Success + } else { + new lib.ReflectBuild(build).callNullary(task) + } + } + + 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 _) + val allTriggerFiles = triggerFiles ++ triggerCbtFiles + + logger.loop("Looping change detection over:\n - "++allTriggerFiles.mkString("\n - ")) + + lib.watch(allTriggerFiles){ + case file if triggerCbtFiles.exists(file.toString startsWith _.toString) => + 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) => + val build = lib.loadDynamic(context) + logger.loop(s"Re-running $task for " ++ build.show) + call(build) + } + } else { + val code = call(build) + logger.stage2(s"Stage2 end") + System.exit(code.integer) + } + } +} |