Pruning build steps if no change

176 views
Skip to first unread message

Jussi Pakkanen

unread,
Jun 4, 2013, 5:41:14 AM6/4/13
to ninja...@googlegroups.com
Hi

Suppose we have the following build steps:

shared.c -> shared.o -> shared library A
prog.c -> prog.o -> program B, linked with A

If we change shared.c, then program B gets relinked. But we should only need to relink B if symbols exported by A change (or prog.c or its dependencies change, but let's ignore that). This is a common scenario so it would be nice to make this fast. Let's assume that we can extract this dependency to a file with script C. Then we have something like this:

shared.c -> shared.o -> shared library A
A -> A.symbols (generated with C)
prog.c -> prog.o -> program B, linked with A but only if A.symbols has changed

The dependency tree is quite simple to generate with Ninja but the problem comes when processing A.symbols. Suppose the generator script will only update A.symbols if its contents would change.

In this case Ninja has a build rule that is triggered, but the output file is not updated. I could not find any text in Ninja's manual that would specify what happens in this case.  Does Ninja notice that the output was not updated and assume from that point on that it was up to date? Does it blindly go on? More importantly, is what happens next undefined or platform-dependent behavior. Is there a better way of achieving the same result?

IIRC tells me that Chrome's build system does something like this so it should be possible.

Reid Kleckner

unread,
Jun 4, 2013, 8:09:07 AM6/4/13
to Jussi Pakkanen, ninja-build
Right, that's what the 'restat = 1' rule variable is for:

If it is set, after a build action, ninja will restat the output to see if it has changed, and prune any dependent edges.


--
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.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Evan Martin

unread,
Jun 4, 2013, 2:57:41 PM6/4/13
to Jussi Pakkanen, ninja-build
It's not linked from anywhere so I can't have expected you to find it, but we've collected some notes on patterns like these here:
Since that post doesn't mention 'restat', I'll link the section on shared objects back to this thread.


--
Reply all
Reply to author
Forward
0 new messages