Skip to content

Commit

Permalink
Merge pull request sbt#7519 from adpi2/sbt2-fix-todo
Browse files Browse the repository at this point in the history
[sbt2] Reactivate checkTargets in Load
  • Loading branch information
adpi2 authored Mar 25, 2024
2 parents b921230 + c6ef392 commit 40ba7e9
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 45 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
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,13 @@ def commonSettings: Seq[Def.Setting[_]] =
resolvers += MavenCache("local-maven", (LocalRootProject / target).value / "local-maven"),
)

lazy val root = (project in file("."))
.settings(commonSettings)

val `v1-0-0` = (project in file("v1.0.0"))
val semverSpecTest = project
.settings(commonSettings)
.settings(
name := "semver-spec-test",
version := "1.0.0",
)

val `v1-1-0` = (project in file("v1.1.0"))
.settings(commonSettings)
.settings(
name := "semver-spec-test",
version := "1.1.0",
)

val middle = project
.settings(commonSettings)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
> v1-0-0/publish
> v1-1-0/publish
> semverSpecTest/publish
> set semverSpecTest/version := "1.1.0"
> semverSpecTest/publish
> middle/publish

> use/check
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 40ba7e9

Please sign in to comment.