diff options
author | jbudorick <jbudorick@chromium.org> | 2016-01-11 08:22:59 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-01-11 16:23:48 +0000 |
commit | d28554a567ddb871196a9268c1d76d8a0061370b (patch) | |
tree | 60458b3bb1976ca39f38720faaef6ecce729c704 /build | |
parent | f211b743e659391cf5b674dfe2ea29f6b0fe2b29 (diff) | |
download | chromium_src-d28554a567ddb871196a9268c1d76d8a0061370b.zip chromium_src-d28554a567ddb871196a9268c1d76d8a0061370b.tar.gz chromium_src-d28554a567ddb871196a9268c1d76d8a0061370b.tar.bz2 |
[Android] Prepare build/android/ for catapult+devil.
BUG=476719
Review URL: https://codereview.chromium.org/1571803002
Cr-Commit-Position: refs/heads/master@{#368599}
Diffstat (limited to 'build')
58 files changed, 281 insertions, 225 deletions
diff --git a/build/android/adb_command_line.py b/build/android/adb_command_line.py index ee2c4f9..57882fb 100755 --- a/build/android/adb_command_line.py +++ b/build/android/adb_command_line.py @@ -9,6 +9,7 @@ import argparse import sys import devil_chromium + from devil.android import device_utils from devil.android import device_errors from devil.utils import cmd_helper diff --git a/build/android/adb_reverse_forwarder.py b/build/android/adb_reverse_forwarder.py index 141fca7..d3da6fe 100755 --- a/build/android/adb_reverse_forwarder.py +++ b/build/android/adb_reverse_forwarder.py @@ -16,11 +16,14 @@ import optparse import sys import time +import devil_chromium + from devil.android import device_blacklist from devil.android import device_errors from devil.android import device_utils from devil.android import forwarder from devil.utils import run_tests_helper + from pylib import constants @@ -44,6 +47,8 @@ def main(argv): options, args = parser.parse_args(argv) run_tests_helper.SetLogLevel(options.verbose_count) + devil_chromium.Initialize() + if len(args) < 2 or not len(args) % 2: parser.error('Need even number of port pairs') sys.exit(1) diff --git a/build/android/android.isolate b/build/android/android.isolate index f58d03c..8ffdc58 100644 --- a/build/android/android.isolate +++ b/build/android/android.isolate @@ -8,6 +8,7 @@ '../../third_party/android_tools/sdk/build-tools/', '../../third_party/android_tools/sdk/platform-tools/', '../../third_party/appurify-python/', + '../../third_party/catapult/', '../../third_party/requests/', '../../tools/swarming_client/', '../../tools/telemetry/catapult_base/', diff --git a/build/android/asan_symbolize.py b/build/android/asan_symbolize.py index 0aa1ab8..04dba57 100755 --- a/build/android/asan_symbolize.py +++ b/build/android/asan_symbolize.py @@ -11,13 +11,13 @@ import os import re import sys -from pylib import constants +from pylib.constants import host_paths # Uses symbol.py from third_party/android_platform, not python's. -sys.path.insert(0, - os.path.join(constants.DIR_SOURCE_ROOT, - 'third_party/android_platform/development/scripts')) -import symbol +with host_paths.SysPath( + host_paths.ANDROID_PLATFORM_DEVELOPMENT_SCRIPTS_PATH, + position=0): + import symbol _RE_ASAN = re.compile(r'(.*?)(#\S*?) (\S*?) \((.*?)\+(.*?)\)') @@ -35,7 +35,7 @@ def _ParseAsanLogLine(line): def _FindASanLibraries(): - asan_lib_dir = os.path.join(constants.DIR_SOURCE_ROOT, + asan_lib_dir = os.path.join(host_paths.DIR_SOURCE_ROOT, 'third_party', 'llvm-build', 'Release+Asserts', 'lib') asan_libs = [] diff --git a/build/android/avd.py b/build/android/avd.py index 8f4bc82..c9f73bf 100755 --- a/build/android/avd.py +++ b/build/android/avd.py @@ -14,6 +14,7 @@ import os import re import sys +import devil_chromium import install_emulator_deps from devil.utils import cmd_helper @@ -62,6 +63,8 @@ def main(argv): logging.root.setLevel(logging.INFO) + devil_chromium.Initialize() + if arguments.command == 'kill': logging.info('Killing all existing emulator and existing the program') emulator.KillAllEmulators() diff --git a/build/android/bb_run_sharded_steps.py b/build/android/bb_run_sharded_steps.py deleted file mode 100755 index 1775dc1..0000000 --- a/build/android/bb_run_sharded_steps.py +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (c) 2012 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. - -"""DEPRECATED! -TODO(bulach): remove me once all other repositories reference -'test_runner.py perf' directly. -""" - -import optparse -import sys - -from devil.utils import cmd_helper - - -def main(argv): - parser = optparse.OptionParser() - parser.add_option('-s', '--steps', - help='A JSON file containing all the steps to be ' - 'sharded.') - parser.add_option('--flaky_steps', - help='A JSON file containing steps that are flaky and ' - 'will have its exit code ignored.') - parser.add_option('-p', '--print_results', - help='Only prints the results for the previously ' - 'executed step, do not run it again.') - options, _ = parser.parse_args(argv) - if options.print_results: - return cmd_helper.RunCmd(['build/android/test_runner.py', 'perf', - '--print-step', options.print_results]) - flaky_options = [] - if options.flaky_steps: - flaky_options = ['--flaky-steps', options.flaky_steps] - return cmd_helper.RunCmd(['build/android/test_runner.py', 'perf', '-v', - '--steps', options.steps] + flaky_options) - - -if __name__ == '__main__': - sys.exit(main(sys.argv)) diff --git a/build/android/buildbot/bb_device_status_check.py b/build/android/buildbot/bb_device_status_check.py index 99623dc..8eba829 100755 --- a/build/android/buildbot/bb_device_status_check.py +++ b/build/android/buildbot/bb_device_status_check.py @@ -23,10 +23,11 @@ from devil.android import device_errors from devil.android import device_list from devil.android import device_utils from devil.android.sdk import adb_wrapper +from devil.constants import exit_codes from devil.utils import lsusb from devil.utils import reset_usb from devil.utils import run_tests_helper -from pylib import constants +from pylib.constants import host_paths _RE_DEVICE_ID = re.compile(r'Device ID = (\d+)') @@ -297,7 +298,7 @@ def main(): parser = argparse.ArgumentParser() parser.add_argument('--out-dir', help='Directory where the device path is stored', - default=os.path.join(constants.DIR_SOURCE_ROOT, 'out')) + default=os.path.join(host_paths.DIR_SOURCE_ROOT, 'out')) parser.add_argument('--restart-usb', action='store_true', help='DEPRECATED. ' 'This script now always tries to reset USB.') @@ -390,7 +391,7 @@ def main(): and not _IsBlacklisted(status['serial'], blacklist))] # If all devices failed, or if there are no devices, it's an infra error. - return 0 if live_devices else constants.INFRA_EXIT_CODE + return 0 if live_devices else exit_codes.INFRA if __name__ == '__main__': diff --git a/build/android/buildbot/bb_device_steps.py b/build/android/buildbot/bb_device_steps.py index e4d2998..f52c24b 100755 --- a/build/android/buildbot/bb_device_steps.py +++ b/build/android/buildbot/bb_device_steps.py @@ -17,6 +17,7 @@ import bb_utils import bb_annotations sys.path.append(os.path.join(os.path.dirname(__file__), '..')) +import devil_chromium import provision_devices from devil.android import device_utils from pylib import constants @@ -742,6 +743,8 @@ def main(argv): parser = GetDeviceStepsOptParser() options, args = parser.parse_args(argv[1:]) + devil_chromium.Initialize() + if args: return sys.exit('Unused args %s' % args) diff --git a/build/android/buildbot/bb_host_steps.py b/build/android/buildbot/bb_host_steps.py index 1e927fb..11f5032 100755 --- a/build/android/buildbot/bb_host_steps.py +++ b/build/android/buildbot/bb_host_steps.py @@ -11,20 +11,20 @@ import bb_utils import bb_annotations sys.path.append(os.path.join(os.path.dirname(__file__), '..')) -from pylib import constants +from pylib.constants import host_paths SLAVE_SCRIPTS_DIR = os.path.join(bb_utils.BB_BUILD_DIR, 'scripts', 'slave') VALID_HOST_TESTS = set(['check_webview_licenses']) -DIR_BUILD_ROOT = os.path.dirname(constants.DIR_SOURCE_ROOT) +DIR_BUILD_ROOT = os.path.dirname(host_paths.DIR_SOURCE_ROOT) # Short hand for RunCmd which is used extensively in this file. RunCmd = bb_utils.RunCmd def SrcPath(*path): - return os.path.join(constants.DIR_SOURCE_ROOT, *path) + return os.path.join(host_paths.DIR_SOURCE_ROOT, *path) def CheckWebViewLicenses(_): @@ -68,7 +68,7 @@ def ZipBuild(options): bb_annotations.PrintNamedStep('zip_build') RunCmd([ os.path.join(SLAVE_SCRIPTS_DIR, 'zip_build.py'), - '--src-dir', constants.DIR_SOURCE_ROOT, + '--src-dir', host_paths.DIR_SOURCE_ROOT, '--exclude-files', 'lib.target,gen,android_webview,jingle_unittests'] + bb_utils.EncodeProperties(options), cwd=DIR_BUILD_ROOT) @@ -84,9 +84,9 @@ def BisectPerfRegression(options): if options.extra_src: args = ['--extra_src', options.extra_src] RunCmd([SrcPath('tools', 'prepare-bisect-perf-regression.py'), - '-w', os.path.join(constants.DIR_SOURCE_ROOT, os.pardir)]) + '-w', os.path.join(host_paths.DIR_SOURCE_ROOT, os.pardir)]) RunCmd([SrcPath('tools', 'run-bisect-perf-regression.py'), - '-w', os.path.join(constants.DIR_SOURCE_ROOT, os.pardir), + '-w', os.path.join(host_paths.DIR_SOURCE_ROOT, os.pardir), '--build-properties=%s' % json.dumps(options.build_properties)] + args) diff --git a/build/android/buildbot/bb_utils.py b/build/android/buildbot/bb_utils.py index b78fec0..d1981f4 100644 --- a/build/android/buildbot/bb_utils.py +++ b/build/android/buildbot/bb_utils.py @@ -11,6 +11,7 @@ import sys import bb_annotations sys.path.append(os.path.join(os.path.dirname(__file__), '..')) +import devil_chromium # pylint: disable=unused-import from devil.utils import cmd_helper from pylib import constants diff --git a/build/android/devil_chromium.py b/build/android/devil_chromium.py index c7142ed..8472f65 100644 --- a/build/android/devil_chromium.py +++ b/build/android/devil_chromium.py @@ -5,9 +5,14 @@ """Configures devil for use in chromium.""" import os +import sys -from devil import devil_env +from pylib.constants import host_paths + +if host_paths.DEVIL_PATH not in sys.path: + sys.path.append(host_paths.DEVIL_PATH) +from devil import devil_env _DEVIL_CONFIG = os.path.abspath( os.path.join(os.path.dirname(__file__), 'devil_chromium.json')) @@ -126,6 +131,7 @@ def Initialize(output_directory=None, custom_deps=None): 'dependencies': {}, } if output_directory: + output_directory = os.path.abspath(output_directory) devil_dynamic_config['dependencies'] = { dep_name: { 'file_info': { diff --git a/build/android/emma_coverage_stats.py b/build/android/emma_coverage_stats.py index 6f64f30..20ec8ea 100755 --- a/build/android/emma_coverage_stats.py +++ b/build/android/emma_coverage_stats.py @@ -24,6 +24,7 @@ import re import sys from xml.etree import ElementTree +import devil_chromium from devil.utils import run_tests_helper NOT_EXECUTABLE = -1 @@ -470,6 +471,7 @@ def main(): help='Print verbose log information.') args = argparser.parse_args() run_tests_helper.SetLogLevel(args.verbose) + devil_chromium.Initialize() GenerateCoverageReport(args.lines_for_coverage_file, args.out, args.emma_dir) diff --git a/build/android/emma_coverage_stats_test.py b/build/android/emma_coverage_stats_test.py index c39dd47..30b409e 100755 --- a/build/android/emma_coverage_stats_test.py +++ b/build/android/emma_coverage_stats_test.py @@ -5,17 +5,14 @@ # pylint: disable=protected-access -import os -import sys import unittest from xml.etree import ElementTree import emma_coverage_stats -from pylib import constants +from pylib.constants import host_paths -sys.path.append(os.path.join( - constants.DIR_SOURCE_ROOT, 'third_party', 'pymock')) -import mock # pylint: disable=import-error +with host_paths.SysPath(host_paths.PYMOCK_PATH): + import mock # pylint: disable=import-error EMPTY_COVERAGE_STATS_DICT = { 'files': {}, diff --git a/build/android/enable_asserts.py b/build/android/enable_asserts.py index 0616567..b303eda 100755 --- a/build/android/enable_asserts.py +++ b/build/android/enable_asserts.py @@ -9,6 +9,7 @@ import argparse import sys +import devil_chromium from devil.android import device_blacklist from devil.android import device_utils @@ -28,6 +29,8 @@ def main(): args = parser.parse_args() + devil_chromium.Initialize() + blacklist = (device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None) diff --git a/build/android/findbugs_diff.py b/build/android/findbugs_diff.py index d222e32..8034b71 100755 --- a/build/android/findbugs_diff.py +++ b/build/android/findbugs_diff.py @@ -20,15 +20,17 @@ import argparse import os import sys +import devil_chromium from devil.utils import run_tests_helper -from pylib import constants + +from pylib.constants import host_paths from pylib.utils import findbugs _DEFAULT_BASE_DIR = os.path.join( - constants.DIR_SOURCE_ROOT, 'build', 'android', 'findbugs_filter') + host_paths.DIR_SOURCE_ROOT, 'build', 'android', 'findbugs_filter') sys.path.append( - os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'android', 'gyp')) + os.path.join(host_paths.DIR_SOURCE_ROOT, 'build', 'android', 'gyp')) from util import build_utils # pylint: disable=import-error @@ -75,6 +77,8 @@ def main(): run_tests_helper.SetLogLevel(args.verbose) + devil_chromium.Initialize() + if args.auxclasspath: args.auxclasspath = args.auxclasspath.split(':') elif args.auxclasspath_gyp: diff --git a/build/android/generate_emma_html.py b/build/android/generate_emma_html.py index 699abe5..64d834f 100755 --- a/build/android/generate_emma_html.py +++ b/build/android/generate_emma_html.py @@ -12,8 +12,10 @@ import optparse import os import sys +import devil_chromium from devil.utils import cmd_helper from pylib import constants +from pylib.constants import host_paths def _GetFilesWithExt(root_dir, ext): @@ -49,6 +51,8 @@ def main(): 'runtime.')) options, _ = option_parser.parse_args() + devil_chromium.Initialize() + if not (options.coverage_dir and options.metadata_dir and options.output): option_parser.error('One or more mandatory options are missing.') @@ -62,7 +66,7 @@ def main(): sources_file = os.path.splitext(f)[0] + '_sources.txt' with open(sources_file, 'r') as sf: sources.extend(json.load(sf)) - sources = [os.path.join(constants.DIR_SOURCE_ROOT, s) for s in sources] + sources = [os.path.join(host_paths.DIR_SOURCE_ROOT, s) for s in sources] print 'Sources: %s' % sources input_args = [] diff --git a/build/android/gyp/create_device_library_links.py b/build/android/gyp/create_device_library_links.py index 0fcd176..c7f59dd 100755 --- a/build/android/gyp/create_device_library_links.py +++ b/build/android/gyp/create_device_library_links.py @@ -27,7 +27,7 @@ from devil.android import apk_helper from pylib import constants def RunShellCommand(device, cmd): - output = device.RunShellCommand(cmd) + output = device.RunShellCommand(cmd, check_return=True) if output: raise Exception( diff --git a/build/android/gyp/java_google_api_keys.py b/build/android/gyp/java_google_api_keys.py index 62c92cd..95cb416 100755 --- a/build/android/gyp/java_google_api_keys.py +++ b/build/android/gyp/java_google_api_keys.py @@ -20,7 +20,7 @@ import google_api_keys sys.path.append(os.path.abspath(os.path.join( os.path.dirname(__file__), os.pardir))) -from pylib import constants +from pylib.constants import host_paths PACKAGE = 'org.chromium.chrome' @@ -28,7 +28,7 @@ CLASSNAME = 'GoogleAPIKeys' def GetScriptName(): - return os.path.relpath(__file__, constants.DIR_SOURCE_ROOT) + return os.path.relpath(__file__, host_paths.DIR_SOURCE_ROOT) def GenerateOutput(constant_definitions): diff --git a/build/android/gyp/jinja_template.py b/build/android/gyp/jinja_template.py index a3633ae..7e9624b 100755 --- a/build/android/gyp/jinja_template.py +++ b/build/android/gyp/jinja_template.py @@ -11,12 +11,13 @@ import optparse import os import sys -sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir)) -from pylib import constants from util import build_utils +sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir)) +from pylib.constants import host_paths + # Import jinja2 from third_party/jinja2 -sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, 'third_party')) +sys.path.append(os.path.join(host_paths.DIR_SOURCE_ROOT, 'third_party')) import jinja2 # pylint: disable=F0401 @@ -79,7 +80,7 @@ def main(): parser.add_option('--loader-base-dir', help='Base path used by the template ' 'loader. Must be a common ancestor directory of ' 'the inputs. Defaults to DIR_SOURCE_ROOT.', - default=constants.DIR_SOURCE_ROOT) + default=host_paths.DIR_SOURCE_ROOT) parser.add_option('--variables', help='Variables to be made available in the ' 'template processing environment, as a GYP list (e.g. ' '--variables "channel=beta mstone=39")', default='') diff --git a/build/android/gyp/push_libraries.py b/build/android/gyp/push_libraries.py index e1a01d7..3dae6f0 100755 --- a/build/android/gyp/push_libraries.py +++ b/build/android/gyp/push_libraries.py @@ -12,16 +12,17 @@ import optparse import os import sys +from util import build_device +from util import build_utils +from util import md5_check + BUILD_ANDROID_DIR = os.path.abspath( os.path.join(os.path.dirname(__file__), os.pardir)) sys.path.append(BUILD_ANDROID_DIR) +import devil_chromium from pylib import constants -from util import build_device -from util import build_utils -from util import md5_check - def DoPush(options): libraries = build_utils.ParseGypList(options.libraries) @@ -63,13 +64,15 @@ def main(args): parser.add_option('--stamp', help='Path to touch on success.') parser.add_option('--build-device-configuration', help='Path to build device configuration.') - parser.add_option('--configuration-name', - help='The build CONFIGURATION_NAME') + parser.add_option('--output-directory', + help='The output directory.') options, _ = parser.parse_args(args) required_options = ['libraries', 'device_dir', 'libraries'] build_utils.CheckOptions(options, parser, required=required_options) - constants.SetBuildType(options.configuration_name) + + devil_chromium.Initialize( + output_directory=os.path.abspath(options.output_directory)) DoPush(options) diff --git a/build/android/gyp/util/build_device.py b/build/android/gyp/util/build_device.py index 34484ac..83aa0d5 100644 --- a/build/android/gyp/util/build_device.py +++ b/build/android/gyp/util/build_device.py @@ -13,10 +13,6 @@ import sys from util import build_utils -BUILD_ANDROID_DIR = os.path.abspath( - os.path.join(os.path.dirname(__file__), '..', '..')) -sys.path.append(BUILD_ANDROID_DIR) - from devil.android import device_errors from devil.android import device_utils from devil.android.sdk import adb_wrapper diff --git a/build/android/gyp/util/build_utils.py b/build/android/gyp/util/build_utils.py index 10c7ba2b..fe69c95 100644 --- a/build/android/gyp/util/build_utils.py +++ b/build/android/gyp/util/build_utils.py @@ -20,9 +20,9 @@ import zipfile import md5_check # pylint: disable=relative-import sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)) -from pylib import constants +from pylib.constants import host_paths -COLORAMA_ROOT = os.path.join(constants.DIR_SOURCE_ROOT, +COLORAMA_ROOT = os.path.join(host_paths.DIR_SOURCE_ROOT, 'third_party', 'colorama', 'src') # aapt should ignore OWNERS files in addition the default ignore pattern. AAPT_IGNORE_PATTERN = ('!OWNERS:!.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:' + @@ -369,9 +369,9 @@ def GetPythonDependencies(): abs_module_paths = map(os.path.abspath, module_paths) - assert os.path.isabs(constants.DIR_SOURCE_ROOT) + assert os.path.isabs(host_paths.DIR_SOURCE_ROOT) non_system_module_paths = [ - p for p in abs_module_paths if p.startswith(constants.DIR_SOURCE_ROOT)] + p for p in abs_module_paths if p.startswith(host_paths.DIR_SOURCE_ROOT)] def ConvertPycToPy(s): if s.endswith('.pyc'): return s[:-1] diff --git a/build/android/host_heartbeat.py b/build/android/host_heartbeat.py index ced24b2..8990592 100755 --- a/build/android/host_heartbeat.py +++ b/build/android/host_heartbeat.py @@ -12,11 +12,14 @@ This heart beat lets the devices know that they are connected to a host. import sys import time +import devil_chromium from devil.android import device_utils PULSE_PERIOD = 20 def main(): + devil_chromium.Initialize() + while True: try: devices = device_utils.DeviceUtils.HealthyDevices(blacklist=None) diff --git a/build/android/incremental_install/create_install_script.py b/build/android/incremental_install/create_install_script.py index 3de4ed6..4024e05 100755 --- a/build/android/incremental_install/create_install_script.py +++ b/build/android/incremental_install/create_install_script.py @@ -14,7 +14,7 @@ import sys sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir)) sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, 'gyp')) -from pylib import constants +from pylib.constants import host_paths from util import build_utils @@ -125,7 +125,7 @@ def main(args): script_dir = os.path.dirname(options.script_output_path) return path and os.path.relpath(path, script_dir) - installer_path = os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'android', + installer_path = os.path.join(host_paths.DIR_SOURCE_ROOT, 'build', 'android', 'incremental_install', 'installer.py') pformat = pprint.pformat template_args = { diff --git a/build/android/install_emulator_deps.py b/build/android/install_emulator_deps.py index c391af2..acd2093 100755 --- a/build/android/install_emulator_deps.py +++ b/build/android/install_emulator_deps.py @@ -16,6 +16,7 @@ import os import re import sys +import devil_chromium from devil.utils import cmd_helper from devil.utils import run_tests_helper from pylib import constants @@ -276,6 +277,8 @@ def main(argv): run_tests_helper.SetLogLevel(verbose_count=options.verbosity) + devil_chromium.Initialize() + # Calls below will download emulator SDK and/or system images only if needed. if CheckSDK(): logging.info('android_emulator_sdk/ exists') diff --git a/build/android/lint/suppress.py b/build/android/lint/suppress.py index 1c254b7..7357588 100755 --- a/build/android/lint/suppress.py +++ b/build/android/lint/suppress.py @@ -18,7 +18,7 @@ from xml.dom import minidom _BUILD_ANDROID_DIR = os.path.join(os.path.dirname(__file__), '..') sys.path.append(_BUILD_ANDROID_DIR) -from pylib import constants +from pylib.constants import host_paths _THIS_FILE = os.path.abspath(__file__) @@ -36,7 +36,7 @@ _DOC = ( ' globally if it is not applicable to the project.\n' '- You can also automatically add issues found so for in the\n' ' build process by running:\n\n' - ' ' + os.path.relpath(_THIS_FILE, constants.DIR_SOURCE_ROOT) + '\n\n' + ' ' + os.path.relpath(_THIS_FILE, host_paths.DIR_SOURCE_ROOT) + '\n\n' ' which will generate this file (Comments are not preserved).\n' ' Note: PRODUCT_DIR will be substituted at run-time with actual\n' ' directory path (e.g. out/Debug)\n' diff --git a/build/android/method_count.py b/build/android/method_count.py index f2feb6f..c816f10 100755 --- a/build/android/method_count.py +++ b/build/android/method_count.py @@ -11,10 +11,11 @@ import sys import tempfile import zipfile +import devil_chromium from devil.android.sdk import dexdump -from pylib import constants +from pylib.constants import host_paths -sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'util', 'lib', +sys.path.append(os.path.join(host_paths.DIR_SOURCE_ROOT, 'build', 'util', 'lib', 'common')) import perf_tests_results_helper # pylint: disable=import-error @@ -53,6 +54,8 @@ def main(): args = parser.parse_args() + devil_chromium.Initialize() + if not args.apk_name: dirname, basename = os.path.split(args.dexfile) while basename: diff --git a/build/android/play_services/preprocess.py b/build/android/play_services/preprocess.py index e109898..0705729 100755 --- a/build/android/play_services/preprocess.py +++ b/build/android/play_services/preprocess.py @@ -61,6 +61,7 @@ import zipfile from datetime import datetime sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir)) +import devil_chromium from devil.utils import cmd_helper from play_services import utils from pylib.utils import argparse_utils @@ -103,6 +104,8 @@ def main(): args = parser.parse_args() + devil_chromium.Initialize() + return ProcessGooglePlayServices(args.repository, args.out_dir, args.config_file, diff --git a/build/android/play_services/update.py b/build/android/play_services/update.py index 9b97ed5..8a70325 100755 --- a/build/android/play_services/update.py +++ b/build/android/play_services/update.py @@ -18,12 +18,14 @@ import tempfile import zipfile sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir)) +import devil_chromium from devil.utils import cmd_helper from play_services import utils from pylib import constants +from pylib.constants import host_paths from pylib.utils import logging_utils -sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, 'build')) +sys.path.append(os.path.join(host_paths.DIR_SOURCE_ROOT, 'build')) import find_depot_tools # pylint: disable=import-error,unused-import import breakpad import download_from_google_storage @@ -32,7 +34,7 @@ import upload_to_google_storage # Directory where the SHA1 files for the zip and the license are stored # It should be managed by git to provided information about new versions. -SHA1_DIRECTORY = os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'android', +SHA1_DIRECTORY = os.path.join(host_paths.DIR_SOURCE_ROOT, 'build', 'android', 'play_services') # Default bucket used for storing the files. @@ -40,7 +42,7 @@ GMS_CLOUD_STORAGE = 'chromium-android-tools/play-services' # Path to the default configuration file. It exposes the currently installed # version of the library in a human readable way. -CONFIG_DEFAULT_PATH = os.path.join(constants.DIR_SOURCE_ROOT, 'build', +CONFIG_DEFAULT_PATH = os.path.join(host_paths.DIR_SOURCE_ROOT, 'build', 'android', 'play_services', 'config.json') LICENSE_FILE_NAME = 'LICENSE' @@ -93,6 +95,7 @@ def main(raw_args): if args.verbose: logging.basicConfig(level=logging.DEBUG) logging_utils.ColorStreamHandler.MakeDefault(not _IsBotEnvironment()) + devil_chromium.Initialize() return args.func(args) @@ -263,7 +266,7 @@ def Upload(args): config = utils.ConfigParser(args.config) paths = PlayServicesPaths(args.sdk_root, config.version_xml_path) - if not args.skip_git and utils.IsRepoDirty(constants.DIR_SOURCE_ROOT): + if not args.skip_git and utils.IsRepoDirty(host_paths.DIR_SOURCE_ROOT): logging.error('The repo is dirty. Please commit or stash your changes.') return -1 @@ -306,7 +309,7 @@ def Upload(args): if not args.skip_git: commit_message = ('Update the Google Play services dependency to %s\n' '\n') % new_version_number - utils.MakeLocalCommit(constants.DIR_SOURCE_ROOT, + utils.MakeLocalCommit(host_paths.DIR_SOURCE_ROOT, [new_lib_zip_sha1, new_license_sha1, config.path], commit_message) diff --git a/build/android/provision_devices.py b/build/android/provision_devices.py index b973351..5f8fce2 100755 --- a/build/android/provision_devices.py +++ b/build/android/provision_devices.py @@ -33,6 +33,7 @@ from devil.utils import run_tests_helper from devil.utils import timeout_retry from pylib import constants from pylib import device_settings +from pylib.constants import host_paths _SYSTEM_WEBVIEW_PATHS = ['/system/app/webview', '/system/app/WebViewGoogle'] _CHROME_PACKAGE_REGEX = re.compile('.*chrom.*') @@ -427,7 +428,7 @@ def _PushAndLaunchAdbReboot(device, target): device.KillAll('adb_reboot', blocking=True, timeout=2, quiet=True) # Push adb_reboot logging.info(' Pushing adb_reboot ...') - adb_reboot = os.path.join(constants.DIR_SOURCE_ROOT, + adb_reboot = os.path.join(host_paths.DIR_SOURCE_ROOT, 'out/%s/adb_reboot' % target) device.PushChangedFiles([(adb_reboot, '/data/local/tmp/')]) # Launch adb_reboot @@ -442,7 +443,7 @@ def _LaunchHostHeartbeat(): KillHostHeartbeat() # Launch a new host_heartbeat logging.info('Spawning host heartbeat...') - subprocess.Popen([os.path.join(constants.DIR_SOURCE_ROOT, + subprocess.Popen([os.path.join(host_paths.DIR_SOURCE_ROOT, 'build/android/host_heartbeat.py')]) def KillHostHeartbeat(): diff --git a/build/android/push_libraries.gypi b/build/android/push_libraries.gypi index a4a6fcd..8bce798 100644 --- a/build/android/push_libraries.gypi +++ b/build/android/push_libraries.gypi @@ -44,6 +44,6 @@ '--device-dir=<(device_library_dir)', '--libraries=@FileArg(<(ordered_libraries_file):libraries)', '--stamp=<(push_stamp)', - '--configuration-name=<(CONFIGURATION_NAME)', + '--output-directory=<(PRODUCT_DIR)', ], } diff --git a/build/android/pylib/__init__.py b/build/android/pylib/__init__.py index 96196cf..16ee312 100644 --- a/build/android/pylib/__init__.py +++ b/build/android/pylib/__init__.py @@ -1,3 +1,13 @@ # Copyright (c) 2012 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 os +import sys + +_DEVIL_PATH = os.path.abspath(os.path.join( + os.path.dirname(__file__), '..', '..', '..', 'third_party', 'catapult', + 'devil')) + +if _DEVIL_PATH not in sys.path: + sys.path.append(_DEVIL_PATH) diff --git a/build/android/pylib/base/base_setup.py b/build/android/pylib/base/base_setup.py index 84441dc..ac4d108 100644 --- a/build/android/pylib/base/base_setup.py +++ b/build/android/pylib/base/base_setup.py @@ -9,6 +9,7 @@ import os from pylib import constants from pylib import valgrind_tools +from pylib.constants import host_paths from pylib.utils import isolator def GenerateDepsDirUsingIsolate(suite_name, isolate_file_path, @@ -30,14 +31,15 @@ def GenerateDepsDirUsingIsolate(suite_name, isolate_file_path, if os.path.isabs(isolate_file_path): isolate_abs_path = isolate_file_path else: - isolate_abs_path = os.path.join(constants.DIR_SOURCE_ROOT, + isolate_abs_path = os.path.join(host_paths.DIR_SOURCE_ROOT, isolate_file_path) else: isolate_rel_path = isolate_file_paths.get(suite_name) if not isolate_rel_path: logging.info('Did not find an isolate file for the test suite.') return - isolate_abs_path = os.path.join(constants.DIR_SOURCE_ROOT, isolate_rel_path) + isolate_abs_path = os.path.join(host_paths.DIR_SOURCE_ROOT, + isolate_rel_path) isolated_abs_path = os.path.join( constants.GetOutDirectory(), '%s.isolated' % suite_name) diff --git a/build/android/pylib/base/test_dispatcher_unittest.py b/build/android/pylib/base/test_dispatcher_unittest.py index 57f271f..9b8633e 100755 --- a/build/android/pylib/base/test_dispatcher_unittest.py +++ b/build/android/pylib/base/test_dispatcher_unittest.py @@ -4,25 +4,23 @@ # found in the LICENSE file. """Unittests for test_dispatcher.py.""" -# pylint: disable=R0201 -# pylint: disable=W0212 -import os -import sys -import unittest +# pylint: disable=no-self-use +# pylint: disable=protected-access +import unittest from devil.android import device_utils from devil.android.sdk import adb_wrapper +from devil.constants import exit_codes from devil.utils import watchdog_timer -from pylib import constants from pylib.base import base_test_result from pylib.base import test_collection from pylib.base import test_dispatcher +from pylib.constants import host_paths -sys.path.append( - os.path.join(constants.DIR_SOURCE_ROOT, 'third_party', 'pymock')) -import mock # pylint: disable=import-error +with host_paths.SysPath(host_paths.PYMOCK_PATH): + import mock # pylint: disable=import-error class TestException(Exception): @@ -175,7 +173,7 @@ class TestThreadGroupFunctions(unittest.TestCase): results, exit_code = test_dispatcher._RunAllTests( runners, self.test_collection_factory, 0) self.assertEqual(len(results.GetFail()), len(self.tests)) - self.assertEqual(exit_code, constants.ERROR_EXIT_CODE) + self.assertEqual(exit_code, exit_codes.ERROR) def testReraise(self): runners = test_dispatcher._CreateRunners( @@ -201,13 +199,13 @@ class TestShard(unittest.TestCase): results, exit_code = TestShard._RunShard(MockRunnerFail) self.assertEqual(len(results.GetPass()), 0) self.assertEqual(len(results.GetFail()), 3) - self.assertEqual(exit_code, constants.ERROR_EXIT_CODE) + self.assertEqual(exit_code, exit_codes.ERROR) def testNoTests(self): results, exit_code = test_dispatcher.RunTests( [], MockRunner, [_MockDevice('0'), _MockDevice('1')], shard=True) self.assertEqual(len(results.GetAll()), 0) - self.assertEqual(exit_code, constants.ERROR_EXIT_CODE) + self.assertEqual(exit_code, exit_codes.ERROR) class TestReplicate(unittest.TestCase): @@ -228,13 +226,13 @@ class TestReplicate(unittest.TestCase): results, exit_code = TestReplicate._RunReplicate(MockRunnerFail) self.assertEqual(len(results.GetPass()), 0) self.assertEqual(len(results.GetFail()), 6) - self.assertEqual(exit_code, constants.ERROR_EXIT_CODE) + self.assertEqual(exit_code, exit_codes.ERROR) def testNoTests(self): results, exit_code = test_dispatcher.RunTests( [], MockRunner, [_MockDevice('0'), _MockDevice('1')], shard=False) self.assertEqual(len(results.GetAll()), 0) - self.assertEqual(exit_code, constants.ERROR_EXIT_CODE) + self.assertEqual(exit_code, exit_codes.ERROR) if __name__ == '__main__': diff --git a/build/android/pylib/chrome_test_server_spawner.py b/build/android/pylib/chrome_test_server_spawner.py index f4e7e96..ec2896f 100644 --- a/build/android/pylib/chrome_test_server_spawner.py +++ b/build/android/pylib/chrome_test_server_spawner.py @@ -25,16 +25,17 @@ from devil.android import forwarder from devil.android import ports from pylib import constants +from pylib.constants import host_paths # Path that are needed to import necessary modules when launching a testserver. os.environ['PYTHONPATH'] = os.environ.get('PYTHONPATH', '') + (':%s:%s:%s:%s:%s' - % (os.path.join(constants.DIR_SOURCE_ROOT, 'third_party'), - os.path.join(constants.DIR_SOURCE_ROOT, 'third_party', 'tlslite'), - os.path.join(constants.DIR_SOURCE_ROOT, 'third_party', 'pyftpdlib', + % (os.path.join(host_paths.DIR_SOURCE_ROOT, 'third_party'), + os.path.join(host_paths.DIR_SOURCE_ROOT, 'third_party', 'tlslite'), + os.path.join(host_paths.DIR_SOURCE_ROOT, 'third_party', 'pyftpdlib', 'src'), - os.path.join(constants.DIR_SOURCE_ROOT, 'net', 'tools', 'testserver'), - os.path.join(constants.DIR_SOURCE_ROOT, 'sync', 'tools', 'testserver'))) + os.path.join(host_paths.DIR_SOURCE_ROOT, 'net', 'tools', 'testserver'), + os.path.join(host_paths.DIR_SOURCE_ROOT, 'sync', 'tools', 'testserver'))) SERVER_TYPES = { @@ -216,7 +217,7 @@ class TestServerThread(threading.Thread): logging.info('Start running the thread!') self.wait_event.clear() self._GenerateCommandLineArguments() - command = constants.DIR_SOURCE_ROOT + command = host_paths.DIR_SOURCE_ROOT if self.arguments['server-type'] == 'sync': command = [os.path.join(command, 'sync', 'tools', 'testserver', 'sync_testserver.py')] + self.command_line @@ -233,7 +234,7 @@ class TestServerThread(threading.Thread): # paths in the arguments are resolved correctly. self.process = subprocess.Popen( command, preexec_fn=self._CloseUnnecessaryFDsForTestServerProcess, - cwd=constants.DIR_SOURCE_ROOT) + cwd=host_paths.DIR_SOURCE_ROOT) if unbuf: os.environ['PYTHONUNBUFFERED'] = unbuf if self.process: diff --git a/build/android/pylib/constants/host_paths.py b/build/android/pylib/constants/host_paths.py new file mode 100644 index 0000000..98aa53d --- /dev/null +++ b/build/android/pylib/constants/host_paths.py @@ -0,0 +1,38 @@ +# Copyright 2016 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 contextlib +import os +import sys + +DIR_SOURCE_ROOT = os.environ.get( + 'CHECKOUT_SOURCE_ROOT', + os.path.abspath(os.path.join(os.path.dirname(__file__), + os.pardir, os.pardir, os.pardir, os.pardir))) + +BUILD_COMMON_PATH = os.path.join( + DIR_SOURCE_ROOT, 'build', 'util', 'lib', 'common') + +# third-party libraries +ANDROID_PLATFORM_DEVELOPMENT_SCRIPTS_PATH = os.path.join( + DIR_SOURCE_ROOT, 'third_party', 'android_platform', 'development', + 'scripts') +DEVIL_PATH = os.path.join( + DIR_SOURCE_ROOT, 'third_party', 'catapult', 'devil') +PYMOCK_PATH = os.path.join( + DIR_SOURCE_ROOT, 'third_party', 'pymock') + +@contextlib.contextmanager +def SysPath(path, position=None): + if position is None: + sys.path.append(path) + else: + sys.path.insert(position, path) + try: + yield + finally: + if sys.path[-1] == path: + sys.path.pop() + else: + sys.path.remove(path) diff --git a/build/android/pylib/gtest/gtest_test_instance.py b/build/android/pylib/gtest/gtest_test_instance.py index 4250ea3..a118ea7 100644 --- a/build/android/pylib/gtest/gtest_test_instance.py +++ b/build/android/pylib/gtest/gtest_test_instance.py @@ -5,17 +5,16 @@ import logging import os import re -import sys import tempfile from devil.android import apk_helper from pylib import constants +from pylib.constants import host_paths from pylib.base import base_test_result from pylib.base import test_instance -sys.path.append(os.path.join( - constants.DIR_SOURCE_ROOT, 'build', 'util', 'lib', 'common')) -import unittest_util # pylint: disable=import-error +with host_paths.SysPath(host_paths.BUILD_COMMON_PATH): + import unittest_util # pylint: disable=import-error BROWSER_TEST_SUITES = [ @@ -176,7 +175,7 @@ class GtestTestInstance(test_instance.TestInstance): default_isolate_file_path = _DEFAULT_ISOLATE_FILE_PATHS.get(self._suite) if default_isolate_file_path: args.isolate_file_path = os.path.join( - constants.DIR_SOURCE_ROOT, default_isolate_file_path) + host_paths.DIR_SOURCE_ROOT, default_isolate_file_path) if args.isolate_file_path: self._isolate_abs_path = os.path.abspath(args.isolate_file_path) @@ -315,7 +314,7 @@ class GtestTestInstance(test_instance.TestInstance): disabled_filter_items += ['*.%s*' % dp for dp in disabled_prefixes] disabled_tests_file_path = os.path.join( - constants.DIR_SOURCE_ROOT, 'build', 'android', 'pylib', 'gtest', + host_paths.DIR_SOURCE_ROOT, 'build', 'android', 'pylib', 'gtest', 'filter', '%s_disabled' % self._suite) if disabled_tests_file_path and os.path.exists(disabled_tests_file_path): with open(disabled_tests_file_path) as disabled_tests_file: diff --git a/build/android/pylib/host_driven/test_info_collection.py b/build/android/pylib/host_driven/test_info_collection.py index c65d417..2e2db25 100644 --- a/build/android/pylib/host_driven/test_info_collection.py +++ b/build/android/pylib/host_driven/test_info_collection.py @@ -6,17 +6,12 @@ import logging import os -import sys +from pylib.constants import host_paths from pylib.host_driven import tests_annotations -from pylib import constants - -sys.path.insert(0, - os.path.join(constants.DIR_SOURCE_ROOT, - 'build', 'util', 'lib', 'common')) - -import unittest_util # pylint: disable=F0401 +with host_paths.SysPath(host_paths.BUILD_COMMON_PATH): + import unittest_util # pylint: disable=import-error class TestInfo(object): """An object containing and representing a test function, plus metadata.""" diff --git a/build/android/pylib/host_driven/test_server.py b/build/android/pylib/host_driven/test_server.py index af58ddc..02560c9 100644 --- a/build/android/pylib/host_driven/test_server.py +++ b/build/android/pylib/host_driven/test_server.py @@ -23,6 +23,7 @@ import time import urllib2 from pylib import constants +from pylib.constants import host_paths # NOTE: when adding or modifying these lines, omit any leading slashes! # Otherwise os.path.join() will (correctly) treat them as absolute paths @@ -87,7 +88,7 @@ class TestServer(object): self.host = _TEST_SERVER_HOST self.port = test_server_port + shard_index - src_dir = constants.DIR_SOURCE_ROOT + src_dir = host_paths.DIR_SOURCE_ROOT # Make dirs into a list of absolute paths. abs_dirs = [os.path.join(src_dir, d) for d in _PYTHONPATH_DIRS] # Add the generated python files to the path diff --git a/build/android/pylib/instrumentation/instrumentation_test_instance.py b/build/android/pylib/instrumentation/instrumentation_test_instance.py index 84b130d..00ce2bc 100644 --- a/build/android/pylib/instrumentation/instrumentation_test_instance.py +++ b/build/android/pylib/instrumentation/instrumentation_test_instance.py @@ -8,20 +8,19 @@ import logging import os import pickle import re -import sys from devil.android import apk_helper from devil.android import md5sum from pylib import constants from pylib.base import base_test_result from pylib.base import test_instance +from pylib.constants import host_paths from pylib.instrumentation import test_result from pylib.instrumentation import instrumentation_parser from pylib.utils import proguard -sys.path.append( - os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'util', 'lib', 'common')) -import unittest_util # pylint: disable=import-error +with host_paths.SysPath(host_paths.BUILD_COMMON_PATH): + import unittest_util # pylint: disable=import-error # Ref: http://developer.android.com/reference/android/app/Activity.html _ACTIVITY_RESULT_CANCELED = 0 @@ -441,7 +440,7 @@ class InstrumentationTestInstance(test_instance.TestInstance): if self._test_data: for t in self._test_data: device_rel_path, host_rel_path = t.split(':') - host_abs_path = os.path.join(constants.DIR_SOURCE_ROOT, host_rel_path) + host_abs_path = os.path.join(host_paths.DIR_SOURCE_ROOT, host_rel_path) self._data_deps.extend( [(host_abs_path, [None, 'chrome', 'test', 'data', device_rel_path])]) diff --git a/build/android/pylib/instrumentation/instrumentation_test_instance_test.py b/build/android/pylib/instrumentation/instrumentation_test_instance_test.py index b6787b2..3837f1f 100755 --- a/build/android/pylib/instrumentation/instrumentation_test_instance_test.py +++ b/build/android/pylib/instrumentation/instrumentation_test_instance_test.py @@ -6,19 +6,14 @@ """Unit tests for instrumentation.TestRunner.""" -# pylint: disable=W0212 - -import os -import sys import unittest -from pylib import constants from pylib.base import base_test_result +from pylib.constants import host_paths from pylib.instrumentation import instrumentation_test_instance -sys.path.append(os.path.join( - constants.DIR_SOURCE_ROOT, 'third_party', 'pymock')) -import mock # pylint: disable=F0401 +with host_paths.SysPath(host_paths.PYMOCK_PATH): + import mock # pylint: disable=import-error class InstrumentationTestInstanceTest(unittest.TestCase): diff --git a/build/android/pylib/instrumentation/setup.py b/build/android/pylib/instrumentation/setup.py index b401371..7a8f901 100644 --- a/build/android/pylib/instrumentation/setup.py +++ b/build/android/pylib/instrumentation/setup.py @@ -8,9 +8,9 @@ import logging import os from devil.android import device_utils -from pylib import constants from pylib import valgrind_tools from pylib.base import base_setup +from pylib.constants import host_paths from pylib.instrumentation import test_package from pylib.instrumentation import test_runner @@ -35,7 +35,7 @@ def _PushExtraSuiteDataDeps(device, test_apk): 'CronetTestInstrumentation']: test_files = 'net/data/ssl/certificates' host_device_file_tuple = [ - (os.path.join(constants.DIR_SOURCE_ROOT, test_files), + (os.path.join(host_paths.DIR_SOURCE_ROOT, test_files), os.path.join(device.GetExternalStoragePath(), test_files))] device.PushChangedFiles(host_device_file_tuple) @@ -50,7 +50,7 @@ def _PushDataDeps(device, test_options): dst_src = dest_host_pair.split(':', 1) dst_layer = dst_src[0] host_src = dst_src[1] - host_test_files_path = os.path.join(constants.DIR_SOURCE_ROOT, host_src) + host_test_files_path = os.path.join(host_paths.DIR_SOURCE_ROOT, host_src) if os.path.exists(host_test_files_path): host_device_file_tuples += [( host_test_files_path, diff --git a/build/android/pylib/instrumentation/test_jar.py b/build/android/pylib/instrumentation/test_jar.py index 1ae653c..599f97b 100644 --- a/build/android/pylib/instrumentation/test_jar.py +++ b/build/android/pylib/instrumentation/test_jar.py @@ -9,18 +9,15 @@ import logging import os import pickle import re -import sys from devil.android import device_utils from devil.android import md5sum from pylib import constants +from pylib.constants import host_paths from pylib.utils import proguard -sys.path.insert(0, - os.path.join(constants.DIR_SOURCE_ROOT, - 'build', 'util', 'lib', 'common')) - -import unittest_util # pylint: disable=F0401 +with host_paths.SysPath(host_paths.BUILD_COMMON_PATH): + import unittest_util # pylint: disable=import-error # If you change the cached output of proguard, increment this number PICKLE_FORMAT_VERSION = 4 diff --git a/build/android/pylib/instrumentation/test_runner.py b/build/android/pylib/instrumentation/test_runner.py index aab0c124..003a74c 100644 --- a/build/android/pylib/instrumentation/test_runner.py +++ b/build/android/pylib/instrumentation/test_runner.py @@ -8,7 +8,6 @@ import collections import logging import os import re -import sys import time from devil.android import device_errors @@ -17,14 +16,14 @@ from pylib import flag_changer from pylib import valgrind_tools from pylib.base import base_test_result from pylib.base import base_test_runner +from pylib.constants import host_paths from pylib.instrumentation import instrumentation_test_instance from pylib.instrumentation import json_perf_parser from pylib.instrumentation import test_result from pylib.local.device import local_device_instrumentation_test_run -sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'util', 'lib', - 'common')) -import perf_tests_results_helper # pylint: disable=F0401 +with host_paths.SysPath(host_paths.BUILD_COMMON_PATH): + import perf_tests_results_helper # pylint: disable=import-error _PERF_TEST_ANNOTATION = 'PerfTest' @@ -109,7 +108,7 @@ class TestRunner(base_test_runner.BaseTestRunner): # because it may have race condition when multiple processes are trying to # launch lighttpd with same port at same time. self.LaunchTestHttpServer( - os.path.join(constants.DIR_SOURCE_ROOT), self._lighttp_port) + os.path.join(host_paths.DIR_SOURCE_ROOT), self._lighttp_port) if self.flags: flags_to_add = ['--disable-fre', '--enable-test-intents'] if self.options.device_flags: diff --git a/build/android/pylib/linker/setup.py b/build/android/pylib/linker/setup.py index e561957..3f380ea 100644 --- a/build/android/pylib/linker/setup.py +++ b/build/android/pylib/linker/setup.py @@ -5,17 +5,13 @@ """Setup for linker tests.""" import logging -import os -import sys -from pylib import constants +from pylib.constants import host_paths from pylib.linker import test_case from pylib.linker import test_runner -sys.path.insert(0, - os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'util', 'lib', - 'common')) -import unittest_util # pylint: disable=F0401 +with host_paths.SysPath(host_paths.BUILD_COMMON_PATH): + import unittest_util # pylint: disable=import-error # ModernLinker requires Android M (API level 23) or later. _VERSION_SDK_PROPERTY = 'ro.build.version.sdk' diff --git a/build/android/pylib/perf/test_runner.py b/build/android/pylib/perf/test_runner.py index fde95ed..5482b26 100644 --- a/build/android/pylib/perf/test_runner.py +++ b/build/android/pylib/perf/test_runner.py @@ -68,6 +68,7 @@ from devil.utils import cmd_helper from pylib import constants from pylib.base import base_test_result from pylib.base import base_test_runner +from pylib.constants import host_paths # Regex for the master branch commit position. @@ -86,7 +87,7 @@ def _GetChromiumRevision(): # pylint: enable=line-too-long status, output = cmd_helper.GetCmdStatusAndOutput( ['git', 'log', '-n', '1', '--pretty=format:%H%n%B', 'HEAD'], - constants.DIR_SOURCE_ROOT) + host_paths.DIR_SOURCE_ROOT) revision = None commit_pos = None if not status: @@ -372,9 +373,9 @@ class TestRunner(base_test_runner.BaseTestRunner): # Just print a heart-beat so that the outer buildbot scripts won't timeout # without response. logfile = _HeartBeatLogger() - cwd = os.path.abspath(constants.DIR_SOURCE_ROOT) + cwd = os.path.abspath(host_paths.DIR_SOURCE_ROOT) if full_cmd.startswith('src/'): - cwd = os.path.abspath(os.path.join(constants.DIR_SOURCE_ROOT, os.pardir)) + cwd = os.path.abspath(os.path.join(host_paths.DIR_SOURCE_ROOT, os.pardir)) try: exit_code, output = cmd_helper.GetCmdStatusAndOutputWithTimeout( full_cmd, timeout, cwd=cwd, shell=True, logfile=logfile) diff --git a/build/android/pylib/remote/device/appurify_sanitized.py b/build/android/pylib/remote/device/appurify_sanitized.py index a75d63d..48736d5 100644 --- a/build/android/pylib/remote/device/appurify_sanitized.py +++ b/build/android/pylib/remote/device/appurify_sanitized.py @@ -5,27 +5,30 @@ import contextlib import logging import os -import sys -from pylib import constants +from pylib.constants import host_paths -sys.path.append(os.path.join( - constants.DIR_SOURCE_ROOT, 'third_party', 'requests', 'src')) -sys.path.append(os.path.join( - constants.DIR_SOURCE_ROOT, 'third_party', 'appurify-python', 'src')) -handlers_before = list(logging.getLogger().handlers) +_REQUESTS_PATH = os.path.join( + host_paths.DIR_SOURCE_ROOT, 'third_party', 'requests', 'src') +_APPURIFY_PYTHON_PATH = os.path.join( + host_paths.DIR_SOURCE_ROOT, 'third_party', 'appurify-python', 'src') -import appurify.api # pylint: disable=import-error -import appurify.utils # pylint: disable=import-error +with host_paths.SysPath(_REQUESTS_PATH), ( + host_paths.SysPath(_APPURIFY_PYTHON_PATH)): -handlers_after = list(logging.getLogger().handlers) -new_handler = list(set(handlers_after) - set(handlers_before)) -while new_handler: - logging.info("Removing logging handler.") - logging.getLogger().removeHandler(new_handler.pop()) + handlers_before = list(logging.getLogger().handlers) -api = appurify.api -utils = appurify.utils + import appurify.api # pylint: disable=import-error + import appurify.utils # pylint: disable=import-error + + handlers_after = list(logging.getLogger().handlers) + new_handler = list(set(handlers_after) - set(handlers_before)) + while new_handler: + logging.info("Removing logging handler.") + logging.getLogger().removeHandler(new_handler.pop()) + + api = appurify.api + utils = appurify.utils # This is not thread safe. If multiple threads are ever supported with appurify # this may cause logging messages to go missing. diff --git a/build/android/pylib/results/flakiness_dashboard/results_uploader.py b/build/android/pylib/results/flakiness_dashboard/results_uploader.py index 1360b80..71fbee1 100644 --- a/build/android/pylib/results/flakiness_dashboard/results_uploader.py +++ b/build/android/pylib/results/flakiness_dashboard/results_uploader.py @@ -13,7 +13,7 @@ import xml from devil.utils import cmd_helper -from pylib import constants +from pylib.constants import host_paths from pylib.results.flakiness_dashboard import json_results_generator from pylib.utils import repo_utils @@ -61,11 +61,11 @@ class JSONResultsGenerator(json_results_generator.JSONResultsGeneratorBase): if os.path.exists(os.path.join(in_directory, '.git')): return True parent = os.path.dirname(in_directory) - if parent == constants.DIR_SOURCE_ROOT or parent == in_directory: + if parent == host_paths.DIR_SOURCE_ROOT or parent == in_directory: return False return _is_git_directory(parent) - in_directory = os.path.join(constants.DIR_SOURCE_ROOT, in_directory) + in_directory = os.path.join(host_paths.DIR_SOURCE_ROOT, in_directory) if not os.path.exists(os.path.join(in_directory, '.svn')): if _is_git_directory(in_directory): @@ -99,7 +99,7 @@ class ResultsUploader(object): # This requires passing the actual master name (e.g. 'ChromiumFYI' not # 'chromium.fyi'). from slave import slave_utils # pylint: disable=F0401 - self._build_name = slave_utils.SlaveBuildName(constants.DIR_SOURCE_ROOT) + self._build_name = slave_utils.SlaveBuildName(host_paths.DIR_SOURCE_ROOT) self._master_name = slave_utils.GetActiveMaster() else: self._build_name = 'chromium-android' diff --git a/build/android/pylib/utils/findbugs.py b/build/android/pylib/utils/findbugs.py index ee2d5a7..0456893 100644 --- a/build/android/pylib/utils/findbugs.py +++ b/build/android/pylib/utils/findbugs.py @@ -8,14 +8,15 @@ import xml.dom.minidom from devil.utils import cmd_helper from pylib import constants +from pylib.constants import host_paths -_FINDBUGS_HOME = os.path.join(constants.DIR_SOURCE_ROOT, 'third_party', +_FINDBUGS_HOME = os.path.join(host_paths.DIR_SOURCE_ROOT, 'third_party', 'findbugs') _FINDBUGS_JAR = os.path.join(_FINDBUGS_HOME, 'lib', 'findbugs.jar') _FINDBUGS_MAX_HEAP = 768 _FINDBUGS_PLUGIN_PATH = os.path.join( - constants.DIR_SOURCE_ROOT, 'tools', 'android', 'findbugs_plugin', 'lib', + host_paths.DIR_SOURCE_ROOT, 'tools', 'android', 'findbugs_plugin', 'lib', 'chromiumPlugin.jar') diff --git a/build/android/pylib/utils/isolator.py b/build/android/pylib/utils/isolator.py index 3e8b643..7f7b980 100644 --- a/build/android/pylib/utils/isolator.py +++ b/build/android/pylib/utils/isolator.py @@ -11,15 +11,16 @@ import tempfile from devil.utils import cmd_helper from pylib import constants +from pylib.constants import host_paths _ISOLATE_SCRIPT = os.path.join( - constants.DIR_SOURCE_ROOT, 'tools', 'swarming_client', 'isolate.py') + host_paths.DIR_SOURCE_ROOT, 'tools', 'swarming_client', 'isolate.py') def DefaultPathVariables(): return { - 'DEPTH': constants.DIR_SOURCE_ROOT, + 'DEPTH': host_paths.DIR_SOURCE_ROOT, 'PRODUCT_DIR': constants.GetOutDirectory(), } @@ -159,7 +160,7 @@ class Isolator(object): deps_out_dir = os.path.join( self._isolate_deps_dir, os.path.relpath(os.path.join(constants.GetOutDirectory(), os.pardir), - constants.DIR_SOURCE_ROOT)) + host_paths.DIR_SOURCE_ROOT)) for root, _, filenames in os.walk(deps_out_dir): for filename in fnmatch.filter(filenames, '*.pak'): shutil.move(os.path.join(root, filename), paks_dir) diff --git a/build/android/pylib/utils/logging_utils.py b/build/android/pylib/utils/logging_utils.py index 326a8b0..2c2eabf 100644 --- a/build/android/pylib/utils/logging_utils.py +++ b/build/android/pylib/utils/logging_utils.py @@ -5,12 +5,14 @@ import contextlib import logging import os -import sys -from pylib import constants -sys.path.insert(0, os.path.join(constants.DIR_SOURCE_ROOT, - 'third_party', 'colorama', 'src')) -import colorama +from pylib.constants import host_paths + +_COLORAMA_PATH = os.path.join( + host_paths.DIR_SOURCE_ROOT, 'third_party', 'colorama', 'src') + +with host_paths.SysPath(_COLORAMA_PATH): + import colorama class ColorStreamHandler(logging.StreamHandler): """Handler that can be used to colorize logging output. diff --git a/build/android/resource_sizes.py b/build/android/resource_sizes.py index db008bb..00df8ef 100755 --- a/build/android/resource_sizes.py +++ b/build/android/resource_sizes.py @@ -20,14 +20,17 @@ import tempfile import zipfile import zlib +import devil_chromium from devil.utils import cmd_helper -from pylib import constants +from pylib.constants import host_paths -sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, 'tools', 'grit')) -from grit.format import data_pack # pylint: disable=import-error -sys.path.append(os.path.join( - constants.DIR_SOURCE_ROOT, 'build', 'util', 'lib', 'common')) -import perf_tests_results_helper # pylint: disable=import-error +_GRIT_PATH = os.path.join(host_paths.DIR_SOURCE_ROOT, 'tools', 'grit') + +with host_paths.SysPath(_GRIT_PATH): + from grit.format import data_pack # pylint: disable=import-error + +with host_paths.SysPath(host_paths.BUILD_COMMON_PATH): + import perf_tests_results_helper # pylint: disable=import-error # Static initializers expected in official builds. Note that this list is built @@ -271,7 +274,7 @@ def PrintPakAnalysis(apk_filename, min_pak_resource_size, build_type): def _GetResourceIdNameMap(build_type): """Returns a map of {resource_id: resource_name}.""" - out_dir = os.path.join(constants.DIR_SOURCE_ROOT, 'out', build_type) + out_dir = os.path.join(host_paths.DIR_SOURCE_ROOT, 'out', build_type) assert os.path.isdir(out_dir), 'Failed to locate out dir at %s' % out_dir print 'Looking at resources in: %s' % out_dir @@ -367,6 +370,8 @@ Pass any number of files to graph their sizes. Any files with the extension if not files: option_parser.error('Must specify a file') + devil_chromium.Initialize() + if options.so_with_symbols_path: PrintStaticInitializersCount( options.so_with_symbols_path, chartjson=chartjson) diff --git a/build/android/screenshot.py b/build/android/screenshot.py index 88f46f7..6ab9060 100755 --- a/build/android/screenshot.py +++ b/build/android/screenshot.py @@ -5,7 +5,9 @@ import sys +import devil_chromium from devil.android.tools import screenshot if __name__ == '__main__': + devil_chromium.Initialize() sys.exit(screenshot.main()) diff --git a/build/android/symbolize.py b/build/android/symbolize.py index acd4e51..d5f6d7c 100755 --- a/build/android/symbolize.py +++ b/build/android/symbolize.py @@ -10,17 +10,16 @@ Sample usage: adb logcat chromium:V | symbolize.py """ -import os import re import sys -from pylib import constants +from pylib.constants import host_paths # Uses symbol.py from third_party/android_platform, not python's. -sys.path.insert(0, - os.path.join(constants.DIR_SOURCE_ROOT, - 'third_party/android_platform/development/scripts')) -import symbol +with host_paths.SysPath( + host_paths.ANDROID_PLATFORM_DEVELOPMENT_SCRIPTS_PATH, + position=0): + import symbol # Sample output from base/debug/stack_trace_android.cc #00 0x693cd34f /path/to/some/libfoo.so+0x0007434f diff --git a/build/android/test_runner.py b/build/android/test_runner.py index 4f968b5..2de0a33 100755 --- a/build/android/test_runner.py +++ b/build/android/test_runner.py @@ -17,7 +17,6 @@ import threading import unittest import devil_chromium - from devil import base_error from devil import devil_env from devil.android import apk_helper @@ -30,6 +29,7 @@ from devil.utils import reraiser_thread from devil.utils import run_tests_helper from pylib import constants +from pylib.constants import host_paths from pylib.base import base_test_result from pylib.base import environment_factory from pylib.base import test_dispatcher @@ -51,7 +51,7 @@ from pylib.results import report_results _DEVIL_STATIC_CONFIG_FILE = os.path.abspath(os.path.join( - constants.DIR_SOURCE_ROOT, 'build', 'android', 'devil_config.json')) + host_paths.DIR_SOURCE_ROOT, 'build', 'android', 'devil_config.json')) def AddCommonOptions(parser): diff --git a/build/android/tombstones.py b/build/android/tombstones.py index ccb86a4..39fa505 100755 --- a/build/android/tombstones.py +++ b/build/android/tombstones.py @@ -239,12 +239,12 @@ def main(): 'crash stacks.') options, _ = parser.parse_args() + devil_chromium.Initialize() + blacklist = (device_blacklist.Blacklist(options.blacklist_file) if options.blacklist_file else None) - devil_chromium.Initialize() - if options.device: devices = [device_utils.DeviceUtils(options.device)] else: diff --git a/build/android/update_verification.py b/build/android/update_verification.py index bdd49f1a..40cb64a 100755 --- a/build/android/update_verification.py +++ b/build/android/update_verification.py @@ -28,6 +28,8 @@ import argparse import logging import sys +import devil_chromium + from devil.android import apk_helper from devil.android import device_blacklist from devil.android import device_errors @@ -87,6 +89,8 @@ def main(): args = parser.parse_args() run_tests_helper.SetLogLevel(args.verbose) + devil_chromium.Initialize() + blacklist = (device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None) diff --git a/build/android/video_recorder.py b/build/android/video_recorder.py index 666ede6..b21759a3 100755 --- a/build/android/video_recorder.py +++ b/build/android/video_recorder.py @@ -5,7 +5,9 @@ import sys +import devil_chromium from devil.android.tools import video_recorder if __name__ == '__main__': + devil_chromium.Initialize() sys.exit(video_recorder.main()) |