1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
# Copyright 2018 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Template to generate wayland protocol code with wayland-scanner.
#
# Generates C source and header files from XML manifest files that declare
# Wayland protocols.
#
# The invoker MUST define `sources` which is the list of XML files.
#
# The invoker MAY define `generator_type` which is one of: protocol-marshalling,
# protocol-server, protocol-client, all (default assumed if the parameter is not
# specified).
#
# Example:
# wayland_protocol("foo") {
# sources = [ "foo.xml", "bar.xml" ]
# generator_type = "protocol-client" # optional, "all" is the default
# }
template("wayland_protocol") {
assert(defined(invoker.sources), "Need sources for wayland protocol")
if (defined(invoker.generator_type)) {
assert(invoker.generator_type == "protocol-marshalling" ||
invoker.generator_type == "protocol-client" ||
invoker.generator_type == "protocol-server")
generator_type = invoker.generator_type
} else {
generator_type = "all"
}
# Calculate the output paths.
protocol_outputs = []
output_dirs = []
foreach(protocol, invoker.sources) {
dir = "$root_gen_dir/" + rebase_path(get_path_info(protocol, "dir"), "//")
name = get_path_info(protocol, "name")
if (generator_type == "protocol-marshalling") {
# If it's a protocol marshalling code, only private marshalling code will
# be generated.
protocol_outputs += [ "${dir}/${name}-protocol.c" ]
} else if (generator_type == "protocol-server") {
# In case of server protocol generation, only server headers are generated.
protocol_outputs += [
"${dir}/${name}-server-protocol-core.h",
"${dir}/${name}-server-protocol.h",
]
} else if (generator_type == "protocol-client") {
# In case of server protocol generation, only client headers are generated.
protocol_outputs += [
"${dir}/${name}-client-protocol-core.h",
"${dir}/${name}-client-protocol.h",
]
} else {
assert(generator_type == "all")
# In all the other cases(generation of protocols from
# //third_party/wayland-protocols), private source with server and client
# headers are generated.
protocol_outputs += [
"${dir}/${name}-protocol.c",
"${dir}/${name}-server-protocol.h",
"${dir}/${name}-client-protocol.h",
]
}
output_dirs += [ dir ]
}
action_name = "${target_name}_gen"
config_name = "${target_name}_config"
source_set_name = "${target_name}"
# Action which runs wayland-scanner to generate the code.
action(action_name) {
visibility = [ ":$source_set_name" ]
script = "//third_party/wayland/wayland_scanner_wrapper.py"
sources = invoker.sources
outputs = protocol_outputs
# Paths in invoker.sources are relative to the invoker.
# Make it relative to the src root.
args = rebase_path(invoker.sources, "//")
args += [
"--src-root",
rebase_path("//", root_build_dir),
]
args += [
"--root-gen-dir",
rebase_path(root_gen_dir, root_build_dir),
]
args += [
"--generator-type",
generator_type,
]
wayland_scanner_label =
"//third_party/wayland:wayland_scanner($host_toolchain)"
deps = [ wayland_scanner_label ]
wayland_scanner_path = get_label_info(wayland_scanner_label,
"root_out_dir") + "/wayland_scanner"
args += [
"--cmd",
"./" + rebase_path(wayland_scanner_path, root_build_dir),
]
sources += [ wayland_scanner_path ]
}
# Config to include the generated headers only with the file names.
# e.g. #include <foo-client-protocol.h>
config(config_name) {
include_dirs = output_dirs
}
# Source set which consists of the generated code.
source_set(source_set_name) {
sources = get_target_outputs(":$action_name")
deps = [
":$action_name",
"//third_party/wayland:wayland_util",
]
configs -= [ "//build/config/compiler:chromium_code" ]
configs += [ "//build/config/compiler:no_chromium_code" ]
public_configs = [ ":$config_name" ]
}
}
|