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..977249eef --- /dev/null +++ b/modules/codegen-plugin/src/sbt-test/codegen-plugin/cross-builds/test @@ -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 diff --git a/modules/codegen-plugin/src/smithy4s/codegen/Smithy4sCodegenPlugin.scala b/modules/codegen-plugin/src/smithy4s/codegen/Smithy4sCodegenPlugin.scala index d0d15baae..a97ac8a3c 100644 --- a/modules/codegen-plugin/src/smithy4s/codegen/Smithy4sCodegenPlugin.scala +++ b/modules/codegen-plugin/src/smithy4s/codegen/Smithy4sCodegenPlugin.scala @@ -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)) => @@ -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")