So I want to have a GN template that determines its outputs based on reading a file. Is this possible? If so, what am I doing wrong?
For the sake of a simple test, I have a file, step_one.json, that lists a few files:
iby@iby3:/ssd/iby/chromium/src$ more /ssd/iby/chromium/src/out/Debug/gen/chrome/browser/step_one.json
["/ssd/iby/chromium/src/out/Debug/a.txt", "/ssd/iby/chromium/src/out/Debug/b.txt", "/ssd/iby/chromium/src/out/Debug/c.txt"]
I then create a simple template in step_two.gni:
import("//build/config/chrome_build.gni")
template("step_two") {
action(target_name) {
script = "//build/util/step_two.py"
args = ["--file_list", rebase_path(invoker.filelist, root_build_dir)]
inputs = [invoker.filelist]
outputs = []
foreach(filename, read_file(invoker.filelist, "json")) {
outputs += [filename]
}
forward_variables_from(invoker,
[
"deps",
"public_deps",
])
}
}
and try to use it in a BUILD.gn file:
step_two("second_step") {
filelist = "$target_gen_dir/step_one.json"
}
Inevitably, I get an error like:
iby@iby3:/ssd/iby/chromium/src$ autoninja -C out/Debug/ chrome
ninja: Entering directory `out/Debug/'
[0/1] Regenerating ninja files
ERROR at //build/util/step_two.gni:13:19: File is not inside output directory.
outputs += [filename]
^-------
The given file should be in the output directory. Normally you would specify
"$target_out_dir/foo" or "$target_gen_dir/foo". I interpreted this as
"/ssd/iby/chromium/src/out/Debug/a.txt".
See //chrome/browser/BUILD.gn:132:1: whence it was called.
step_two("second_step") {
^------------------------
See //chrome/browser/media/router/BUILD.gn:80:7: which caused the file to be included.
"//chrome/browser:browser_process",
^---------------------------------
FAILED: build.ninja
../../buildtools/linux64/gn --root=../.. -q --regeneration gen .
ninja: error: rebuilding 'build.ninja': subcommand failed
The error seems very strange. "/ssd/iby/chromium/src/out/Debug/a.txt" is inside the output directory, so why does it keep complaining that it's not?
I've also tried having a relative path, with no better luck:
iby@iby3:/ssd/iby/chromium/src$ more /ssd/iby/chromium/src/out/Debug/gen/chrome/browser/step_one.json
["out/Debug/a.txt", "out/Debug/b.txt", "out/Debug/c.txt"]
iby@iby3:/ssd/iby/chromium/src$ autoninja -C out/Debug/ chrome
ninja: Entering directory `out/Debug/'
[0/1] Regenerating ninja files
ERROR at //build/util/step_two.gni:13:19: File is not inside output directory.
outputs += [filename]
^-------
The given file should be in the output directory. Normally you would specify
"$target_out_dir/foo" or "$target_gen_dir/foo". I interpreted this as
"out/Debug/a.txt".
See //chrome/browser/BUILD.gn:132:1: whence it was called.
step_two("second_step") {
^------------------------
See //chrome/browser/media/router/BUILD.gn:80:7: which caused the file to be included.
"//chrome/browser:browser_process",
^---------------------------------
FAILED: build.ninja
../../buildtools/linux64/gn --root=../.. -q --regeneration gen .
ninja: error: rebuilding 'build.ninja': subcommand failed
And a whole bunch of other variations.
Is this possible? If so, what am I doing wrong?
Thanks in advance for any help,
Ian