From 59f924752ed0a05e31170d02ced023eedfbb0872 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 18 Jul 2022 16:55:03 +0100 Subject: [PATCH 1/6] update: twirllib to 2.13, update scala-parser-combinators, use twirl 1.5.1 in test --- contrib/twirllib/src/TwirlModule.scala | 4 ++-- contrib/twirllib/test/src/HelloWorldTests.scala | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/contrib/twirllib/src/TwirlModule.scala b/contrib/twirllib/src/TwirlModule.scala index 83ef77d460c..f3e4e2df178 100644 --- a/contrib/twirllib/src/TwirlModule.scala +++ b/contrib/twirllib/src/TwirlModule.scala @@ -25,10 +25,10 @@ trait TwirlModule extends mill.Module { coursier.LocalRepositories.ivy2Local, MavenRepository("https://repo1.maven.org/maven2") ), - Lib.depToDependency(_, "2.12.5"), + Lib.depToDependency(_, "2.13.8"), Seq( ivy"com.typesafe.play::twirl-compiler:${twirlVersion()}", - ivy"org.scala-lang.modules::scala-parser-combinators:1.1.0" + ivy"org.scala-lang.modules::scala-parser-combinators:2.1.1" ) ) } diff --git a/contrib/twirllib/test/src/HelloWorldTests.scala b/contrib/twirllib/test/src/HelloWorldTests.scala index f24ab25a17c..bea4495c670 100644 --- a/contrib/twirllib/test/src/HelloWorldTests.scala +++ b/contrib/twirllib/test/src/HelloWorldTests.scala @@ -15,7 +15,7 @@ object HelloWorldTests extends TestSuite { trait HelloWorldModule extends mill.twirllib.TwirlModule { - def twirlVersion = "1.3.15" + def twirlVersion = "1.5.1" } @@ -86,7 +86,7 @@ object HelloWorldTests extends TestSuite { eval.apply(HelloWorld.core.twirlVersion) assert( - result == "1.3.15", + result == "1.5.1", evalCount > 0 ) } From 64115ce8ba8c6edcabd09ab602adde01b25ca28d Mon Sep 17 00:00:00 2001 From: James Date: Mon, 18 Jul 2022 16:55:40 +0100 Subject: [PATCH 2/6] docs: twirl 1.3.15 -> 1.5.1 in docs --- docs/antora/modules/ROOT/pages/Plugin_Twirl.adoc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/antora/modules/ROOT/pages/Plugin_Twirl.adoc b/docs/antora/modules/ROOT/pages/Plugin_Twirl.adoc index 0803a360da3..1d982e8cb8e 100644 --- a/docs/antora/modules/ROOT/pages/Plugin_Twirl.adoc +++ b/docs/antora/modules/ROOT/pages/Plugin_Twirl.adoc @@ -50,7 +50,7 @@ import mill.scalalib._ import $ivy.`com.lihaoyi::mill-contrib-twirllib:`, mill.twirllib._ object app extends ScalaModule with TwirlModule { - def twirlVersion = "1.3.15" + def twirlVersion = "1.5.1" def generatedSources = T{ Seq(compileTwirl().classes) } } ---- @@ -59,7 +59,7 @@ object app extends ScalaModule with TwirlModule { === +def twirlVersion: T[String]+ -Mandatory - the version of the twirl compiler to use, like "1.3.15". +Mandatory - the version of the twirl compiler to use, like "1.5.1". === +def twirlImports: T[Seq[String]]+ @@ -87,7 +87,7 @@ import mill.scalalib._ import $ivy.`com.lihaoyi::mill-contrib-twirllib:`, mill.twirllib._ object app extends ScalaModule with TwirlModule { - def twirlVersion = "1.3.15" + def twirlVersion = "1.5.1" override def twirlImports = super.twirlImports() ++ Seq("my.additional.stuff._", "my.other.stuff._") def generatedSources = T{ Seq(compileTwirl().classes) } } @@ -129,7 +129,7 @@ import mill.scalalib._ import $ivy.`com.lihaoyi::mill-contrib-twirllib:`, mill.twirllib._ object app extends ScalaModule with TwirlModule { - def twirlVersion = "1.3.15" + def twirlVersion = "1.5.1" override def twirlFormats = super.twirlFormats() + Map("svg" -> "play.twirl.api.HtmlFormat") def generatedSources = T{ Seq(compileTwirl().classes) } } From a307a632c9a55b89f339a5b873b4c62035e6efc0 Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Sun, 24 Jul 2022 16:53:58 +0200 Subject: [PATCH 3/6] Reworked Twirl setup and resolution; added `twirlScalaVersion` target The new `twirlScalaVersion` target is mandatory for now. Also added more test to test with Scala 2.12 and 2.13 --- contrib/twirllib/src/TwirlModule.scala | 44 ++++++++++++------- contrib/twirllib/src/TwirlWorker.scala | 2 +- .../twirllib/test/src/HelloWorldTests.scala | 26 ++++++++--- .../modules/ROOT/pages/Plugin_Twirl.adoc | 7 ++- 4 files changed, 56 insertions(+), 23 deletions(-) diff --git a/contrib/twirllib/src/TwirlModule.scala b/contrib/twirllib/src/TwirlModule.scala index f3e4e2df178..642e31154f5 100644 --- a/contrib/twirllib/src/TwirlModule.scala +++ b/contrib/twirllib/src/TwirlModule.scala @@ -1,38 +1,52 @@ package mill package twirllib -import coursier.MavenRepository -import mill.define.Sources +import coursier.{Dependency, Repository} +import mill.define.{Sources, Task} import mill.api.PathRef -import mill.scalalib.Lib.resolveDependencies import mill.scalalib._ import mill.api.Loose import scala.io.Codec import scala.util.Properties -trait TwirlModule extends mill.Module { +trait TwirlModule extends mill.Module { twirlModule => def twirlVersion: T[String] + /** + * The Scala version matching the twirl version. + */ + def twirlScalaVersion: T[String] + def twirlSources: Sources = T.sources { millSourcePath / "views" } - def twirlClasspath: T[Loose.Agg[PathRef]] = T { - resolveDependencies( - Seq( - coursier.LocalRepositories.ivy2Local, - MavenRepository("https://repo1.maven.org/maven2") - ), - Lib.depToDependency(_, "2.13.8"), - Seq( - ivy"com.typesafe.play::twirl-compiler:${twirlVersion()}", - ivy"org.scala-lang.modules::scala-parser-combinators:2.1.1" - ) + def twirlIvyDeps: T[Agg[Dep]] = T { + Agg( + ivy"com.typesafe.play::twirl-compiler:${twirlVersion()}", + ivy"org.scala-lang.modules::scala-parser-combinators:1.1.2" ) } + /** Class instead of an object, to allow re-configuration. */ + class TwirlResolver()(implicit ctx0: mill.define.Ctx) extends mill.Module()(ctx0) with CoursierModule { + override def resolveCoursierDependency: Task[Dep => Dependency] = T.task { d: Dep => + Lib.depToDependency(d, twirlScalaVersion()) + } + + override def repositoriesTask: Task[Seq[Repository]] = twirlModule match { + case m: CoursierModule => m.repositoriesTask + case _ => super.repositoriesTask + } + } + val twirlCoursierResolver = new TwirlResolver() + + def twirlClasspath: T[Loose.Agg[PathRef]] = T { + twirlCoursierResolver.resolveDeps(twirlIvyDeps) + } + def twirlImports: T[Seq[String]] = T { TwirlWorkerApi.twirlWorker.defaultImports(twirlClasspath().map(_.path)) } diff --git a/contrib/twirllib/src/TwirlWorker.scala b/contrib/twirllib/src/TwirlWorker.scala index e8ec14a6e31..bf5815d9d3d 100644 --- a/contrib/twirllib/src/TwirlWorker.scala +++ b/contrib/twirllib/src/TwirlWorker.scala @@ -18,7 +18,7 @@ class TwirlWorker { private var twirlInstanceCache = Option.empty[(Long, (TwirlWorkerApi, Class[_]))] private def twirlCompilerAndClass(twirlClasspath: Agg[os.Path]): (TwirlWorkerApi, Class[_]) = { - val classloaderSig = twirlClasspath.map(p => p.toString().hashCode + os.mtime(p)).sum + val classloaderSig = twirlClasspath.map(p => p.toString().hashCode + os.mtime(p)).iterator.sum twirlInstanceCache match { case Some((sig, instance)) if sig == classloaderSig => instance case _ => diff --git a/contrib/twirllib/test/src/HelloWorldTests.scala b/contrib/twirllib/test/src/HelloWorldTests.scala index bea4495c670..b7f2b9e8215 100644 --- a/contrib/twirllib/test/src/HelloWorldTests.scala +++ b/contrib/twirllib/test/src/HelloWorldTests.scala @@ -6,7 +6,10 @@ import utest.{TestSuite, Tests, assert, _} import scala.io.Codec -object HelloWorldTests extends TestSuite { +trait HelloWorldTests extends TestSuite { + val testTwirlVersion: String + val testTwirlScalaVersion: String + trait HelloBase extends TestUtil.BaseModule { override def millSourcePath: os.Path = @@ -14,9 +17,8 @@ object HelloWorldTests extends TestSuite { } trait HelloWorldModule extends mill.twirllib.TwirlModule { - - def twirlVersion = "1.5.1" - + def twirlVersion = testTwirlVersion + val twirlScalaVersion = testTwirlScalaVersion } object HelloWorld extends HelloBase { @@ -86,13 +88,15 @@ object HelloWorldTests extends TestSuite { eval.apply(HelloWorld.core.twirlVersion) assert( - result == "1.5.1", + result == testTwirlVersion, evalCount > 0 ) } } "compileTwirl" - workspaceTest(HelloWorld, "hello-world") { eval => - val Right((result, evalCount)) = eval.apply(HelloWorld.core.compileTwirl) + val res = eval.apply(HelloWorld.core.compileTwirl) + assert(res.isRight) + val Right((result, evalCount)) = res val outputFiles = os.walk(result.classes.path).filter(_.last.endsWith(".scala")) val expectedClassfiles = compileClassfiles.map( @@ -160,3 +164,13 @@ object HelloWorldTests extends TestSuite { } } } + +object HelloWorldTests2_12 extends HelloWorldTests { + override val testTwirlVersion = "1.3.15" + override val testTwirlScalaVersion = sys.props.getOrElse("MILL_SCALA_2_12_VERSION", ???) +} +object HelloWorldTests2_13 extends HelloWorldTests { + override val testTwirlVersion = "1.5.1" + override val testTwirlScalaVersion = sys.props.getOrElse("MILL_SCALA_2_13_VERSION", ???) +} + diff --git a/docs/antora/modules/ROOT/pages/Plugin_Twirl.adoc b/docs/antora/modules/ROOT/pages/Plugin_Twirl.adoc index 1d982e8cb8e..e426a883f81 100644 --- a/docs/antora/modules/ROOT/pages/Plugin_Twirl.adoc +++ b/docs/antora/modules/ROOT/pages/Plugin_Twirl.adoc @@ -59,7 +59,11 @@ object app extends ScalaModule with TwirlModule { === +def twirlVersion: T[String]+ -Mandatory - the version of the twirl compiler to use, like "1.5.1". +Mandatory - the version of the Twirl compiler to use. + +=== +def twirlScalaVersion: T[String]+ + +Mandatory - the Scala version matching the `twirlVersion`. Older Twirl versions (before 1.4.2) only supported Scala 2.12. === +def twirlImports: T[Seq[String]]+ @@ -88,6 +92,7 @@ import $ivy.`com.lihaoyi::mill-contrib-twirllib:`, mill.twirllib._ object app extends ScalaModule with TwirlModule { def twirlVersion = "1.5.1" + def twirlScalaVersion = "2.13.8" override def twirlImports = super.twirlImports() ++ Seq("my.additional.stuff._", "my.other.stuff._") def generatedSources = T{ Seq(compileTwirl().classes) } } From d924bcb398ec69eb957b8cb79f93a931bd05d685 Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Sun, 24 Jul 2022 17:34:32 +0200 Subject: [PATCH 4/6] Fixed downstream twirl module usage in playlib tests --- .../test/src/mill/playlib/PlayModuleTests.scala | 1 + .../src/mill/playlib/PlaySingleApiModuleTests.scala | 1 - .../test/src/mill/playlib/PlaySingleModuleTests.scala | 4 +++- .../playlib/test/src/mill/playlib/PlayTestSuite.scala | 10 +++++++--- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/contrib/playlib/test/src/mill/playlib/PlayModuleTests.scala b/contrib/playlib/test/src/mill/playlib/PlayModuleTests.scala index 2a592c67420..0d39b8506c8 100644 --- a/contrib/playlib/test/src/mill/playlib/PlayModuleTests.scala +++ b/contrib/playlib/test/src/mill/playlib/PlayModuleTests.scala @@ -16,6 +16,7 @@ object PlayModuleTests extends TestSuite with PlayTestSuite { override def playVersion = crossPlayVersion override def scalaVersion = crossScalaVersion override def twirlVersion = "1.5.1" + override def twirlScalaVersion = sys.props.getOrElse("MILL_SCALA_2_13_VERSION", ???) object test extends PlayTests override def ivyDeps = T { super.ivyDeps() ++ Agg(ws()) } } diff --git a/contrib/playlib/test/src/mill/playlib/PlaySingleApiModuleTests.scala b/contrib/playlib/test/src/mill/playlib/PlaySingleApiModuleTests.scala index 3651f22fc3f..355c5e96ff4 100644 --- a/contrib/playlib/test/src/mill/playlib/PlaySingleApiModuleTests.scala +++ b/contrib/playlib/test/src/mill/playlib/PlaySingleApiModuleTests.scala @@ -9,7 +9,6 @@ object PlaySingleApiModuleTests extends TestSuite with PlayTestSuite { object playsingleapi extends TestUtil.BaseModule with PlayApiModule with SingleModule { override def playVersion = T { "2.7.0" } - def twirlVersion = T { "1.4.0" } override def scalaVersion = T { "2.12.8" } object test extends PlayTests } diff --git a/contrib/playlib/test/src/mill/playlib/PlaySingleModuleTests.scala b/contrib/playlib/test/src/mill/playlib/PlaySingleModuleTests.scala index a9756b23352..08510cb07d3 100644 --- a/contrib/playlib/test/src/mill/playlib/PlaySingleModuleTests.scala +++ b/contrib/playlib/test/src/mill/playlib/PlaySingleModuleTests.scala @@ -12,7 +12,9 @@ object PlaySingleModuleTests extends TestSuite with PlayTestSuite { object playsingle extends TestUtil.BaseModule with PlayModule with SingleModule { override def playVersion = T { "2.8.9" } override def twirlVersion = T { "1.5.1" } - override def scalaVersion = T { "2.13.6" } + override def twirlScalaVersion: T[String] = + T { sys.props.getOrElse("MILL_SCALA_2_13_VERSION", ???) } + override def scalaVersion = T { sys.props.getOrElse("MILL_SCALA_2_13_VERSION", ???) } object test extends PlayTests } diff --git a/contrib/playlib/test/src/mill/playlib/PlayTestSuite.scala b/contrib/playlib/test/src/mill/playlib/PlayTestSuite.scala index f43606cf904..43372adc78d 100644 --- a/contrib/playlib/test/src/mill/playlib/PlayTestSuite.scala +++ b/contrib/playlib/test/src/mill/playlib/PlayTestSuite.scala @@ -4,10 +4,14 @@ import mill.util.{TestEvaluator, TestUtil} import utest.framework.TestPath trait PlayTestSuite { + + val testScala212 = sys.props.getOrElse("MILL_SCALA_2_12_VERSION", ???) + val testScala213 = sys.props.getOrElse("MILL_SCALA_2_13_VERSION", ???) + val matrix = Seq( - ("2.12.13", "2.6.15"), - ("2.12.13", "2.7.9"), - ("2.13.6", "2.8.8") + (testScala212, "2.6.15"), + (testScala212, "2.7.9"), + (testScala213, "2.8.8") ) def resourcePath: os.Path From 4ab7483f622120a0a5e4dd230b43c3821a5a38f0 Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Sun, 24 Jul 2022 23:42:38 +0200 Subject: [PATCH 5/6] Update MiMa setup to ignore twirllib changes and formatting --- build.sc | 29 +++++++++++++++++-- contrib/twirllib/src/TwirlModule.scala | 3 +- .../twirllib/test/src/HelloWorldTests.scala | 2 -- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/build.sc b/build.sc index c15729d42fd..444ef462908 100755 --- a/build.sc +++ b/build.sc @@ -2,14 +2,16 @@ import $file.ci.shared import $file.ci.upload import $ivy.`org.scalaj::scalaj-http:2.4.2` import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version::0.1.4` -import $ivy.`com.github.lolgab::mill-mima::0.0.10` +import $ivy.`com.github.lolgab::mill-mima::0.0.11` import $ivy.`net.sourceforge.htmlcleaner:htmlcleaner:2.25` import com.github.lolgab.mill.mima import com.github.lolgab.mill.mima.{ + CheckDirection, DirectMissingMethodProblem, IncompatibleMethTypeProblem, IncompatibleSignatureProblem, - ProblemFilter + ProblemFilter, + ReversedMissingMethodProblem } import coursier.maven.MavenRepository import de.tobiasroeser.mill.vcs.version.VcsVersion @@ -21,6 +23,7 @@ import mill.scalalib._ import mill.scalalib.publish._ import mill.modules.Jvm import mill.define.SelectMode +import upickle.default.{ReadWriter, macroRW} object Settings { val pomOrg = "com.lihaoyi" @@ -186,6 +189,16 @@ trait MillMimaConfig extends mima.Mima { "mill.api.internal", "mill.api.experimental" ) + + implicit val checkDirectionBackwardUpickleRW: ReadWriter[CheckDirection.Backward.type] = macroRW + implicit val checkDirectionBothUpickleRW: ReadWriter[CheckDirection.Both.type] = macroRW + implicit val checkDirectionForwardUpickleRW: ReadWriter[CheckDirection.Forward.type] = macroRW + implicit val checkDirectionUpickleRW: ReadWriter[CheckDirection] = ReadWriter.merge( + checkDirectionBackwardUpickleRW, + checkDirectionBothUpickleRW, + checkDirectionForwardUpickleRW + ) + override def mimaCheckDirection: Target[CheckDirection] = T { CheckDirection.Backward } override def mimaBinaryIssueFilters: Target[Seq[ProblemFilter]] = T { issueFilterByModule.getOrElse(this, Seq()) } @@ -225,6 +238,18 @@ trait MillMimaConfig extends mima.Mima { ProblemFilter.exclude[DirectMissingMethodProblem]( "mill.contrib.scoverage.ScoverageReport#workerModule.bspCompileClasspath" ) + ), + // we added a new target and a submodule after 0.10.5 + contrib.twirllib -> Seq( + ProblemFilter.exclude[ReversedMissingMethodProblem]( + "mill.twirllib.TwirlModule.twirlScalaVersion" + ), + ProblemFilter.exclude[ReversedMissingMethodProblem]( + "mill.twirllib.TwirlModule.twirlCoursierResolver" + ), + ProblemFilter.exclude[ReversedMissingMethodProblem]( + "mill.twirllib.TwirlModule.mill$twirllib$TwirlModule$_setter_$twirlCoursierResolver_=" + ) ) ) } diff --git a/contrib/twirllib/src/TwirlModule.scala b/contrib/twirllib/src/TwirlModule.scala index 642e31154f5..6a65e808747 100644 --- a/contrib/twirllib/src/TwirlModule.scala +++ b/contrib/twirllib/src/TwirlModule.scala @@ -31,7 +31,8 @@ trait TwirlModule extends mill.Module { twirlModule => } /** Class instead of an object, to allow re-configuration. */ - class TwirlResolver()(implicit ctx0: mill.define.Ctx) extends mill.Module()(ctx0) with CoursierModule { + class TwirlResolver()(implicit ctx0: mill.define.Ctx) extends mill.Module()(ctx0) + with CoursierModule { override def resolveCoursierDependency: Task[Dep => Dependency] = T.task { d: Dep => Lib.depToDependency(d, twirlScalaVersion()) } diff --git a/contrib/twirllib/test/src/HelloWorldTests.scala b/contrib/twirllib/test/src/HelloWorldTests.scala index b7f2b9e8215..816e7845cc8 100644 --- a/contrib/twirllib/test/src/HelloWorldTests.scala +++ b/contrib/twirllib/test/src/HelloWorldTests.scala @@ -10,7 +10,6 @@ trait HelloWorldTests extends TestSuite { val testTwirlVersion: String val testTwirlScalaVersion: String - trait HelloBase extends TestUtil.BaseModule { override def millSourcePath: os.Path = TestUtil.getSrcPathBase() / millOuterCtx.enclosing.split('.') @@ -173,4 +172,3 @@ object HelloWorldTests2_13 extends HelloWorldTests { override val testTwirlVersion = "1.5.1" override val testTwirlScalaVersion = sys.props.getOrElse("MILL_SCALA_2_13_VERSION", ???) } - From 5674f1ad5aff4f2d6b40a2458b4c49a9036e1d39 Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Mon, 25 Jul 2022 06:54:35 +0200 Subject: [PATCH 6/6] Updated changelog --- contrib/twirllib/src/TwirlModule.scala | 11 ++++++++++- readme.adoc | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/contrib/twirllib/src/TwirlModule.scala b/contrib/twirllib/src/TwirlModule.scala index 6a65e808747..1176acb02f3 100644 --- a/contrib/twirllib/src/TwirlModule.scala +++ b/contrib/twirllib/src/TwirlModule.scala @@ -16,6 +16,7 @@ trait TwirlModule extends mill.Module { twirlModule => /** * The Scala version matching the twirl version. + * @since Mill after 0.10.5 */ def twirlScalaVersion: T[String] @@ -23,6 +24,9 @@ trait TwirlModule extends mill.Module { twirlModule => millSourcePath / "views" } + /** + * @since Mill after 0.10.5 + */ def twirlIvyDeps: T[Agg[Dep]] = T { Agg( ivy"com.typesafe.play::twirl-compiler:${twirlVersion()}", @@ -30,7 +34,9 @@ trait TwirlModule extends mill.Module { twirlModule => ) } - /** Class instead of an object, to allow re-configuration. */ + /** Class instead of an object, to allow re-configuration. + * @since Mill after 0.10.5 + */ class TwirlResolver()(implicit ctx0: mill.define.Ctx) extends mill.Module()(ctx0) with CoursierModule { override def resolveCoursierDependency: Task[Dep => Dependency] = T.task { d: Dep => @@ -42,6 +48,9 @@ trait TwirlModule extends mill.Module { twirlModule => case _ => super.repositoriesTask } } + /** + * @since Mill after 0.10.5 + */ val twirlCoursierResolver = new TwirlResolver() def twirlClasspath: T[Loose.Agg[PathRef]] = T { diff --git a/readme.adoc b/readme.adoc index eb9713437f4..2c13a106eda 100644 --- a/readme.adoc +++ b/readme.adoc @@ -238,6 +238,8 @@ corresponding version of Mill. _Changes since {prev-version}:_ +* `mill.twirllib.TwirlModule` - new mandatory target `twirlScalaVersion` to configure the Scala version used by Twirl compiler + _For details refer to {link-milestone}/{milestone}?closed=1[milestone {milestone-name}] and the {link-compare}/{prev-version}\...{version}[list of commits]._