Skip to content

Commit

Permalink
Introduce the Scala version into the codegen cache namespace (#1590)
Browse files Browse the repository at this point in the history
* add a failing sbt scripted test to demonstrate #1589
* add the Scala version to the caches used by codegen
* properly isolate the cache stores
  • Loading branch information
bpholt authored Oct 8, 2024
1 parent 92d56f2 commit 551c5f4
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
lazy val root = (project in file("."))
.enablePlugins(Smithy4sCodegenPlugin)
.settings(
crossScalaVersions := Seq("2.13.15", "3.3.3"),
libraryDependencies ++= Seq(
"com.disneystreaming.smithy4s" %% "smithy4s-core" % smithy4sVersion.value
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.8.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sys.props.get("plugin.version") match {
case Some(x) =>
addSbtPlugin("com.disneystreaming.smithy4s" % "smithy4s-sbt-codegen" % x)
case _ =>
sys.error(
"""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace smithy4s.example

structure Simple {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# generate for Scala 2.13
> ++ 2.13
> compile

$ exists target/scala-2.13/src_managed/main/smithy/generated-metadata.smithy
$ exists target/scala-2.13/src_managed/main/smithy4s/smithy4s/example/Simple.scala

> ++ 3
> compile

$ exists target/scala-3.3.3/src_managed/main/smithy/generated-metadata.smithy
$ exists target/scala-3.3.3/src_managed/main/smithy4s/smithy4s/example/Simple.scala

# switch back to Scala 2.13 and compile again; codegen should not happen a second time
> ++ 2.13
> compile

$ newer target/scala-3.3.3/src_managed/main/smithy/generated-metadata.smithy target/scala-2.13/src_managed/main/smithy/generated-metadata.smithy
$ newer target/scala-3.3.3/src_managed/main/smithy4s/smithy4s/example/Simple.scala target/scala-2.13/src_managed/main/smithy4s/smithy4s/example/Simple.scala
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ object Smithy4sCodegenPlugin extends AutoPlugin {
(config / sourceManaged).value / "smithy" / "generated-metadata.smithy"
},
config / smithy4sGeneratedSmithyFiles := {
val cacheFactory = (config / streams).value.cacheStoreFactory
val cacheFactory =
(config / streams).value.cacheStoreFactory.sub(scalaVersion.value)
val cached = Tracked.inputChanged[(String, Boolean), Seq[File]](
cacheFactory.make("smithy4sGeneratedSmithyFilesInput")
) { case (changed, (wildcardArg, shouldGenerateOptics)) =>
Expand Down Expand Up @@ -454,14 +455,15 @@ object Smithy4sCodegenPlugin extends AutoPlugin {
smithyBuild = smithyBuildValue
)

val cacheStoreFactory = s.cacheStoreFactory.sub(scalaVersion.value)
val cached =
CachedTask.inputChanged[CodegenArgs, Seq[File]](
s.cacheStoreFactory.make("input"),
cacheStoreFactory.make("input"),
s.log
) {
Function.untupled {
Tracked.lastOutput[(Boolean, CodegenArgs), Seq[File]](
s.cacheStoreFactory.make("output")
cacheStoreFactory.make("output")
) { case ((inputChanged, args), outputs) =>
if (inputChanged || outputs.isEmpty) {
s.log.debug(s"[smithy4s] Input changed: $inputChanged")
Expand Down

0 comments on commit 551c5f4

Please sign in to comment.