mirror of https://github.com/sbt/sbt.git
[2.x] fix: Undefined per-project settings order (#8953)
Closes #7173 Co-authored-by: Daniil Sivak <seroperson@gmail.com>
This commit is contained in:
parent
2d375097e4
commit
b4ee7ffc52
|
|
@ -427,7 +427,14 @@ private[sbt] object Load {
|
||||||
inScope(GlobalScope)(loaded.autos.globalSettings) ++
|
inScope(GlobalScope)(loaded.autos.globalSettings) ++
|
||||||
loaded.units.toSeq.flatMap { (uri, build) =>
|
loaded.units.toSeq.flatMap { (uri, build) =>
|
||||||
val pluginBuildSettings = loaded.autos.buildSettings(uri)
|
val pluginBuildSettings = loaded.autos.buildSettings(uri)
|
||||||
val projectSettings = build.defined flatMap { (id, project) =>
|
// Collect transformed settings per project and split them into "own-scope" and "cross-project":
|
||||||
|
// "own-scope" - key's project axis is `ref` itself (or global)
|
||||||
|
// "cross-project" - key explicitly targets a different project (`otherProj / key += ...`)
|
||||||
|
//
|
||||||
|
// It's necessary so that global defaults always precedes any other project's append
|
||||||
|
// See https://github.com/sbt/sbt/issues/7173
|
||||||
|
val (ownSettingsSeqs, crossSettingsSeqs) =
|
||||||
|
build.defined.toSeq.map { (id, project) =>
|
||||||
val ref = ProjectRef(uri, id)
|
val ref = ProjectRef(uri, id)
|
||||||
val defineConfig: Seq[Setting[?]] =
|
val defineConfig: Seq[Setting[?]] =
|
||||||
for (c <- project.configurations)
|
for (c <- project.configurations)
|
||||||
|
|
@ -436,8 +443,15 @@ private[sbt] object Load {
|
||||||
(thisProject :== project) +: (thisProjectRef :== ref) +: defineConfig
|
(thisProject :== project) +: (thisProjectRef :== ref) +: defineConfig
|
||||||
val settings = builtin ++ injectSettings.project ++ project.settings
|
val settings = builtin ++ injectSettings.project ++ project.settings
|
||||||
// map This to thisScope, Select(p) to mapRef(uri, rootProject, p)
|
// map This to thisScope, Select(p) to mapRef(uri, rootProject, p)
|
||||||
transformSettings(projectScope(ref), uri, rootProject, settings)
|
val transformed = transformSettings(projectScope(ref), uri, rootProject, settings)
|
||||||
|
transformed.partition { s =>
|
||||||
|
s.key.scope.project match {
|
||||||
|
case Select(r) => r == ref
|
||||||
|
case _ => true // global scope
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}.unzip
|
||||||
|
val projectSettings = (ownSettingsSeqs ++ crossSettingsSeqs).flatten
|
||||||
val buildScope = Scope(Select(BuildRef(uri)), Zero, Zero, Zero)
|
val buildScope = Scope(Select(BuildRef(uri)), Zero, Zero, Zero)
|
||||||
val buildBase = baseDirectory :== build.localBase
|
val buildBase = baseDirectory :== build.localBase
|
||||||
val settings3 = pluginBuildSettings ++ (buildBase +: build.buildSettings)
|
val settings3 = pluginBuildSettings ++ (buildBase +: build.buildSettings)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
val check = taskKey[Unit]("Verify cross-project source generator is applied")
|
||||||
|
|
||||||
|
lazy val foo = project
|
||||||
|
.in(file("foo"))
|
||||||
|
.settings(
|
||||||
|
check := Def.uncached {
|
||||||
|
val gens = (Compile / sourceGenerators).value
|
||||||
|
assert(
|
||||||
|
gens.nonEmpty,
|
||||||
|
s"#7173: `foo / Compile / sourceGenerators` should contain the generator registered by fooAux"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
lazy val fooAux = project
|
||||||
|
.in(file("foo-aux"))
|
||||||
|
.settings(
|
||||||
|
foo / Compile / sourceGenerators += Def.task(Seq.empty[File])
|
||||||
|
)
|
||||||
|
|
||||||
|
lazy val bar = project
|
||||||
|
|
||||||
|
// Fails:
|
||||||
|
lazy val baz = project
|
||||||
|
|
||||||
|
// Succeeds without i7173 edits:
|
||||||
|
// lazy val ewikqelkqweqopweo = project
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
# Adding an unrelated project (baz) should not prevent foo / Compile / sourceGenerators
|
||||||
|
# from including the generator registered by fooAux.
|
||||||
|
> foo/check
|
||||||
Loading…
Reference in New Issue