dlang / dub

Package and build management system for D
MIT License
675 stars 227 forks source link

How to deal with generated code via preBuildCommands? #2656

Open AndrejMitrovic opened 1 year ago

AndrejMitrovic commented 1 year ago

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.

rikkimax commented 1 year ago

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

AndrejMitrovic commented 1 year ago

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.

rikkimax commented 1 year ago

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.

AndrejMitrovic commented 1 year ago

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

WebFreak001 commented 1 year ago

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