summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/build/android/resource_sizes.gni
blob: 2c91749c5ee131129e842383bc2de8df75a802fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/android/internal_rules.gni")

# Generates a script in the bin directory that runs
# //build/android/resource_sizes.py against the provided apk.
#
# Only one of apk_name or file_path should be provided.
#
# Variables:
#   apk_name: The name of the apk, without the extension.
#   file_path: The path to the apk or .minimal.apks.
#   trichrome_chrome_path: The path to chrome apk or .minimal.apks.
#   trichrome_webview_path: The path to webview apk or .minimal.apks.
#   trichrome_library_path: The path to library apk or .minimal.apks.
template("android_resource_sizes_test") {
  generate_android_wrapper(target_name) {
    forward_variables_from(invoker, [ "data_deps" ])
    executable = "//build/android/resource_sizes.py"
    wrapper_script = "$root_out_dir/bin/run_${target_name}"

    assert(defined(invoker.apk_name) != defined(invoker.file_path),
           "Exactly one of apk_name or file_path should be provided.")

    deps = [ "//build/android:resource_sizes_py" ]
    executable_args = [
      "--output-format",
      "histograms",
      "--chromium-output-directory",
      "@WrappedPath(.)",
    ]

    data = [
      "//.vpython",
      "//.vpython3",
    ]
    if (defined(invoker.trichrome_chrome_path)) {
      data += [
        invoker.trichrome_chrome_path,
        invoker.trichrome_webview_path,
        invoker.trichrome_library_path,
      ]
      _rebased_chrome =
          rebase_path(invoker.trichrome_chrome_path, root_build_dir)
      _rebased_webview =
          rebase_path(invoker.trichrome_webview_path, root_build_dir)
      _rebased_library =
          rebase_path(invoker.trichrome_library_path, root_build_dir)

      # apk_name used only as test suite name. Not a path in this case.
      executable_args += [
        "--trichrome-chrome",
        "@WrappedPath(${_rebased_chrome})",
        "--trichrome-webview",
        "@WrappedPath(${_rebased_webview})",
        "--trichrome-library",
        "@WrappedPath(${_rebased_library})",
        "${invoker.apk_name}",
      ]
    } else {
      if (defined(invoker.apk_name)) {
        _file_path = "$root_out_dir/apks/${invoker.apk_name}.apk"
        data += [ "$root_out_dir/arsc/apks/${invoker.apk_name}.ap_" ]
      } else if (defined(invoker.file_path)) {
        _file_path = invoker.file_path
      }
      data += [ _file_path ]
      _rebased_file_path = rebase_path(_file_path, root_build_dir)
      executable_args += [ "@WrappedPath(${_rebased_file_path})" ]
    }
  }
}

# Generates a "size config JSON file" to specify data to be passed from recipes
# to Python scripts for binary size measurement on bots. All filenames are
# relative to $root_build_dir. The resulting JSON file is written to
# "$root_build_dir/config/${invoker.name}_size_config.json".
#
# Variables:
#   name: The name of the path to the generated size config JSON file.
#   mapping_files: List of mapping files.
#   to_resource_sizes_py: Scope containing data to pass to resource_sizes.py,
#     processed by generate_commit_size_analysis.py.
#   supersize_input_file: Main input for SuperSize.
template("android_size_bot_config") {
  _full_target_name = get_label_info(target_name, "label_no_toolchain")
  _out_json = {
    _HEADER = "Written by build target '${_full_target_name}'"
    forward_variables_from(invoker,
                           [
                             "mapping_files",
                             "to_resource_sizes_py",
                             "supersize_input_file",
                           ])
  }
  _output_json_path = "$root_build_dir/config/${invoker.name}_size_config.json"
  write_file(_output_json_path, _out_json, "json")
}