1# Copyright 2019 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/internal_rules.gni") 6 7# Generates a script in the bin directory that runs 8# //build/android/resource_sizes.py against the provided apk. 9# 10# Only one of apk_name or file_path should be provided. 11# 12# Variables: 13# apk_name: The name of the apk, without the extension. 14# file_path: The path to the apk or .minimal.apks. 15# trichrome_chrome_path: The path to chrome apk or .minimal.apks. 16# trichrome_webview_path: The path to webview apk or .minimal.apks. 17# trichrome_library_path: The path to library apk or .minimal.apks. 18template("android_resource_sizes_test") { 19 generate_android_wrapper(target_name) { 20 forward_variables_from(invoker, [ "data_deps" ]) 21 executable = "//build/android/resource_sizes.py" 22 wrapper_script = "$root_out_dir/bin/run_${target_name}" 23 24 assert(defined(invoker.apk_name) != defined(invoker.file_path), 25 "Exactly one of apk_name or file_path should be provided.") 26 27 deps = [ "//build/android:resource_sizes_py" ] 28 executable_args = [ 29 "--output-format", 30 "histograms", 31 "--chromium-output-directory", 32 "@WrappedPath(.)", 33 ] 34 35 data = [] 36 if (defined(invoker.trichrome_chrome_path)) { 37 data += [ 38 invoker.trichrome_chrome_path, 39 invoker.trichrome_webview_path, 40 invoker.trichrome_library_path, 41 ] 42 _rebased_chrome = 43 rebase_path(invoker.trichrome_chrome_path, root_build_dir) 44 _rebased_webview = 45 rebase_path(invoker.trichrome_webview_path, root_build_dir) 46 _rebased_library = 47 rebase_path(invoker.trichrome_library_path, root_build_dir) 48 49 # apk_name used only as test suite name. Not a path in this case. 50 executable_args += [ 51 "--trichrome-chrome", 52 "@WrappedPath(${_rebased_chrome})", 53 "--trichrome-webview", 54 "@WrappedPath(${_rebased_webview})", 55 "--trichrome-library", 56 "@WrappedPath(${_rebased_library})", 57 "${invoker.apk_name}", 58 ] 59 } else { 60 if (defined(invoker.apk_name)) { 61 _file_path = "$root_out_dir/apks/${invoker.apk_name}.apk" 62 data += [ "$root_out_dir/arsc/apks/${invoker.apk_name}.ap_" ] 63 } else if (defined(invoker.file_path)) { 64 _file_path = invoker.file_path 65 } 66 data += [ _file_path ] 67 _rebased_file_path = rebase_path(_file_path, root_build_dir) 68 executable_args += [ "@WrappedPath(${_rebased_file_path})" ] 69 } 70 } 71} 72 73# Generates a "size config JSON file" to specify data to be passed from recipes 74# to Python scripts for binary size measurement on bots. All filenames are 75# relative to $root_build_dir. The resulting JSON file is written to 76# "$root_build_dir/config/${invoker.name}_size_config.json". 77# 78# Refer to tools/binary_size/generate_commit_size_analysis.py for JSON schema. 79# 80template("android_size_bot_config") { 81 _full_target_name = get_label_info(target_name, "label_no_toolchain") 82 _out_json = { 83 _HEADER = "Written by build target '${_full_target_name}'" 84 forward_variables_from(invoker, 85 [ 86 "archive_files", 87 "mapping_files", 88 "to_resource_sizes_py", 89 "to_resource_sizes_py_64", 90 "supersize_input_file", 91 ]) 92 } 93 _output_json_path = "$root_build_dir/config/${invoker.name}_size_config.json" 94 write_file(_output_json_path, _out_json, "json") 95} 96