template("foo") {
header = "$target_gen_dir/$target_name.h"
_deps = []
if (defined(invoker.deps)) {
_deps = invoker.deps
}
action(target_name + "__script") {
script = "s.py"
inputs = invoker.info_files
outputs = [ header ]
deps = _deps
}
source_set(target_name) {
sources = [ header ] + invoker.sources
deps = _deps + [":${target_name}__script"]
}
}
foo("target1") {
info_files = [ "target1.json" ]
sources = [ "target1.cc" ]
}
foo("target2") {
info_files = [ "target2.json" ]
sources = [ "target2.cc" ]
deps = [ ":target1" ]
}
In toolchain.ninja:
rule ___target2__script___build_toolchain_gcc__rule
command = python ../s.py
description = ACTION //:target2__script(//build/toolchain:gcc)
restat = 1
build gen/target2.h: ___target2__script___build_toolchain_gcc__rule | ../s.py ../target2.json phony/target1
build phony/target2__script: phony gen/target2.h
So, `target2__script` depends on `target1`, and that's a situation that I'm describing.
Answering the question