Intial implementation of CompositeProject

This commit is contained in:
Alistair Johnson 2018-03-31 20:28:09 +02:00
parent fa56cf394b
commit cbb953279c
10 changed files with 51 additions and 7 deletions

View File

@ -119,7 +119,13 @@ sealed trait ProjectDefinition[PR <: ProjectReference] {
if (ts.isEmpty) Nil else s"$label: $ts" :: Nil
}
sealed trait Project extends ProjectDefinition[ProjectReference] {
trait CompositeProject {
def componentProjects: Seq[Project]
}
sealed trait Project extends ProjectDefinition[ProjectReference] with CompositeProject {
def componentProjects: Seq[Project] = this :: Nil
private[sbt] def copy(
id: String = id,
base: File = base,

View File

@ -17,7 +17,8 @@ import sbt.internal.inc.ReflectUtilities
trait BuildDef {
def projectDefinitions(baseDirectory: File): Seq[Project] = projects
def projects: Seq[Project] = ReflectUtilities.allVals[Project](this).values.toSeq
def projects: Seq[Project] =
ReflectUtilities.allVals[CompositeProject](this).values.toSeq.flatMap(_.componentProjects)
// TODO: Should we grab the build core settings here or in a plugin?
def settings: Seq[Setting[_]] = Defaults.buildCore
def buildLoaders: Seq[BuildLoader.Components] = Nil

View File

@ -123,10 +123,10 @@ private[sbt] object EvaluateConfigurations {
// Tracks all the files we generated from evaluating the sbt file.
val allGeneratedFiles = (definitions.generated ++ dslEntries.flatMap(_.generated))
loader => {
val projects =
definitions.values(loader).collect {
case p: Project => resolveBase(file.getParentFile, p)
}
val projects = definitions.values(loader).flatMap {
case p: CompositeProject => p.componentProjects.map(resolveBase(file.getParentFile, _))
case _ => Nil
}
val (settingsRaw, manipulationsRaw) =
dslEntries map (_.result apply loader) partition {
case DslEntry.ProjectSettings(_) => true
@ -234,7 +234,7 @@ private[sbt] object EvaluateConfigurations {
}
private[this] def extractedValTypes: Seq[String] =
Seq(classOf[Project], classOf[InputKey[_]], classOf[TaskKey[_]], classOf[SettingKey[_]]).map(_.getName)
Seq(classOf[CompositeProject], classOf[InputKey[_]], classOf[TaskKey[_]], classOf[SettingKey[_]]).map(_.getName)
private[this] def evaluateDefinitions(eval: Eval, name: String, imports: Seq[(String, Int)], definitions: Seq[(String, LineRange)], file: Option[File]): compiler.EvalDefinitions =
{

View File

@ -0,0 +1 @@
object A

View File

@ -0,0 +1,2 @@
val aa = taskKey[Unit]("A task in the 'a' project")
aa := println("Hello.")

View File

@ -0,0 +1,2 @@
val h = taskKey[Unit]("A task in project 'b'")
h := println("Hello.")

View File

@ -0,0 +1,13 @@
import sbt.internal.AddSettings
import sbt.CompositeProject
// Based on sbt-file-projects test
val cross = new CompositeProject
{
val p1 = Project.apply("a", new File("a"))
val p2 = Project.apply("b", new File("b"))
def componentProjects: Seq[Project] = Seq(p1, p2)
}
val g = taskKey[Unit]("A task in the root project")
g := println("Hello.")

View File

@ -0,0 +1 @@
lazy val root = (project in file("."))

View File

@ -0,0 +1 @@
val c = project

View File

@ -0,0 +1,17 @@
> g
-> root/compile
> a/compile
> a/aa
> b/compile
> b/h
> c/compile
$ copy-file changes/basic.sbt basic.sbt
> reload
> g
> root/compile
> a/compile
> a/aa
> b/compile
> b/h
> c/compile