From 0972023722e8f6a59002d2d78defb7c5dec0240f Mon Sep 17 00:00:00 2001 From: Christopher Vogt Date: Wed, 22 Feb 2017 17:02:13 +0800 Subject: treat subdirectores as subbuilds via cmd line --- stage2/BasicBuild.scala | 5 +++-- stage2/Lib.scala | 25 +++++++++++++++++++------ stage2/Stage2.scala | 4 ++-- stage2/ToolsStage2.scala | 2 +- 4 files changed, 25 insertions(+), 11 deletions(-) (limited to 'stage2') diff --git a/stage2/BasicBuild.scala b/stage2/BasicBuild.scala index 5c49395..e3b1c1b 100644 --- a/stage2/BasicBuild.scala +++ b/stage2/BasicBuild.scala @@ -189,7 +189,8 @@ trait BaseBuild extends BuildInterface with DependencyImplementation with Trigge def test: Any = lib.callReflective( DirectoryDependency(projectDirectory++"/test").dependency, - Some("run") + Some("run"), + context ) def t = test @@ -229,7 +230,7 @@ trait BaseBuild extends BuildInterface with DependencyImplementation with Trigge System.err.println(b.show) lib.trapExitCode{ // FIXME: trapExitCode does not seem to work here try{ - lib.callReflective(b,code) + lib.callReflective(b,code,context) ExitCode.Success } catch { case e: Throwable => println(e.getClass); throw e diff --git a/stage2/Lib.scala b/stage2/Lib.scala index d6047f9..700f18d 100644 --- a/stage2/Lib.scala +++ b/stage2/Lib.scala @@ -154,8 +154,8 @@ final class Lib(val logger: Logger) extends Stage1Lib(logger){ ) ++ "\n" } - def callReflective[T <: AnyRef]( obj: T, code: Option[String] ): ExitCode = { - callInternal( obj, code.toSeq.flatMap(_.split("\\.").map( NameTransformer.encode )), Nil ) match { + def callReflective[T <: AnyRef]( obj: T, code: Option[String], context: Context ): ExitCode = { + callInternal( obj, code.toSeq.flatMap(_.split("\\.").map( NameTransformer.encode )), Nil, context ) match { case (obj, code, None) => val s = render(obj) if(s.nonEmpty) @@ -182,7 +182,7 @@ final class Lib(val logger: Logger) extends Stage1Lib(logger){ } } - private def callInternal[T <: AnyRef]( obj: T, members: Seq[String], previous: Seq[String] ): (Option[Object], Option[ExitCode], Option[String]) = { + private def callInternal[T <: AnyRef]( obj: T, members: Seq[String], previous: Seq[String], context: Context ): (Option[Object], Option[ExitCode], Option[String]) = { members.headOption.map{ taskName => logger.lib("Calling task " ++ taskName.toString) taskMethods(obj.getClass).get(taskName).map{ method => @@ -192,12 +192,25 @@ final class Lib(val logger: Logger) extends Stage1Lib(logger){ // FIXME: ExitCode needs to be part of the compatibility interfaces (None, Some(ExitCode(Stage0Lib.get(code,"integer").asInstanceOf[Int])), None) case Seq(bs @ _*) if bs.forall(_.isInstanceOf[BaseBuild]) => - bs.map( b => callInternal(b.asInstanceOf[BaseBuild], members.tail, previous :+ taskName) ).head - case _ => callInternal(result, members.tail, previous :+ taskName) + bs.map( b => callInternal(b.asInstanceOf[BaseBuild], members.tail, previous :+ taskName, context) ).head + case _ => callInternal(result, members.tail, previous :+ taskName, context) } }.getOrElse( (None, None, None) ) }.getOrElse{ - ( Some(obj), None, Some("\nMethod not found: " ++ (previous :+ taskName).mkString(".") ++ "\n") ) + val folder = NameTransformer.decode(taskName) + if( context != null && (context.workingDirectory / folder).exists ){ + val newContext = context.copy( workingDirectory = context.workingDirectory / folder ) + callInternal( + lib.loadRoot( + newContext + ).finalBuild, + members.tail, + previous, + newContext + ) + } else { + ( Some(obj), None, Some("\nMethod not found: " ++ (previous :+ taskName).mkString(".") ++ "\n") ) + } } }.getOrElse{ ( Some(obj), None, None ) diff --git a/stage2/Stage2.scala b/stage2/Stage2.scala index 7ac7a2a..d43c4f6 100644 --- a/stage2/Stage2.scala +++ b/stage2/Stage2.scala @@ -59,11 +59,11 @@ object Stage2 extends Stage2Base{ case file if triggerFiles.exists(file.toString startsWith _.toString) => val build = lib.loadRoot(context).finalBuild( context.cwd ) logger.loop(s"Re-running $task for " ++ build.show) - lib.callReflective(build, task) + lib.callReflective(build, task, context) } ExitCode.Success } else { - val code = lib.callReflective(build, task) + val code = lib.callReflective(build, task, context) logger.stage2(s"Stage2 end") code } diff --git a/stage2/ToolsStage2.scala b/stage2/ToolsStage2.scala index c71f2b7..ba7a27f 100644 --- a/stage2/ToolsStage2.scala +++ b/stage2/ToolsStage2.scala @@ -5,6 +5,6 @@ object ToolsStage2 extends Stage2Base{ val args = _args.args.dropWhile(Seq("tools","direct") contains _) val lib = new Lib(_args.logger) val toolsTasks = new ToolsTasks(lib, args, _args.cwd, _args.cache, _args.cbtHome, _args.stage2LastModified)(_args.classLoaderCache) - lib.callReflective(toolsTasks, args.lift(0)) + lib.callReflective(toolsTasks, args.lift(0), null) } } -- cgit v1.2.3