1# Modified `llvm/utils/gn/build/compiled_action.gni` file to suit clspv build 2# structure. 3import("//build_overrides/clspv.gni") 4 5# Defines compiled_action(). 6# 7# compiled_action() is like action(), except that it runs a built binary 8# instead of a script. 9# 10# Parameters: 11# 12# tool (required) 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). This 15# tool will be built for the host. 16# 17# outputs (required) 18# [list of files] Same meaning as for action(). 19# 20# args (required) 21# [list of strings] Flags to pass to the built binary. Almost identical 22# to action()'s `args`, except that `tool` is implicitly added as first 23# element. 24# 25# depfile 26# inputs 27# public_configs 28# visibility (all optional) 29# Same meaning as for action(). 30# 31# Example use: 32# 33# compiled_action("run_my_tool") { 34# tool = "//tools/something:mytool" 35# inputs = [ "my_input_file.txt" ] 36# outputs = [ "$target_gen_dir/mysource.inc" ] 37# args = [ 38# rebase_path(inputs[0], root_build_dir), 39# rebase_path(outputs[0], root_build_dir), 40# ] 41# } 42# 43# You would typically declare your tool like this: 44# if (host_toolchain == current_toolchain) { 45# executable("mytool") { 46# ... 47# } 48# } 49# The if statement around the executable is optional. It means "I only care 50# about this target in the host toolchain". Usually this is what you want, and 51# saves unnecessarily compiling your tool for the target platform. If you 52# need a target build of your tool as well, omit the if statement. 53 54template("compiled_action") { 55 assert(defined(invoker.args), "must set 'args' in $target_name") 56 assert(defined(invoker.outputs), "must set 'outputs' in $target_name") 57 assert(defined(invoker.tool), "must set 'tool' in $target_name") 58 assert(!defined(invoker.sources), 59 "use 'inputs' instead of 'sources' in $target_name") 60 61 action(target_name) { 62 forward_variables_from(invoker, 63 [ 64 "depfile", 65 "inputs", 66 "outputs", 67 "public_configs", 68 "visibility", 69 ]) 70 host_tool = rebase_path(invoker.tool) + "($host_toolchain)" 71 72 # TODO Need to get the path from the toolchain itself 73 host_executable = get_label_info(host_tool, "root_out_dir") + "/" + 74 get_label_info(host_tool, "name") # "/bin/" + 75 deps = [ host_tool ] 76 script = "//$clspv_llvm_dir/llvm/utils/gn/build/run_built_binary.py" 77 args = [ rebase_path(host_executable, root_build_dir) ] + invoker.args 78 } 79} 80