Howdy,
I expected files read via subninja to have their path modified accordingly (or at least the executed rules to behave as if cwd was the location of the ninja file), but they don't seem to. I've got a project that has a toplevel build.ninja that includes a file with some rules, and then calls subninja to include some additional rules from a subdir. That subdir can be built as a project of its own; it has its own build.ninja with the same rules and includes the target.ninja file.
If that explanation doesn't make sense:
a/build.ninja:
rule cc...
rule link...
include targets.ninja
subninja b/c/targets.ninja
a/targets.ninja:
build foo.o: cc foo.c
build foo: link foo.o b/c/bar.o
a/b/c/build.ninja (identical to a/build.ninja, minus subninja line)
rule cc...
rule link...
include targets.ninja
a/b/c/targets.ninja
build bar.o: cc bar.c
I would expect that the build command for bar.o would have "b/c" as the cwd, but that's not the case; it's all executed from the toplevel. (Doesn't even start executing, because the bar.c dependency can't be found -- it's in a/b/c/bar.c, not in a/bar.c.)
Is being able to support this type of subproject behaviour desired? I saw the thread at https://groups.google.com/forum/#!topic/ninja-build/aqT63egYRXI talking about a similar setup (and with a similar solution for the edges), but seems like it would run into the same issue.
- Vlad
--
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.
> (ninja generators usually set things up so that all build artifacts end up in a build directory, not next to the source files, and if you're writing `ninja -C build -f gen/b/c/build.ninja`, generating a named target for "b/c" might be more convenient.)As someone who has written a generator, I agree this wasn't obvious to
me initially. Are there any conventions of what a ninja generator
should produce & where?
I wanted to build different default targets when running ninja from
different source directories, so putting ninja files in a build
directory seemed contradictory at first. Eventually I wrote a bash
wrapper script to launch ninja rather than extend it. It provides
ninja with a -C argument to point to the build dir, and a -f argument
to point to the current dir's ninja file (which then subninja's in to
the build dir's ninja file). Not pretty, but probably the best
solution.
Also ninja will error if you include/subninja a ninja file twice, ie.
it won't ignore the 2nd include. Thus it makes it hard to reuse
existing ninja scripts - eg. say project P depends on A,B, and both
A&B depend on D, and P,A,B & D all have their own ninja files. In this
case, you would want P to subninja in to A & B's ninja files. But you
can't, as D would be included twice.