1 # Copyright 2019 The Pigweed Authors
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 # use this file except in compliance with the License. You may obtain a copy of
7 # https://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations under
15 import("python_action.gni")
17 # Runs a program which isn't in Python.
19 # This is provided to avoid having to write a new Python wrapper script every
20 # time a program needs to be run from GN.
23 # program: The program to run. Can be a full path or just a name (in which case
26 # args: Optional list of arguments to the program.
28 # deps: Dependencies for this target.
30 # inputs: Optional list of build inputs to the program.
32 # outputs: Optional list of artifacts produced by the program's execution.
34 # env: Optional list of key-value pairs defining environment variables for
37 # env_file: Optional path to a file containing a list of newline-separated
38 # key-value pairs defining environment variables for the program.
40 # args_file: Optional path to a file containing additional positional arguments
41 # to the program. Each line of the file is appended to the invocation. Useful
42 # for specifying arguments from GN metadata.
44 # skip_empty_args: If args_file is provided, boolean indicating whether to skip
45 # running the program if the file is empty. Used to avoid running commands
46 # which error when called without arguments.
48 # capture_output: If true, output from the program is hidden unless the program
49 # exits with an error. Defaults to true.
53 # pw_exec("hello_world") {
57 # "echo hello \$WORLD",
65 assert(defined(invoker.program), "pw_exec requires a program to run")
72 if (defined(invoker.env_file)) {
75 rebase_path(invoker.env_file),
79 if (defined(invoker.args_file)) {
82 rebase_path(invoker.args_file),
85 if (defined(invoker.skip_empty_args) && invoker.skip_empty_args) {
86 _script_args += [ "--skip-empty-args" ]
90 if (defined(invoker.env)) {
91 foreach(_env, invoker.env) {
99 if (!defined(invoker.capture_output) || invoker.capture_output) {
100 _script_args += [ "--capture-output" ]
107 if (defined(invoker.args)) {
108 _script_args += invoker.args
111 pw_python_action(target_name) {
112 script = "$dir_pw_build/py/pw_build/exec.py"
115 forward_variables_from(invoker,
122 if (!defined(inputs)) {
125 if (defined(invoker.env_file)) {
126 inputs += [ invoker.env_file ]
129 if (defined(invoker.outputs)) {
130 outputs = invoker.outputs