diff --git a/modules/codegen-plugin/src/sbt-test/codegen-plugin/custom-settings/build.sbt b/modules/codegen-plugin/src/sbt-test/codegen-plugin/custom-settings/build.sbt index 8b4c80ea7..5377ed157 100644 --- a/modules/codegen-plugin/src/sbt-test/codegen-plugin/custom-settings/build.sbt +++ b/modules/codegen-plugin/src/sbt-test/codegen-plugin/custom-settings/build.sbt @@ -1,6 +1,8 @@ lazy val commonSettings = Def.settings( scalaVersion := "2.13.6", - Compile / smithy4sInputDir := (ThisBuild / baseDirectory).value / "smithy_input", + Compile / smithy4sInputDirs := Seq( + (ThisBuild / baseDirectory).value / "smithy_input" + ), Compile / smithy4sAllowedNamespaces := List( "aws.iam", "smithy4s.example" diff --git a/modules/codegen-plugin/src/smithy4s/codegen/Smithy4sCodegenPlugin.scala b/modules/codegen-plugin/src/smithy4s/codegen/Smithy4sCodegenPlugin.scala index 8569bb2d2..9102af081 100644 --- a/modules/codegen-plugin/src/smithy4s/codegen/Smithy4sCodegenPlugin.scala +++ b/modules/codegen-plugin/src/smithy4s/codegen/Smithy4sCodegenPlugin.scala @@ -33,10 +33,9 @@ object Smithy4sCodegenPlugin extends AutoPlugin { val smithy4sVersion = settingKey[String]("Smithy4sVersion") - val smithy4sInputDir = - settingKey[File]( - "Input directory for smithy specs (.smithy or .json files)" - ) + val smithy4sInputDirs = settingKey[Seq[File]]( + "Input directories for smithy specs (.smithy or .json files)" + ) val smithy4sOutputDir = settingKey[File]( @@ -98,7 +97,8 @@ object Smithy4sCodegenPlugin extends AutoPlugin { // Use this with any configuration to enable the codegen in it. def defaultSettings(config: Configuration) = Seq( - config / smithy4sInputDir := (config / sourceDirectory).value / "smithy", + config / smithy4sInputDirs := (config / unmanagedSourceDirectories).value + .map(_.getParentFile() / "smithy"), config / smithy4sOutputDir := (config / sourceManaged).value, config / smithy4sResourceDir := (config / resourceManaged).value, config / smithy4sCodegen := cachedSmithyCodegen(config).value, @@ -139,7 +139,7 @@ object Smithy4sCodegenPlugin extends AutoPlugin { def cachedSmithyCodegen(conf: Configuration) = Def.task { val inputFiles = - Option((conf / smithy4sInputDir).value) + Option((conf / smithy4sInputDirs).value).toSeq.flatten .filter(_.exists()) .toList val outputPath = (conf / smithy4sOutputDir).value diff --git a/modules/docs/markdown/01-overview/03-installation.md b/modules/docs/markdown/01-overview/03-installation.md index 34f9bfbc2..d210d3311 100644 --- a/modules/docs/markdown/01-overview/03-installation.md +++ b/modules/docs/markdown/01-overview/03-installation.md @@ -31,7 +31,7 @@ val myModule = project This will enable the plugin on `myModule`. We also need to add `smithy4s-core ` here since it is needed for compiling the generated code. -By default, the plugin will look in the `$MY_MODULE/src/main/smithy` directory and will write scala code in `$MY_MODULE/target/scala-/src_managed/` when invoking `compile`. The paths are configurable via the `smithy4sInputDir` and `smithy4sOutputDir` settings keys. +By default, the plugin will look in the `$MY_MODULE/src/main/smithy` directory and will write scala code in `$MY_MODULE/target/scala-/src_managed/` when invoking `compile`. The paths are configurable via the `smithy4sInputDirs` and `smithy4sOutputDir` settings keys. For example, in order for the plugin to source `.smithy` specs from `./smithy_input` (inside the folder where our `build.sbt` is) and output the generated files into `./smithy_output`. @@ -41,8 +41,8 @@ val myModule = project .enablePlugins(Smithy4sCodegenPlugin) .settings( scalaVersion := "@SCALA_VERSION@", - smithy4sInputDir in Compile := (ThisBuild / baseDirectory).value / "smithy_input", - smithy4sOutputDir in Compile := (ThisBuild / baseDirectory).value / "smithy_output", + Compile / smithy4sInputDirs := Seq((ThisBuild / baseDirectory).value / "smithy_input"), + Compile / smithy4sOutputDir := (ThisBuild / baseDirectory).value / "smithy_output", libraryDependencies += "com.disneystreaming.smithy4s" %% "smithy4s-core" % smithy4sVersion.value ) ``` @@ -66,7 +66,7 @@ object example extends ScalaModule with Smithy4sModule { } ``` -By default, the `mill` plugin will look for Smithy files under the `$MY_MODULE/smithy` directory. The generated code ends up in `out/$MY_MODULE/smithy4sOutputDir.dest/scala/`, again, by default. Code generation happens automatically when you before you `compile` the module. The paths are configurable via the `smithy4sInputDir` and `smithy4sOutputDir` tasks. +By default, the `mill` plugin will look for Smithy files under the `$MY_MODULE/smithy` directory. The generated code ends up in `out/$MY_MODULE/smithy4sOutputDir.dest/scala/`, again, by default. Code generation happens automatically when you before you `compile` the module. The paths are configurable via the `smithy4sInputDirs` and `smithy4sOutputDir` tasks. For example, here we'll read Smithy files from `smithy_input` and write to `smithy_output`. @@ -81,8 +81,8 @@ object example extends ScalaModule with Smithy4sModule { ivy"com.disneystreaming.smithy4s::smithy4s-core:${smithy4sVersion()}" ) - override def smithy4sInputDir = T.source { - PathRef(T.ctx().workspace / "smithy_input") + override def smithy4sInputDirs = T.sources { + Seq(PathRef(T.ctx().workspace / "smithy_input")) } override def smithy4sOutputDir = T { PathRef(T.ctx().workspace / "smithy_output") diff --git a/modules/mill-codegen-plugin/src/smithy4s/codegen/mill/Smithy4sModule.scala b/modules/mill-codegen-plugin/src/smithy4s/codegen/mill/Smithy4sModule.scala index d47c6ef47..f8f71e03b 100644 --- a/modules/mill-codegen-plugin/src/smithy4s/codegen/mill/Smithy4sModule.scala +++ b/modules/mill-codegen-plugin/src/smithy4s/codegen/mill/Smithy4sModule.scala @@ -19,7 +19,7 @@ package smithy4s.codegen.mill import coursier.maven.MavenRepository import mill._ import mill.api.PathRef -import mill.define.Source +import mill.define.Sources import mill.scalalib._ import smithy4s.codegen.{CodegenArgs, Codegen => Smithy4s, FileType} import smithy4s.codegen.BuildInfo @@ -27,8 +27,8 @@ import smithy4s.codegen.BuildInfo trait Smithy4sModule extends ScalaModule { /** Input directory for .smithy files */ - protected def smithy4sInputDir: Source = T.source { - PathRef(millSourcePath / "smithy") + protected def smithy4sInputDirs: Sources = T.sources { + Seq(PathRef(millSourcePath / "smithy")) } protected def smithy4sOutputDir: T[PathRef] = T { @@ -85,7 +85,7 @@ trait Smithy4sModule extends ScalaModule { def smithy4sCodegen: T[(PathRef, PathRef)] = T { - val specFiles = List(smithy4sInputDir().path).filter(os.exists(_)) + val specFiles = smithy4sInputDirs().map(_.path).filter(os.exists(_)) val scalaOutput = smithy4sOutputDir().path val resourcesOutput = smithy4sResourceOutputDir().path