summaryrefslogtreecommitdiff
path: root/project/build/ExternalTaskRunner.scala
blob: b99af1b003435ff5a3194f0d480bda428fdfb953 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import sbt._
import ExternalTaskRunner._

/**
 * Provide a way to launch a specific task in a new sbt instance.
 * As the compilation process need to be able to compile in a different process (due to memory related
 * performance issue) and that in order to keep incremental compilation, we allow to launch a task from a
 * specific project / sub-project in a different instance of sbt that disappear once the task has finished.
 */
class ExternalTaskRunner(root:Path,projectName:String, taskName :String,errorMessage:String, log: Logger ){

  def runTask:Option[String] ={

    val cmd:Seq[String] = Seq("project "+projectName,taskName) // TODO forward logging level (for example debug)
    val externalSbt = Process(sbtCommand ++ cmd)
    log.info("Launching task ["+taskName+"] of project ["+projectName+"] in new sbt instance")
    externalSbt.! match{
      case 0 => None
      case _ => Some(errorMessage)
    }

  }

}

object ExternalTaskRunner{
  /**
   * parameters needed to launch another instance of sbt
   */
  val sbtCommand = Seq("sbt") // TODO remove dependency on sbt being on the path of the user



}