blob: fd138b197b8b4da61b7088bddbc40d2e3c768f9b [file] [log] [blame]
Avi Drissman73a09d12022-09-08 20:33:381# Copyright 2015 The Chromium Authors
jbudorick0c2a94a2015-12-04 14:27:432# 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
7import os
jbudorickd28554a2016-01-11 16:22:598import sys
9
Andrew Grieve4c4cede2020-11-20 22:09:3610from pylib import constants
jbudorickd28554a2016-01-11 16:22:5911from pylib.constants import host_paths
12
13if host_paths.DEVIL_PATH not in sys.path:
Andrew Grieve4c4cede2020-11-20 22:09:3614 sys.path.insert(1, host_paths.DEVIL_PATH)
jbudorick0c2a94a2015-12-04 14:27:4315
16from devil import devil_env
Nate Fischer0da4b2e2019-01-25 17:57:1417from devil.android.ndk import abis
jbudorick0c2a94a2015-12-04 14:27:4318
Andrew Grieve4c4cede2020-11-20 22:09:3619_BUILD_DIR = os.path.join(constants.DIR_SOURCE_ROOT, 'build')
20if _BUILD_DIR not in sys.path:
21 sys.path.insert(1, _BUILD_DIR)
22
23import gn_helpers
24
kjellanderd4087132016-04-12 10:58:2525_DEVIL_CONFIG = os.path.abspath(
26 os.path.join(os.path.dirname(__file__), 'devil_chromium.json'))
27
28_DEVIL_BUILD_PRODUCT_DEPS = {
Martin Kongd10fb8062025-02-27 15:27:1329 '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 Kongd10fb8062025-02-27 15:27:1358 '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 ],
kjellanderd4087132016-04-12 10:58:2597}
98
jbudorick0c2a94a2015-12-04 14:27:4399
Andrew Grieve4c4cede2020-11-20 22:09:36100def _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 Wenb51e4542021-06-30 17:42:57114 for dep_name, dep_configs in _DEVIL_BUILD_PRODUCT_DEPS.items()
Andrew Grieve4c4cede2020-11-20 22:09:36115 }
116
117
118def _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 Grievecae4f9572023-05-03 21:48:46129def Initialize(output_directory=None,
130 custom_deps=None,
131 adb_path=None,
132 use_local_devil_tools=False):
jbudorick0c2a94a2015-12-04 14:27:43133 """Initializes devil with chromium's binaries and third-party libraries.
134
135 This includes:
136 - Libraries:
137 - the android SDK ("android_sdk")
jbudorick0c2a94a2015-12-04 14:27:43138 - Build products:
139 - host & device forwarder binaries
140 ("forwarder_device" and "forwarder_host")
Martin Kongd10fb8062025-02-27 15:27:13141 - host & device devil_util binaries
142 ("devil_util_device" and "devil_util_host")
jbudorick0c2a94a2015-12-04 14:27:43143
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 Fischerdfd9812e2019-07-18 22:03:00157 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 Kongd10fb8062025-02-27 15:27:13159 use_local_devil_tools: Use locally built versions of devil_util,
Andrew Grievecae4f9572023-05-03 21:48:46160 forwarder_dist, etc.
jbudorick0c2a94a2015-12-04 14:27:43161 """
Andrew Grieve4c4cede2020-11-20 22:09:36162 build_with_chromium = _BuildWithChromium()
jbudorick0c2a94a2015-12-04 14:27:43163
kjellanderd4087132016-04-12 10:58:25164 devil_dynamic_config = {
jbudorick0c2a94a2015-12-04 14:27:43165 'config_type': 'BaseConfig',
jbudorick239245992015-12-22 22:36:24166 'dependencies': {},
167 }
Andrew Grievecae4f9572023-05-03 21:48:46168 if use_local_devil_tools:
Andrew Grieve4c4cede2020-11-20 22:09:36169 # 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
jbudorick0c2a94a2015-12-04 14:27:43174 if custom_deps:
kjellanderd4087132016-04-12 10:58:25175 devil_dynamic_config['dependencies'].update(custom_deps)
jbudorick3e0f4b22016-05-28 04:49:47176 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 })
jbudorick0c2a94a2015-12-04 14:27:43186
Andrew Grieve4c4cede2020-11-20 22:09:36187 config_files = [_DEVIL_CONFIG] if build_with_chromium else None
188 devil_env.config.Initialize(configs=[devil_dynamic_config],
189 config_files=config_files)