smithy4s icon indicating copy to clipboard operation
smithy4s copied to clipboard

(sbt) Files not removed on subsequent codegen run

Open kubukoz opened this issue 1 year ago • 5 comments

To reproduce:

  1. Generate code for any shape
  2. Rename the shape
  3. Generate code again
  4. Look at the output

Example:

https://github.com/disneystreaming/smithy4s/assets/894884/687fc3df-d561-44f5-9dd9-a9e16de3be42

Happens in 0.18.18.

kubukoz avatar May 16 '24 21:05 kubukoz

I'm thinking to delete previously generated files in sbt only, because:

  • CLI: people are very likely to use . as the target which could very easily turn into an annoying experience
  • Mill: we generate to a task-specific path that gets cleared on invalidation, so this shouldn't be happening in the first place

kubukoz avatar May 16 '24 21:05 kubukoz

I'm not too sure what kind of impact deleting would have, which is why I elected not to do it in the first place. In the grand scheme of things it shouldn't matter too much, because SBT expects the sourceGenerator task to return the list of all files that were generated :

https://github.com/disneystreaming/smithy4s/blob/b96f736b0ea8a01447d91d6c4a2204b0be980320/modules/codegen-plugin/src/smithy4s/codegen/Smithy4sCodegenPlugin.scala#L291-L293

So maybe this impacts the editor, but I'm not sure it's actually a good idea to clean up before regeneration.

Baccata avatar May 17 '24 13:05 Baccata

I think it does have impact, because your app code may still have references to the old files, and it'll compile locally but e.g. won't compile anymore when you push changes and CI runs on them.

If we can access the list of previously generated files, removing them is IMO the right thing to do, but I suppose we should see what other codegens do, like scalapb.

kubukoz avatar May 17 '24 16:05 kubukoz

and it'll compile locally

What I'm saying is that it won't compile locally, at least I don't think it will compile in SBT.

Baccata avatar May 17 '24 18:05 Baccata

oh I see what you mean - the files not on the list shouldn't be included in the compilation, so only the IDE will see them, at least (I guess) until you re-import your project.

kubukoz avatar May 17 '24 18:05 kubukoz