xref: /aosp_15_r20/external/cronet/build/android/BUILD.gn (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1# Copyright 2014 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import("//build/config/android/build_vars.gni")
6import("//build/config/android/config.gni")
7import("//build/config/android/rules.gni")
8import("//build/config/clang/clang.gni")
9import("//build/config/coverage/coverage.gni")
10import("//build/config/gclient_args.gni")
11import("//build/config/python.gni")
12import("//build_overrides/build.gni")
13
14if (build_with_chromium) {
15  import("//base/allocator/partition_allocator/partition_alloc.gni")
16}
17
18if (enable_java_templates) {
19  # Create or update the API versions cache if necessary by running a
20  # functionally empty lint task. This prevents racy creation of the
21  # cache while linting java targets in android_lint.
22  android_lint("prepare_android_lint_cache") {
23    create_cache = true
24  }
25
26  generate_build_config_srcjar("build_config_gen") {
27    use_final_fields = false
28  }
29
30  generate_build_config_srcjar("build_config_for_testing_gen") {
31    use_final_fields = false
32    testonly = true
33  }
34
35  write_native_libraries_java("native_libraries_gen") {
36    use_final_fields = false
37  }
38
39  java_library("build_java") {
40    supports_android = true
41    srcjar_deps = [
42      ":build_config_gen",
43      ":native_libraries_gen",
44    ]
45    sources = [
46      "java/src/org/chromium/build/annotations/AlwaysInline.java",
47      "java/src/org/chromium/build/annotations/AssumeNonNull.java",
48      "java/src/org/chromium/build/annotations/CheckDiscard.java",
49      "java/src/org/chromium/build/annotations/DoNotClassMerge.java",
50      "java/src/org/chromium/build/annotations/DoNotInline.java",
51      "java/src/org/chromium/build/annotations/DoNotStripLogs.java",
52      "java/src/org/chromium/build/annotations/IdentifierNameString.java",
53      "java/src/org/chromium/build/annotations/MockedInTests.java",
54      "java/src/org/chromium/build/annotations/UsedByReflection.java",
55    ]
56
57    jar_excluded_patterns = [ "*/build/BuildConfig.class" ]
58
59    # New version of NativeLibraries.java (with the actual correct values) will
60    # be created when creating an apk.
61    jar_excluded_patterns += [ "*/NativeLibraries.class" ]
62
63    proguard_configs = [ "chromium_annotations.flags" ]
64  }
65
66  # Not all //build embedders pull in junit_binary deps that live in //third_party.
67  if (build_with_chromium) {
68    android_assets("junit_test_assets") {
69      testonly = true
70
71      # We just need any file here, so use the test itself.
72      sources = [ "junit/src/org/chromium/build/AndroidAssetsTest.java" ]
73    }
74    android_resources("junit_test_resources") {
75      testonly = true
76      sources = [ "junit/res/values/strings.xml" ]
77      mergeable_android_manifests = [ "junit/AndroidManifest_mergetest.xml" ]
78    }
79    robolectric_binary("build_junit_tests") {
80      # Test has no JNI, so skip JNI Generator step.
81      resources_package = "org.chromium.build"
82      sources = [
83        "junit/src/org/chromium/build/AndroidAssetsTest.java",
84        "junit/src/org/chromium/build/IncrementalJavacTest.java",
85      ]
86      deps = [
87        ":junit_test_assets",
88        ":junit_test_resources",
89        "//build/android/test/incremental_javac_gn:no_signature_change_prebuilt_java",
90        "//third_party/junit",
91      ]
92    }
93  }
94}
95
96# TODO(go/turn-down-test-results): Remove once we turn down
97# test-results.appspot.com
98python_library("test_result_presentations_py") {
99  pydeps_file = "pylib/results/presentation/test_results_presentation.pydeps"
100  data = [
101    "//build/android/pylib/results/presentation/template",
102    "//build/android/pylib/results/presentation/javascript/main_html.js",
103    "//third_party/catapult/third_party/gsutil/",
104    "//third_party/jinja2/debug.py",
105    "//third_party/six",
106  ]
107}
108
109python_library("devil_chromium_py") {
110  pydeps_file = "devil_chromium.pydeps"
111  data = [
112    "devil_chromium.py",
113    "devil_chromium.json",
114    "//third_party/catapult/third_party/gsutil/",
115    "//third_party/catapult/devil/devil/devil_dependencies.json",
116
117    # Read by gn_helpers.BuildWithChromium()
118    "//build/config/gclient_args.gni",
119  ]
120}
121
122# Contains runtime deps for installing apks.
123# E.g. from test_runner.py or from apk_operations.py.
124group("apk_installer_data") {
125  # Other //build users let devil library fetch these from Google Storage.
126  if (build_with_chromium) {
127    if (is_component_build) {
128      data_deps = [
129        "//build/android/pylib/device/commands",
130        "//tools/android/md5sum",
131      ]
132    }
133    data = [ "//third_party/android_build_tools/bundletool/bundletool.jar" ]
134  }
135}
136
137python_library("apk_operations_py") {
138  pydeps_file = "apk_operations.pydeps"
139  deps = [ ":apk_installer_data" ]
140}
141
142group("test_runner_py") {
143  testonly = true
144  deps = [
145    ":test_runner_core_py",
146    ":test_runner_device_support",
147  ]
148}
149
150python_library("test_runner_core_py") {
151  testonly = true
152  pydeps_file = "test_runner.pydeps"
153  data = [
154    "pylib/gtest/filter/",
155    "pylib/instrumentation/render_test.html.jinja",
156    "pylib/local/machine/local_machine_hostside_tradefed_config.xml",
157    "test_wrapper/logdog_wrapper.py",
158    "//third_party/requests/",
159  ]
160  data_deps = [ ":logdog_wrapper_py" ]
161  if (use_clang_coverage && checkout_clang_coverage_tools) {
162    # Test runner script may use `llvm-profdata` (if exists) to merge
163    # clang code coverage data after each instrumentation test to
164    # save space. The tool only exists when `checkout_clang_coverage_tools`
165    # gclient custom_var is true.
166    data += [ "${clang_base_path}/bin/llvm-profdata" ]
167  }
168}
169
170group("test_runner_device_support") {
171  testonly = true
172
173  # We hardcode using these tools from the public sdk in devil_chromium.json and
174  # in pylib's constants.
175  data = [
176    "${public_android_sdk_build_tools}/aapt",
177    "${public_android_sdk_build_tools}/aapt2",
178    "${public_android_sdk_build_tools}/dexdump",
179    "${public_android_sdk_build_tools}/lib64/libc++.so",
180    "${public_android_sdk_build_tools}/split-select",
181    "${public_android_sdk_root}/platform-tools/adb",
182  ]
183  data_deps = [
184    ":apk_installer_data",
185    ":devil_chromium_py",
186    ":stack_tools",
187  ]
188
189  # Other //build users let devil library fetch these from Google Storage.
190  if (build_with_chromium) {
191    if (!is_component_build) {
192      data_deps += [ "//tools/android/forwarder2" ]
193    }
194    data += [ "//tools/android/avd/proto/" ]
195    if (enable_chrome_android_internal) {
196      data += [ "//clank/tools/android/avd/proto/" ]
197    }
198    if (is_asan) {
199      data_deps += [ "//tools/android/asan/third_party:asan_device_setup" ]
200    }
201    if (use_full_mte) {
202      data_deps += [ "//tools/android/mte:mte_device_setup" ]
203    }
204  }
205
206  # Proguard is needed only when using apks (rather than native executables).
207  if (enable_java_templates) {
208    data_deps += [ "//build/android/stacktrace:java_deobfuscate" ]
209  }
210}
211
212python_library("logdog_wrapper_py") {
213  pydeps_file = "test_wrapper/logdog_wrapper.pydeps"
214}
215
216python_library("resource_sizes_py") {
217  pydeps_file = "resource_sizes.pydeps"
218  data_deps = [
219    ":devil_chromium_py",
220    "//third_party/catapult/tracing:convert_chart_json",
221  ]
222
223  data = [
224    build_vars_file,
225    "//third_party/llvm-build/Release+Asserts/bin/llvm-readobj",
226  ]
227}
228
229# Tools necessary for symbolizing tombstones or stack traces that are output to
230# logcat.
231# Hidden behind build_with_chromium because some third party repos that use
232# //build don't pull in //third_party/android_platform.
233# TODO(crbug.com/1120190): Move stack script into //build/third_party
234#     and enable unconditionally.
235group("stack_tools") {
236  if (build_with_chromium) {
237    data = [
238      "tombstones.py",
239      "pylib/symbols/",
240      "stacktrace/",
241    ]
242
243    data_deps =
244        [ "//third_party/android_platform/development/scripts:stack_py" ]
245  }
246}
247
248# GN evaluates each .gn file once per toolchain, so restricting to default
249# toolchain will ensure write_file() is called only once.
250assert(current_toolchain == default_toolchain)
251
252# NOTE: If other platforms would benefit from exporting variables, we should
253# move this to a more top-level place.
254# It is currently here (instead of //BUILD.gn) to ensure that the file is
255# written even for non-chromium embedders of //build.
256_build_vars_json = {
257  # Underscore prefix so that it appears at the top.
258  _HEADER = "Generated during 'gn gen' by //build/android/BUILD.gn."
259  forward_variables_from(android_build_vars_json, "*")
260}
261
262write_file(build_vars_file, _build_vars_json, "json")
263