Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursively return all the generated files #215

Merged
merged 2 commits into from
May 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}