summaryrefslogtreecommitdiffstats
path: root/chromium/chrome/android/modules/chrome_feature_module_tmpl.gni
blob: cfc20859aaf7b892fede93c520195203567bb7ac (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
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
# 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/rules.gni")
import("//build/config/locales.gni")
import("//chrome/android/modules/chrome_feature_modules.gni")

# Instantiates a Chrome-specific app bundle module.
#
# Supports most attributes of the android_app_bundle_module target, plus:
#   module_desc: Descriptor of this module. See
#     //chrome/android/modules/chrome_feature_modules.gni for the format.
#   is_monochrome_or_trichrome: (Optional) Whether this module is packaged into
#     Monochrome or Trichrome.
#   is_64_bit_browser: (Optional) Whether Chrome (as opposed to WebView) runs in
#     64 bit.
#   include_32_bit_webview: (Optional) Whether to include 32 bit code for
#     WebView.
template("chrome_feature_module") {
  assert(defined(invoker.module_desc))
  _module_desc = invoker.module_desc
  _is_monochrome_or_trichrome = defined(invoker.is_monochrome_or_trichrome) &&
                                invoker.is_monochrome_or_trichrome
  _is_64_bit_browser =
      defined(invoker.is_64_bit_browser) && invoker.is_64_bit_browser
  _include_32_bit_webview =
      defined(invoker.include_32_bit_webview) && invoker.include_32_bit_webview

  android_app_bundle_module(target_name) {
    forward_variables_from(invoker,
                           [
                             "base_module_target",
                             "manifest_package",
                             "min_sdk_version",
                             "package_id",
                             "uncompress_shared_libraries",
                             "version_code",
                             "version_name",
                           ])
    android_manifest = _module_desc.android_manifest
    target_sdk_version = android_sdk_version
    deps = []
    if (defined(_module_desc.java_deps)) {
      deps += _module_desc.java_deps
    }

    # Don't embed more translations than required (http://crbug.com/932017).
    aapt_locale_whitelist = locales

    proguard_enabled = !is_java_debug

    package_name = _module_desc.name

    _loadable_modules_32_bit = []
    _loadable_modules_64_bit = []
    if (defined(_module_desc.loadable_modules_32_bit)) {
      _loadable_modules_32_bit += _module_desc.loadable_modules_32_bit
    }
    if (defined(_module_desc.loadable_modules_64_bit)) {
      _loadable_modules_64_bit += _module_desc.loadable_modules_64_bit
    }

    if (use_native_partitions && defined(_module_desc.native_deps) &&
        _module_desc.native_deps != []) {
      _arch = ""
      _toolchain = ""
      _root_out_dir = root_out_dir
      if (android_64bit_target_cpu && _is_monochrome_or_trichrome) {
        if (_is_64_bit_browser) {
          _arch = "_64"
        } else {
          _toolchain = "($android_secondary_abi_toolchain)"
          _root_out_dir =
              get_label_info(":foo($android_secondary_abi_toolchain)",
                             "root_out_dir")
        }
      }
      if (_is_monochrome_or_trichrome) {
        _base_target_name = "libmonochrome${_arch}"
      } else {
        _base_target_name = "libchrome${_arch}"
      }
      deps += [ "//chrome/android:${_base_target_name}_${_module_desc.name}${_toolchain}" ]
      _native_library = "${_root_out_dir}/${_base_target_name}_partitions/lib${_module_desc.name}.so"

      # Pass the correct library as both the 32 and 64-bit options. Underlying
      # logic will choose from the correct variable, and supply a dummy library
      # for the other architecture if required.
      _loadable_modules_32_bit += [ _native_library ]
      _loadable_modules_64_bit += [ _native_library ]
    } else {
      not_needed([ "_is_monochrome_or_trichrome" ])
    }

    # Specify native libraries and placeholders.
    if (_loadable_modules_32_bit != [] || _loadable_modules_64_bit != []) {
      # Decision logic: Assign decision variables:
      #   _loadable_modules_to_use: Either |_loadable_modules_64_bit| or
      #     |_loadable_modules_32_bit|.
      #   _native_is_primary: Whether |_loadable_modules_to_use| should be
      #     assigned as primary ABI or secondary ABI.
      #   _native_need_placeholder: Whether a placeholder is needed for the
      #     complementary ABI to the library.
      if (_is_64_bit_browser) {
        assert(_loadable_modules_64_bit != [])
        not_needed([ "_loadable_modules_32_bit" ])
        _loadable_modules_to_use = _loadable_modules_64_bit
        _native_is_primary =
            !build_apk_secondary_abi || android_64bit_target_cpu
        _native_need_placeholder =
            build_apk_secondary_abi && _include_32_bit_webview
        not_needed([ "_include_32_bit_webview" ])
      } else {
        assert(_loadable_modules_32_bit != [])
        not_needed([
                     "_loadable_modules_64_bit",
                     "_include_32_bit_webview",
                   ])
        _loadable_modules_to_use = _loadable_modules_32_bit
        _native_is_primary =
            !build_apk_secondary_abi || !android_64bit_target_cpu
        _native_need_placeholder =
            build_apk_secondary_abi && android_64bit_target_cpu
      }

      # Realization logic: Assign libraries and placeholders.
      if (_native_is_primary) {
        loadable_modules = _loadable_modules_to_use
        if (_native_need_placeholder) {
          secondary_native_lib_placeholders = [ "libdummy.so" ]
        }
      } else {
        secondary_abi_loadable_modules = _loadable_modules_to_use
        if (_native_need_placeholder) {
          native_lib_placeholders = [ "libdummy.so" ]
        }
      }
    } else {
      not_needed([
                   "_is_64_bit_browser",
                   "_include_32_bit_webview",
                 ])
    }
  }
}