Avi Drissman | 73a09d1 | 2022-09-08 20:33:38 | [diff] [blame] | 1 | # Copyright 2015 The Chromium Authors |
jbudorick | 0c2a94a | 2015-12-04 14:27:43 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """Configures devil for use in chromium.""" |
| 6 | |
| 7 | import os |
jbudorick | d28554a | 2016-01-11 16:22:59 | [diff] [blame] | 8 | import sys |
| 9 | |
Andrew Grieve | 4c4cede | 2020-11-20 22:09:36 | [diff] [blame] | 10 | from pylib import constants |
jbudorick | d28554a | 2016-01-11 16:22:59 | [diff] [blame] | 11 | from pylib.constants import host_paths |
| 12 | |
| 13 | if host_paths.DEVIL_PATH not in sys.path: |
Andrew Grieve | 4c4cede | 2020-11-20 22:09:36 | [diff] [blame] | 14 | sys.path.insert(1, host_paths.DEVIL_PATH) |
jbudorick | 0c2a94a | 2015-12-04 14:27:43 | [diff] [blame] | 15 | |
| 16 | from devil import devil_env |
Nate Fischer | 0da4b2e | 2019-01-25 17:57:14 | [diff] [blame] | 17 | from devil.android.ndk import abis |
jbudorick | 0c2a94a | 2015-12-04 14:27:43 | [diff] [blame] | 18 | |
Andrew Grieve | 4c4cede | 2020-11-20 22:09:36 | [diff] [blame] | 19 | _BUILD_DIR = os.path.join(constants.DIR_SOURCE_ROOT, 'build') |
| 20 | if _BUILD_DIR not in sys.path: |
| 21 | sys.path.insert(1, _BUILD_DIR) |
| 22 | |
| 23 | import gn_helpers |
| 24 | |
kjellander | d408713 | 2016-04-12 10:58:25 | [diff] [blame] | 25 | _DEVIL_CONFIG = os.path.abspath( |
| 26 | os.path.join(os.path.dirname(__file__), 'devil_chromium.json')) |
| 27 | |
| 28 | _DEVIL_BUILD_PRODUCT_DEPS = { |
Martin Kong | d10fb806 | 2025-02-27 15:27:13 | [diff] [blame] | 29 | 'devil_util_device': [ |
| 30 | { |
| 31 | 'platform': 'android', |
| 32 | 'arch': abis.ARM, |
| 33 | 'path_components': ['devil_util_dist'], |
| 34 | }, |
| 35 | { |
| 36 | 'platform': 'android', |
| 37 | 'arch': abis.ARM_64, |
| 38 | 'path_components': ['devil_util_dist'], |
| 39 | }, |
| 40 | { |
| 41 | 'platform': 'android', |
| 42 | 'arch': abis.X86, |
| 43 | 'path_components': ['devil_util_dist'], |
| 44 | }, |
| 45 | { |
| 46 | 'platform': 'android', |
| 47 | 'arch': abis.X86_64, |
| 48 | 'path_components': ['devil_util_dist'], |
| 49 | }, |
| 50 | ], |
| 51 | 'devil_util_host': [ |
| 52 | { |
| 53 | 'platform': 'linux2', |
| 54 | 'arch': 'x86_64', |
| 55 | 'path_components': ['devil_util_host'], |
| 56 | }, |
| 57 | ], |
Martin Kong | d10fb806 | 2025-02-27 15:27:13 | [diff] [blame] | 58 | 'forwarder_device': [ |
| 59 | { |
| 60 | 'platform': 'android', |
| 61 | 'arch': abis.ARM, |
| 62 | 'path_components': ['forwarder_dist'], |
| 63 | }, |
| 64 | { |
| 65 | 'platform': 'android', |
| 66 | 'arch': abis.ARM_64, |
| 67 | 'path_components': ['forwarder_dist'], |
| 68 | }, |
| 69 | { |
| 70 | 'platform': 'android', |
| 71 | 'arch': 'mips', |
| 72 | 'path_components': ['forwarder_dist'], |
| 73 | }, |
| 74 | { |
| 75 | 'platform': 'android', |
| 76 | 'arch': 'mips64', |
| 77 | 'path_components': ['forwarder_dist'], |
| 78 | }, |
| 79 | { |
| 80 | 'platform': 'android', |
| 81 | 'arch': abis.X86, |
| 82 | 'path_components': ['forwarder_dist'], |
| 83 | }, |
| 84 | { |
| 85 | 'platform': 'android', |
| 86 | 'arch': abis.X86_64, |
| 87 | 'path_components': ['forwarder_dist'], |
| 88 | }, |
| 89 | ], |
| 90 | 'forwarder_host': [ |
| 91 | { |
| 92 | 'platform': 'linux2', |
| 93 | 'arch': 'x86_64', |
| 94 | 'path_components': ['host_forwarder'], |
| 95 | }, |
| 96 | ], |
kjellander | d408713 | 2016-04-12 10:58:25 | [diff] [blame] | 97 | } |
| 98 | |
jbudorick | 0c2a94a | 2015-12-04 14:27:43 | [diff] [blame] | 99 | |
Andrew Grieve | 4c4cede | 2020-11-20 22:09:36 | [diff] [blame] | 100 | def _UseLocalBuildProducts(output_directory, devil_dynamic_config): |
| 101 | output_directory = os.path.abspath(output_directory) |
| 102 | devil_dynamic_config['dependencies'] = { |
| 103 | dep_name: { |
| 104 | 'file_info': { |
| 105 | '%s_%s' % (dep_config['platform'], dep_config['arch']): { |
| 106 | 'local_paths': [ |
| 107 | os.path.join(output_directory, |
| 108 | *dep_config['path_components']), |
| 109 | ], |
| 110 | } |
| 111 | for dep_config in dep_configs |
| 112 | } |
| 113 | } |
Peter Wen | b51e454 | 2021-06-30 17:42:57 | [diff] [blame] | 114 | for dep_name, dep_configs in _DEVIL_BUILD_PRODUCT_DEPS.items() |
Andrew Grieve | 4c4cede | 2020-11-20 22:09:36 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | |
| 118 | def _BuildWithChromium(): |
| 119 | """Returns value of gclient's |build_with_chromium|.""" |
| 120 | gni_path = os.path.join(_BUILD_DIR, 'config', 'gclient_args.gni') |
| 121 | if not os.path.exists(gni_path): |
| 122 | return False |
| 123 | with open(gni_path) as f: |
| 124 | data = f.read() |
| 125 | args = gn_helpers.FromGNArgs(data) |
| 126 | return args.get('build_with_chromium', False) |
| 127 | |
| 128 | |
Andrew Grieve | cae4f957 | 2023-05-03 21:48:46 | [diff] [blame] | 129 | def Initialize(output_directory=None, |
| 130 | custom_deps=None, |
| 131 | adb_path=None, |
| 132 | use_local_devil_tools=False): |
jbudorick | 0c2a94a | 2015-12-04 14:27:43 | [diff] [blame] | 133 | """Initializes devil with chromium's binaries and third-party libraries. |
| 134 | |
| 135 | This includes: |
| 136 | - Libraries: |
| 137 | - the android SDK ("android_sdk") |
jbudorick | 0c2a94a | 2015-12-04 14:27:43 | [diff] [blame] | 138 | - Build products: |
| 139 | - host & device forwarder binaries |
| 140 | ("forwarder_device" and "forwarder_host") |
Martin Kong | d10fb806 | 2025-02-27 15:27:13 | [diff] [blame] | 141 | - host & device devil_util binaries |
| 142 | ("devil_util_device" and "devil_util_host") |
jbudorick | 0c2a94a | 2015-12-04 14:27:43 | [diff] [blame] | 143 | |
| 144 | Args: |
| 145 | output_directory: An optional path to the output directory. If not set, |
| 146 | no built dependencies are configured. |
| 147 | custom_deps: An optional dictionary specifying custom dependencies. |
| 148 | This should be of the form: |
| 149 | |
| 150 | { |
| 151 | 'dependency_name': { |
| 152 | 'platform': 'path', |
| 153 | ... |
| 154 | }, |
| 155 | ... |
| 156 | } |
Nate Fischer | dfd9812e | 2019-07-18 22:03:00 | [diff] [blame] | 157 | adb_path: An optional path to use for the adb binary. If not set, this uses |
| 158 | the adb binary provided by the Android SDK. |
Martin Kong | d10fb806 | 2025-02-27 15:27:13 | [diff] [blame] | 159 | use_local_devil_tools: Use locally built versions of devil_util, |
Andrew Grieve | cae4f957 | 2023-05-03 21:48:46 | [diff] [blame] | 160 | forwarder_dist, etc. |
jbudorick | 0c2a94a | 2015-12-04 14:27:43 | [diff] [blame] | 161 | """ |
Andrew Grieve | 4c4cede | 2020-11-20 22:09:36 | [diff] [blame] | 162 | build_with_chromium = _BuildWithChromium() |
jbudorick | 0c2a94a | 2015-12-04 14:27:43 | [diff] [blame] | 163 | |
kjellander | d408713 | 2016-04-12 10:58:25 | [diff] [blame] | 164 | devil_dynamic_config = { |
jbudorick | 0c2a94a | 2015-12-04 14:27:43 | [diff] [blame] | 165 | 'config_type': 'BaseConfig', |
jbudorick | 23924599 | 2015-12-22 22:36:24 | [diff] [blame] | 166 | 'dependencies': {}, |
| 167 | } |
Andrew Grieve | cae4f957 | 2023-05-03 21:48:46 | [diff] [blame] | 168 | if use_local_devil_tools: |
Andrew Grieve | 4c4cede | 2020-11-20 22:09:36 | [diff] [blame] | 169 | # Non-chromium users of chromium's //build directory fetch build products |
| 170 | # from google storage rather than use locally built copies. Chromium uses |
| 171 | # locally-built copies so that changes to the tools can be easily tested. |
| 172 | _UseLocalBuildProducts(output_directory, devil_dynamic_config) |
| 173 | |
jbudorick | 0c2a94a | 2015-12-04 14:27:43 | [diff] [blame] | 174 | if custom_deps: |
kjellander | d408713 | 2016-04-12 10:58:25 | [diff] [blame] | 175 | devil_dynamic_config['dependencies'].update(custom_deps) |
jbudorick | 3e0f4b2 | 2016-05-28 04:49:47 | [diff] [blame] | 176 | if adb_path: |
| 177 | devil_dynamic_config['dependencies'].update({ |
| 178 | 'adb': { |
| 179 | 'file_info': { |
| 180 | devil_env.GetPlatform(): { |
| 181 | 'local_paths': [adb_path] |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | }) |
jbudorick | 0c2a94a | 2015-12-04 14:27:43 | [diff] [blame] | 186 | |
Andrew Grieve | 4c4cede | 2020-11-20 22:09:36 | [diff] [blame] | 187 | config_files = [_DEVIL_CONFIG] if build_with_chromium else None |
| 188 | devil_env.config.Initialize(configs=[devil_dynamic_config], |
| 189 | config_files=config_files) |