Skip to content

Commit

Permalink
Merge pull request #215 from disneystreaming/fix-codegen-plugin
Browse files Browse the repository at this point in the history
Recursively return all the generated files
  • Loading branch information
Baccata authored May 16, 2022
2 parents fb8f87a + 5bf151a commit 7f31df8
Showing 1 changed file with 42 additions and 29 deletions.
71 changes: 42 additions & 29 deletions modules/codegen-plugin/src/smithy4s/codegen/CodegenPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ object Smithy4sCodegenPlugin extends AutoPlugin {
.map(_.toGlob)
.toSeq,
Compile / smithy4sCodegenDependencies := List.empty: @annotation.nowarn,
Compile / sourceGenerators += (Compile / smithy4sCodegen).map(
_.filter(_.ext == "scala")
),
Compile / resourceGenerators += (Compile / smithy4sCodegen).map(
_.filter(_.ext != "scala")
),
Compile / sourceGenerators +=
(Compile / smithy4sCodegen).taskValue
.map(_.filter(_.ext == "scala")),
Compile / resourceGenerators +=
(Compile / smithy4sCodegen).taskValue
.map(_.filterNot(_.ext == "scala")),
cleanFiles += (Compile / smithy4sOutputDir).value,
Compile / smithy4sModelTransformers := List.empty
)
Expand Down Expand Up @@ -146,32 +146,45 @@ object Smithy4sCodegenPlugin extends AutoPlugin {
}
val transforms = (conf / smithy4sModelTransformers).value

val fileChangesReport = (conf / smithy4sCodegen).inputFileChanges

if (fileChangesReport.hasChanges) {
val out = streams.value
val cacheFile =
out.cacheDirectory / s"smithy4s_${scalaBinaryVersion.value}"

// This is important - it's what re-triggers this task on file changes
val _ = (conf / smithy4sCodegen).inputFileChanges

val schemas = ((conf / smithy4sInputDir).value ** "*.smithy").get().toSet

out.log.debug(s"[Smithy4s] discovered specs: $schemas")

val compile = FileFunction
.cached(
cacheFile,
inStyle = FilesInfo.lastModified,
outStyle = FilesInfo.hash
) { (filePaths: Set[File]) =>
val codegenArgs = CodegenArgs(
filePaths.map(os.Path(_)).toList,
output = os.Path(outputPath),
openapiOutput = os.Path(openApiOutputPath),
skipScala = false,
skipOpenapi = false,
allowedNS = allowedNamespaces,
excludedNS = excludedNamespaces,
repositories = res,
dependencies = dependencies,
transforms
)

import fileChangesReport.*
val resPaths = smithy4s.codegen.Codegen
.processSpecs(codegenArgs)
.map(_.toIO)

val filePaths = modified ++ created ++ unmodified
out.log.debug(s"[Smithy4s] generated files: $resPaths")

val codegenArgs = CodegenArgs(
filePaths.map(os.Path(_)).toList,
output = os.Path(outputPath),
openapiOutput = os.Path(openApiOutputPath),
skipScala = false,
skipOpenapi = false,
allowedNS = allowedNamespaces,
excludedNS = excludedNamespaces,
repositories = res,
dependencies = dependencies,
transforms
)

val resPaths = smithy4s.codegen.Codegen
.processSpecs(codegenArgs)
.toList
resPaths
}

resPaths.map(path => new File(path.toString))
} else (conf / smithy4sOutputDir).value.listFiles().toSeq
compile(schemas).toSeq
}
}

0 comments on commit 7f31df8

Please sign in to comment.