dune icon indicating copy to clipboard operation
dune copied to clipboard

`dune build --watch` should have an option to show which changes triggered a restart of the current build

Open Khady opened this issue 1 year ago • 7 comments

Desired Behavior

I'm having an issue with dune build --watch which restarts a build forever and never finishes. Every few seconds it tells me something like

Source files changed, restarting current build... (43017/68213)

It's tricky to debug what is going on as there are no details about what triggered a restart of the build. --verbose doesn't help and _build/log is also silent about that matter.

It would be nice to have a way for dune to detect that it is in such kind of loop and report it with the cause. If such an advanced behavior is not possible, there should be a way to ask dune what is causing the restart of a build.

Example

Source files changed
- gen_sql.ml
- gen_atd.ml
restarting current build... (43017/68213)

Khady avatar Feb 16 '24 09:02 Khady

which restarts a build forever and never finishes.

This sounds like a bug. Do you have a promoted files in your build? cc @snowleopard

nojb avatar Feb 26 '24 09:02 nojb

yes we have promoted files and it's one of them that was triggering the rebuild. I don't think it's a bug in dune, more like a bug in our rules. That was way too troublesome to figure out.

Khady avatar Feb 26 '24 10:02 Khady

It would be nice to have a way for dune to detect that it is in such kind of loop and report it with the cause.

At least for debugging, you can use --debug-cache=fs. That will show you the reasons for restarting the build.

@nojb Yes, we have promotions, and some of them restart the build, but not in a loop.

If I recall correctly, the main footgun here is (promote (into ...)), which we don't use and which, I think, we should just delete/deprecate.

snowleopard avatar Mar 20 '24 13:03 snowleopard

There was a change to delay promotions to the end of the build. Did that ever make it upstream? @snowleopard @pmwhite

rgrinberg avatar Mar 20 '24 14:03 rgrinberg

I don't think so.

Note that deferring promotions is not going to fix the looping.

snowleopard avatar Mar 20 '24 14:03 snowleopard

Right, but I'm not sure there's indeed a loop. There could be just a bunch of restarts here making everything slow.

rgrinberg avatar Mar 20 '24 14:03 rgrinberg

Running watch mode with --terminal-persistence=preserve will show the file that triggered a rebuild, regardless if the previous build has finished or not, e.g.

$ dune build @foo -w --terminal-persistence=preserve
                                              
********** NEW BUILD (bar/file.ml changed) **********

It seems this msg is only printed when using this mode:

https://github.com/ocaml/dune/blob/034e352f5cde97e6866e44e29815da917d022e16/bin/import.ml#L130-L138

jchavarri avatar May 31 '24 16:05 jchavarri