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
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138
  139
  140
  141
  142
  143
  144
  145
  146
  147
  148
  149
  150
  151
  152
  153
  154
  155
  156
  157
  158
  159
  160
  161
  162
  163
  164
  165
  166
  167
  168
  169
  170
  171
  172
  173
  174
  175
  176
  177
  178
  179
  180
  181
  182
  183
  184
  185
  186
  187
  188
  189
  190
  191
  192
  193
  194
  195
  196
  197
  198
  199
  200
  201
  202
  203
  204
  205
  206
  207
  208
  209
  210
  211
  212
  213
  214
  215
  216
  217

chrome / android / trichrome.gni [blame]

# Copyright 2018 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/android/abi.gni")
import("//build/config/android/channel.gni")
import("//build/config/android/config.gni")
import("//build/config/android/rules.gni")
import("//chrome/android/modules/buildflags.gni")
import("//chrome/version.gni")
import("//device/vr/buildflags/buildflags.gni")

if (!defined(default_trichrome_certdigest)) {
  default_trichrome_certdigest =
      "32a2fc74d731105859e5a85df16d95f102d85b22099b8064c5d8915c61dad1e0"
}

declare_args() {
  # The package name for the Trichrome static shared library on Android.
  trichrome_library_package = "org.chromium.trichromelibrary"

  # The SHA256 certificate digest for the Trichrome static shared library on
  # Android. You can use "apksigner verify --print-certs" on the signed APK to
  # calculate the correct digest.
  trichrome_certdigest = default_trichrome_certdigest
}

trichrome_jinja_variables = [
  "trichrome_library=$trichrome_library_package",
  "trichrome_certdigest=$trichrome_certdigest",
  "zygote_preload_class=org.chromium.chrome.app.TrichromeZygotePreload",
]

template("trichrome_library_apk_tmpl") {
  _is_64_bit_browser = android_64bit_target_cpu && invoker.is_64_bit_browser
  _include_64_bit_webview =
      (!defined(invoker.include_64_bit_webview) ||
       invoker.include_64_bit_webview) && android_64bit_target_cpu
  _include_32_bit_webview =
      !defined(invoker.include_32_bit_webview) || invoker.include_32_bit_webview
  _version_code = TRICHROME_VERSION_MAP["${android_64bit_target_cpu}_${_is_64_bit_browser}_${_include_64_bit_webview}_${_include_32_bit_webview}"]

  if (defined(invoker.version_code)) {
    _version_code = invoker.version_code
  }

  # Need to apply override explicitly to have it apply to library version.
  if (android_override_version_code != "") {
    _version_code = android_override_version_code
  }

  # Include the ABI that is shared between webview & chrome.
  _include_primary_abi = !android_64bit_target_cpu || _is_64_bit_browser

  if (!_include_primary_abi) {
    _secondary_out_dir =
        get_label_info("X($android_secondary_abi_toolchain)", "root_out_dir")
  }

  if (defined(invoker.manifest_package)) {
    _manifest_package = invoker.manifest_package
  } else {
    _manifest_package = trichrome_library_package
  }
  _android_manifest = "$target_gen_dir/$target_name/AndroidManifest.xml"
  _android_manifest_target_name = "${target_name}__android_manifest"
  jinja_template(_android_manifest_target_name) {
    input = "//chrome/android/java/AndroidManifest_trichrome_library.xml"
    output = _android_manifest
    _force_32_bit = _include_32_bit_webview && _include_64_bit_webview &&
                    !_is_64_bit_browser
    variables = trichrome_jinja_variables + [
                  "force_32_bit=$_force_32_bit",
                  "manifest_package=$_manifest_package",
                  "trichrome_version=$_version_code",
                ]

    if (defined(invoker.jinja_extra_variables)) {
      variables += invoker.jinja_extra_variables
    }
  }
  android_apk(target_name) {
    android_manifest = _android_manifest
    android_manifest_dep = ":$_android_manifest_target_name"
    manifest_package = _manifest_package

    if (defined(invoker.expected_android_manifest)) {
      if (android_64bit_target_cpu) {
        _version_code_offset = chrome_32_version_code
      } else {
        _version_code_offset = chrome_version_code
      }
      expected_android_manifest_version_code_offset = _version_code_offset
      expected_android_manifest_library_version_offset = _version_code_offset
    }

    omit_dex = true
    include_size_info = is_official_build
    app_as_shared_lib = true
    version_name = chrome_version_name
    version_code = _version_code
    min_sdk_version = 29

    # Only the .build_config.json is used from this target, and it's fine if
    # it contains more assets than we need (always use the 64_32 variant).
    # https://crbug.com/357131361
    suffix_apk_assets_used_by = system_webview_apk_target

    # No support for this has been added, also not supported by test runner
    # since trichrome library is used in "additional_apks" in the trichrome
    # bundle smoke tests.
    never_incremental = true

    # TODO(torne): using icon_resources just to get a temporary icon
    deps = [
      "//android_webview/nonembedded:icon_resources",
      "//third_party/icu:icu_assets",
    ]
    if (_include_primary_abi) {
      deps += [ "//gin:v8_snapshot_assets" ]
    } else {
      deps += [ "//gin:v8_snapshot_secondary_abi_assets" ]
    }
    if (defined(invoker.deps)) {
      deps += invoker.deps
    }

    if (android_64bit_target_cpu) {
      # Include the actual browser-bitness libmonochrome library, dependencies
      # (crashpad and linker), and an opposite-bitness placeholder library to
      # ensure that the library is treated as multiarch and gets its Java code
      # precompiled for both architectures.
      if (_is_64_bit_browser) {
        shared_libraries = [ "//chrome/android:libmonochrome_64" ]
        if (_include_32_bit_webview) {
          secondary_native_lib_placeholders = [ "libplaceholder.so" ]
        }
        if (build_hwasan_splits) {
          _hwasan_toolchain =
              "//build/toolchain/android:android_clang_arm64_hwasan"
          shared_libraries +=
              [ "//chrome/android:libmonochrome_64($_hwasan_toolchain)" ]
        }
      } else {
        secondary_abi_shared_libraries =
            [ "//chrome/android:monochrome_secondary_abi_lib" ]
        if (invoker.include_64_bit_webview) {
          native_lib_placeholders = [ "libplaceholder.so" ]
        }
      }
    } else {
      shared_libraries = [ "//chrome/android:libmonochrome" ]
    }

    # https://chromium.googlesource.com/chromium/src/+/main/docs/android_native_libraries.md#Crashpad-Packaging
    loadable_modules = []
    secondary_abi_loadable_modules = []
    if (_include_primary_abi) {
      deps += [
        "//third_party/crashpad/crashpad/handler:crashpad_handler_trampoline",
      ]
      loadable_modules += [ "$root_out_dir/libcrashpad_handler_trampoline.so" ]
    } else {
      deps += [ "//third_party/crashpad/crashpad/handler:crashpad_handler_trampoline($android_secondary_abi_toolchain)" ]
      secondary_abi_loadable_modules +=
          [ "$_secondary_out_dir/libcrashpad_handler_trampoline.so" ]
    }

    if (enable_arcore) {
      _arcore_target = "//third_party/arcore-android-sdk-client:com_google_ar_core_J__unpack_aar"
      _libarcore_dir = get_label_info(_arcore_target, "target_out_dir") +
                       "/com_google_ar_core_java/jni"
      deps += [ _arcore_target ]

      # Secondary ABI is stored in webview when enabled.
      if (_include_primary_abi) {
        loadable_modules +=
            [ "$_libarcore_dir/$android_app_abi/libarcore_sdk_c.so" ]
      } else {
        secondary_abi_loadable_modules +=
            [ "$_libarcore_dir/$android_app_secondary_abi/libarcore_sdk_c.so" ]
      }
    }
    forward_variables_from(invoker,
                           "*",
                           TESTONLY_AND_VISIBILITY + [
                                 "deps",
                                 "include_64_bit_webview",
                                 "include_32_bit_webview",
                                 "is_64_bit_browser",
                               ])
    forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
  }
}

# An .ssargs file is a text file to specify multiple input files with respective
# parameters, and is used by SuperSize-archive to create multi-container .size
# files. This is used to support SuperSize on Trichrome.
template("write_ssargs_trichrome") {
  _extra_args = " --abi-filter ${invoker.abi_filter}"
  if (defined(invoker.symbols_dir)) {
    _extra_args += " --symbols-dir ${invoker.symbols_dir}"
  }

  # Base names (i.e., no full path) are used because .ssargs files specifies
  # files using paths relative to itself. It is expected for |ssargs_path| to
  # be in the same directory as all Trichrome files whose sizes are measured
  # by SuperSize.
  _lines = [
    "# Written by build target \"${target_name}.\"",
    "Library -f ${invoker.trichrome_library_basename}$_extra_args --no-java",
    "Chrome -f ${invoker.trichrome_chrome_basename}$_extra_args",
    "WebView -f ${invoker.trichrome_webview_basename}$_extra_args",
  ]

  write_file(invoker.ssargs_path, _lines)
}