-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprotoctxt.gni
73 lines (65 loc) · 2.73 KB
/
protoctxt.gni
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
# Helper file to convert text format protobuf files to binary format.
# Note: This file is similar to proto_library.gni, but is kept separate because
# - They expect different inputs/outputs: both rules would have to set default
# values for variables that are not really sensible.
# To use this rule, add a target to your gn file defining:
# protoc_proto_dir: The directory where the proto definition can be found.
# protoc_proto_def: Relative path to proto definition from |protoc_proto_dir|.
# protoc_message_name: The fully qualified name of the message contained in
# the protobuf.
# protoc_text_dir: The directory where the text format protobuf[s] can be found.
# protoc_bin_dir: The full path to the output directory. Note that this path is
# not relative to the <(SHARED_INTERMEDIATE_DIR). You must ensure that this
# directory is unique across all platform2 projects to avoid collisions. One
# way to do this is to include your project name in the directory path.
# Finally, specify the protobuf files in text format as the sources. These files
# should have a '.prototxt' file extension.
template("protoc_text_to_bin") {
action_name = "${target_name}_gen"
action_foreach(action_name) {
visibility = [ ":*" ]
forward_variables_from(invoker,
[
"protoc_bin_dir",
"protoc_message_name",
"protoc_proto_dir",
"protoc_proto_def",
"protoc_text_dir",
# Sources might be generated by actions in deps,
# which must be explicitly specified.
"deps",
])
protoc_proto_dir = rebase_path(protoc_proto_dir)
protoc_text_dir = rebase_path(protoc_text_dir)
sources = invoker.sources
script = "//common-mk/file_generator_wrapper.py"
args = [
"protoc",
"--proto_path",
"${protoc_proto_dir}",
"--encode",
"${protoc_message_name}",
"--protobuf_in",
"${protoc_text_dir}/{{source_file_part}}",
"--protobuf_out",
"${protoc_bin_dir}/{{source_name_part}}.pbf",
"${protoc_proto_dir}/${protoc_proto_def}",
]
outputs = [ "${protoc_bin_dir}/{{source_name_part}}.pbf" ]
}
source_set(target_name) {
forward_variables_from(invoker,
[
"defines",
"visibility",
])
if (defined(invoker.configs)) {
configs += invoker.configs
}
data = get_target_outputs(":${action_name}")
deps = [ ":${action_name}" ]
if (defined(invoker.deps)) {
deps += invoker.deps
}
}
}