1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 # This file introduces two related templates that act like action and
6 # action_foreach but instead of running a Python script, it will compile a
7 # given tool in the host toolchain and run that (either once or over the list
8 # of inputs, depending on the variant).
13 # [label] Label of the tool to run. This should be an executable, and
14 # this label should not include a toolchain (anything in parens). The
15 # host compile of this tool will be used.
18 # [list of files] Like the outputs of action (if using "compiled_action",
19 # this would be just the list of outputs), or action_foreach (if using
20 # "compiled_action_foreach", this would contain source expansions mapping
21 # input to output files).
24 # [list of strings] Same meaning as action/action_foreach.
30 # Same meaning as action/action_foreach.
35 # compiled_action("run_my_tool") {
36 # tool = "//tools/something:mytool"
38 # "$target_gen_dir/mysource.cc",
39 # "$target_gen_dir/mysource.h",
42 # # The tool takes this input.
43 # source_prereqs = [ "my_input_file.idl" ]
45 # # In this case, the tool takes as arguments the input file and the output
46 # # build dir (both relative to the "cd" that the script will be run in)
47 # # and will produce the output files listed above.
49 # rebase_path("my_input_file.idl", root_build_dir),
50 # "--output-dir", rebase_path(target_gen_dir, root_build_dir),
54 # You would typically declare your tool like this:
55 # if (host_toolchain == current_toolchain) {
56 # executable("mytool") {
60 # The if statement around the executable is optional. That says "I only care
61 # about this target in the host toolchain". Usually this is what you want, and
62 # saves unnecessarily compiling your tool for the target platform. But if you
63 # need a target build of your tool as well, just leave off the if statement.
65 template("compiled_action") {
66 assert(defined(invoker.tool), "tool must be defined for $target_name")
67 assert(defined(invoker.outputs), "outputs must be defined for $target_name")
68 assert(defined(invoker.args), "args must be defined for $target_name")
71 if (defined(invoker.visibility)) {
72 visibility = invoker.visibility
75 script = "//build/gn_run_binary.py"
77 if (defined(invoker.source_prereqs)) {
78 source_prereqs = invoker.source_prereqs
80 outputs = invoker.outputs
82 # Constuct the host toolchain version of the tool.
83 host_tool = invoker.tool + "($host_toolchain)"
85 # Get the path to the executable. Currently, this assumes that the tool
86 # does not specify output_name so that the target name is the name to use.
87 # If that's not the case, we'll need another argument to the script to
88 # specify this, since we can't know what the output name is (it might be in
89 # another file not processed yet).
90 host_executable = get_label_info(host_tool, "root_out_dir") + "/" +
91 get_label_info(host_tool, "name")
94 if (defined(invoker.deps)) {
98 # The script takes as arguments the binary to run, and then the arguments
101 rebase_path(host_executable, root_build_dir)
106 template("compiled_action_foreach") {
107 assert(defined(invoker.sources), "sources must be defined for $target_name")
108 assert(defined(invoker.tool), "tool must be defined for $target_name")
109 assert(defined(invoker.outputs), "outputs must be defined for $target_name")
110 assert(defined(invoker.args), "args must be defined for $target_name")
112 action_foreach(target_name) {
113 # Otherwise this is a standalone action, define visibility if requested.
114 if (defined(invoker.visibility)) {
115 visibility = invoker.visibility
118 script = "//build/gn_run_binary.py"
119 sources = invoker.sources
121 if (defined(invoker.source_prereqs)) {
122 source_prereqs = invoker.source_prereqs
124 outputs = invoker.outputs
126 # Constuct the host toolchain version of the tool.
127 host_tool = invoker.tool + "($host_toolchain)"
129 # Get the path to the executable. Currently, this assumes that the tool
130 # does not specify output_name so that the target name is the name to use.
131 # If that's not the case, we'll need another argument to the script to
132 # specify this, since we can't know what the output name is (it might be in
133 # another file not processed yet).
134 host_executable = get_label_info(host_tool, "root_out_dir") + "/" +
135 get_label_info(host_tool, "name")
138 if (defined(invoker.deps)) {
142 # The script takes as arguments the binary to run, and then the arguments
145 rebase_path(host_executable, root_build_dir)