74 lines · plain
1# Defines compiled_action().2#3# compiled_action() is like action(), except that it runs a built binary4# instead of a script.5#6# Parameters:7#8# tool (required)9# [label] Label of the tool to run. This should be an executable, and10# this label should not include a toolchain (anything in parens). This11# tool will be built for the host.12#13# outputs (required)14# [list of files] Same meaning as for action().15#16# args (required)17# [list of strings] Flags to pass to the built binary. Almost identical18# to action()'s `args`, except that `tool` is implicitly added as first19# element.20#21# depfile22# inputs23# public_configs24# visibility (all optional)25# Same meaning as for action().26#27# Example use:28#29# compiled_action("run_my_tool") {30# tool = "//tools/something:mytool"31# inputs = [ "my_input_file.txt" ]32# outputs = [ "$target_gen_dir/mysource.inc" ]33# args = [34# rebase_path(inputs[0], root_build_dir),35# rebase_path(outputs[0], root_build_dir),36# ]37# }38#39# You would typically declare your tool like this:40# if (host_toolchain == current_toolchain) {41# executable("mytool") {42# ...43# }44# }45# The if statement around the executable is optional. It means "I only care46# about this target in the host toolchain". Usually this is what you want, and47# saves unnecessarily compiling your tool for the target platform. If you48# need a target build of your tool as well, omit the if statement.49 50template("compiled_action") {51 assert(defined(invoker.args), "must set 'args' in $target_name")52 assert(defined(invoker.outputs), "must set 'outputs' in $target_name")53 assert(defined(invoker.tool), "must set 'tool' in $target_name")54 assert(!defined(invoker.sources),55 "use 'inputs' instead of 'sources' in $target_name")56 57 action(target_name) {58 forward_variables_from(invoker,59 [60 "depfile",61 "inputs",62 "outputs",63 "public_configs",64 "visibility",65 ])66 host_tool = invoker.tool + "($host_toolchain)"67 host_executable = get_label_info(host_tool, "root_out_dir") + "/bin/" +68 get_label_info(host_tool, "name")69 deps = [ host_tool ]70 script = "//llvm/utils/gn/build/run_built_binary.py"71 args = [ rebase_path(host_executable, root_build_dir) ] + invoker.args72 }73}74