Skip to content

Commit

Permalink
fix: Fix common settings loading when root is synthetic
Browse files Browse the repository at this point in the history
**Problem**
The new common settings feature doesn't work when the root isn't created by the user.

**Solution**
This fixes common settings by calling `expandCommonSettingsPerBase(...)` on
the synthetic root's base first.
  • Loading branch information
eed3si9n committed Sep 22, 2024
1 parent 864da87 commit 354dd25
Show file tree
Hide file tree
Showing 13 changed files with 275 additions and 206 deletions.
350 changes: 186 additions & 164 deletions main/src/main/scala/sbt/internal/Load.scala

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
scalaVersion := "2.12.19"
name := "root"

lazy val core = project
.settings(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
ThisBuild / organization := "com.example"
ThisBuild / ivyPaths := IvyPaths((ThisBuild / baseDirectory).value.toString, Some(((ThisBuild / baseDirectory).value / "ivy" / "cache").toString))
organization := "com.example"
ivyPaths := IvyPaths((ThisBuild / baseDirectory).value.toString, Some(((ThisBuild / baseDirectory).value / "ivy" / "cache").toString))

name := "root"

lazy val core = project
.settings(
name := "core",
// organization := "com.example",
ivyPaths := IvyPaths((ThisBuild / baseDirectory).value.toString, Some(((ThisBuild / baseDirectory).value / "ivy" / "cache").toString))
)
16 changes: 7 additions & 9 deletions sbt-app/src/sbt-test/project-matrix/custom/build.sbt
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
ThisBuild / organization := "com.example"
ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / publishMavenStyle := true

ThisBuild / ivyPaths := {
val base = (ThisBuild / baseDirectory).value
IvyPaths(base.toString, s"$base/ivy-cache")
organization := "com.example"
version := "0.1.0-SNAPSHOT"
publishMavenStyle := true
ivyPaths := {
val base = baseDirectory.value
val thisBuildBase = (ThisBuild / baseDirectory).value
IvyPaths(base.toString, s"$thisBuildBase/ivy-cache")
}
publish / skip := true

lazy val config12 = ConfigAxis("Config1_2", "config1.2")
lazy val config13 = ConfigAxis("Config1_3", "config1.3")
Expand All @@ -21,7 +20,6 @@ lazy val app = (projectMatrix in file("app"))
.dependsOn(core)
.settings(
name := "app",
ivyPaths := (ThisBuild / ivyPaths).value
)
.customRow(
scalaVersions = Seq(scala212, scala211),
Expand Down
16 changes: 7 additions & 9 deletions sbt-app/src/sbt-test/project-matrix/java/build.sbt
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
ThisBuild / organization := "com.example"
ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / publishMavenStyle := true

ThisBuild / ivyPaths := {
val base = (ThisBuild / baseDirectory).value
IvyPaths(base.toString, s"$base/ivy-cache")
organization := "com.example"
version := "0.1.0-SNAPSHOT"
publishMavenStyle := true
ivyPaths := {
val base = baseDirectory.value
val thisBuildBase = (ThisBuild / baseDirectory).value
IvyPaths(base.toString, s"$thisBuildBase/ivy-cache")
}
publish / skip := true

lazy val config12 = ConfigAxis("Config1_2", "-config1.2")
lazy val config13 = ConfigAxis("Config1_3", "-config1.3")
Expand All @@ -16,7 +15,6 @@ lazy val scala212 = "2.12.10"
lazy val app = (projectMatrix in file("app"))
.settings(
name := "app",
ivyPaths := (ThisBuild / ivyPaths).value
)
.customRow(
scalaVersions = Seq(scala212),
Expand Down
13 changes: 0 additions & 13 deletions sbt-app/src/sbt-test/project/bare-settings/build.sbt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
organization := "com.example.baz"
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
lazy val check = taskKey[Unit]("")

def scala212 = "2.12.19"
scalaVersion := scala212
val o = "com.example"
organization := o

lazy val foo = project
lazy val bar = project
.settings(
name := "bar",
organization := "com.example.bar",
)

lazy val baz = project

check := {
assert((foo / scalaVersion).value == scala212)
assert((bar / scalaVersion).value == scala212)
assert((baz / scalaVersion).value == scala212)

assert((foo / organization).value == o)
// Test that bar can override common setting in settings(...)
assert((bar / organization).value == "com.example.bar", s"unexpected bar / organization = {(bar / organization).value}")
// Test that baz/build.sbt bare settings get loaded
assert((baz / organization).value == "com.example.baz", s"unexpected baz/organization")
}
check / aggregate := false
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
> check
1 change: 1 addition & 0 deletions sbt-app/src/sbt-test/project/common-settings/baz/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
organization := "com.example.baz"
33 changes: 33 additions & 0 deletions sbt-app/src/sbt-test/project/common-settings/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
lazy val check = taskKey[Unit]("")

def scala212 = "2.12.19"
scalaVersion := scala212
val o = "com.example"
organization := o

lazy val root = (project in file("."))
.aggregate(foo, bar, baz)

lazy val foo = project
lazy val bar = project
.settings(
name := "bar",
organization := "com.example.bar",
)

lazy val baz = project

check := {
assert((root / scalaVersion).value == scala212)
assert((foo / scalaVersion).value == scala212)
assert((bar / scalaVersion).value == scala212)
assert((baz / scalaVersion).value == scala212)

assert((root / organization).value == o)
assert((foo / organization).value == o)
// Test that bar can override common setting in settings(...)
assert((bar / organization).value == "com.example.bar")
// Test that baz/build.sbt bare settings get loaded
assert((baz / organization).value == "com.example.baz")
}
check / aggregate := false
1 change: 1 addition & 0 deletions sbt-app/src/sbt-test/project/common-settings/test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
> check
14 changes: 8 additions & 6 deletions sbt-app/src/sbt-test/reporter/nowarn/build.sbt
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
ThisBuild / scalaVersion := "2.12.17"
scalaVersion := "2.12.19"

lazy val sub1 = project

lazy val sub2 = project

val assertNoWarning = taskKey[Unit]("checks warning *is not* emitted")

val assertWarning = taskKey[Unit]("checks warning *is* emitted")

lazy val root = (project in file("."))
.aggregate(sub1, sub2)
.settings(
assertWarning := check(true).value,
assertNoWarning := check(false).value,
)

def check(expectation: Boolean) = Def.task[Unit] {
val lastLog: File = BuiltinCommands.lastLogFile(state.value).get
val last: String = IO.read(lastLog)
Expand All @@ -20,7 +26,3 @@ def check(expectation: Boolean) = Def.task[Unit] {
IO.write(lastLog, "") // clear the backing log for for 'last'.
}
}

assertWarning := check(true).value

assertNoWarning := check(false).value

0 comments on commit 354dd25

Please sign in to comment.