• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (C) 2025 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
17# Actions defined in this file are used to generate Android.bp and Bazel
18# targets, they don't produce any output during the GN build process.
19
20template("perfetto_android_jni_library") {
21  _vars_to_forward = [
22    "sources",
23    "deps",
24    "binary_name",
25    "bazel_linkopts",
26    "testonly",
27    "visibility",
28  ]
29  shared_library(target_name) {
30    forward_variables_from(invoker, _vars_to_forward)
31    metadata = {
32      perfetto_custom_target_type = [ "perfetto_android_jni_library" ]
33      perfetto_argument_binary_name = [ binary_name ]
34      perfetto_bazel_argument_linkopts = [ bazel_linkopts ]
35    }
36  }
37}
38
39template("perfetto_android_library") {
40  _vars_to_forward = [
41    "sources",
42    "deps",
43    "manifest",
44    "testonly",
45    "visibility",
46  ]
47  action(target_name) {
48    forward_variables_from(invoker, _vars_to_forward)
49    out_file_name = target_name + "_stub.txt"
50    out_path = "$target_gen_dir/" + out_file_name
51    rebased_out_path =
52        rebase_path(target_gen_dir, root_build_dir) + "/" + out_file_name
53    script = "$perfetto_root_path/tools/touch_file.py"
54    args = [
55      "--output",
56      rebased_out_path,
57    ]
58    outputs = [ out_path ]
59    metadata = {
60      perfetto_action_type_for_generator = [ "perfetto_android_library" ]
61      if (defined(manifest)) {
62        perfetto_android_manifest = [ get_path_info(manifest, "abspath") ]
63      }
64    }
65  }
66}
67
68template("perfetto_android_app") {
69  _vars_to_forward = [
70    "sources",
71    "deps",
72    "manifest",
73    "resource_files_glob",
74    "testonly",
75    "visibility",
76  ]
77  action(target_name) {
78    forward_variables_from(invoker, _vars_to_forward)
79    out_file_name = target_name + "_stub.txt"
80    out_path = "$target_gen_dir/" + out_file_name
81    rebased_out_path =
82        rebase_path(target_gen_dir, root_build_dir) + "/" + out_file_name
83    script = "$perfetto_root_path/tools/touch_file.py"
84    args = [
85      "--output",
86      rebased_out_path,
87    ]
88    outputs = [ out_path ]
89    metadata = {
90      perfetto_action_type_for_generator = [ "perfetto_android_app" ]
91      perfetto_android_manifest = [ get_path_info(manifest, "abspath") ]
92      if (defined(resource_files_glob)) {
93        perfetto_android_resource_files_glob =
94            [ get_path_info(resource_files_glob, "abspath") ]
95      }
96    }
97  }
98}
99
100template("perfetto_android_instrumentation_test") {
101  _vars_to_forward = [
102    "app",
103    "test_app",
104    "android_bp_test_manifest",
105    "android_bp_test_config",
106    "testonly",
107    "visibility",
108  ]
109  action(target_name) {
110    forward_variables_from(invoker, _vars_to_forward)
111    out_file_name = target_name + "_stub.txt"
112    out_path = "$target_gen_dir/" + out_file_name
113    rebased_out_path =
114        rebase_path(target_gen_dir, root_build_dir) + "/" + out_file_name
115    script = "$perfetto_root_path/tools/touch_file.py"
116    args = [
117      "--output",
118      rebased_out_path,
119    ]
120
121    # Build generators ignore this 'deps' variable and read metada instead.
122    # We create this variable to tell GN that this test depends on two android
123    # app targets and to maintain build graph connectivity.
124    deps = [
125      app,
126      test_app,
127    ]
128    outputs = [ out_path ]
129    metadata = {
130      perfetto_action_type_for_generator =
131          [ "perfetto_android_instrumentation_test" ]
132      perfetto_android_a_i_t_app = [ get_label_info(app, "label_no_toolchain") ]
133      perfetto_android_a_i_t_test_app =
134          [ get_label_info(test_app, "label_no_toolchain") ]
135      if (defined(android_bp_test_manifest)) {
136        perfetto_android_a_i_t_android_bp_test_manifest =
137            [ get_path_info(android_bp_test_manifest, "abspath") ]
138      }
139      if (defined(android_bp_test_config)) {
140        perfetto_android_a_i_t_android_bp_test_config =
141            [ get_path_info(android_bp_test_config, "abspath") ]
142      }
143    }
144  }
145}
146