How to represent an optional dependency in ninja

6 views
Skip to first unread message

David Given

unread,
Jan 6, 2026, 5:31:44 AM (5 days ago) Jan 6
to ninja-build
I have a situation where a file may be provided by the user, or generated at run-time by ninja. I'm finding that the obvious way to represent this (by simply having a rule generating a file) doesn't work; the file is always regenerated, even if it doesn't exist.

-d explain says it's being rebuilt because:

ninja explain: command line not found in log for <filename>

I mean... that's true, but it's not helpful. Looking at the source code to ninja it seems that this happens if there's no command line log entry and the edge isn't tagged with generator=true. And indeed, setting generator=true makes ninja behave the way I'd expect.

But that's terrible. Is there a better way?

Thanks!

Ben Boeckel

unread,
Jan 6, 2026, 7:54:05 AM (5 days ago) Jan 6
to David Given, ninja-build
On Mon, Jan 05, 2026 at 14:10:51 -0800, David Given wrote:
> I have a situation where a file may be provided by the user, or generated
> at run-time by ninja. I'm finding that the obvious way to represent this
> (by simply having a rule generating a file) doesn't work; the file is
> always regenerated, even if it doesn't exist.

Hi,

Can the file always be "generated" with a `cp` command in the "provided
by the user" case? Just place it in the location of the path as-if it
were generated and depend on the source file for the `cp`.

Perhaps a concrete example would help as well if this is misguided
advice.

Thanks,

--Ben
Reply all
Reply to author
Forward
0 new messages