From b97de940a564b8456c60718ab24a3c3c548b3de2 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Sat, 22 Feb 2020 04:45:34 -0500 Subject: [PATCH] Make val loading order top-to-bottom Fixes #2232 Within `build.sbt` this makes sure that definitions are ordered from top to bottom. This matters when multiple subprojects refer to the same setting (probably not a good practice). --- .../src/main/scala/sbt/compiler/Eval.scala | 4 +-- sbt/src/sbt-test/project/val-order/build.sbt | 36 +++++++++++++++++++ sbt/src/sbt-test/project/val-order/test | 1 + 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 sbt/src/sbt-test/project/val-order/build.sbt create mode 100644 sbt/src/sbt-test/project/val-order/test diff --git a/main-actions/src/main/scala/sbt/compiler/Eval.scala b/main-actions/src/main/scala/sbt/compiler/Eval.scala index f1d408af0..461a8c727 100644 --- a/main-actions/src/main/scala/sbt/compiler/Eval.scala +++ b/main-actions/src/main/scala/sbt/compiler/Eval.scala @@ -161,8 +161,8 @@ final class Eval( case None => "" } } - val i = evalCommon(definitions.map(_._1), imports, Some(""), ev) - new EvalDefinitions(i.loader, i.generated, i.enclosingModule, i.extra) + val i: EvalIntermediate[Seq[String]] = evalCommon(definitions.map(_._1), imports, Some(""), ev) + new EvalDefinitions(i.loader, i.generated, i.enclosingModule, i.extra.reverse) } private[this] def evalCommon[T]( diff --git a/sbt/src/sbt-test/project/val-order/build.sbt b/sbt/src/sbt-test/project/val-order/build.sbt new file mode 100644 index 000000000..d34d36cdc --- /dev/null +++ b/sbt/src/sbt-test/project/val-order/build.sbt @@ -0,0 +1,36 @@ +ThisBuild / scalaVersion := "2.13.1" +ThisBuild / version := "0.1.0-SNAPSHOT" + +lazy val check = taskKey[Unit]("") +lazy val intTask = taskKey[Int]("int task") + +lazy val root = (project in file(".")) + .settings( + name := "val-ordering-test", + ThisBuild / organization := "root", + check := { + val o = (ThisBuild / organization).value + assert(o == "root.api.database.web", s"$o") + val x = (api / intTask).value + assert(x == 1, x.toString) + + }, + ) + +lazy val api = project + .settings( + intTask := 0, + ThisBuild / organization := (ThisBuild / organization).value + ".api", + ) + +lazy val database = project + .settings( + ThisBuild / organization := (ThisBuild / organization).value + ".database", + ) + +lazy val web = project + .dependsOn(api, database) + .settings( + api / intTask := 1, + ThisBuild / organization := (ThisBuild / organization).value + ".web", + ) diff --git a/sbt/src/sbt-test/project/val-order/test b/sbt/src/sbt-test/project/val-order/test new file mode 100644 index 000000000..15675b169 --- /dev/null +++ b/sbt/src/sbt-test/project/val-order/test @@ -0,0 +1 @@ +> check