1import("//build/ohos.gni") 2 3template("python3_action") { 4 action(target_name) { 5 # Forward all variables. Ensure that testonly and visibility are forwarded 6 # explicitly, since this performs recursive scope lookups, which is 7 # required to ensure their definition from scopes above the caller are 8 # properly handled. All other variables are forwarded with "*", which 9 # doesn't perform recursive lookups at all. See https://crbug.com/862232 10 forward_variables_from(invoker, 11 [ 12 "testonly", 13 "visibility", 14 ]) 15 forward_variables_from(invoker, 16 "*", 17 [ 18 "testonly", 19 "visibility", 20 ]) 21 22 script = "//third_party/wayland_standard/python3_action.py" 23 _rebased_script = rebase_path(invoker.script, root_build_dir) 24 inputs = [] 25 inputs = [ invoker.script ] 26 if (defined(invoker.inputs)) { 27 inputs += invoker.inputs 28 } 29 args = [] 30 args = [ _rebased_script ] 31 if (defined(invoker.args)) { 32 args += invoker.args 33 } 34 } 35} 36 37template("wayland_protocol") { 38 assert(defined(invoker.sources), "Need sources for wayland_protocol template") 39 40 # Calculate the output paths. 41 protocol_outputs = [] 42 output_dirs = [] 43 foreach(protocol, invoker.sources) { 44 dir = "$root_gen_dir/" + rebase_path(get_path_info(protocol, "dir"), "//") 45 name = get_path_info(protocol, "name") 46 protocol_outputs += [ 47 "${dir}/${name}-protocol.c", 48 "${dir}/${name}-client-protocol.h", 49 "${dir}/${name}-server-protocol.h", 50 ] 51 output_dirs += [ dir ] 52 } 53 54 action_name = "${target_name}_gen" 55 config_name = "${target_name}_config" 56 source_set_name = "${target_name}" 57 58 # Action which runs wayland-scanner to generate the code. 59 # TODO(crbug.com/1112471): Get this to run cleanly under Python 3. 60 python3_action(action_name) { 61 visibility = [ ":$source_set_name" ] 62 script = "//third_party/wayland_standard/wayland_scanner_wrapper.py" 63 sources = invoker.sources 64 outputs = protocol_outputs 65 66 # Paths in invoker.sources are relative to the invoker. 67 # Make it relative to the src root. 68 args = rebase_path(invoker.sources, "//") 69 70 args += [ 71 "--src-root", 72 rebase_path("//", root_build_dir), 73 ] 74 args += [ 75 "--root-gen-dir", 76 rebase_path(root_gen_dir, root_build_dir), 77 ] 78 79 wayland_scanner_label = 80 "//third_party/wayland_standard:wayland_scanner($host_toolchain)" 81 82 deps = [ wayland_scanner_label ] 83 84 args += [ 85 "--cmd", 86 "./" + rebase_path(get_label_info(wayland_scanner_label, "root_out_dir"), 87 root_build_dir) + 88 "/graphic/graphic_standard/wayland_scanner", 89 ] 90 } 91 92 # Config to include the generated headers only with the file names. 93 # e.g. #include <foo-client-protocol.h> 94 config(config_name) { 95 include_dirs = output_dirs 96 } 97 98 # Source set which consists of the generated code. 99 source_set(source_set_name) { 100 sources = get_target_outputs(":$action_name") 101 102 public_deps = [ 103 ":$action_name", 104 "//third_party/wayland_standard:wayland_util", 105 ] 106 107 public_configs = [ ":$config_name" ] 108 } 109} 110