From 765318f78169c2b2041063d1229031abe95ac0d5 Mon Sep 17 00:00:00 2001 From: kyri-petrou <67301607+kyri-petrou@users.noreply.github.com> Date: Tue, 26 Dec 2023 19:44:16 +1100 Subject: [PATCH] Create sbt submodules per scala version (#2057) * Add scala version subprojects to make testing easier * Only compile production code prior to running tests * Add to welcome message * Delete unused code * Use single line for scala versions * Simplify --------- Co-authored-by: Pierre Ricadat --- .circleci/config.yml | 10 +++---- build.sbt | 55 +++++++++++++++++++++++++++++++------ project/ConsoleHelper.scala | 18 ++++++------ 3 files changed, 62 insertions(+), 21 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2e54d5f936..a3076f661e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -23,7 +23,7 @@ jobs: - checkout - restore_cache: key: sbtcache - - run: sbt ++2.12.18 core/test http4s/test akkaHttp/test pekkoHttp/test zioHttp/test quickAdapter/test catsInterop/test tools/test codegenSbt/test clientJVM/test monixInterop/compile tapirInterop/test federation/test reporting/test tracing/test + - run: sbt ++2.12.18 rootJVM212/test - save_cache: key: sbtcache paths: @@ -68,7 +68,7 @@ jobs: - checkout - restore_cache: key: sbtcache - - run: sbt ++2.13.12 core/test http4s/test akkaHttp/test pekkoHttp/test play/test zioHttp/test quickAdapter/test examples/compile catsInterop/test benchmarks/compile monixInterop/compile tapirInterop/test clientJVM/test tools/test federation/test reporting/test tracing/test + - run: sbt ++2.13.12 rootJVM213/test examples/compile benchmarks/compile - save_cache: key: sbtcache paths: @@ -83,7 +83,7 @@ jobs: - checkout - restore_cache: key: sbtcache - - run: sbt ++2.13.12 core/test http4s/test akkaHttp/test pekkoHttp/test play/test zioHttp/test quickAdapter/test examples/compile catsInterop/test benchmarks/compile monixInterop/compile tapirInterop/test clientJVM/test tools/test federation/test reporting/test tracing/test + - run: sbt ++2.13.12 rootJVM213/test examples/compile benchmarks/compile - save_cache: key: sbtcache paths: @@ -98,7 +98,7 @@ jobs: - checkout - restore_cache: key: sbtcache - - run: sbt ++3.3.1 core/test catsInterop/test benchmarks/compile monixInterop/compile clientJVM/test clientJS/compile zioHttp/test quickAdapter/test tapirInterop/test pekkoHttp/test http4s/test play/test federation/test tools/test reporting/test tracing/test + - run: sbt ++3.3.1 rootJVM3/test benchmarks/compile - save_cache: key: sbtcache paths: @@ -113,7 +113,7 @@ jobs: - checkout - restore_cache: key: sbtcache - - run: sbt ++3.3.1 core/test catsInterop/test benchmarks/compile monixInterop/compile clientJVM/test clientJS/compile zioHttp/test quickAdapter/test tapirInterop/test pekkoHttp/test http4s/test play/test federation/test tools/test reporting/test tracing/test + - run: sbt ++3.3.1 rootJVM3/test benchmarks/compile - save_cache: key: sbtcache paths: diff --git a/build.sbt b/build.sbt index 5a60ec5e05..1ee2ecd6c0 100644 --- a/build.sbt +++ b/build.sbt @@ -38,7 +38,7 @@ Global / onChangedBuildSource := ReloadOnSourceChanges inThisBuild( List( - scalaVersion := scala213, // Change to control IntelliJ's highlighting + scalaVersion := scala213, crossScalaVersions := allScala, organization := "com.github.ghostdogpr", homepage := Some(url("https://github.com/ghostdogpr/caliban")), @@ -60,7 +60,7 @@ inThisBuild( ) ), versionScheme := Some("pvp"), - ConsoleHelper.welcomeMessage, + ConsoleHelper.welcomeMessage(scala212, scala213, scala3), // See https://github.com/playframework/playframework/issues/11461#issuecomment-1276028512 // Can be removed when the entire Scala ecosystem has migrated to Scala 2.12.17+, sbt 1.8.x, and moved away from scala-xml v1 in general. libraryDependencySchemes ++= Seq( @@ -76,12 +76,8 @@ addCommandAlias( "all scalafmtSbtCheck scalafmtCheck test:scalafmtCheck" ) -lazy val root = project - .in(file(".")) - .enablePlugins(ScalaJSPlugin) - .settings(publish / skip := true) - .settings(crossScalaVersions := Nil) - .aggregate( +lazy val allProjects: Seq[ProjectReference] = + List( macros, core, http4s, @@ -104,6 +100,49 @@ lazy val root = project tracing ) +lazy val root = project + .in(file(".")) + .enablePlugins(ScalaJSPlugin) + .settings(publish / skip := true) + .settings(crossScalaVersions := Nil) + .aggregate(allProjects *) + +lazy val rootJVM212 = project + .in(file("target/rootJVM212")) + .settings( + crossScalaVersions := Nil, + publish / skip := true, + ideSkipProject := true + ) + .aggregate({ + val excluded: Set[ProjectReference] = Set(clientJS, clientNative, clientLaminext, play) + allProjects.filterNot(excluded.contains) + } *) + +lazy val rootJVM213 = project + .in(file("target/rootJVM213")) + .settings( + crossScalaVersions := Nil, + publish / skip := true, + ideSkipProject := true + ) + .aggregate({ + val excluded: Set[ProjectReference] = Set(clientJS, clientNative, clientLaminext, codegenSbt) + allProjects.filterNot(excluded.contains) + } *) + +lazy val rootJVM3 = project + .in(file("target/rootJVM3")) + .settings( + crossScalaVersions := Nil, + publish / skip := true, + ideSkipProject := true + ) + .aggregate({ + val excluded: Set[ProjectReference] = Set(clientJS, clientNative, clientLaminext, codegenSbt, akkaHttp) + allProjects.filterNot(excluded.contains) + } *) + lazy val macros = project .in(file("macros")) .settings(name := "caliban-macros") diff --git a/project/ConsoleHelper.scala b/project/ConsoleHelper.scala index 9bd7c0bcab..81120db8d0 100644 --- a/project/ConsoleHelper.scala +++ b/project/ConsoleHelper.scala @@ -1,4 +1,4 @@ -import sbt.Keys._ +import sbt.Keys.* object ConsoleHelper { def prompt: String = s"${Console.CYAN}>${Console.RESET} " @@ -7,8 +7,9 @@ object ConsoleHelper { def item(text: String): String = s"${Console.RED}> ${Console.CYAN}$text${Console.RESET}" - def welcomeMessage = - onLoadMessage := + def welcomeMessage(scala212Version: String, scala213Version: String, scala3Version: String) = + onLoadMessage := { + val scalaVersions = s"++$scala212Version; ++$scala213Version; ++$scala3Version" raw"""|${header(s""" ____ _ _ _ """)} |${header(s""" / ___|__ _| (_) |__ __ _ _ __ """)} |${header(s""" | | / _` | | | '_ \\ / _` | '_ \\ """)} @@ -17,12 +18,13 @@ object ConsoleHelper { | |Useful sbt tasks: |${item("~compile")} - Compile all modules with file-watch enabled - |${item("test")} - Run the unit test suite + |${item("+test")} - Run the unit test suite for all modules and Scala versions + |${item(s"++$scala3Version; rootJVM3/test")} - Run tests for all JVM modules in Scala 3 |${item("fmt")} - Run scalafmt on the entire project |${item("scripted")} - Run the scripted test suite - |${item("examples/runMain example.http4s.ExampleApp")} - Start the example server (http4s based) - |${item("examples/runMain example.akkahttp.ExampleApp")} - Start the example server (akka-http based) + |${item("examples/runMain example.quick.ExampleApp")} - Start the example server |${item("benchmarks/jmh:run")} - Run the benchmarks - |${item("+publishLocal")} - Publish caliban locally""".stripMargin - + |${item("+publishLocal")} - Publish caliban locally + |${item(scalaVersions)} - Changing scala versions""".stripMargin + } }