mirror of https://github.com/sbt/sbt.git
support delegating to a project with different configurations
This commit is contained in:
parent
673f9923ab
commit
399dd8ec48
|
|
@ -59,7 +59,7 @@ object Load
|
|||
case BuildRef(uri) => configInheritRef(lb, ProjectRef(uri, rootProject(uri)), config)
|
||||
}
|
||||
def configInheritRef(lb: LoadedBuild, ref: ProjectRef, config: ConfigKey): Seq[ConfigKey] =
|
||||
getConfiguration(lb.units, ref.build, ref.project, config).extendsConfigs.map(c => ConfigKey(c.name))
|
||||
configurationOpt(lb.units, ref.build, ref.project, config).toList.flatMap(_.extendsConfigs).map(c => ConfigKey(c.name))
|
||||
|
||||
def projectInherit(lb: LoadedBuild, ref: ResolvedReference): Seq[ProjectRef] =
|
||||
ref match
|
||||
|
|
@ -282,7 +282,9 @@ object Load
|
|||
def getRootProject(map: Map[URI, BuildUnitBase]): URI => String =
|
||||
uri => getBuild(map, uri).rootProjects.headOption getOrElse emptyBuild(uri)
|
||||
def getConfiguration(map: Map[URI, LoadedBuildUnit], uri: URI, id: String, conf: ConfigKey): Configuration =
|
||||
getProject(map, uri, id).configurations.find(_.name == conf.name) getOrElse noConfiguration(uri, id, conf.name)
|
||||
configurationOpt(map, uri, id, conf) getOrElse noConfiguration(uri, id, conf.name)
|
||||
def configurationOpt(map: Map[URI, LoadedBuildUnit], uri: URI, id: String, conf: ConfigKey): Option[Configuration] =
|
||||
getProject(map, uri, id).configurations.find(_.name == conf.name)
|
||||
|
||||
def getProject(map: Map[URI, LoadedBuildUnit], uri: URI, id: String): ResolvedProject =
|
||||
getBuild(map, uri).defined.getOrElse(id, noProject(uri, id))
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
import sbt._
|
||||
import complete.DefaultParsers._
|
||||
import Keys._
|
||||
|
||||
object B extends Build
|
||||
{
|
||||
// This configuration is added to 'sub' only.
|
||||
// This verifies that delegation works when a configuration is not defined in the project that is being delegated to
|
||||
val newConfig = config("sample")
|
||||
|
||||
val sample = SettingKey[Int]("sample")
|
||||
val check = TaskKey[Unit]("check")
|
||||
|
||||
lazy val projects = Seq(root, sub)
|
||||
lazy val root = Project("root", file("."), settings = Nil)
|
||||
lazy val sub = Project("sub", file("."), delegates = root :: Nil, configurations = newConfig :: Nil, settings = incSample :: checkTask(4) :: Nil)
|
||||
override lazy val settings =
|
||||
(sample in newConfig := 3) ::
|
||||
checkTask(3) ::
|
||||
Nil
|
||||
|
||||
def incSample = sample <<= sample in newConfig apply (_ + 1)
|
||||
def checkTask(expected: Int) = check <<= sample in newConfig map ( i => assert(i == expected, "Expected " + expected + ", got " + i ) )
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
-> root/sample
|
||||
> sub/sample
|
||||
|
||||
-> root/*:sample
|
||||
> sub/*:sample
|
||||
|
||||
> root/*:check
|
||||
> root/check
|
||||
|
||||
> sub/*:check
|
||||
> sub/check
|
||||
|
|
@ -8,7 +8,7 @@ object B extends Build
|
|||
|
||||
lazy val projects = Seq(root, sub)
|
||||
lazy val root = Project("root", file("."))
|
||||
lazy val sub = Project("sub", file(".")) delegates(root) settings(check <<= checkTask)
|
||||
lazy val sub = Project("sub", file(".")) delegateTo(root) settings(check <<= checkTask)
|
||||
|
||||
lazy val checkTask = InputTask(_ => Space ~> NatBasic) { result =>
|
||||
(result, maxErrors) map { (i, max) =>
|
||||
|
|
|
|||
Loading…
Reference in New Issue