devil_chromium.py 5.2 KB

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