dune
                                
                                 dune copied to clipboard
                                
                                    dune copied to clipboard
                            
                            
                            
                        `dune build --watch` should have an option to show which changes triggered a restart of the current build
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)
which restarts a build forever and never finishes.
This sounds like a bug. Do you have a promoted files in your build? cc @snowleopard
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.
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.
There was a change to delay promotions to the end of the build. Did that ever make it upstream? @snowleopard @pmwhite
I don't think so.
Note that deferring promotions is not going to fix the looping.
Right, but I'm not sure there's indeed a loop. There could be just a bunch of restarts here making everything slow.
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