dub icon indicating copy to clipboard operation
dub copied to clipboard

How to deal with generated code via preBuildCommands?

Open AndrejMitrovic opened this issue 2 years ago • 5 comments

I have what is essentially:

preBuildCommands "./scripts/run-protobuf.sh"
sourcePaths "lib/generated"

Where the script runs the protobuf compiler and generates some D code within lib/generated.

But on the first invocation dub will emit a warning (plus a build error):

Warning Invalid source/import path: /c/dev/project/lib

Is there a better way to do this?

Because the current behavior is very unstable, essentially the build will fail the first time around if any of the project's code imports the generated code, but it will then succeed on the next dub rebuild as the preBuildCommands will have been executed by then and the import warnings will no longer exist.

Moved from https://github.com/vibe-d/vibe.d/issues/2733, filed there by accident.

AndrejMitrovic avatar Jun 05 '23 10:06 AndrejMitrovic

That is odd, but try creating the lib directory manually and don't let the generator own it.

rikkimax avatar Jun 05 '23 11:06 rikkimax

Yeah I think the best thing to do is just commit the auto-generated code, and only update when necessary. Using preBuildCommands for these tricks is probably abusing what it's supposed to be used for.

AndrejMitrovic avatar Jun 05 '23 11:06 AndrejMitrovic

No, that's fine, I just think dub is doing some analysis a bit too soon and you're giving the generator the control to create a directory in which it's doing analysis on.

rikkimax avatar Jun 05 '23 11:06 rikkimax

I see what you mean, make the dir and commit it empty first. Yeah, that can do the trick.

AndrejMitrovic avatar Jun 05 '23 11:06 AndrejMitrovic

yeah this is not great right now, generated sources or things like modifying dub.json/dub.sdl of subpackages is not currently working yet.

WebFreak001 avatar Jun 05 '23 12:06 WebFreak001