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 96if (defined(sanitizer_arch)) { 97 action("generate_wrap_sh") { 98 script = "generate_wrap_sh.py" 99 outputs = [ "$target_gen_dir/$target_name/wrap.sh" ] 100 args = [ 101 "--arch=$sanitizer_arch", 102 "--output", 103 rebase_path(outputs[0], root_build_dir), 104 ] 105 } 106} 107 108# TODO(go/turn-down-test-results): Remove once we turn down 109# test-results.appspot.com 110python_library("test_result_presentations_py") { 111 pydeps_file = "pylib/results/presentation/test_results_presentation.pydeps" 112 data = [ 113 "//build/android/pylib/results/presentation/template", 114 "//build/android/pylib/results/presentation/javascript/main_html.js", 115 "//third_party/catapult/third_party/gsutil/", 116 "//third_party/jinja2/debug.py", 117 "//third_party/six", 118 ] 119} 120 121python_library("devil_chromium_py") { 122 pydeps_file = "devil_chromium.pydeps" 123 data = [ 124 "devil_chromium.py", 125 "devil_chromium.json", 126 "//third_party/catapult/third_party/gsutil/", 127 "//third_party/catapult/devil/devil/devil_dependencies.json", 128 129 # Read by gn_helpers.BuildWithChromium() 130 "//build/config/gclient_args.gni", 131 ] 132} 133 134# Contains runtime deps for installing apks. 135# E.g. from test_runner.py or from apk_operations.py. 136group("apk_installer_data") { 137 # Other //build users let devil library fetch these from Google Storage. 138 if (build_with_chromium) { 139 if (is_component_build) { 140 data_deps = [ 141 "//build/android/pylib/device/commands", 142 "//tools/android/md5sum", 143 ] 144 } 145 data = [ "//third_party/android_build_tools/bundletool/bundletool.jar" ] 146 } 147} 148 149python_library("apk_operations_py") { 150 pydeps_file = "apk_operations.pydeps" 151 deps = [ ":apk_installer_data" ] 152} 153 154group("test_runner_py") { 155 testonly = true 156 deps = [ 157 ":test_runner_core_py", 158 ":test_runner_device_support", 159 ] 160} 161 162python_library("test_runner_core_py") { 163 testonly = true 164 pydeps_file = "test_runner.pydeps" 165 data = [ 166 "pylib/gtest/filter/", 167 "pylib/instrumentation/render_test.html.jinja", 168 "pylib/local/machine/local_machine_hostside_tradefed_config.xml", 169 "test_wrapper/logdog_wrapper.py", 170 "//third_party/requests/", 171 ] 172 data_deps = [ ":logdog_wrapper_py" ] 173 if (use_clang_coverage && checkout_clang_coverage_tools) { 174 # Test runner script may use `llvm-profdata` (if exists) to merge 175 # clang code coverage data after each instrumentation test to 176 # save space. The tool only exists when `checkout_clang_coverage_tools` 177 # gclient custom_var is true. 178 data += [ "${clang_base_path}/bin/llvm-profdata" ] 179 } 180} 181 182group("test_runner_device_support") { 183 testonly = true 184 185 # We hardcode using these tools from the public sdk in devil_chromium.json and 186 # in pylib's constants. 187 data = [ 188 "${public_android_sdk_build_tools}/aapt", 189 "${public_android_sdk_build_tools}/aapt2", 190 "${public_android_sdk_build_tools}/dexdump", 191 "${public_android_sdk_build_tools}/lib64/libc++.so", 192 "${public_android_sdk_build_tools}/split-select", 193 "${public_android_sdk_root}/platform-tools/adb", 194 ] 195 data_deps = [ 196 ":apk_installer_data", 197 ":devil_chromium_py", 198 ":stack_tools", 199 ] 200 201 # Other //build users let devil library fetch these from Google Storage. 202 if (build_with_chromium) { 203 if (!is_component_build) { 204 data_deps += [ "//tools/android/forwarder2" ] 205 } 206 data += [ "//tools/android/avd/proto/" ] 207 if (enable_chrome_android_internal) { 208 data += [ "//clank/tools/android/avd/proto/" ] 209 } 210 if (use_full_mte) { 211 data_deps += [ "//tools/android/mte:mte_device_setup" ] 212 } 213 } 214 215 # Proguard is needed only when using apks (rather than native executables). 216 if (enable_java_templates) { 217 data_deps += [ "//build/android/stacktrace:java_deobfuscate" ] 218 } 219} 220 221python_library("logdog_wrapper_py") { 222 pydeps_file = "test_wrapper/logdog_wrapper.pydeps" 223} 224 225python_library("resource_sizes_py") { 226 pydeps_file = "resource_sizes.pydeps" 227 data_deps = [ 228 ":devil_chromium_py", 229 "//third_party/catapult/tracing:convert_chart_json", 230 ] 231 232 data = [ 233 build_vars_file, 234 "//third_party/llvm-build/Release+Asserts/bin/llvm-readobj", 235 ] 236} 237 238# Tools necessary for symbolizing tombstones or stack traces that are output to 239# logcat. 240# Hidden behind build_with_chromium because some third party repos that use 241# //build don't pull in //third_party/android_platform. 242# TODO(crbug.com/40145789): Move stack script into //build/third_party 243# and enable unconditionally. 244group("stack_tools") { 245 if (build_with_chromium) { 246 data = [ 247 "tombstones.py", 248 "pylib/symbols/", 249 "stacktrace/", 250 ] 251 252 data_deps = 253 [ "//third_party/android_platform/development/scripts:stack_py" ] 254 } 255} 256 257# GN evaluates each .gn file once per toolchain, so restricting to default 258# toolchain will ensure write_file() is called only once. 259assert(current_toolchain == default_toolchain) 260 261# NOTE: If other platforms would benefit from exporting variables, we should 262# move this to a more top-level place. 263# It is currently here (instead of //BUILD.gn) to ensure that the file is 264# written even for non-chromium embedders of //build. 265_build_vars_json = { 266 # Underscore prefix so that it appears at the top. 267 _HEADER = "Generated during 'gn gen' by //build/android/BUILD.gn." 268 forward_variables_from(android_build_vars_json, "*") 269} 270 271write_file(build_vars_file, _build_vars_json, "json") 272