-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
depfile as separate build step #2361
Comments
In a nutshell, what you are trying to do is not directly possible with Ninja. I.e. depfiles and dyndeps files can only add dependencies between input/output paths (a.k.a. "Nodes" in the source tree) and existing build statements (a.k.a. "Edges"). There is no way to create new edges dynamically, like the Make pattern matching allows. And this is by design, to keep Ninja fast. |
OK, so lets try reorganizing this in a different way. If you notice, rule initial
command = initial_build -l $out $srcs && touch $stamps
rule incremental
command = incremental_build -l my.lib $in && touch $out
rule link
command = link_binary -l my.lib $out
depfile = $out.d
rule gendeps
command = generate_dependencies -l my.lib && postprocess
build my.lib: initial
srcs = foo.src baz.src qux.src
stamps = foo.stamp baz.stamp qux.stamp
build foo.stamp: incremental foo.src
build baz.o: incremental baz.src
build qux.o: incremental qux.src
build foo.bin: link || my.lib
build qux.bin: link || my.lib
build foo.bin.d qux.bin.d: gendeps | foo.bin qux.bin || my.lib And processed the depfile to generate something like # foo.bin.d
foo.bin: foo.stamp bar.stamp
# qux.bin.d
qux.bin: qux.stamp bar.stamp I'm away from the project atm, so I can't try this out, but it seems much closer to what ninja can do. Will I run into trouble with generating the depfiles in one step? Of course, there is the potential downside that (for example) moving a unit from one file to another will break the build (or maybe my.lib would get rebuilt since the arguments changed?). I think this would happen in the original makefile, though. |
I want to use ninja with a tool that generates dependencies as a separate build step. These dependencies are not necessary when building from scratch, but they can be used after an initial (full) build to correctly rebuild targets when source files change. In make, I do something roughly like
Where
library.d
contains dependencies likeOn the first build, the
incremental_build
rule is never executed, but oncelibrary
is created,incremental_build
will be used. This is not an ideal solution, but the tool is rather constraining in this regard.I would like to replace my makefiles with ninja, as I find it difficult to manage all the different rules. However, I could not figure out the right way to replicate the above setup. I tried something like
So
dyndeps
won't work here. But we can't usedepfile
either, since the dependencies aren't generated as part of the build steps. Maybe I can makebuild.ninja
depend onmy.d
and regenerate the ninja file whenever the dependencies change?The text was updated successfully, but these errors were encountered: