- there is no "the build has no work to do" state because the glob
always needs to be resolved to search for new or removed files
On Thu, Oct 5, 2023 at 6:45 PM 'Ben Boeckel' via ninja-build <ninja...@googlegroups.com> wrote:- there is no "the build has no work to do" state because the glob
always needs to be resolved to search for new or removed filesWhile that may be true of how CMake writes globbing rules today, I don't think that is an inherent issue.
You could add all directories (yes the directories themselves) that the glob covers as inputs to the globbing build. You could even make them runtime deps and have the glob tool just announce every directory that it opens*. That would allow you to have real no-op builds if nothing has changed. Of course, since many editors use the atomic write-to-temp-file-and-rename trick rather than overwriting the single file, you will still need to reglob every time someone edits a file in one of those directories. But those probably wouldn't be no-op builds anyway.* my favorite way of doing this is using `deps=msvc` + `msvc_deps_prefix=Opening file: `. Then you can just have your tool print("Opening file: {path}") every time it opens a file, rather than teaching every tool to emit a well-formed Makefile fragment.
--
You received this message because you are subscribed to the Google Groups "ninja-build" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ninja-build...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ninja-build/CAHnCjA3Kii0iDvrS41--C4hAMdta5Hb7VwQJzh%3DOuHEqLYxZKA%40mail.gmail.com.
On Thu, Oct 12, 2023 at 11:24 AM 'Mathias Stearn' via ninja-build <ninja...@googlegroups.com> wrote:On Thu, Oct 5, 2023 at 6:45 PM 'Ben Boeckel' via ninja-build <ninja...@googlegroups.com> wrote:- there is no "the build has no work to do" state because the glob
always needs to be resolved to search for new or removed filesWhile that may be true of how CMake writes globbing rules today, I don't think that is an inherent issue.
I believe it is an inherent issue if you care about correctness: if your Ninja generator performs globbing, this means that _any_ time a file is added to or removed from one of the globbed directories, the project's final build graph changes (inputs and/or outputs are added or removed). Thus the Ninja build plan becomes _immediately_ _stale_ and should always be regenerated. Otherwise your next Ninja incremental build is not going to reflect the real state of your project, and this introduces all kinds of really flaky and hard-to-debug correctness issues that will drive you mad.
Which implies that every Ninja incremental build would need to re-run the generator to perform the globs again, and no-op builds are impossible, unless you really really like building from stale Ninja build plans.
On Thu, Oct 12, 2023 at 2:24 PM David Turner <di...@google.com> wrote:On Thu, Oct 12, 2023 at 11:24 AM 'Mathias Stearn' via ninja-build <ninja...@googlegroups.com> wrote:On Thu, Oct 5, 2023 at 6:45 PM 'Ben Boeckel' via ninja-build <ninja...@googlegroups.com> wrote:- there is no "the build has no work to do" state because the glob
always needs to be resolved to search for new or removed filesWhile that may be true of how CMake writes globbing rules today, I don't think that is an inherent issue.
I believe it is an inherent issue if you care about correctness: if your Ninja generator performs globbing, this means that _any_ time a file is added to or removed from one of the globbed directories, the project's final build graph changes (inputs and/or outputs are added or removed). Thus the Ninja build plan becomes _immediately_ _stale_ and should always be regenerated. Otherwise your next Ninja incremental build is not going to reflect the real state of your project, and this introduces all kinds of really flaky and hard-to-debug correctness issues that will drive you mad.
Which implies that every Ninja incremental build would need to re-run the generator to perform the globs again, and no-op builds are impossible, unless you really really like building from stale Ninja build plans.I don't think you read the rest of my message. I was suggesting having the directories that are covered by the globs being input edges to the task running the glob. At least on linux, whenever you add or remove a file to a directory, that bumps the mtime for the directory, which will cause the glob evaluating task to be considered dirty and rerun. To make this more explicit, if the glob task is also restat=1 and avoids touching its output if it doesn't change, then you now have precisely evaluated globs that are correctly updated only as needed, and downstream tasks (including rerunning your generator) can depend on them. This is nice because I basically always run `ninja blah && run_my_program` so that I'm always running my tests with an up-to-date build. So it is pretty common to run ninja back-to-back even if no source files have been touched, and I like no-op builds to be as close to instant as possible.That said, as Ben correctly pointed out this only covers the cases where your globs are not modified during the build. I think this covers the majority of use cases of globing your source directories (which should (almost) never be modified during a build), it does not support globbing on outputs of your build. This seems less important IMO since most of the time, the generator needs to know what it is outputting up front, but there are a handful of exceptions.