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