Skip to content

Commit

Permalink
Fix checkTargets
Browse files Browse the repository at this point in the history
  • Loading branch information
adpi2 committed Mar 25, 2024
1 parent b921230 commit 627bd6b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 27 deletions.
25 changes: 0 additions & 25 deletions main/src/main/scala/sbt/ProjectExtra.scala
Original file line number Diff line number Diff line change
Expand Up @@ -357,31 +357,6 @@ trait ProjectExtra extends Scoped.Syntax:
def setCond[T](key: AttributeKey[T], vopt: Option[T], attributes: AttributeMap): AttributeMap =
attributes.setCond(key, vopt)

private[sbt] def checkTargets(data: Settings[Scope]): Option[String] =
val dups = overlappingTargets(allTargets(data))
if (dups.isEmpty) None
else {
val dupStrs = dups map { case (dir, scopes) =>
s"${dir.getAbsolutePath}:\n\t${scopes.mkString("\n\t")}"
}
Some(s"Overlapping output directories:${dupStrs.mkString}")
}

private[this] def overlappingTargets(
targets: Seq[(ProjectRef, File)]
): Map[File, Seq[ProjectRef]] =
targets.groupBy(_._2).view.filter(_._2.size > 1).mapValues(_.map(_._1)).toMap

private[this] def allTargets(data: Settings[Scope]): Seq[(ProjectRef, File)] = {
import ScopeFilter._
val allProjects = ScopeFilter(Make.inAnyProject)
val targetAndRef = Def.setting { (Keys.thisProjectRef.value, Keys.target.value) }
new SettingKeyAll(Def.optional(targetAndRef)(identity))
.all(allProjects)
.evaluate(data)
.flatMap(x => x)
}

private[sbt] def equalKeys(a: ScopedKey[_], b: ScopedKey[_], mask: ScopeMask): Boolean =
a.key == b.key && Scope.equal(a.scope, b.scope, mask)

Expand Down
26 changes: 24 additions & 2 deletions main/src/main/scala/sbt/internal/Load.scala
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,7 @@ private[sbt] object Load {
)
}

// todo: fix this
// Project.checkTargets(data) foreach sys.error
checkTargets(data).foreach(sys.error)
val index = timed("Load.apply: structureIndex", log) {
structureIndex(data, settings, loaded.extra(data), projects)
}
Expand All @@ -304,6 +303,29 @@ private[sbt] object Load {
(rootEval, bs)
}

private def checkTargets(data: Settings[Scope]): Option[String] =
val dups = overlappingTargets(allTargets(data))
if (dups.isEmpty) None
else {
val dupStr = dups.map { case (dir, scopes) =>
s"${dir.getAbsolutePath}:\n\t${scopes.mkString("\n\t")}"
}.mkString
Some(s"Overlapping output directories:$dupStr")
}

private def overlappingTargets(targets: Seq[(ProjectRef, File)]): Map[File, Seq[ProjectRef]] =
targets.groupBy(_._2).view.filter(_._2.size > 1).mapValues(_.map(_._1)).toMap

private def allTargets(data: Settings[Scope]): Seq[(ProjectRef, File)] = {
import ScopeFilter._
val allProjects = ScopeFilter(Make.inAnyProject)
val targetAndRef = Def.setting { (Keys.thisProjectRef.value, Keys.target.value) }
new SettingKeyAll(Def.optional(targetAndRef)(identity))
.all(allProjects)
.evaluate(data)
.flatMap(x => x)
}

// map dependencies on the special tasks:
// 1. the scope of 'streams' is the same as the defining key and has the task axis set to the defining key
// 2. the defining key is stored on constructed tasks: used for error reporting among other things
Expand Down

0 comments on commit 627bd6b

Please sign in to comment.