mirror of https://github.com/sbt/sbt.git
[2.x] fix: Relax non-delegation for settings on shell (#8751)
Allow settings to delegate when the user specifies an explicit scope (config or task axis), so that e.g. Compile/console/fork resolves when console/fork is defined in a delegated scope. Tasks continue to not delegate (getDirect only) so non-existent scopes like Compile/update still fail as in 2.0.0.
This commit is contained in:
parent
02d9d4c699
commit
b634e1b507
|
|
@ -600,14 +600,21 @@ object Act {
|
||||||
keys.flatMap(key => getValue(structure.data, key).map(KeyValue(key, _)))
|
keys.flatMap(key => getValue(structure.data, key).map(KeyValue(key, _)))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starting sbt 2.0.0, we will not delegate when a non-existent scoping
|
* Resolves a key from settings data. Starting sbt 2.0.0 we do not delegate for
|
||||||
* such as Compile / update is required.
|
* tasks when the user specified an explicit scope (config or task axis), so that
|
||||||
|
* non-existent scopes like `Compile / update` fail. Settings may still delegate
|
||||||
|
* so that e.g. `Compile/console/fork` resolves when `console/fork` is defined
|
||||||
|
* in a delegated scope (see #8757).
|
||||||
*/
|
*/
|
||||||
private def getValue[T](data: Def.Settings, key: ScopedKey[T]): Option[T] =
|
private def getValue[T](data: Def.Settings, key: ScopedKey[T]): Option[T] =
|
||||||
if key.scope.config.isSelect ||
|
val scopeExplicit = key.scope.config.isSelect || key.scope.task.isSelect
|
||||||
key.scope.task.isSelect
|
if !scopeExplicit then data.get(key)
|
||||||
then data.getDirect(key)
|
else
|
||||||
else data.get(key)
|
data
|
||||||
|
.getDirect(key)
|
||||||
|
.orElse:
|
||||||
|
if key.key.tag.isSetting then data.get(key)
|
||||||
|
else None
|
||||||
|
|
||||||
def requireSession[T](s: State, p: => Parser[T]): Parser[T] =
|
def requireSession[T](s: State, p: => Parser[T]): Parser[T] =
|
||||||
if s.get(sessionSettings).isEmpty then failure("No project loaded") else p
|
if s.get(sessionSettings).isEmpty then failure("No project loaded") else p
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
scalaVersion := "3.8.1"
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
# Fix #8757: settings may delegate when scope is explicit (tasks still must not).
|
||||||
|
# console/fork is defined in default scope; Compile/console/fork should resolve via delegation.
|
||||||
|
> compile
|
||||||
|
|
||||||
|
# Setting with explicit config scope delegates (e.g. Compile/console/fork -> console/fork)
|
||||||
|
> show Compile/console/fork
|
||||||
Loading…
Reference in New Issue