xref: /aosp_15_r20/external/perfetto/gn/perfetto_cc_proto_descriptor.gni (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1# Copyright (C) 2021 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import("perfetto.gni")
16
17template("perfetto_cc_proto_descriptor") {
18  is_target = defined(invoker.descriptor_target)
19  is_path = defined(invoker.descriptor_path)
20
21  # You must define exactly one of:
22  # descriptor_target
23  # descriptor_path
24  assert((is_target || is_path) && !(is_target && is_path))
25
26  config("${target_name}_config") {
27    include_dirs = [ "${root_gen_dir}/${perfetto_root_path}" ]
28  }
29
30  action(target_name) {
31    generated_header = "${target_gen_dir}/${invoker.descriptor_name}.h"
32    if (is_target) {
33      descriptor_file_path =
34          get_label_info(invoker.descriptor_target, "target_gen_dir") +
35          "/${invoker.descriptor_name}"
36      deps = [ invoker.descriptor_target ]
37    } else {
38      descriptor_file_path = invoker.descriptor_path
39      deps = []
40    }
41
42    script = "$perfetto_root_path/tools/gen_cc_proto_descriptor.py"
43    args = [
44      "--gen_dir",
45      rebase_path(root_gen_dir, root_build_dir),
46      "--cpp_out",
47      rebase_path(generated_header, root_build_dir),
48    ]
49    if (defined(invoker.namespace)) {
50      args += [
51        "--namespace",
52        invoker.namespace,
53      ]
54    }
55    args += [
56      rebase_path(descriptor_file_path, root_build_dir),
57    ]
58    inputs = [ descriptor_file_path ]
59    outputs = [ generated_header ]
60    public_configs = [ ":${target_name}_config" ]
61    metadata = {
62      perfetto_action_type_for_generator = [ "cc_proto_descriptor" ]
63    }
64  }
65}
66