From b21afb0849c1f4f0a3b01766355ada1511f04197 Mon Sep 17 00:00:00 2001 From: Brian Holt Date: Wed, 25 Sep 2024 16:43:53 -0500 Subject: [PATCH 1/3] add a failing sbt scripted test to demonstrate #1589 --- .../codegen-plugin/cross-builds/build.sbt | 8 ++++++++ .../cross-builds/project/build.properties | 1 + .../cross-builds/project/plugins.sbt | 9 +++++++++ .../cross-builds/src/main/smithy/simple.smithy | 3 +++ .../sbt-test/codegen-plugin/cross-builds/test | 16 ++++++++++++++++ 5 files changed, 37 insertions(+) create mode 100644 modules/codegen-plugin/src/sbt-test/codegen-plugin/cross-builds/build.sbt create mode 100644 modules/codegen-plugin/src/sbt-test/codegen-plugin/cross-builds/project/build.properties create mode 100644 modules/codegen-plugin/src/sbt-test/codegen-plugin/cross-builds/project/plugins.sbt create mode 100644 modules/codegen-plugin/src/sbt-test/codegen-plugin/cross-builds/src/main/smithy/simple.smithy create mode 100644 modules/codegen-plugin/src/sbt-test/codegen-plugin/cross-builds/test diff --git a/modules/codegen-plugin/src/sbt-test/codegen-plugin/cross-builds/build.sbt b/modules/codegen-plugin/src/sbt-test/codegen-plugin/cross-builds/build.sbt new file mode 100644 index 000000000..5b4e4ab9d --- /dev/null +++ b/modules/codegen-plugin/src/sbt-test/codegen-plugin/cross-builds/build.sbt @@ -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 + ) + ) diff --git a/modules/codegen-plugin/src/sbt-test/codegen-plugin/cross-builds/project/build.properties b/modules/codegen-plugin/src/sbt-test/codegen-plugin/cross-builds/project/build.properties new file mode 100644 index 000000000..8b9a0b0ab --- /dev/null +++ b/modules/codegen-plugin/src/sbt-test/codegen-plugin/cross-builds/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.8.0 diff --git a/modules/codegen-plugin/src/sbt-test/codegen-plugin/cross-builds/project/plugins.sbt b/modules/codegen-plugin/src/sbt-test/codegen-plugin/cross-builds/project/plugins.sbt new file mode 100644 index 000000000..b8589b92c --- /dev/null +++ b/modules/codegen-plugin/src/sbt-test/codegen-plugin/cross-builds/project/plugins.sbt @@ -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 + ) +} diff --git a/modules/codegen-plugin/src/sbt-test/codegen-plugin/cross-builds/src/main/smithy/simple.smithy b/modules/codegen-plugin/src/sbt-test/codegen-plugin/cross-builds/src/main/smithy/simple.smithy new file mode 100644 index 000000000..522b18cff --- /dev/null +++ b/modules/codegen-plugin/src/sbt-test/codegen-plugin/cross-builds/src/main/smithy/simple.smithy @@ -0,0 +1,3 @@ +namespace smithy4s.example + +structure Simple {} diff --git a/modules/codegen-plugin/src/sbt-test/codegen-plugin/cross-builds/test b/modules/codegen-plugin/src/sbt-test/codegen-plugin/cross-builds/test new file mode 100644 index 000000000..5543ff904 --- /dev/null +++ b/modules/codegen-plugin/src/sbt-test/codegen-plugin/cross-builds/test @@ -0,0 +1,16 @@ +# generate for Scala 2.13 +> ++ 2.13 +> compile + +$ exists target/scala-2.13/src_managed/main/smithy4s/smithy4s/example/Simple.scala + +> ++ 3 +> compile + +$ 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/smithy4s/smithy4s/example/Simple.scala target/scala-2.13/src_managed/main/smithy4s/smithy4s/example/Simple.scala From c25381b5a2b18aeee72b5b72e7589112b5928580 Mon Sep 17 00:00:00 2001 From: Brian Holt Date: Fri, 4 Oct 2024 17:17:34 -0500 Subject: [PATCH 2/3] add the Scala version to the caches used by codegen --- .../src/sbt-test/codegen-plugin/cross-builds/test | 3 +++ .../src/smithy4s/codegen/Smithy4sCodegenPlugin.scala | 12 ++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/modules/codegen-plugin/src/sbt-test/codegen-plugin/cross-builds/test b/modules/codegen-plugin/src/sbt-test/codegen-plugin/cross-builds/test index 5543ff904..977249eef 100644 --- a/modules/codegen-plugin/src/sbt-test/codegen-plugin/cross-builds/test +++ b/modules/codegen-plugin/src/sbt-test/codegen-plugin/cross-builds/test @@ -2,15 +2,18 @@ > ++ 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 diff --git a/modules/codegen-plugin/src/smithy4s/codegen/Smithy4sCodegenPlugin.scala b/modules/codegen-plugin/src/smithy4s/codegen/Smithy4sCodegenPlugin.scala index d0d15baae..90216f42c 100644 --- a/modules/codegen-plugin/src/smithy4s/codegen/Smithy4sCodegenPlugin.scala +++ b/modules/codegen-plugin/src/smithy4s/codegen/Smithy4sCodegenPlugin.scala @@ -266,10 +266,14 @@ object Smithy4sCodegenPlugin extends AutoPlugin { config / smithy4sGeneratedSmithyFiles := { val cacheFactory = (config / streams).value.cacheStoreFactory val cached = Tracked.inputChanged[(String, Boolean), Seq[File]]( - cacheFactory.make("smithy4sGeneratedSmithyFilesInput") + cacheFactory.make( + s"smithy4sGeneratedSmithyFilesInput${scalaVersion.value}" + ) ) { case (changed, (wildcardArg, shouldGenerateOptics)) => val lastOutput = Tracked.lastOutput[Boolean, Seq[File]]( - cacheFactory.make("smithy4sGeneratedSmithyFilesOutput") + cacheFactory.make( + s"smithy4sGeneratedSmithyFilesOutput${scalaVersion.value}" + ) ) { case (changed, prevResult) => if (changed || prevResult.isEmpty) { val file = @@ -456,12 +460,12 @@ object Smithy4sCodegenPlugin extends AutoPlugin { val cached = CachedTask.inputChanged[CodegenArgs, Seq[File]]( - s.cacheStoreFactory.make("input"), + s.cacheStoreFactory.make(s"input${scalaVersion.value}"), s.log ) { Function.untupled { Tracked.lastOutput[(Boolean, CodegenArgs), Seq[File]]( - s.cacheStoreFactory.make("output") + s.cacheStoreFactory.make(s"output${scalaVersion.value}") ) { case ((inputChanged, args), outputs) => if (inputChanged || outputs.isEmpty) { s.log.debug(s"[smithy4s] Input changed: $inputChanged") From d588328ea907b6f4db38ee687877f295d7c530b0 Mon Sep 17 00:00:00 2001 From: Brian Holt Date: Fri, 4 Oct 2024 22:24:31 -0500 Subject: [PATCH 3/3] properly isolate the cache stores --- .../smithy4s/codegen/Smithy4sCodegenPlugin.scala | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/modules/codegen-plugin/src/smithy4s/codegen/Smithy4sCodegenPlugin.scala b/modules/codegen-plugin/src/smithy4s/codegen/Smithy4sCodegenPlugin.scala index 90216f42c..a97ac8a3c 100644 --- a/modules/codegen-plugin/src/smithy4s/codegen/Smithy4sCodegenPlugin.scala +++ b/modules/codegen-plugin/src/smithy4s/codegen/Smithy4sCodegenPlugin.scala @@ -264,16 +264,13 @@ 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( - s"smithy4sGeneratedSmithyFilesInput${scalaVersion.value}" - ) + cacheFactory.make("smithy4sGeneratedSmithyFilesInput") ) { case (changed, (wildcardArg, shouldGenerateOptics)) => val lastOutput = Tracked.lastOutput[Boolean, Seq[File]]( - cacheFactory.make( - s"smithy4sGeneratedSmithyFilesOutput${scalaVersion.value}" - ) + cacheFactory.make("smithy4sGeneratedSmithyFilesOutput") ) { case (changed, prevResult) => if (changed || prevResult.isEmpty) { val file = @@ -458,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(s"input${scalaVersion.value}"), + cacheStoreFactory.make("input"), s.log ) { Function.untupled { Tracked.lastOutput[(Boolean, CodegenArgs), Seq[File]]( - s.cacheStoreFactory.make(s"output${scalaVersion.value}") + cacheStoreFactory.make("output") ) { case ((inputChanged, args), outputs) => if (inputChanged || outputs.isEmpty) { s.log.debug(s"[smithy4s] Input changed: $inputChanged")