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

Log the args diff when re-running the smithy4s codegen #1559

Merged
merged 5 commits into from
Jun 10, 2024

Conversation

majk-p
Copy link
Contributor

@majk-p majk-p commented Jun 10, 2024

This PR introduces a change in Smithy4s sbt codegen plugin that would allow users to see what caused the codegen to re-execute. It is done by replacing sbt.util.Tracked.inputChanged with a similar implementation that keeps the entire codegen args serialized in cache, and when codegen needs to be rerun, plugin will print the diff of the values to debug log. The diff is calculated using munit-diff.

When running sbt with set logLevel := Level.Debug, user will notice a diff like this when codegen needs to rerun:

obraz

PR Checklist (not all items are relevant to all PRs)

  • Added unit-tests (for runtime code)
  • Added bootstrapped code + smoke tests (when the rendering logic is modified)
  • Added build-plugins integration tests (when reflection loading is required at codegen-time)
  • Added alloy compliance tests (when simpleRestJson protocol behaviour is expanded/updated)
  • Updated dynamic module to match generated-code behaviour
  • Added documentation
  • Updated changelog

val core: Def.Initialize[ModuleID] =
Def.setting("org.scalameta" %%% "munit" % munitVersion)
val scalacheck: Def.Initialize[ModuleID] =
Def.setting("org.scalameta" %%% "munit-scalacheck" % munitVersion)
}
object Munit extends MunitCross("0.7.29")
object MunitMilestone extends MunitCross("1.0.0-M6")
object MunitV1 extends MunitCross("1.0.0") {
Copy link
Contributor

@Baccata Baccata Jun 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may as well use 1.0.0 everywhere (or at the very least replace the milestone with it)

Copy link
Contributor Author

@majk-p majk-p Jun 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried that, but 1.0.0 is not published for native 0.4.x. This would involve upgrading native to 0.5.x and I'm not sure about cats-effect support there.


case Some(oldValue) =>
(serializeCodegenArgs(oldValue), serializeCodegenArgs(in)) match {
case (Some(oldArgs), Some(newArgs)) if (oldArgs != newArgs) =>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (oldArgs != newArgs) string comparison is not enough, I'll switch to by-hash check

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I'd rather you compared the json payloads than the json strings

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's done now. We'll first compare JValues - if they differ we're able to produce the diff and log it. If arguments match structurally, hashes are checked to catch changes to the underlying files.

@Baccata
Copy link
Contributor

Baccata commented Jun 10, 2024

out of curiosity, what's the motivation for this change ?

@majk-p
Copy link
Contributor Author

majk-p commented Jun 10, 2024

out of curiosity, what's the motivation for this change ?

With the extensive use of smithy4s at $work, both my coworkers and myself we have noticed unexpected re-compilation of smithy sources. I'm not sure what caused it yet, I had no luck reproducing it with small projects, but it seems to happen in more complex sbt setups.

A way to debug when and what exactly triggers smithy4s code generation would be a very helpful tool to proceed with the investigation.

@Baccata Baccata merged commit 72a9503 into disneystreaming:series/0.18 Jun 10, 2024
11 checks passed
@majk-p majk-p deleted the codegen-debug-diff-log branch June 11, 2024 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants