Kaido Kert | 5ac52c4 | 2021-05-14 12:23:37 -0700 | [diff] [blame] | 1 | # Copyright 2019 The Chromium Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | import("//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. |
| 18 | template("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 | "//.vpython", |
| 37 | "//.vpython3", |
| 38 | ] |
| 39 | if (defined(invoker.trichrome_chrome_path)) { |
| 40 | data += [ |
| 41 | invoker.trichrome_chrome_path, |
| 42 | invoker.trichrome_webview_path, |
| 43 | invoker.trichrome_library_path, |
| 44 | ] |
| 45 | _rebased_chrome = |
| 46 | rebase_path(invoker.trichrome_chrome_path, root_build_dir) |
| 47 | _rebased_webview = |
| 48 | rebase_path(invoker.trichrome_webview_path, root_build_dir) |
| 49 | _rebased_library = |
| 50 | rebase_path(invoker.trichrome_library_path, root_build_dir) |
| 51 | |
| 52 | # apk_name used only as test suite name. Not a path in this case. |
| 53 | executable_args += [ |
| 54 | "--trichrome-chrome", |
| 55 | "@WrappedPath(${_rebased_chrome})", |
| 56 | "--trichrome-webview", |
| 57 | "@WrappedPath(${_rebased_webview})", |
| 58 | "--trichrome-library", |
| 59 | "@WrappedPath(${_rebased_library})", |
| 60 | "${invoker.apk_name}", |
| 61 | ] |
| 62 | } else { |
| 63 | if (defined(invoker.apk_name)) { |
| 64 | _file_path = "$root_out_dir/apks/${invoker.apk_name}.apk" |
| 65 | data += [ "$root_out_dir/arsc/apks/${invoker.apk_name}.ap_" ] |
| 66 | } else if (defined(invoker.file_path)) { |
| 67 | _file_path = invoker.file_path |
| 68 | } |
| 69 | data += [ _file_path ] |
| 70 | _rebased_file_path = rebase_path(_file_path, root_build_dir) |
| 71 | executable_args += [ "@WrappedPath(${_rebased_file_path})" ] |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | # Generates a "size config JSON file" to specify data to be passed from recipes |
| 77 | # to Python scripts for binary size measurement on bots. All filenames are |
| 78 | # relative to $root_build_dir. The resulting JSON file is written to |
| 79 | # "$root_build_dir/config/${invoker.name}_size_config.json". |
| 80 | # |
| 81 | # Variables: |
| 82 | # name: The name of the path to the generated size config JSON file. |
| 83 | # mapping_files: List of mapping files. |
| 84 | # to_resource_sizes_py: Scope containing data to pass to resource_sizes.py, |
| 85 | # processed by generate_commit_size_analysis.py. |
| 86 | # supersize_input_file: Main input for SuperSize. |
| 87 | template("android_size_bot_config") { |
| 88 | _full_target_name = get_label_info(target_name, "label_no_toolchain") |
| 89 | _out_json = { |
| 90 | _HEADER = "Written by build target '${_full_target_name}'" |
| 91 | forward_variables_from(invoker, |
| 92 | [ |
| 93 | "mapping_files", |
| 94 | "to_resource_sizes_py", |
| 95 | "supersize_input_file", |
| 96 | ]) |
| 97 | } |
| 98 | _output_json_path = "$root_build_dir/config/${invoker.name}_size_config.json" |
| 99 | write_file(_output_json_path, _out_json, "json") |
| 100 | } |