[email protected] | cb155a8 | 2011-11-29 17:25:34 | [diff] [blame] | 1 | #!/usr/bin/env python |
[email protected] | 5e93cf16 | 2012-01-28 02:16:56 | [diff] [blame] | 2 | # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 67e0bc6 | 2009-09-03 22:06:09 | [diff] [blame] | 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | """Snapshot Build Bisect Tool |
| 7 | |
[email protected] | 7ad66a7 | 2009-09-04 17:52:33 | [diff] [blame] | 8 | This script bisects a snapshot archive using binary search. It starts at |
[email protected] | 67e0bc6 | 2009-09-03 22:06:09 | [diff] [blame] | 9 | a bad revision (it will try to guess HEAD) and asks for a last known-good |
| 10 | revision. It will then binary search across this revision range by downloading, |
| 11 | unzipping, and opening Chromium for you. After testing the specific revision, |
| 12 | it will ask you whether it is good or bad before continuing the search. |
[email protected] | 67e0bc6 | 2009-09-03 22:06:09 | [diff] [blame] | 13 | """ |
| 14 | |
Raul Tambre | 57e09d6 | 2019-09-22 17:18:52 | [diff] [blame] | 15 | from __future__ import print_function |
| 16 | |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 17 | # The base URL for stored build archives. |
| 18 | CHROMIUM_BASE_URL = ('http://commondatastorage.googleapis.com' |
| 19 | '/chromium-browser-snapshots') |
| 20 | WEBKIT_BASE_URL = ('http://commondatastorage.googleapis.com' |
| 21 | '/chromium-webkit-snapshots') |
[email protected] | 01188669 | 2014-08-01 21:00:21 | [diff] [blame] | 22 | ASAN_BASE_URL = ('http://commondatastorage.googleapis.com' |
| 23 | '/chromium-browser-asan') |
[email protected] | 67e0bc6 | 2009-09-03 22:06:09 | [diff] [blame] | 24 | |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 25 | # URL template for viewing changelogs between revisions. |
pshenoy | 9ce271f | 2014-09-02 22:14:05 | [diff] [blame] | 26 | CHANGELOG_URL = ('https://chromium.googlesource.com/chromium/src/+log/%s..%s') |
| 27 | |
| 28 | # URL to convert SVN revision to git hash. |
pshenoy | 13cb79e0 | 2014-09-05 01:42:53 | [diff] [blame] | 29 | CRREV_URL = ('https://cr-rev.appspot.com/_ah/api/crrev/v1/redirect/') |
[email protected] | f6a71a7 | 2009-10-08 19:55:38 | [diff] [blame] | 30 | |
[email protected] | b2fe7f2 | 2011-10-25 22:58:31 | [diff] [blame] | 31 | # DEPS file URL. |
Di Mu | 08c5968 | 2016-07-11 23:05:07 | [diff] [blame] | 32 | DEPS_FILE = ('https://chromium.googlesource.com/chromium/src/+/%s/DEPS') |
[email protected] | b2fe7f2 | 2011-10-25 22:58:31 | [diff] [blame] | 33 | |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 34 | # Blink changelogs URL. |
| 35 | BLINK_CHANGELOG_URL = ('http://build.chromium.org' |
| 36 | '/f/chromium/perf/dashboard/ui/changelog_blink.html' |
| 37 | '?url=/trunk&range=%d%%3A%d') |
| 38 | |
| 39 | DONE_MESSAGE_GOOD_MIN = ('You are probably looking for a change made after %s (' |
| 40 | 'known good), but no later than %s (first known bad).') |
| 41 | DONE_MESSAGE_GOOD_MAX = ('You are probably looking for a change made after %s (' |
| 42 | 'known bad), but no later than %s (first known good).') |
[email protected] | 05ff3fd | 2012-04-17 23:24:06 | [diff] [blame] | 43 | |
[email protected] | 3e7c8532 | 2014-06-27 20:27:36 | [diff] [blame] | 44 | CHROMIUM_GITHASH_TO_SVN_URL = ( |
| 45 | 'https://chromium.googlesource.com/chromium/src/+/%s?format=json') |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 46 | |
[email protected] | 3e7c8532 | 2014-06-27 20:27:36 | [diff] [blame] | 47 | BLINK_GITHASH_TO_SVN_URL = ( |
| 48 | 'https://chromium.googlesource.com/chromium/blink/+/%s?format=json') |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 49 | |
| 50 | GITHASH_TO_SVN_URL = { |
| 51 | 'chromium': CHROMIUM_GITHASH_TO_SVN_URL, |
| 52 | 'blink': BLINK_GITHASH_TO_SVN_URL, |
| 53 | } |
| 54 | |
Bruce Dawson | cd63ea2 | 2020-10-26 16:37:41 | [diff] [blame] | 55 | VERSION_HISTORY_URL = ('https://versionhistory.googleapis.com/v1/chrome' |
| 56 | '/platforms/win/channels/stable/versions/all/releases') |
| 57 | |
| 58 | OMAHA_REVISIONS_URL = ('https://omahaproxy.appspot.com/deps.json?version=%s') |
| 59 | |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 60 | # Search pattern to be matched in the JSON output from |
[email protected] | 3e7c8532 | 2014-06-27 20:27:36 | [diff] [blame] | 61 | # CHROMIUM_GITHASH_TO_SVN_URL to get the chromium revision (svn revision). |
pshenoy | b23a145 | 2014-09-05 22:52:05 | [diff] [blame] | 62 | CHROMIUM_SEARCH_PATTERN_OLD = ( |
[email protected] | 3e7c8532 | 2014-06-27 20:27:36 | [diff] [blame] | 63 | r'.*git-svn-id: svn://svn.chromium.org/chrome/trunk/src@(\d+) ') |
pshenoy | b23a145 | 2014-09-05 22:52:05 | [diff] [blame] | 64 | CHROMIUM_SEARCH_PATTERN = ( |
| 65 | r'Cr-Commit-Position: refs/heads/master@{#(\d+)}') |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 66 | |
[email protected] | 3e7c8532 | 2014-06-27 20:27:36 | [diff] [blame] | 67 | # Search pattern to be matched in the json output from |
| 68 | # BLINK_GITHASH_TO_SVN_URL to get the blink revision (svn revision). |
| 69 | BLINK_SEARCH_PATTERN = ( |
| 70 | r'.*git-svn-id: svn://svn.chromium.org/blink/trunk@(\d+) ') |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 71 | |
| 72 | SEARCH_PATTERN = { |
| 73 | 'chromium': CHROMIUM_SEARCH_PATTERN, |
| 74 | 'blink': BLINK_SEARCH_PATTERN, |
| 75 | } |
[email protected] | 3e7c8532 | 2014-06-27 20:27:36 | [diff] [blame] | 76 | |
[email protected] | 48036978 | 2014-08-22 20:15:58 | [diff] [blame] | 77 | CREDENTIAL_ERROR_MESSAGE = ('You are attempting to access protected data with ' |
| 78 | 'no configured credentials') |
| 79 | |
[email protected] | 67e0bc6 | 2009-09-03 22:06:09 | [diff] [blame] | 80 | ############################################################################### |
| 81 | |
Dominic Mazzoni | 215e80b | 2017-11-29 20:05:27 | [diff] [blame] | 82 | import glob |
[email protected] | 8304850 | 2014-08-21 16:48:44 | [diff] [blame] | 83 | import httplib |
[email protected] | 4c6fec6b | 2013-09-17 17:44:08 | [diff] [blame] | 84 | import json |
[email protected] | 7ad66a7 | 2009-09-04 17:52:33 | [diff] [blame] | 85 | import optparse |
[email protected] | 67e0bc6 | 2009-09-03 22:06:09 | [diff] [blame] | 86 | import os |
| 87 | import re |
[email protected] | 61ea90a | 2013-09-26 10:17:34 | [diff] [blame] | 88 | import shlex |
[email protected] | 67e0bc6 | 2009-09-03 22:06:09 | [diff] [blame] | 89 | import shutil |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 90 | import subprocess |
[email protected] | 67e0bc6 | 2009-09-03 22:06:09 | [diff] [blame] | 91 | import sys |
[email protected] | 7ad66a7 | 2009-09-04 17:52:33 | [diff] [blame] | 92 | import tempfile |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 93 | import threading |
[email protected] | 67e0bc6 | 2009-09-03 22:06:09 | [diff] [blame] | 94 | import urllib |
[email protected] | d0149c5c | 2012-05-29 21:12:11 | [diff] [blame] | 95 | from distutils.version import LooseVersion |
[email protected] | 183706d9 | 2011-06-10 13:06:22 | [diff] [blame] | 96 | from xml.etree import ElementTree |
[email protected] | bd8dcb9 | 2010-03-31 01:05:24 | [diff] [blame] | 97 | import zipfile |
| 98 | |
[email protected] | cb155a8 | 2011-11-29 17:25:34 | [diff] [blame] | 99 | |
[email protected] | 183706d9 | 2011-06-10 13:06:22 | [diff] [blame] | 100 | class PathContext(object): |
| 101 | """A PathContext is used to carry the information used to construct URLs and |
| 102 | paths when dealing with the storage server and archives.""" |
[email protected] | 4c6fec6b | 2013-09-17 17:44:08 | [diff] [blame] | 103 | def __init__(self, base_url, platform, good_revision, bad_revision, |
Jason Kersey | 97bb027a | 2016-05-11 20:10:43 | [diff] [blame] | 104 | is_asan, use_local_cache, flash_path = None): |
[email protected] | 183706d9 | 2011-06-10 13:06:22 | [diff] [blame] | 105 | super(PathContext, self).__init__() |
| 106 | # Store off the input parameters. |
[email protected] | 4c6fec6b | 2013-09-17 17:44:08 | [diff] [blame] | 107 | self.base_url = base_url |
[email protected] | 183706d9 | 2011-06-10 13:06:22 | [diff] [blame] | 108 | self.platform = platform # What's passed in to the '-a/--archive' option. |
| 109 | self.good_revision = good_revision |
| 110 | self.bad_revision = bad_revision |
[email protected] | 01188669 | 2014-08-01 21:00:21 | [diff] [blame] | 111 | self.is_asan = is_asan |
| 112 | self.build_type = 'release' |
[email protected] | fc3702e | 2013-11-09 04:23:00 | [diff] [blame] | 113 | self.flash_path = flash_path |
[email protected] | 3e7c8532 | 2014-06-27 20:27:36 | [diff] [blame] | 114 | # Dictionary which stores svn revision number as key and it's |
| 115 | # corresponding git hash as value. This data is populated in |
| 116 | # _FetchAndParse and used later in GetDownloadURL while downloading |
| 117 | # the build. |
| 118 | self.githash_svn_dict = {} |
[email protected] | 183706d9 | 2011-06-10 13:06:22 | [diff] [blame] | 119 | # The name of the ZIP file in a revision directory on the server. |
| 120 | self.archive_name = None |
| 121 | |
rob | 724c906 | 2015-01-22 00:26:42 | [diff] [blame] | 122 | # Whether to cache and use the list of known revisions in a local file to |
| 123 | # speed up the initialization of the script at the next run. |
| 124 | self.use_local_cache = use_local_cache |
| 125 | |
| 126 | # Locate the local checkout to speed up the script by using locally stored |
| 127 | # metadata. |
| 128 | abs_file_path = os.path.abspath(os.path.realpath(__file__)) |
| 129 | local_src_path = os.path.join(os.path.dirname(abs_file_path), '..') |
| 130 | if abs_file_path.endswith(os.path.join('tools', 'bisect-builds.py')) and\ |
| 131 | os.path.exists(os.path.join(local_src_path, '.git')): |
| 132 | self.local_src_path = os.path.normpath(local_src_path) |
| 133 | else: |
| 134 | self.local_src_path = None |
[email protected] | 6a7a5d6 | 2014-07-09 04:45:50 | [diff] [blame] | 135 | |
[email protected] | 183706d9 | 2011-06-10 13:06:22 | [diff] [blame] | 136 | # Set some internal members: |
| 137 | # _listing_platform_dir = Directory that holds revisions. Ends with a '/'. |
| 138 | # _archive_extract_dir = Uncompressed directory in the archive_name file. |
| 139 | # _binary_name = The name of the executable to run. |
dmazzoni | 76e907d | 2015-01-22 08:14:49 | [diff] [blame] | 140 | if self.platform in ('linux', 'linux64', 'linux-arm', 'chromeos'): |
[email protected] | 183706d9 | 2011-06-10 13:06:22 | [diff] [blame] | 141 | self._binary_name = 'chrome' |
[email protected] | 48036978 | 2014-08-22 20:15:58 | [diff] [blame] | 142 | elif self.platform in ('mac', 'mac64'): |
[email protected] | 183706d9 | 2011-06-10 13:06:22 | [diff] [blame] | 143 | self.archive_name = 'chrome-mac.zip' |
| 144 | self._archive_extract_dir = 'chrome-mac' |
[email protected] | 48036978 | 2014-08-22 20:15:58 | [diff] [blame] | 145 | elif self.platform in ('win', 'win64'): |
Dominic Mazzoni | e84e40b | 2018-10-08 06:44:45 | [diff] [blame] | 146 | # Note: changed at revision 591483; see GetDownloadURL and GetLaunchPath |
| 147 | # below where these are patched. |
[email protected] | 183706d9 | 2011-06-10 13:06:22 | [diff] [blame] | 148 | self.archive_name = 'chrome-win32.zip' |
| 149 | self._archive_extract_dir = 'chrome-win32' |
| 150 | self._binary_name = 'chrome.exe' |
| 151 | else: |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 152 | raise Exception('Invalid platform: %s' % self.platform) |
[email protected] | 183706d9 | 2011-06-10 13:06:22 | [diff] [blame] | 153 | |
Jason Kersey | 97bb027a | 2016-05-11 20:10:43 | [diff] [blame] | 154 | if self.platform in ('linux', 'linux64', 'linux-arm', 'chromeos'): |
Dominic Mazzoni | e84e40b | 2018-10-08 06:44:45 | [diff] [blame] | 155 | # Note: changed at revision 591483; see GetDownloadURL and GetLaunchPath |
| 156 | # below where these are patched. |
Jason Kersey | 97bb027a | 2016-05-11 20:10:43 | [diff] [blame] | 157 | self.archive_name = 'chrome-linux.zip' |
| 158 | self._archive_extract_dir = 'chrome-linux' |
[email protected] | d0149c5c | 2012-05-29 21:12:11 | [diff] [blame] | 159 | if self.platform == 'linux': |
Jason Kersey | 97bb027a | 2016-05-11 20:10:43 | [diff] [blame] | 160 | self._listing_platform_dir = 'Linux/' |
[email protected] | d0149c5c | 2012-05-29 21:12:11 | [diff] [blame] | 161 | elif self.platform == 'linux64': |
Jason Kersey | 97bb027a | 2016-05-11 20:10:43 | [diff] [blame] | 162 | self._listing_platform_dir = 'Linux_x64/' |
| 163 | elif self.platform == 'linux-arm': |
| 164 | self._listing_platform_dir = 'Linux_ARM_Cross-Compile/' |
| 165 | elif self.platform == 'chromeos': |
| 166 | self._listing_platform_dir = 'Linux_ChromiumOS_Full/' |
| 167 | elif self.platform in ('mac', 'mac64'): |
| 168 | self._listing_platform_dir = 'Mac/' |
| 169 | self._binary_name = 'Chromium.app/Contents/MacOS/Chromium' |
| 170 | elif self.platform == 'win': |
| 171 | self._listing_platform_dir = 'Win/' |
jiawei.shao | 734efbc9 | 2016-09-23 02:11:45 | [diff] [blame] | 172 | elif self.platform == 'win64': |
| 173 | self._listing_platform_dir = 'Win_x64/' |
[email protected] | d0149c5c | 2012-05-29 21:12:11 | [diff] [blame] | 174 | |
[email protected] | 01188669 | 2014-08-01 21:00:21 | [diff] [blame] | 175 | def GetASANPlatformDir(self): |
| 176 | """ASAN builds are in directories like "linux-release", or have filenames |
| 177 | like "asan-win32-release-277079.zip". This aligns to our platform names |
| 178 | except in the case of Windows where they use "win32" instead of "win".""" |
| 179 | if self.platform == 'win': |
| 180 | return 'win32' |
| 181 | else: |
| 182 | return self.platform |
| 183 | |
[email protected] | 183706d9 | 2011-06-10 13:06:22 | [diff] [blame] | 184 | def GetListingURL(self, marker=None): |
| 185 | """Returns the URL for a directory listing, with an optional marker.""" |
| 186 | marker_param = '' |
| 187 | if marker: |
| 188 | marker_param = '&marker=' + str(marker) |
[email protected] | 01188669 | 2014-08-01 21:00:21 | [diff] [blame] | 189 | if self.is_asan: |
| 190 | prefix = '%s-%s' % (self.GetASANPlatformDir(), self.build_type) |
| 191 | return self.base_url + '/?delimiter=&prefix=' + prefix + marker_param |
| 192 | else: |
| 193 | return (self.base_url + '/?delimiter=/&prefix=' + |
| 194 | self._listing_platform_dir + marker_param) |
[email protected] | 183706d9 | 2011-06-10 13:06:22 | [diff] [blame] | 195 | |
| 196 | def GetDownloadURL(self, revision): |
| 197 | """Gets the download URL for a build archive of a specific revision.""" |
[email protected] | 01188669 | 2014-08-01 21:00:21 | [diff] [blame] | 198 | if self.is_asan: |
| 199 | return '%s/%s-%s/%s-%d.zip' % ( |
| 200 | ASAN_BASE_URL, self.GetASANPlatformDir(), self.build_type, |
| 201 | self.GetASANBaseName(), revision) |
Jason Kersey | 97bb027a | 2016-05-11 20:10:43 | [diff] [blame] | 202 | if str(revision) in self.githash_svn_dict: |
| 203 | revision = self.githash_svn_dict[str(revision)] |
Dominic Mazzoni | e84e40b | 2018-10-08 06:44:45 | [diff] [blame] | 204 | archive_name = self.archive_name |
| 205 | |
| 206 | # At revision 591483, the names of two of the archives changed |
| 207 | # due to: https://chromium-review.googlesource.com/#/q/1226086 |
| 208 | # See: http://crbug.com/789612 |
| 209 | if revision >= 591483: |
| 210 | if self.platform == 'chromeos': |
| 211 | archive_name = 'chrome-chromeos.zip' |
| 212 | elif self.platform in ('win', 'win64'): |
| 213 | archive_name = 'chrome-win.zip' |
| 214 | |
Jason Kersey | 97bb027a | 2016-05-11 20:10:43 | [diff] [blame] | 215 | return '%s/%s%s/%s' % (self.base_url, self._listing_platform_dir, |
Dominic Mazzoni | e84e40b | 2018-10-08 06:44:45 | [diff] [blame] | 216 | revision, archive_name) |
[email protected] | 183706d9 | 2011-06-10 13:06:22 | [diff] [blame] | 217 | |
| 218 | def GetLastChangeURL(self): |
| 219 | """Returns a URL to the LAST_CHANGE file.""" |
[email protected] | 4c6fec6b | 2013-09-17 17:44:08 | [diff] [blame] | 220 | return self.base_url + '/' + self._listing_platform_dir + 'LAST_CHANGE' |
[email protected] | 183706d9 | 2011-06-10 13:06:22 | [diff] [blame] | 221 | |
[email protected] | 01188669 | 2014-08-01 21:00:21 | [diff] [blame] | 222 | def GetASANBaseName(self): |
| 223 | """Returns the base name of the ASAN zip file.""" |
| 224 | if 'linux' in self.platform: |
| 225 | return 'asan-symbolized-%s-%s' % (self.GetASANPlatformDir(), |
| 226 | self.build_type) |
| 227 | else: |
| 228 | return 'asan-%s-%s' % (self.GetASANPlatformDir(), self.build_type) |
| 229 | |
| 230 | def GetLaunchPath(self, revision): |
[email protected] | 183706d9 | 2011-06-10 13:06:22 | [diff] [blame] | 231 | """Returns a relative path (presumably from the archive extraction location) |
| 232 | that is used to run the executable.""" |
[email protected] | 01188669 | 2014-08-01 21:00:21 | [diff] [blame] | 233 | if self.is_asan: |
| 234 | extract_dir = '%s-%d' % (self.GetASANBaseName(), revision) |
| 235 | else: |
| 236 | extract_dir = self._archive_extract_dir |
Dominic Mazzoni | e84e40b | 2018-10-08 06:44:45 | [diff] [blame] | 237 | |
| 238 | # At revision 591483, the names of two of the archives changed |
| 239 | # due to: https://chromium-review.googlesource.com/#/q/1226086 |
| 240 | # See: http://crbug.com/789612 |
| 241 | if revision >= 591483: |
| 242 | if self.platform == 'chromeos': |
| 243 | extract_dir = 'chrome-chromeos' |
| 244 | elif self.platform in ('win', 'win64'): |
Lei Zhang | 1c8c6f7e | 2018-11-09 16:46:30 | [diff] [blame] | 245 | extract_dir = 'chrome-win' |
Dominic Mazzoni | e84e40b | 2018-10-08 06:44:45 | [diff] [blame] | 246 | |
[email protected] | 01188669 | 2014-08-01 21:00:21 | [diff] [blame] | 247 | return os.path.join(extract_dir, self._binary_name) |
[email protected] | 183706d9 | 2011-06-10 13:06:22 | [diff] [blame] | 248 | |
rob | 724c906 | 2015-01-22 00:26:42 | [diff] [blame] | 249 | def ParseDirectoryIndex(self, last_known_rev): |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 250 | """Parses the Google Storage directory listing into a list of revision |
[email protected] | eadd95d | 2012-11-02 22:42:09 | [diff] [blame] | 251 | numbers.""" |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 252 | |
rob | 724c906 | 2015-01-22 00:26:42 | [diff] [blame] | 253 | def _GetMarkerForRev(revision): |
| 254 | if self.is_asan: |
| 255 | return '%s-%s/%s-%d.zip' % ( |
| 256 | self.GetASANPlatformDir(), self.build_type, |
| 257 | self.GetASANBaseName(), revision) |
| 258 | return '%s%d' % (self._listing_platform_dir, revision) |
| 259 | |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 260 | def _FetchAndParse(url): |
| 261 | """Fetches a URL and returns a 2-Tuple of ([revisions], next-marker). If |
| 262 | next-marker is not None, then the listing is a partial listing and another |
| 263 | fetch should be performed with next-marker being the marker= GET |
| 264 | parameter.""" |
| 265 | handle = urllib.urlopen(url) |
| 266 | document = ElementTree.parse(handle) |
| 267 | |
| 268 | # All nodes in the tree are namespaced. Get the root's tag name to extract |
| 269 | # the namespace. Etree does namespaces as |{namespace}tag|. |
| 270 | root_tag = document.getroot().tag |
| 271 | end_ns_pos = root_tag.find('}') |
| 272 | if end_ns_pos == -1: |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 273 | raise Exception('Could not locate end namespace for directory index') |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 274 | namespace = root_tag[:end_ns_pos + 1] |
| 275 | |
| 276 | # Find the prefix (_listing_platform_dir) and whether or not the list is |
| 277 | # truncated. |
| 278 | prefix_len = len(document.find(namespace + 'Prefix').text) |
| 279 | next_marker = None |
| 280 | is_truncated = document.find(namespace + 'IsTruncated') |
| 281 | if is_truncated is not None and is_truncated.text.lower() == 'true': |
| 282 | next_marker = document.find(namespace + 'NextMarker').text |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 283 | # Get a list of all the revisions. |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 284 | revisions = [] |
[email protected] | 3e7c8532 | 2014-06-27 20:27:36 | [diff] [blame] | 285 | githash_svn_dict = {} |
[email protected] | 01188669 | 2014-08-01 21:00:21 | [diff] [blame] | 286 | if self.is_asan: |
| 287 | asan_regex = re.compile(r'.*%s-(\d+)\.zip$' % (self.GetASANBaseName())) |
| 288 | # Non ASAN builds are in a <revision> directory. The ASAN builds are |
| 289 | # flat |
| 290 | all_prefixes = document.findall(namespace + 'Contents/' + |
| 291 | namespace + 'Key') |
| 292 | for prefix in all_prefixes: |
| 293 | m = asan_regex.match(prefix.text) |
| 294 | if m: |
| 295 | try: |
| 296 | revisions.append(int(m.group(1))) |
| 297 | except ValueError: |
| 298 | pass |
| 299 | else: |
| 300 | all_prefixes = document.findall(namespace + 'CommonPrefixes/' + |
| 301 | namespace + 'Prefix') |
| 302 | # The <Prefix> nodes have content of the form of |
| 303 | # |_listing_platform_dir/revision/|. Strip off the platform dir and the |
| 304 | # trailing slash to just have a number. |
| 305 | for prefix in all_prefixes: |
| 306 | revnum = prefix.text[prefix_len:-1] |
| 307 | try: |
dimu | a1dfa0ce | 2016-03-31 01:08:45 | [diff] [blame] | 308 | revnum = int(revnum) |
| 309 | revisions.append(revnum) |
| 310 | # Notes: |
| 311 | # Ignore hash in chromium-browser-snapshots as they are invalid |
| 312 | # Resulting in 404 error in fetching pages: |
| 313 | # https://chromium.googlesource.com/chromium/src/+/[rev_hash] |
[email protected] | 01188669 | 2014-08-01 21:00:21 | [diff] [blame] | 314 | except ValueError: |
| 315 | pass |
[email protected] | 3e7c8532 | 2014-06-27 20:27:36 | [diff] [blame] | 316 | return (revisions, next_marker, githash_svn_dict) |
[email protected] | 9639b00 | 2013-08-30 14:45:52 | [diff] [blame] | 317 | |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 318 | # Fetch the first list of revisions. |
rob | 724c906 | 2015-01-22 00:26:42 | [diff] [blame] | 319 | if last_known_rev: |
| 320 | revisions = [] |
| 321 | # Optimization: Start paging at the last known revision (local cache). |
| 322 | next_marker = _GetMarkerForRev(last_known_rev) |
| 323 | # Optimization: Stop paging at the last known revision (remote). |
| 324 | last_change_rev = GetChromiumRevision(self, self.GetLastChangeURL()) |
| 325 | if last_known_rev == last_change_rev: |
| 326 | return [] |
| 327 | else: |
| 328 | (revisions, next_marker, new_dict) = _FetchAndParse(self.GetListingURL()) |
| 329 | self.githash_svn_dict.update(new_dict) |
| 330 | last_change_rev = None |
| 331 | |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 332 | # If the result list was truncated, refetch with the next marker. Do this |
| 333 | # until an entire directory listing is done. |
| 334 | while next_marker: |
rob | 724c906 | 2015-01-22 00:26:42 | [diff] [blame] | 335 | sys.stdout.write('\rFetching revisions at marker %s' % next_marker) |
| 336 | sys.stdout.flush() |
| 337 | |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 338 | next_url = self.GetListingURL(next_marker) |
[email protected] | 3e7c8532 | 2014-06-27 20:27:36 | [diff] [blame] | 339 | (new_revisions, next_marker, new_dict) = _FetchAndParse(next_url) |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 340 | revisions.extend(new_revisions) |
[email protected] | 3e7c8532 | 2014-06-27 20:27:36 | [diff] [blame] | 341 | self.githash_svn_dict.update(new_dict) |
rob | 724c906 | 2015-01-22 00:26:42 | [diff] [blame] | 342 | if last_change_rev and last_change_rev in new_revisions: |
| 343 | break |
| 344 | sys.stdout.write('\r') |
| 345 | sys.stdout.flush() |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 346 | return revisions |
| 347 | |
[email protected] | 6a7a5d6 | 2014-07-09 04:45:50 | [diff] [blame] | 348 | def _GetSVNRevisionFromGitHashWithoutGitCheckout(self, git_sha1, depot): |
[email protected] | 3e7c8532 | 2014-06-27 20:27:36 | [diff] [blame] | 349 | json_url = GITHASH_TO_SVN_URL[depot] % git_sha1 |
[email protected] | 2e0f267 | 2014-08-13 20:32:58 | [diff] [blame] | 350 | response = urllib.urlopen(json_url) |
| 351 | if response.getcode() == 200: |
| 352 | try: |
| 353 | data = json.loads(response.read()[4:]) |
| 354 | except ValueError: |
Raul Tambre | 57e09d6 | 2019-09-22 17:18:52 | [diff] [blame] | 355 | print('ValueError for JSON URL: %s' % json_url) |
[email protected] | 2e0f267 | 2014-08-13 20:32:58 | [diff] [blame] | 356 | raise ValueError |
| 357 | else: |
| 358 | raise ValueError |
[email protected] | 3e7c8532 | 2014-06-27 20:27:36 | [diff] [blame] | 359 | if 'message' in data: |
| 360 | message = data['message'].split('\n') |
| 361 | message = [line for line in message if line.strip()] |
| 362 | search_pattern = re.compile(SEARCH_PATTERN[depot]) |
| 363 | result = search_pattern.search(message[len(message)-1]) |
| 364 | if result: |
| 365 | return result.group(1) |
pshenoy | b23a145 | 2014-09-05 22:52:05 | [diff] [blame] | 366 | else: |
| 367 | if depot == 'chromium': |
| 368 | result = re.search(CHROMIUM_SEARCH_PATTERN_OLD, |
| 369 | message[len(message)-1]) |
| 370 | if result: |
| 371 | return result.group(1) |
Raul Tambre | 57e09d6 | 2019-09-22 17:18:52 | [diff] [blame] | 372 | print('Failed to get svn revision number for %s' % git_sha1) |
[email protected] | 1f99f4d | 2014-07-23 16:44:14 | [diff] [blame] | 373 | raise ValueError |
[email protected] | 3e7c8532 | 2014-06-27 20:27:36 | [diff] [blame] | 374 | |
[email protected] | 6a7a5d6 | 2014-07-09 04:45:50 | [diff] [blame] | 375 | def _GetSVNRevisionFromGitHashFromGitCheckout(self, git_sha1, depot): |
| 376 | def _RunGit(command, path): |
| 377 | command = ['git'] + command |
[email protected] | 6a7a5d6 | 2014-07-09 04:45:50 | [diff] [blame] | 378 | shell = sys.platform.startswith('win') |
| 379 | proc = subprocess.Popen(command, shell=shell, stdout=subprocess.PIPE, |
rob | 724c906 | 2015-01-22 00:26:42 | [diff] [blame] | 380 | stderr=subprocess.PIPE, cwd=path) |
[email protected] | 6a7a5d6 | 2014-07-09 04:45:50 | [diff] [blame] | 381 | (output, _) = proc.communicate() |
[email protected] | 6a7a5d6 | 2014-07-09 04:45:50 | [diff] [blame] | 382 | return (output, proc.returncode) |
| 383 | |
rob | 724c906 | 2015-01-22 00:26:42 | [diff] [blame] | 384 | path = self.local_src_path |
[email protected] | 6a7a5d6 | 2014-07-09 04:45:50 | [diff] [blame] | 385 | if depot == 'blink': |
rob | 724c906 | 2015-01-22 00:26:42 | [diff] [blame] | 386 | path = os.path.join(self.local_src_path, 'third_party', 'WebKit') |
| 387 | revision = None |
| 388 | try: |
[email protected] | 6a7a5d6 | 2014-07-09 04:45:50 | [diff] [blame] | 389 | command = ['svn', 'find-rev', git_sha1] |
| 390 | (git_output, return_code) = _RunGit(command, path) |
| 391 | if not return_code: |
rob | 724c906 | 2015-01-22 00:26:42 | [diff] [blame] | 392 | revision = git_output.strip('\n') |
| 393 | except ValueError: |
| 394 | pass |
| 395 | if not revision: |
| 396 | command = ['log', '-n1', '--format=%s', git_sha1] |
| 397 | (git_output, return_code) = _RunGit(command, path) |
| 398 | if not return_code: |
| 399 | revision = re.match('SVN changes up to revision ([0-9]+)', git_output) |
| 400 | revision = revision.group(1) if revision else None |
| 401 | if revision: |
| 402 | return revision |
| 403 | raise ValueError |
[email protected] | 6a7a5d6 | 2014-07-09 04:45:50 | [diff] [blame] | 404 | |
| 405 | def GetSVNRevisionFromGitHash(self, git_sha1, depot='chromium'): |
rob | 724c906 | 2015-01-22 00:26:42 | [diff] [blame] | 406 | if not self.local_src_path: |
[email protected] | 6a7a5d6 | 2014-07-09 04:45:50 | [diff] [blame] | 407 | return self._GetSVNRevisionFromGitHashWithoutGitCheckout(git_sha1, depot) |
| 408 | else: |
| 409 | return self._GetSVNRevisionFromGitHashFromGitCheckout(git_sha1, depot) |
| 410 | |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 411 | def GetRevList(self): |
| 412 | """Gets the list of revision numbers between self.good_revision and |
| 413 | self.bad_revision.""" |
rob | 724c906 | 2015-01-22 00:26:42 | [diff] [blame] | 414 | |
| 415 | cache = {} |
| 416 | # The cache is stored in the same directory as bisect-builds.py |
| 417 | cache_filename = os.path.join( |
| 418 | os.path.abspath(os.path.dirname(__file__)), |
| 419 | '.bisect-builds-cache.json') |
| 420 | cache_dict_key = self.GetListingURL() |
| 421 | |
| 422 | def _LoadBucketFromCache(): |
| 423 | if self.use_local_cache: |
| 424 | try: |
| 425 | with open(cache_filename) as cache_file: |
rob | 1c83605 | 2015-05-18 16:34:02 | [diff] [blame] | 426 | for (key, value) in json.load(cache_file).items(): |
| 427 | cache[key] = value |
rob | 724c906 | 2015-01-22 00:26:42 | [diff] [blame] | 428 | revisions = cache.get(cache_dict_key, []) |
| 429 | githash_svn_dict = cache.get('githash_svn_dict', {}) |
| 430 | if revisions: |
Raul Tambre | 57e09d6 | 2019-09-22 17:18:52 | [diff] [blame] | 431 | print('Loaded revisions %d-%d from %s' % |
| 432 | (revisions[0], revisions[-1], cache_filename)) |
rob | 724c906 | 2015-01-22 00:26:42 | [diff] [blame] | 433 | return (revisions, githash_svn_dict) |
| 434 | except (EnvironmentError, ValueError): |
| 435 | pass |
| 436 | return ([], {}) |
| 437 | |
| 438 | def _SaveBucketToCache(): |
| 439 | """Save the list of revisions and the git-svn mappings to a file. |
| 440 | The list of revisions is assumed to be sorted.""" |
| 441 | if self.use_local_cache: |
| 442 | cache[cache_dict_key] = revlist_all |
| 443 | cache['githash_svn_dict'] = self.githash_svn_dict |
| 444 | try: |
| 445 | with open(cache_filename, 'w') as cache_file: |
| 446 | json.dump(cache, cache_file) |
Raul Tambre | 57e09d6 | 2019-09-22 17:18:52 | [diff] [blame] | 447 | print('Saved revisions %d-%d to %s' % |
| 448 | (revlist_all[0], revlist_all[-1], cache_filename)) |
rob | 724c906 | 2015-01-22 00:26:42 | [diff] [blame] | 449 | except EnvironmentError: |
| 450 | pass |
| 451 | |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 452 | # Download the revlist and filter for just the range between good and bad. |
[email protected] | eadd95d | 2012-11-02 22:42:09 | [diff] [blame] | 453 | minrev = min(self.good_revision, self.bad_revision) |
| 454 | maxrev = max(self.good_revision, self.bad_revision) |
rob | 724c906 | 2015-01-22 00:26:42 | [diff] [blame] | 455 | |
| 456 | (revlist_all, self.githash_svn_dict) = _LoadBucketFromCache() |
| 457 | last_known_rev = revlist_all[-1] if revlist_all else 0 |
| 458 | if last_known_rev < maxrev: |
| 459 | revlist_all.extend(map(int, self.ParseDirectoryIndex(last_known_rev))) |
| 460 | revlist_all = list(set(revlist_all)) |
| 461 | revlist_all.sort() |
| 462 | _SaveBucketToCache() |
[email protected] | 37ed317 | 2013-09-24 23:49:30 | [diff] [blame] | 463 | |
| 464 | revlist = [x for x in revlist_all if x >= int(minrev) and x <= int(maxrev)] |
[email protected] | 37ed317 | 2013-09-24 23:49:30 | [diff] [blame] | 465 | |
| 466 | # Set good and bad revisions to be legit revisions. |
| 467 | if revlist: |
| 468 | if self.good_revision < self.bad_revision: |
| 469 | self.good_revision = revlist[0] |
| 470 | self.bad_revision = revlist[-1] |
| 471 | else: |
| 472 | self.bad_revision = revlist[0] |
| 473 | self.good_revision = revlist[-1] |
| 474 | |
| 475 | # Fix chromium rev so that the deps blink revision matches REVISIONS file. |
| 476 | if self.base_url == WEBKIT_BASE_URL: |
| 477 | revlist_all.sort() |
| 478 | self.good_revision = FixChromiumRevForBlink(revlist, |
| 479 | revlist_all, |
| 480 | self, |
| 481 | self.good_revision) |
| 482 | self.bad_revision = FixChromiumRevForBlink(revlist, |
| 483 | revlist_all, |
| 484 | self, |
| 485 | self.bad_revision) |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 486 | return revlist |
| 487 | |
prasadv | 2375e6d | 2017-03-20 19:23:23 | [diff] [blame] | 488 | |
| 489 | def IsMac(): |
| 490 | return sys.platform.startswith('darwin') |
| 491 | |
| 492 | |
[email protected] | fc3702e | 2013-11-09 04:23:00 | [diff] [blame] | 493 | def UnzipFilenameToDir(filename, directory): |
| 494 | """Unzip |filename| to |directory|.""" |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 495 | cwd = os.getcwd() |
| 496 | if not os.path.isabs(filename): |
| 497 | filename = os.path.join(cwd, filename) |
[email protected] | bd8dcb9 | 2010-03-31 01:05:24 | [diff] [blame] | 498 | # Make base. |
[email protected] | fc3702e | 2013-11-09 04:23:00 | [diff] [blame] | 499 | if not os.path.isdir(directory): |
| 500 | os.mkdir(directory) |
| 501 | os.chdir(directory) |
prasadv | 2375e6d | 2017-03-20 19:23:23 | [diff] [blame] | 502 | |
| 503 | # The Python ZipFile does not support symbolic links, which makes it |
| 504 | # unsuitable for Mac builds. so use ditto instead. |
| 505 | if IsMac(): |
| 506 | unzip_cmd = ['ditto', '-x', '-k', filename, '.'] |
| 507 | proc = subprocess.Popen(unzip_cmd, bufsize=0, stdout=subprocess.PIPE, |
| 508 | stderr=subprocess.PIPE) |
| 509 | proc.communicate() |
| 510 | os.chdir(cwd) |
| 511 | return |
| 512 | |
| 513 | zf = zipfile.ZipFile(filename) |
[email protected] | e29c08c | 2012-09-17 20:50:50 | [diff] [blame] | 514 | # Extract files. |
| 515 | for info in zf.infolist(): |
| 516 | name = info.filename |
| 517 | if name.endswith('/'): # dir |
| 518 | if not os.path.isdir(name): |
| 519 | os.makedirs(name) |
| 520 | else: # file |
[email protected] | fc3702e | 2013-11-09 04:23:00 | [diff] [blame] | 521 | directory = os.path.dirname(name) |
John Budorick | 06e5df1 | 2015-02-27 17:44:27 | [diff] [blame] | 522 | if not os.path.isdir(directory): |
[email protected] | fc3702e | 2013-11-09 04:23:00 | [diff] [blame] | 523 | os.makedirs(directory) |
[email protected] | e29c08c | 2012-09-17 20:50:50 | [diff] [blame] | 524 | out = open(name, 'wb') |
| 525 | out.write(zf.read(name)) |
| 526 | out.close() |
| 527 | # Set permissions. Permission info in external_attr is shifted 16 bits. |
| 528 | os.chmod(name, info.external_attr >> 16L) |
| 529 | os.chdir(cwd) |
[email protected] | bd8dcb9 | 2010-03-31 01:05:24 | [diff] [blame] | 530 | |
[email protected] | 67e0bc6 | 2009-09-03 22:06:09 | [diff] [blame] | 531 | |
[email protected] | 468a977 | 2011-08-09 18:42:00 | [diff] [blame] | 532 | def FetchRevision(context, rev, filename, quit_event=None, progress_event=None): |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 533 | """Downloads and unzips revision |rev|. |
| 534 | @param context A PathContext instance. |
| 535 | @param rev The Chromium revision number/tag to download. |
| 536 | @param filename The destination for the downloaded file. |
| 537 | @param quit_event A threading.Event which will be set by the master thread to |
| 538 | indicate that the download should be aborted. |
[email protected] | 468a977 | 2011-08-09 18:42:00 | [diff] [blame] | 539 | @param progress_event A threading.Event which will be set by the master thread |
| 540 | to indicate that the progress of the download should be |
| 541 | displayed. |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 542 | """ |
| 543 | def ReportHook(blocknum, blocksize, totalsize): |
[email protected] | 946be75 | 2011-10-25 23:34:21 | [diff] [blame] | 544 | if quit_event and quit_event.isSet(): |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 545 | raise RuntimeError('Aborting download of revision %s' % str(rev)) |
[email protected] | 946be75 | 2011-10-25 23:34:21 | [diff] [blame] | 546 | if progress_event and progress_event.isSet(): |
[email protected] | 468a977 | 2011-08-09 18:42:00 | [diff] [blame] | 547 | size = blocknum * blocksize |
| 548 | if totalsize == -1: # Total size not known. |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 549 | progress = 'Received %d bytes' % size |
[email protected] | 468a977 | 2011-08-09 18:42:00 | [diff] [blame] | 550 | else: |
| 551 | size = min(totalsize, size) |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 552 | progress = 'Received %d of %d bytes, %.2f%%' % ( |
[email protected] | 468a977 | 2011-08-09 18:42:00 | [diff] [blame] | 553 | size, totalsize, 100.0 * size / totalsize) |
| 554 | # Send a \r to let all progress messages use just one line of output. |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 555 | sys.stdout.write('\r' + progress) |
[email protected] | 468a977 | 2011-08-09 18:42:00 | [diff] [blame] | 556 | sys.stdout.flush() |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 557 | download_url = context.GetDownloadURL(rev) |
| 558 | try: |
John Budorick | 06e5df1 | 2015-02-27 17:44:27 | [diff] [blame] | 559 | urllib.urlretrieve(download_url, filename, ReportHook) |
[email protected] | 946be75 | 2011-10-25 23:34:21 | [diff] [blame] | 560 | if progress_event and progress_event.isSet(): |
Raul Tambre | 57e09d6 | 2019-09-22 17:18:52 | [diff] [blame] | 561 | print() |
mikecase | e2b6ce8 | 2015-02-06 18:22:39 | [diff] [blame] | 562 | |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 563 | except RuntimeError: |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 564 | pass |
[email protected] | 7ad66a7 | 2009-09-04 17:52:33 | [diff] [blame] | 565 | |
[email protected] | 7ad66a7 | 2009-09-04 17:52:33 | [diff] [blame] | 566 | |
Dominic Mazzoni | 215e80b | 2017-11-29 20:05:27 | [diff] [blame] | 567 | def CopyMissingFileFromCurrentSource(src_glob, dst): |
| 568 | """Work around missing files in archives. |
| 569 | This happens when archives of Chrome don't contain all of the files |
| 570 | needed to build it. In many cases we can work around this using |
| 571 | files from the current checkout. The source is in the form of a glob |
| 572 | so that it can try to look for possible sources of the file in |
| 573 | multiple locations, but we just arbitrarily try the first match. |
| 574 | |
| 575 | Silently fail if this doesn't work because we don't yet have clear |
| 576 | markers for builds that require certain files or a way to test |
| 577 | whether or not launching Chrome succeeded. |
| 578 | """ |
| 579 | if not os.path.exists(dst): |
| 580 | matches = glob.glob(src_glob) |
| 581 | if matches: |
| 582 | shutil.copy2(matches[0], dst) |
| 583 | |
| 584 | |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 585 | def RunRevision(context, revision, zip_file, profile, num_runs, command, args): |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 586 | """Given a zipped revision, unzip it and run the test.""" |
Raul Tambre | 57e09d6 | 2019-09-22 17:18:52 | [diff] [blame] | 587 | print('Trying revision %s...' % str(revision)) |
[email protected] | 3ff00b7 | 2011-07-20 21:34:47 | [diff] [blame] | 588 | |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 589 | # Create a temp directory and unzip the revision into it. |
[email protected] | 7ad66a7 | 2009-09-04 17:52:33 | [diff] [blame] | 590 | cwd = os.getcwd() |
| 591 | tempdir = tempfile.mkdtemp(prefix='bisect_tmp') |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 592 | UnzipFilenameToDir(zip_file, tempdir) |
dmazzoni | 76e907d | 2015-01-22 08:14:49 | [diff] [blame] | 593 | |
Dominic Mazzoni | 215e80b | 2017-11-29 20:05:27 | [diff] [blame] | 594 | # Hack: Some Chrome OS archives are missing some files; try to copy them |
| 595 | # from the local directory. |
Dominic Mazzoni | e84e40b | 2018-10-08 06:44:45 | [diff] [blame] | 596 | if context.platform == 'chromeos' and revision < 591483: |
Dominic Mazzoni | 215e80b | 2017-11-29 20:05:27 | [diff] [blame] | 597 | CopyMissingFileFromCurrentSource('third_party/icu/common/icudtl.dat', |
| 598 | '%s/chrome-linux/icudtl.dat' % tempdir) |
| 599 | CopyMissingFileFromCurrentSource('*out*/*/libminigbm.so', |
| 600 | '%s/chrome-linux/libminigbm.so' % tempdir) |
dmazzoni | 76e907d | 2015-01-22 08:14:49 | [diff] [blame] | 601 | |
[email protected] | 7ad66a7 | 2009-09-04 17:52:33 | [diff] [blame] | 602 | os.chdir(tempdir) |
[email protected] | 67e0bc6 | 2009-09-03 22:06:09 | [diff] [blame] | 603 | |
[email protected] | 5e93cf16 | 2012-01-28 02:16:56 | [diff] [blame] | 604 | # Run the build as many times as specified. |
[email protected] | 4646a75 | 2013-07-19 22:14:34 | [diff] [blame] | 605 | testargs = ['--user-data-dir=%s' % profile] + args |
[email protected] | d0149c5c | 2012-05-29 21:12:11 | [diff] [blame] | 606 | # The sandbox must be run as root on Official Chrome, so bypass it. |
Jason Kersey | 97bb027a | 2016-05-11 20:10:43 | [diff] [blame] | 607 | if (context.flash_path and context.platform.startswith('linux')): |
[email protected] | d0149c5c | 2012-05-29 21:12:11 | [diff] [blame] | 608 | testargs.append('--no-sandbox') |
[email protected] | fc3702e | 2013-11-09 04:23:00 | [diff] [blame] | 609 | if context.flash_path: |
| 610 | testargs.append('--ppapi-flash-path=%s' % context.flash_path) |
| 611 | # We have to pass a large enough Flash version, which currently needs not |
| 612 | # be correct. Instead of requiring the user of the script to figure out and |
| 613 | # pass the correct version we just spoof it. |
| 614 | testargs.append('--ppapi-flash-version=99.9.999.999') |
[email protected] | d0149c5c | 2012-05-29 21:12:11 | [diff] [blame] | 615 | |
[email protected] | 4646a75 | 2013-07-19 22:14:34 | [diff] [blame] | 616 | runcommand = [] |
[email protected] | 61ea90a | 2013-09-26 10:17:34 | [diff] [blame] | 617 | for token in shlex.split(command): |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 618 | if token == '%a': |
[email protected] | 4646a75 | 2013-07-19 22:14:34 | [diff] [blame] | 619 | runcommand.extend(testargs) |
| 620 | else: |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 621 | runcommand.append( |
[email protected] | 01188669 | 2014-08-01 21:00:21 | [diff] [blame] | 622 | token.replace('%p', os.path.abspath(context.GetLaunchPath(revision))). |
| 623 | replace('%s', ' '.join(testargs))) |
[email protected] | fb61fc3 | 2019-04-18 19:47:20 | [diff] [blame] | 624 | result = None |
[email protected] | 7ad66a7 | 2009-09-04 17:52:33 | [diff] [blame] | 625 | try: |
[email protected] | fb61fc3 | 2019-04-18 19:47:20 | [diff] [blame] | 626 | for _ in range(num_runs): |
| 627 | subproc = subprocess.Popen( |
| 628 | runcommand, |
| 629 | bufsize=-1, |
| 630 | stdout=subprocess.PIPE, |
| 631 | stderr=subprocess.PIPE) |
| 632 | (stdout, stderr) = subproc.communicate() |
| 633 | result = (subproc.returncode, stdout, stderr) |
| 634 | if subproc.returncode: |
| 635 | break |
| 636 | return result |
| 637 | finally: |
| 638 | os.chdir(cwd) |
| 639 | try: |
| 640 | shutil.rmtree(tempdir, True) |
| 641 | except Exception: |
| 642 | pass |
[email protected] | 79f1474 | 2010-03-10 01:01:57 | [diff] [blame] | 643 | |
[email protected] | cb155a8 | 2011-11-29 17:25:34 | [diff] [blame] | 644 | |
Jason Kersey | 97bb027a | 2016-05-11 20:10:43 | [diff] [blame] | 645 | # The arguments status, stdout and stderr are unused. |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 646 | # They are present here because this function is passed to Bisect which then |
| 647 | # calls it with 5 arguments. |
| 648 | # pylint: disable=W0613 |
Jason Kersey | 97bb027a | 2016-05-11 20:10:43 | [diff] [blame] | 649 | def AskIsGoodBuild(rev, exit_status, stdout, stderr): |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 650 | """Asks the user whether build |rev| is good or bad.""" |
Fergal Daly | 0dd1953 | 2019-04-04 07:45:33 | [diff] [blame] | 651 | if exit_status: |
Raul Tambre | 57e09d6 | 2019-09-22 17:18:52 | [diff] [blame] | 652 | print('Chrome exit_status: %d. Use s to see output' % exit_status) |
[email protected] | 79f1474 | 2010-03-10 01:01:57 | [diff] [blame] | 653 | # Loop until we get a response that we can parse. |
[email protected] | 67e0bc6 | 2009-09-03 22:06:09 | [diff] [blame] | 654 | while True: |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 655 | response = raw_input('Revision %s is ' |
wangxianzhu | d8c4c56 | 2015-12-15 23:39:51 | [diff] [blame] | 656 | '[(g)ood/(b)ad/(r)etry/(u)nknown/(s)tdout/(q)uit]: ' % |
[email protected] | 53bb634 | 2012-06-01 04:11:00 | [diff] [blame] | 657 | str(rev)) |
wangxianzhu | d8c4c56 | 2015-12-15 23:39:51 | [diff] [blame] | 658 | if response in ('g', 'b', 'r', 'u'): |
[email protected] | 53bb634 | 2012-06-01 04:11:00 | [diff] [blame] | 659 | return response |
wangxianzhu | d8c4c56 | 2015-12-15 23:39:51 | [diff] [blame] | 660 | if response == 'q': |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 661 | raise SystemExit() |
wangxianzhu | d8c4c56 | 2015-12-15 23:39:51 | [diff] [blame] | 662 | if response == 's': |
Raul Tambre | 57e09d6 | 2019-09-22 17:18:52 | [diff] [blame] | 663 | print(stdout) |
| 664 | print(stderr) |
[email protected] | 67e0bc6 | 2009-09-03 22:06:09 | [diff] [blame] | 665 | |
[email protected] | cb155a8 | 2011-11-29 17:25:34 | [diff] [blame] | 666 | |
Jason Kersey | 97bb027a | 2016-05-11 20:10:43 | [diff] [blame] | 667 | def IsGoodASANBuild(rev, exit_status, stdout, stderr): |
[email protected] | 01188669 | 2014-08-01 21:00:21 | [diff] [blame] | 668 | """Determine if an ASAN build |rev| is good or bad |
| 669 | |
| 670 | Will examine stderr looking for the error message emitted by ASAN. If not |
| 671 | found then will fallback to asking the user.""" |
| 672 | if stderr: |
| 673 | bad_count = 0 |
| 674 | for line in stderr.splitlines(): |
Raul Tambre | 57e09d6 | 2019-09-22 17:18:52 | [diff] [blame] | 675 | print(line) |
[email protected] | 01188669 | 2014-08-01 21:00:21 | [diff] [blame] | 676 | if line.find('ERROR: AddressSanitizer:') != -1: |
| 677 | bad_count += 1 |
| 678 | if bad_count > 0: |
Raul Tambre | 57e09d6 | 2019-09-22 17:18:52 | [diff] [blame] | 679 | print('Revision %d determined to be bad.' % rev) |
[email protected] | 01188669 | 2014-08-01 21:00:21 | [diff] [blame] | 680 | return 'b' |
Jason Kersey | 97bb027a | 2016-05-11 20:10:43 | [diff] [blame] | 681 | return AskIsGoodBuild(rev, exit_status, stdout, stderr) |
skobes | 21b5cdfb | 2016-03-21 23:13:02 | [diff] [blame] | 682 | |
| 683 | |
Jason Kersey | 97bb027a | 2016-05-11 20:10:43 | [diff] [blame] | 684 | def DidCommandSucceed(rev, exit_status, stdout, stderr): |
skobes | 21b5cdfb | 2016-03-21 23:13:02 | [diff] [blame] | 685 | if exit_status: |
Raul Tambre | 57e09d6 | 2019-09-22 17:18:52 | [diff] [blame] | 686 | print('Bad revision: %s' % rev) |
skobes | 21b5cdfb | 2016-03-21 23:13:02 | [diff] [blame] | 687 | return 'b' |
| 688 | else: |
Raul Tambre | 57e09d6 | 2019-09-22 17:18:52 | [diff] [blame] | 689 | print('Good revision: %s' % rev) |
skobes | 21b5cdfb | 2016-03-21 23:13:02 | [diff] [blame] | 690 | return 'g' |
| 691 | |
[email protected] | 01188669 | 2014-08-01 21:00:21 | [diff] [blame] | 692 | |
[email protected] | 53bb634 | 2012-06-01 04:11:00 | [diff] [blame] | 693 | class DownloadJob(object): |
| 694 | """DownloadJob represents a task to download a given Chromium revision.""" |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 695 | |
| 696 | def __init__(self, context, name, rev, zip_file): |
[email protected] | 53bb634 | 2012-06-01 04:11:00 | [diff] [blame] | 697 | super(DownloadJob, self).__init__() |
| 698 | # Store off the input parameters. |
| 699 | self.context = context |
| 700 | self.name = name |
| 701 | self.rev = rev |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 702 | self.zip_file = zip_file |
[email protected] | 53bb634 | 2012-06-01 04:11:00 | [diff] [blame] | 703 | self.quit_event = threading.Event() |
| 704 | self.progress_event = threading.Event() |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 705 | self.thread = None |
[email protected] | 53bb634 | 2012-06-01 04:11:00 | [diff] [blame] | 706 | |
| 707 | def Start(self): |
| 708 | """Starts the download.""" |
| 709 | fetchargs = (self.context, |
| 710 | self.rev, |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 711 | self.zip_file, |
[email protected] | 53bb634 | 2012-06-01 04:11:00 | [diff] [blame] | 712 | self.quit_event, |
| 713 | self.progress_event) |
| 714 | self.thread = threading.Thread(target=FetchRevision, |
| 715 | name=self.name, |
| 716 | args=fetchargs) |
| 717 | self.thread.start() |
| 718 | |
| 719 | def Stop(self): |
| 720 | """Stops the download which must have been started previously.""" |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 721 | assert self.thread, 'DownloadJob must be started before Stop is called.' |
[email protected] | 53bb634 | 2012-06-01 04:11:00 | [diff] [blame] | 722 | self.quit_event.set() |
| 723 | self.thread.join() |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 724 | os.unlink(self.zip_file) |
[email protected] | 53bb634 | 2012-06-01 04:11:00 | [diff] [blame] | 725 | |
| 726 | def WaitFor(self): |
| 727 | """Prints a message and waits for the download to complete. The download |
| 728 | must have been started previously.""" |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 729 | assert self.thread, 'DownloadJob must be started before WaitFor is called.' |
Raul Tambre | 57e09d6 | 2019-09-22 17:18:52 | [diff] [blame] | 730 | print('Downloading revision %s...' % str(self.rev)) |
[email protected] | 53bb634 | 2012-06-01 04:11:00 | [diff] [blame] | 731 | self.progress_event.set() # Display progress of download. |
rob | 8a4543f | 2016-01-20 00:43:59 | [diff] [blame] | 732 | try: |
| 733 | while self.thread.isAlive(): |
| 734 | # The parameter to join is needed to keep the main thread responsive to |
| 735 | # signals. Without it, the program will not respond to interruptions. |
| 736 | self.thread.join(1) |
| 737 | except (KeyboardInterrupt, SystemExit): |
| 738 | self.Stop() |
| 739 | raise |
[email protected] | 53bb634 | 2012-06-01 04:11:00 | [diff] [blame] | 740 | |
| 741 | |
skobes | 21b5cdfb | 2016-03-21 23:13:02 | [diff] [blame] | 742 | def VerifyEndpoint(fetch, context, rev, profile, num_runs, command, try_args, |
| 743 | evaluate, expected_answer): |
| 744 | fetch.WaitFor() |
| 745 | try: |
Roman Sorokin | 760f06cd | 2019-12-24 08:35:41 | [diff] [blame] | 746 | answer = 'r' |
| 747 | # This is intended to allow evaluate() to return 'r' to retry RunRevision. |
| 748 | while answer == 'r': |
| 749 | (exit_status, stdout, stderr) = RunRevision( |
| 750 | context, rev, fetch.zip_file, profile, num_runs, command, try_args) |
| 751 | answer = evaluate(rev, exit_status, stdout, stderr); |
skobes | 21b5cdfb | 2016-03-21 23:13:02 | [diff] [blame] | 752 | except Exception, e: |
Raul Tambre | 57e09d6 | 2019-09-22 17:18:52 | [diff] [blame] | 753 | print(e, file=sys.stderr) |
Lei Zhang | 2fa7630 | 2018-11-09 20:16:31 | [diff] [blame] | 754 | raise SystemExit |
Roman Sorokin | 760f06cd | 2019-12-24 08:35:41 | [diff] [blame] | 755 | if (answer != expected_answer): |
Raul Tambre | 57e09d6 | 2019-09-22 17:18:52 | [diff] [blame] | 756 | print('Unexpected result at a range boundary! Your range is not correct.') |
skobes | 21b5cdfb | 2016-03-21 23:13:02 | [diff] [blame] | 757 | raise SystemExit |
| 758 | |
| 759 | |
[email protected] | 2e0f267 | 2014-08-13 20:32:58 | [diff] [blame] | 760 | def Bisect(context, |
[email protected] | 5e93cf16 | 2012-01-28 02:16:56 | [diff] [blame] | 761 | num_runs=1, |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 762 | command='%p %a', |
[email protected] | 60ac66e3 | 2011-07-18 16:08:25 | [diff] [blame] | 763 | try_args=(), |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 764 | profile=None, |
skobes | 21b5cdfb | 2016-03-21 23:13:02 | [diff] [blame] | 765 | evaluate=AskIsGoodBuild, |
| 766 | verify_range=False): |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 767 | """Given known good and known bad revisions, run a binary search on all |
| 768 | archived revisions to determine the last known good revision. |
[email protected] | 60ac66e3 | 2011-07-18 16:08:25 | [diff] [blame] | 769 | |
[email protected] | 2e0f267 | 2014-08-13 20:32:58 | [diff] [blame] | 770 | @param context PathContext object initialized with user provided parameters. |
[email protected] | 5e93cf16 | 2012-01-28 02:16:56 | [diff] [blame] | 771 | @param num_runs Number of times to run each build for asking good/bad. |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 772 | @param try_args A tuple of arguments to pass to the test application. |
| 773 | @param profile The name of the user profile to run with. |
[email protected] | 53bb634 | 2012-06-01 04:11:00 | [diff] [blame] | 774 | @param evaluate A function which returns 'g' if the argument build is good, |
| 775 | 'b' if it's bad or 'u' if unknown. |
skobes | 21b5cdfb | 2016-03-21 23:13:02 | [diff] [blame] | 776 | @param verify_range If true, tests the first and last revisions in the range |
| 777 | before proceeding with the bisect. |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 778 | |
| 779 | Threading is used to fetch Chromium revisions in the background, speeding up |
| 780 | the user's experience. For example, suppose the bounds of the search are |
| 781 | good_rev=0, bad_rev=100. The first revision to be checked is 50. Depending on |
| 782 | whether revision 50 is good or bad, the next revision to check will be either |
| 783 | 25 or 75. So, while revision 50 is being checked, the script will download |
| 784 | revisions 25 and 75 in the background. Once the good/bad verdict on rev 50 is |
| 785 | known: |
| 786 | |
| 787 | - If rev 50 is good, the download of rev 25 is cancelled, and the next test |
| 788 | is run on rev 75. |
| 789 | |
| 790 | - If rev 50 is bad, the download of rev 75 is cancelled, and the next test |
| 791 | is run on rev 25. |
[email protected] | 60ac66e3 | 2011-07-18 16:08:25 | [diff] [blame] | 792 | """ |
| 793 | |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 794 | if not profile: |
| 795 | profile = 'profile' |
| 796 | |
[email protected] | 2e0f267 | 2014-08-13 20:32:58 | [diff] [blame] | 797 | good_rev = context.good_revision |
| 798 | bad_rev = context.bad_revision |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 799 | cwd = os.getcwd() |
| 800 | |
Raul Tambre | 57e09d6 | 2019-09-22 17:18:52 | [diff] [blame] | 801 | print('Downloading list of known revisions...', end=' ') |
Jason Kersey | 97bb027a | 2016-05-11 20:10:43 | [diff] [blame] | 802 | if not context.use_local_cache: |
Raul Tambre | 57e09d6 | 2019-09-22 17:18:52 | [diff] [blame] | 803 | print('(use --use-local-cache to cache and re-use the list of revisions)') |
[email protected] | 28a3c12 | 2014-08-09 11:04:51 | [diff] [blame] | 804 | else: |
Raul Tambre | 57e09d6 | 2019-09-22 17:18:52 | [diff] [blame] | 805 | print() |
[email protected] | d0149c5c | 2012-05-29 21:12:11 | [diff] [blame] | 806 | _GetDownloadPath = lambda rev: os.path.join(cwd, |
| 807 | '%s-%s' % (str(rev), context.archive_name)) |
Jason Kersey | 97bb027a | 2016-05-11 20:10:43 | [diff] [blame] | 808 | revlist = context.GetRevList() |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 809 | |
| 810 | # Get a list of revisions to bisect across. |
| 811 | if len(revlist) < 2: # Don't have enough builds to bisect. |
| 812 | msg = 'We don\'t have enough builds to bisect. revlist: %s' % revlist |
| 813 | raise RuntimeError(msg) |
| 814 | |
| 815 | # Figure out our bookends and first pivot point; fetch the pivot revision. |
[email protected] | eadd95d | 2012-11-02 22:42:09 | [diff] [blame] | 816 | minrev = 0 |
| 817 | maxrev = len(revlist) - 1 |
| 818 | pivot = maxrev / 2 |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 819 | rev = revlist[pivot] |
skobes | 21b5cdfb | 2016-03-21 23:13:02 | [diff] [blame] | 820 | fetch = DownloadJob(context, 'initial_fetch', rev, _GetDownloadPath(rev)) |
[email protected] | eadd95d | 2012-11-02 22:42:09 | [diff] [blame] | 821 | fetch.Start() |
skobes | 21b5cdfb | 2016-03-21 23:13:02 | [diff] [blame] | 822 | |
| 823 | if verify_range: |
| 824 | minrev_fetch = DownloadJob( |
| 825 | context, 'minrev_fetch', revlist[minrev], |
| 826 | _GetDownloadPath(revlist[minrev])) |
| 827 | maxrev_fetch = DownloadJob( |
| 828 | context, 'maxrev_fetch', revlist[maxrev], |
| 829 | _GetDownloadPath(revlist[maxrev])) |
| 830 | minrev_fetch.Start() |
| 831 | maxrev_fetch.Start() |
| 832 | try: |
| 833 | VerifyEndpoint(minrev_fetch, context, revlist[minrev], profile, num_runs, |
| 834 | command, try_args, evaluate, 'b' if bad_rev < good_rev else 'g') |
| 835 | VerifyEndpoint(maxrev_fetch, context, revlist[maxrev], profile, num_runs, |
| 836 | command, try_args, evaluate, 'g' if bad_rev < good_rev else 'b') |
| 837 | except (KeyboardInterrupt, SystemExit): |
Raul Tambre | 57e09d6 | 2019-09-22 17:18:52 | [diff] [blame] | 838 | print('Cleaning up...') |
skobes | 21b5cdfb | 2016-03-21 23:13:02 | [diff] [blame] | 839 | fetch.Stop() |
| 840 | sys.exit(0) |
| 841 | finally: |
| 842 | minrev_fetch.Stop() |
| 843 | maxrev_fetch.Stop() |
| 844 | |
[email protected] | eadd95d | 2012-11-02 22:42:09 | [diff] [blame] | 845 | fetch.WaitFor() |
[email protected] | 60ac66e3 | 2011-07-18 16:08:25 | [diff] [blame] | 846 | |
| 847 | # Binary search time! |
Bruce Dawson | 6225741 | 2020-01-17 17:39:53 | [diff] [blame] | 848 | prefetch_revisions = True |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 849 | while fetch and fetch.zip_file and maxrev - minrev > 1: |
[email protected] | eadd95d | 2012-11-02 22:42:09 | [diff] [blame] | 850 | if bad_rev < good_rev: |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 851 | min_str, max_str = 'bad', 'good' |
[email protected] | eadd95d | 2012-11-02 22:42:09 | [diff] [blame] | 852 | else: |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 853 | min_str, max_str = 'good', 'bad' |
Raul Tambre | 57e09d6 | 2019-09-22 17:18:52 | [diff] [blame] | 854 | print( |
| 855 | 'Bisecting range [%s (%s), %s (%s)], ' |
| 856 | 'roughly %d steps left.' % (revlist[minrev], min_str, revlist[maxrev], |
| 857 | max_str, int(maxrev - minrev).bit_length())) |
[email protected] | eadd95d | 2012-11-02 22:42:09 | [diff] [blame] | 858 | |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 859 | # Pre-fetch next two possible pivots |
| 860 | # - down_pivot is the next revision to check if the current revision turns |
| 861 | # out to be bad. |
| 862 | # - up_pivot is the next revision to check if the current revision turns |
| 863 | # out to be good. |
[email protected] | eadd95d | 2012-11-02 22:42:09 | [diff] [blame] | 864 | down_pivot = int((pivot - minrev) / 2) + minrev |
Bruce Dawson | 6225741 | 2020-01-17 17:39:53 | [diff] [blame] | 865 | if prefetch_revisions: |
| 866 | down_fetch = None |
| 867 | if down_pivot != pivot and down_pivot != minrev: |
| 868 | down_rev = revlist[down_pivot] |
| 869 | down_fetch = DownloadJob(context, 'down_fetch', down_rev, |
| 870 | _GetDownloadPath(down_rev)) |
| 871 | down_fetch.Start() |
[email protected] | 60ac66e3 | 2011-07-18 16:08:25 | [diff] [blame] | 872 | |
[email protected] | eadd95d | 2012-11-02 22:42:09 | [diff] [blame] | 873 | up_pivot = int((maxrev - pivot) / 2) + pivot |
Bruce Dawson | 6225741 | 2020-01-17 17:39:53 | [diff] [blame] | 874 | if prefetch_revisions: |
| 875 | up_fetch = None |
| 876 | if up_pivot != pivot and up_pivot != maxrev: |
| 877 | up_rev = revlist[up_pivot] |
| 878 | up_fetch = DownloadJob(context, 'up_fetch', up_rev, |
| 879 | _GetDownloadPath(up_rev)) |
| 880 | up_fetch.Start() |
[email protected] | 60ac66e3 | 2011-07-18 16:08:25 | [diff] [blame] | 881 | |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 882 | # Run test on the pivot revision. |
skobes | 21b5cdfb | 2016-03-21 23:13:02 | [diff] [blame] | 883 | exit_status = None |
[email protected] | e29c08c | 2012-09-17 20:50:50 | [diff] [blame] | 884 | stdout = None |
| 885 | stderr = None |
| 886 | try: |
skobes | 21b5cdfb | 2016-03-21 23:13:02 | [diff] [blame] | 887 | (exit_status, stdout, stderr) = RunRevision( |
| 888 | context, rev, fetch.zip_file, profile, num_runs, command, try_args) |
[email protected] | e29c08c | 2012-09-17 20:50:50 | [diff] [blame] | 889 | except Exception, e: |
Raul Tambre | 57e09d6 | 2019-09-22 17:18:52 | [diff] [blame] | 890 | print(e, file=sys.stderr) |
[email protected] | 60ac66e3 | 2011-07-18 16:08:25 | [diff] [blame] | 891 | |
[email protected] | 53bb634 | 2012-06-01 04:11:00 | [diff] [blame] | 892 | # Call the evaluate function to see if the current revision is good or bad. |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 893 | # On that basis, kill one of the background downloads and complete the |
| 894 | # other, as described in the comments above. |
| 895 | try: |
Jason Kersey | 97bb027a | 2016-05-11 20:10:43 | [diff] [blame] | 896 | answer = evaluate(rev, exit_status, stdout, stderr) |
Bruce Dawson | 6225741 | 2020-01-17 17:39:53 | [diff] [blame] | 897 | prefetch_revisions = True |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 898 | if ((answer == 'g' and good_rev < bad_rev) |
| 899 | or (answer == 'b' and bad_rev < good_rev)): |
[email protected] | 1d4a0624 | 2013-08-20 22:53:12 | [diff] [blame] | 900 | fetch.Stop() |
[email protected] | eadd95d | 2012-11-02 22:42:09 | [diff] [blame] | 901 | minrev = pivot |
[email protected] | 53bb634 | 2012-06-01 04:11:00 | [diff] [blame] | 902 | if down_fetch: |
| 903 | down_fetch.Stop() # Kill the download of the older revision. |
[email protected] | 1d4a0624 | 2013-08-20 22:53:12 | [diff] [blame] | 904 | fetch = None |
[email protected] | 53bb634 | 2012-06-01 04:11:00 | [diff] [blame] | 905 | if up_fetch: |
| 906 | up_fetch.WaitFor() |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 907 | pivot = up_pivot |
[email protected] | eadd95d | 2012-11-02 22:42:09 | [diff] [blame] | 908 | fetch = up_fetch |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 909 | elif ((answer == 'b' and good_rev < bad_rev) |
| 910 | or (answer == 'g' and bad_rev < good_rev)): |
[email protected] | 1d4a0624 | 2013-08-20 22:53:12 | [diff] [blame] | 911 | fetch.Stop() |
[email protected] | eadd95d | 2012-11-02 22:42:09 | [diff] [blame] | 912 | maxrev = pivot |
[email protected] | 53bb634 | 2012-06-01 04:11:00 | [diff] [blame] | 913 | if up_fetch: |
| 914 | up_fetch.Stop() # Kill the download of the newer revision. |
[email protected] | 1d4a0624 | 2013-08-20 22:53:12 | [diff] [blame] | 915 | fetch = None |
[email protected] | 53bb634 | 2012-06-01 04:11:00 | [diff] [blame] | 916 | if down_fetch: |
| 917 | down_fetch.WaitFor() |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 918 | pivot = down_pivot |
[email protected] | eadd95d | 2012-11-02 22:42:09 | [diff] [blame] | 919 | fetch = down_fetch |
[email protected] | 1d4a0624 | 2013-08-20 22:53:12 | [diff] [blame] | 920 | elif answer == 'r': |
Bruce Dawson | 6225741 | 2020-01-17 17:39:53 | [diff] [blame] | 921 | # Don't redundantly prefetch. |
| 922 | prefetch_revisions = False |
[email protected] | 53bb634 | 2012-06-01 04:11:00 | [diff] [blame] | 923 | elif answer == 'u': |
| 924 | # Nuke the revision from the revlist and choose a new pivot. |
[email protected] | 1d4a0624 | 2013-08-20 22:53:12 | [diff] [blame] | 925 | fetch.Stop() |
[email protected] | 53bb634 | 2012-06-01 04:11:00 | [diff] [blame] | 926 | revlist.pop(pivot) |
[email protected] | eadd95d | 2012-11-02 22:42:09 | [diff] [blame] | 927 | maxrev -= 1 # Assumes maxrev >= pivot. |
[email protected] | 53bb634 | 2012-06-01 04:11:00 | [diff] [blame] | 928 | |
[email protected] | eadd95d | 2012-11-02 22:42:09 | [diff] [blame] | 929 | if maxrev - minrev > 1: |
[email protected] | 53bb634 | 2012-06-01 04:11:00 | [diff] [blame] | 930 | # Alternate between using down_pivot or up_pivot for the new pivot |
| 931 | # point, without affecting the range. Do this instead of setting the |
| 932 | # pivot to the midpoint of the new range because adjacent revisions |
| 933 | # are likely affected by the same issue that caused the (u)nknown |
| 934 | # response. |
| 935 | if up_fetch and down_fetch: |
| 936 | fetch = [up_fetch, down_fetch][len(revlist) % 2] |
| 937 | elif up_fetch: |
| 938 | fetch = up_fetch |
| 939 | else: |
| 940 | fetch = down_fetch |
| 941 | fetch.WaitFor() |
| 942 | if fetch == up_fetch: |
| 943 | pivot = up_pivot - 1 # Subtracts 1 because revlist was resized. |
| 944 | else: |
| 945 | pivot = down_pivot |
[email protected] | 53bb634 | 2012-06-01 04:11:00 | [diff] [blame] | 946 | |
| 947 | if down_fetch and fetch != down_fetch: |
| 948 | down_fetch.Stop() |
| 949 | if up_fetch and fetch != up_fetch: |
| 950 | up_fetch.Stop() |
| 951 | else: |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 952 | assert False, 'Unexpected return value from evaluate(): ' + answer |
skobes | 21b5cdfb | 2016-03-21 23:13:02 | [diff] [blame] | 953 | except (KeyboardInterrupt, SystemExit): |
Raul Tambre | 57e09d6 | 2019-09-22 17:18:52 | [diff] [blame] | 954 | print('Cleaning up...') |
skobes | 21b5cdfb | 2016-03-21 23:13:02 | [diff] [blame] | 955 | for f in [_GetDownloadPath(rev), |
| 956 | _GetDownloadPath(revlist[down_pivot]), |
[email protected] | 5e93cf16 | 2012-01-28 02:16:56 | [diff] [blame] | 957 | _GetDownloadPath(revlist[up_pivot])]: |
[email protected] | afe3066 | 2011-07-30 01:05:52 | [diff] [blame] | 958 | try: |
| 959 | os.unlink(f) |
| 960 | except OSError: |
| 961 | pass |
| 962 | sys.exit(0) |
| 963 | |
| 964 | rev = revlist[pivot] |
| 965 | |
[email protected] | 2e0f267 | 2014-08-13 20:32:58 | [diff] [blame] | 966 | return (revlist[minrev], revlist[maxrev], context) |
[email protected] | 60ac66e3 | 2011-07-18 16:08:25 | [diff] [blame] | 967 | |
| 968 | |
pshenoy | cd6bd68 | 2014-09-10 20:50:22 | [diff] [blame] | 969 | def GetBlinkDEPSRevisionForChromiumRevision(self, rev): |
[email protected] | 4c6fec6b | 2013-09-17 17:44:08 | [diff] [blame] | 970 | """Returns the blink revision that was in REVISIONS file at |
[email protected] | b2fe7f2 | 2011-10-25 22:58:31 | [diff] [blame] | 971 | chromium revision |rev|.""" |
pshenoy | cd6bd68 | 2014-09-10 20:50:22 | [diff] [blame] | 972 | |
| 973 | def _GetBlinkRev(url, blink_re): |
| 974 | m = blink_re.search(url.read()) |
| 975 | url.close() |
| 976 | if m: |
fmalita | a898d22 | 2016-07-12 22:29:03 | [diff] [blame] | 977 | return m.group(1) |
pshenoy | cd6bd68 | 2014-09-10 20:50:22 | [diff] [blame] | 978 | |
Di Mu | 08c5968 | 2016-07-11 23:05:07 | [diff] [blame] | 979 | url = urllib.urlopen(DEPS_FILE % GetGitHashFromSVNRevision(rev)) |
pshenoy | cd6bd68 | 2014-09-10 20:50:22 | [diff] [blame] | 980 | if url.getcode() == 200: |
Di Mu | 08c5968 | 2016-07-11 23:05:07 | [diff] [blame] | 981 | blink_re = re.compile(r'webkit_revision\D*\d+;\D*\d+;(\w+)') |
| 982 | blink_git_sha = _GetBlinkRev(url, blink_re) |
| 983 | return self.GetSVNRevisionFromGitHash(blink_git_sha, 'blink') |
pshenoy | cd6bd68 | 2014-09-10 20:50:22 | [diff] [blame] | 984 | raise Exception('Could not get Blink revision for Chromium rev %d' % rev) |
[email protected] | 37ed317 | 2013-09-24 23:49:30 | [diff] [blame] | 985 | |
| 986 | |
[email protected] | 2e0f267 | 2014-08-13 20:32:58 | [diff] [blame] | 987 | def GetBlinkRevisionForChromiumRevision(context, rev): |
[email protected] | 37ed317 | 2013-09-24 23:49:30 | [diff] [blame] | 988 | """Returns the blink revision that was in REVISIONS file at |
| 989 | chromium revision |rev|.""" |
[email protected] | 3e7c8532 | 2014-06-27 20:27:36 | [diff] [blame] | 990 | def _IsRevisionNumber(revision): |
| 991 | if isinstance(revision, int): |
| 992 | return True |
| 993 | else: |
| 994 | return revision.isdigit() |
[email protected] | 2e0f267 | 2014-08-13 20:32:58 | [diff] [blame] | 995 | if str(rev) in context.githash_svn_dict: |
| 996 | rev = context.githash_svn_dict[str(rev)] |
| 997 | file_url = '%s/%s%s/REVISIONS' % (context.base_url, |
| 998 | context._listing_platform_dir, rev) |
[email protected] | 4c6fec6b | 2013-09-17 17:44:08 | [diff] [blame] | 999 | url = urllib.urlopen(file_url) |
[email protected] | 2e0f267 | 2014-08-13 20:32:58 | [diff] [blame] | 1000 | if url.getcode() == 200: |
| 1001 | try: |
| 1002 | data = json.loads(url.read()) |
| 1003 | except ValueError: |
Raul Tambre | 57e09d6 | 2019-09-22 17:18:52 | [diff] [blame] | 1004 | print('ValueError for JSON URL: %s' % file_url) |
[email protected] | 2e0f267 | 2014-08-13 20:32:58 | [diff] [blame] | 1005 | raise ValueError |
| 1006 | else: |
| 1007 | raise ValueError |
[email protected] | b2fe7f2 | 2011-10-25 22:58:31 | [diff] [blame] | 1008 | url.close() |
[email protected] | 4c6fec6b | 2013-09-17 17:44:08 | [diff] [blame] | 1009 | if 'webkit_revision' in data: |
[email protected] | 3e7c8532 | 2014-06-27 20:27:36 | [diff] [blame] | 1010 | blink_rev = data['webkit_revision'] |
| 1011 | if not _IsRevisionNumber(blink_rev): |
[email protected] | 2e0f267 | 2014-08-13 20:32:58 | [diff] [blame] | 1012 | blink_rev = int(context.GetSVNRevisionFromGitHash(blink_rev, 'blink')) |
[email protected] | 3e7c8532 | 2014-06-27 20:27:36 | [diff] [blame] | 1013 | return blink_rev |
[email protected] | b2fe7f2 | 2011-10-25 22:58:31 | [diff] [blame] | 1014 | else: |
[email protected] | ff50d1c | 2013-04-17 18:49:36 | [diff] [blame] | 1015 | raise Exception('Could not get blink revision for cr rev %d' % rev) |
[email protected] | b2fe7f2 | 2011-10-25 22:58:31 | [diff] [blame] | 1016 | |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 1017 | |
[email protected] | 37ed317 | 2013-09-24 23:49:30 | [diff] [blame] | 1018 | def FixChromiumRevForBlink(revisions_final, revisions, self, rev): |
| 1019 | """Returns the chromium revision that has the correct blink revision |
| 1020 | for blink bisect, DEPS and REVISIONS file might not match since |
| 1021 | blink snapshots point to tip of tree blink. |
| 1022 | Note: The revisions_final variable might get modified to include |
| 1023 | additional revisions.""" |
pshenoy | cd6bd68 | 2014-09-10 20:50:22 | [diff] [blame] | 1024 | blink_deps_rev = GetBlinkDEPSRevisionForChromiumRevision(self, rev) |
[email protected] | 37ed317 | 2013-09-24 23:49:30 | [diff] [blame] | 1025 | |
| 1026 | while (GetBlinkRevisionForChromiumRevision(self, rev) > blink_deps_rev): |
| 1027 | idx = revisions.index(rev) |
| 1028 | if idx > 0: |
| 1029 | rev = revisions[idx-1] |
| 1030 | if rev not in revisions_final: |
| 1031 | revisions_final.insert(0, rev) |
| 1032 | |
| 1033 | revisions_final.sort() |
| 1034 | return rev |
[email protected] | b2fe7f2 | 2011-10-25 22:58:31 | [diff] [blame] | 1035 | |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 1036 | |
[email protected] | 5980b75 | 2014-07-02 00:34:40 | [diff] [blame] | 1037 | def GetChromiumRevision(context, url): |
[email protected] | 801fb65 | 2012-07-20 20:13:50 | [diff] [blame] | 1038 | """Returns the chromium revision read from given URL.""" |
| 1039 | try: |
| 1040 | # Location of the latest build revision number |
[email protected] | 5980b75 | 2014-07-02 00:34:40 | [diff] [blame] | 1041 | latest_revision = urllib.urlopen(url).read() |
| 1042 | if latest_revision.isdigit(): |
| 1043 | return int(latest_revision) |
| 1044 | return context.GetSVNRevisionFromGitHash(latest_revision) |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 1045 | except Exception: |
Raul Tambre | 57e09d6 | 2019-09-22 17:18:52 | [diff] [blame] | 1046 | print('Could not determine latest revision. This could be bad...') |
[email protected] | 801fb65 | 2012-07-20 20:13:50 | [diff] [blame] | 1047 | return 999999999 |
| 1048 | |
Bruce Dawson | cd63ea2 | 2020-10-26 16:37:41 | [diff] [blame] | 1049 | |
| 1050 | def GetRevision(revision_text): |
| 1051 | """Translates from a text description of a revision to an integral revision |
| 1052 | number. Currently supported formats are a number (i.e.; '782793') or a |
| 1053 | milestone specifier (i.e.; 'M85') or a full version string |
| 1054 | (i.e. '85.0.4183.121').""" |
| 1055 | |
| 1056 | # Check if we already have a revision number, such as when -g or -b is |
| 1057 | # omitted. |
| 1058 | if type(revision_text) == type(0): |
| 1059 | return revision_text |
| 1060 | |
| 1061 | # Translate from stable milestone name to the latest version number released |
| 1062 | # for that milestone, i.e.; 'M85' to '85.0.4183.121'. |
| 1063 | if revision_text[:1].upper() == 'M': |
| 1064 | milestone = revision_text[1:] |
| 1065 | response = urllib.urlopen(VERSION_HISTORY_URL) |
| 1066 | version_history = json.loads(response.read()) |
| 1067 | version_matcher = re.compile( |
| 1068 | '.*versions/(\d*)\.(\d*)\.(\d*)\.(\d*)/releases.*') |
| 1069 | for version in version_history['releases']: |
| 1070 | match = version_matcher.match(version['name']) |
| 1071 | # There will be multiple versions of each milestone, but we just grab the |
| 1072 | # first one that we see which will be the most recent version. If you need |
| 1073 | # more granularity then specify a full version number or revision number. |
| 1074 | if match and match.groups()[0] == milestone: |
| 1075 | revision_text = '.'.join(match.groups()) |
| 1076 | break |
| 1077 | if revision_text[:1].upper() == 'M': |
| 1078 | raise Exception('No stable release matching %s found.' % revision_text) |
| 1079 | |
| 1080 | # Translate from version number to commit position, also known as revision |
| 1081 | # number. |
| 1082 | if len(revision_text.split('.')) == 4: |
| 1083 | response = urllib.urlopen(OMAHA_REVISIONS_URL % revision_text) |
| 1084 | revision_details = json.loads(response.read()) |
| 1085 | revision_text = revision_details['chromium_base_position'] |
| 1086 | |
| 1087 | # Translate from text commit position to integer commit position. |
| 1088 | return int(revision_text) |
| 1089 | |
| 1090 | |
pshenoy | cd6bd68 | 2014-09-10 20:50:22 | [diff] [blame] | 1091 | def GetGitHashFromSVNRevision(svn_revision): |
| 1092 | crrev_url = CRREV_URL + str(svn_revision) |
| 1093 | url = urllib.urlopen(crrev_url) |
| 1094 | if url.getcode() == 200: |
| 1095 | data = json.loads(url.read()) |
| 1096 | if 'git_sha' in data: |
| 1097 | return data['git_sha'] |
| 1098 | |
pshenoy | 9ce271f | 2014-09-02 22:14:05 | [diff] [blame] | 1099 | def PrintChangeLog(min_chromium_rev, max_chromium_rev): |
| 1100 | """Prints the changelog URL.""" |
| 1101 | |
Raul Tambre | 57e09d6 | 2019-09-22 17:18:52 | [diff] [blame] | 1102 | print(' ' + CHANGELOG_URL % (GetGitHashFromSVNRevision(min_chromium_rev), |
| 1103 | GetGitHashFromSVNRevision(max_chromium_rev))) |
| 1104 | |
pshenoy | 9ce271f | 2014-09-02 22:14:05 | [diff] [blame] | 1105 | |
elawrence | 446bcc3 | 2017-04-14 17:18:51 | [diff] [blame] | 1106 | def error_internal_option(option, opt, value, parser): |
[email protected] | fb61fc3 | 2019-04-18 19:47:20 | [diff] [blame] | 1107 | raise optparse.OptionValueError( |
| 1108 | 'The -o and -r options are only\navailable in the internal version of ' |
| 1109 | 'this script. Google\nemployees should visit http://go/bisect-builds ' |
| 1110 | 'for\nconfiguration instructions.') |
[email protected] | 801fb65 | 2012-07-20 20:13:50 | [diff] [blame] | 1111 | |
[email protected] | 67e0bc6 | 2009-09-03 22:06:09 | [diff] [blame] | 1112 | def main(): |
[email protected] | 2c1d273 | 2009-10-29 19:52:17 | [diff] [blame] | 1113 | usage = ('%prog [options] [-- chromium-options]\n' |
[email protected] | 887c918 | 2013-02-12 20:30:31 | [diff] [blame] | 1114 | 'Perform binary search on the snapshot builds to find a minimal\n' |
| 1115 | 'range of revisions where a behavior change happened. The\n' |
| 1116 | 'behaviors are described as "good" and "bad".\n' |
| 1117 | 'It is NOT assumed that the behavior of the later revision is\n' |
[email protected] | 09c58da | 2013-01-07 21:30:17 | [diff] [blame] | 1118 | 'the bad one.\n' |
[email protected] | 178aab7 | 2010-10-08 17:21:38 | [diff] [blame] | 1119 | '\n' |
[email protected] | 887c918 | 2013-02-12 20:30:31 | [diff] [blame] | 1120 | 'Revision numbers should use\n' |
[email protected] | 887c918 | 2013-02-12 20:30:31 | [diff] [blame] | 1121 | ' SVN revisions (e.g. 123456) for chromium builds, from trunk.\n' |
| 1122 | ' Use base_trunk_revision from http://omahaproxy.appspot.com/\n' |
| 1123 | ' for earlier revs.\n' |
| 1124 | ' Chrome\'s about: build number and omahaproxy branch_revision\n' |
| 1125 | ' are incorrect, they are from branches.\n' |
| 1126 | '\n' |
Bruce Dawson | e357305 | 2020-06-29 23:14:35 | [diff] [blame] | 1127 | 'Use "-- <args-to-pass-to-chromium>" to pass arbitrary extra \n' |
| 1128 | 'arguments to the test binaries.\n' |
| 1129 | 'E.g., add "-- --no-first-run" to bypass the first run prompts.') |
[email protected] | 7ad66a7 | 2009-09-04 17:52:33 | [diff] [blame] | 1130 | parser = optparse.OptionParser(usage=usage) |
[email protected] | 1a45d22 | 2009-09-19 01:58:57 | [diff] [blame] | 1131 | # Strangely, the default help output doesn't include the choice list. |
mikecase | a8cd284c | 2014-12-02 21:30:58 | [diff] [blame] | 1132 | choices = ['mac', 'mac64', 'win', 'win64', 'linux', 'linux64', 'linux-arm', |
dmazzoni | 76e907d | 2015-01-22 08:14:49 | [diff] [blame] | 1133 | 'chromeos'] |
[email protected] | 7ad66a7 | 2009-09-04 17:52:33 | [diff] [blame] | 1134 | parser.add_option('-a', '--archive', |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 1135 | choices=choices, |
| 1136 | help='The buildbot archive to bisect [%s].' % |
| 1137 | '|'.join(choices)) |
Bruce Dawson | cd63ea2 | 2020-10-26 16:37:41 | [diff] [blame] | 1138 | parser.add_option('-b', |
| 1139 | '--bad', |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 1140 | type='str', |
| 1141 | help='A bad revision to start bisection. ' |
Bruce Dawson | cd63ea2 | 2020-10-26 16:37:41 | [diff] [blame] | 1142 | 'May be earlier or later than the good revision. ' |
| 1143 | 'Default is HEAD. Can be a revision number, milestone ' |
| 1144 | 'name (eg. M85, matches the most recent stable release of ' |
| 1145 | 'that milestone) or version number (eg. 85.0.4183.121)') |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 1146 | parser.add_option('-f', '--flash_path', |
| 1147 | type='str', |
| 1148 | help='Absolute path to a recent Adobe Pepper Flash ' |
| 1149 | 'binary to be used in this bisection (e.g. ' |
| 1150 | 'on Windows C:\...\pepflashplayer.dll and on Linux ' |
| 1151 | '/opt/google/chrome/PepperFlash/' |
| 1152 | 'libpepflashplayer.so).') |
Bruce Dawson | cd63ea2 | 2020-10-26 16:37:41 | [diff] [blame] | 1153 | parser.add_option('-g', |
| 1154 | '--good', |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 1155 | type='str', |
| 1156 | help='A good revision to start bisection. ' + |
Bruce Dawson | cd63ea2 | 2020-10-26 16:37:41 | [diff] [blame] | 1157 | 'May be earlier or later than the bad revision. ' + |
| 1158 | 'Default is 0. Can be a revision number, milestone ' |
| 1159 | 'name (eg. M85, matches the most recent stable release of ' |
| 1160 | 'that milestone) or version number (eg. 85.0.4183.121)') |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 1161 | parser.add_option('-p', '--profile', '--user-data-dir', |
| 1162 | type='str', |
| 1163 | default='profile', |
| 1164 | help='Profile to use; this will not reset every run. ' |
| 1165 | 'Defaults to a clean profile.') |
| 1166 | parser.add_option('-t', '--times', |
| 1167 | type='int', |
| 1168 | default=1, |
| 1169 | help='Number of times to run each build before asking ' |
| 1170 | 'if it\'s good or bad. Temporary profiles are reused.') |
Bruce Dawson | e357305 | 2020-06-29 23:14:35 | [diff] [blame] | 1171 | parser.add_option('-c', |
| 1172 | '--command', |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 1173 | type='str', |
| 1174 | default='%p %a', |
| 1175 | help='Command to execute. %p and %a refer to Chrome ' |
Bruce Dawson | e357305 | 2020-06-29 23:14:35 | [diff] [blame] | 1176 | 'executable and specified extra arguments respectively. ' |
| 1177 | 'Use %s to specify all extra arguments as one string. ' |
| 1178 | 'Defaults to "%p %a". Note that any extra paths specified ' |
| 1179 | 'should be absolute. If you just need to append an ' |
| 1180 | 'argument to the Chrome command line use "-- ' |
| 1181 | '<args-to-pass-to-chromium>" instead.') |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 1182 | parser.add_option('-l', '--blink', |
| 1183 | action='store_true', |
| 1184 | help='Use Blink bisect instead of Chromium. ') |
| 1185 | parser.add_option('', '--not-interactive', |
| 1186 | action='store_true', |
| 1187 | default=False, |
| 1188 | help='Use command exit code to tell good/bad revision.') |
[email protected] | 01188669 | 2014-08-01 21:00:21 | [diff] [blame] | 1189 | parser.add_option('--asan', |
| 1190 | dest='asan', |
| 1191 | action='store_true', |
| 1192 | default=False, |
| 1193 | help='Allow the script to bisect ASAN builds') |
rob | 724c906 | 2015-01-22 00:26:42 | [diff] [blame] | 1194 | parser.add_option('--use-local-cache', |
| 1195 | dest='use_local_cache', |
[email protected] | 6a7a5d6 | 2014-07-09 04:45:50 | [diff] [blame] | 1196 | action='store_true', |
| 1197 | default=False, |
rob | 724c906 | 2015-01-22 00:26:42 | [diff] [blame] | 1198 | help='Use a local file in the current directory to cache ' |
| 1199 | 'a list of known revisions to speed up the ' |
| 1200 | 'initialization of this script.') |
skobes | 21b5cdfb | 2016-03-21 23:13:02 | [diff] [blame] | 1201 | parser.add_option('--verify-range', |
| 1202 | dest='verify_range', |
| 1203 | action='store_true', |
| 1204 | default=False, |
| 1205 | help='Test the first and last revisions in the range ' + |
| 1206 | 'before proceeding with the bisect.') |
elawrence | 446bcc3 | 2017-04-14 17:18:51 | [diff] [blame] | 1207 | parser.add_option("-r", action="callback", callback=error_internal_option) |
| 1208 | parser.add_option("-o", action="callback", callback=error_internal_option) |
[email protected] | b3b2051 | 2013-08-26 18:51:04 | [diff] [blame] | 1209 | |
[email protected] | 7ad66a7 | 2009-09-04 17:52:33 | [diff] [blame] | 1210 | (opts, args) = parser.parse_args() |
| 1211 | |
| 1212 | if opts.archive is None: |
Raul Tambre | 57e09d6 | 2019-09-22 17:18:52 | [diff] [blame] | 1213 | print('Error: missing required parameter: --archive') |
| 1214 | print() |
[email protected] | 7ad66a7 | 2009-09-04 17:52:33 | [diff] [blame] | 1215 | parser.print_help() |
| 1216 | return 1 |
| 1217 | |
[email protected] | 01188669 | 2014-08-01 21:00:21 | [diff] [blame] | 1218 | if opts.asan: |
| 1219 | supported_platforms = ['linux', 'mac', 'win'] |
| 1220 | if opts.archive not in supported_platforms: |
Raul Tambre | 57e09d6 | 2019-09-22 17:18:52 | [diff] [blame] | 1221 | print('Error: ASAN bisecting only supported on these platforms: [%s].' % |
| 1222 | ('|'.join(supported_platforms))) |
[email protected] | 01188669 | 2014-08-01 21:00:21 | [diff] [blame] | 1223 | return 1 |
[email protected] | 01188669 | 2014-08-01 21:00:21 | [diff] [blame] | 1224 | |
| 1225 | if opts.asan: |
| 1226 | base_url = ASAN_BASE_URL |
| 1227 | elif opts.blink: |
[email protected] | 4c6fec6b | 2013-09-17 17:44:08 | [diff] [blame] | 1228 | base_url = WEBKIT_BASE_URL |
| 1229 | else: |
| 1230 | base_url = CHROMIUM_BASE_URL |
| 1231 | |
[email protected] | 183706d9 | 2011-06-10 13:06:22 | [diff] [blame] | 1232 | # Create the context. Initialize 0 for the revisions as they are set below. |
[email protected] | 2e0f267 | 2014-08-13 20:32:58 | [diff] [blame] | 1233 | context = PathContext(base_url, opts.archive, opts.good, opts.bad, |
Jason Kersey | 97bb027a | 2016-05-11 20:10:43 | [diff] [blame] | 1234 | opts.asan, opts.use_local_cache, |
vitalybuka | 4d1e1e41 | 2015-07-06 17:21:06 | [diff] [blame] | 1235 | opts.flash_path) |
mikecase | a8cd284c | 2014-12-02 21:30:58 | [diff] [blame] | 1236 | |
[email protected] | 67e0bc6 | 2009-09-03 22:06:09 | [diff] [blame] | 1237 | # Pick a starting point, try to get HEAD for this. |
[email protected] | 2e0f267 | 2014-08-13 20:32:58 | [diff] [blame] | 1238 | if not opts.bad: |
| 1239 | context.bad_revision = '999.0.0.0' |
| 1240 | context.bad_revision = GetChromiumRevision( |
| 1241 | context, context.GetLastChangeURL()) |
[email protected] | 67e0bc6 | 2009-09-03 22:06:09 | [diff] [blame] | 1242 | |
| 1243 | # Find out when we were good. |
[email protected] | 2e0f267 | 2014-08-13 20:32:58 | [diff] [blame] | 1244 | if not opts.good: |
Jason Kersey | 97bb027a | 2016-05-11 20:10:43 | [diff] [blame] | 1245 | context.good_revision = 0 |
[email protected] | 801fb65 | 2012-07-20 20:13:50 | [diff] [blame] | 1246 | |
[email protected] | fc3702e | 2013-11-09 04:23:00 | [diff] [blame] | 1247 | if opts.flash_path: |
[email protected] | 2e0f267 | 2014-08-13 20:32:58 | [diff] [blame] | 1248 | msg = 'Could not find Flash binary at %s' % opts.flash_path |
| 1249 | assert os.path.exists(opts.flash_path), msg |
[email protected] | fc3702e | 2013-11-09 04:23:00 | [diff] [blame] | 1250 | |
Bruce Dawson | cd63ea2 | 2020-10-26 16:37:41 | [diff] [blame] | 1251 | context.good_revision = GetRevision(context.good_revision) |
| 1252 | context.bad_revision = GetRevision(context.bad_revision) |
[email protected] | 801fb65 | 2012-07-20 20:13:50 | [diff] [blame] | 1253 | |
[email protected] | 5e93cf16 | 2012-01-28 02:16:56 | [diff] [blame] | 1254 | if opts.times < 1: |
| 1255 | print('Number of times to run (%d) must be greater than or equal to 1.' % |
| 1256 | opts.times) |
| 1257 | parser.print_help() |
| 1258 | return 1 |
| 1259 | |
skobes | 21b5cdfb | 2016-03-21 23:13:02 | [diff] [blame] | 1260 | if opts.not_interactive: |
| 1261 | evaluator = DidCommandSucceed |
| 1262 | elif opts.asan: |
[email protected] | 01188669 | 2014-08-01 21:00:21 | [diff] [blame] | 1263 | evaluator = IsGoodASANBuild |
| 1264 | else: |
| 1265 | evaluator = AskIsGoodBuild |
| 1266 | |
[email protected] | 2e0f267 | 2014-08-13 20:32:58 | [diff] [blame] | 1267 | # Save these revision numbers to compare when showing the changelog URL |
| 1268 | # after the bisect. |
| 1269 | good_rev = context.good_revision |
| 1270 | bad_rev = context.bad_revision |
| 1271 | |
Bruce Dawson | cd63ea2 | 2020-10-26 16:37:41 | [diff] [blame] | 1272 | print('Scanning from %d to %d (%d revisions).' % |
| 1273 | (good_rev, bad_rev, abs(good_rev - bad_rev))) |
| 1274 | |
[email protected] | 2e0f267 | 2014-08-13 20:32:58 | [diff] [blame] | 1275 | (min_chromium_rev, max_chromium_rev, context) = Bisect( |
| 1276 | context, opts.times, opts.command, args, opts.profile, |
skobes | 21b5cdfb | 2016-03-21 23:13:02 | [diff] [blame] | 1277 | evaluator, opts.verify_range) |
[email protected] | 67e0bc6 | 2009-09-03 22:06:09 | [diff] [blame] | 1278 | |
[email protected] | ff50d1c | 2013-04-17 18:49:36 | [diff] [blame] | 1279 | # Get corresponding blink revisions. |
[email protected] | b2fe7f2 | 2011-10-25 22:58:31 | [diff] [blame] | 1280 | try: |
[email protected] | 4c6fec6b | 2013-09-17 17:44:08 | [diff] [blame] | 1281 | min_blink_rev = GetBlinkRevisionForChromiumRevision(context, |
| 1282 | min_chromium_rev) |
| 1283 | max_blink_rev = GetBlinkRevisionForChromiumRevision(context, |
| 1284 | max_chromium_rev) |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 1285 | except Exception: |
[email protected] | b2fe7f2 | 2011-10-25 22:58:31 | [diff] [blame] | 1286 | # Silently ignore the failure. |
[email protected] | ff50d1c | 2013-04-17 18:49:36 | [diff] [blame] | 1287 | min_blink_rev, max_blink_rev = 0, 0 |
[email protected] | b2fe7f2 | 2011-10-25 22:58:31 | [diff] [blame] | 1288 | |
[email protected] | 3bdaa475 | 2013-09-30 20:13:36 | [diff] [blame] | 1289 | if opts.blink: |
| 1290 | # We're done. Let the user know the results in an official manner. |
| 1291 | if good_rev > bad_rev: |
Raul Tambre | 57e09d6 | 2019-09-22 17:18:52 | [diff] [blame] | 1292 | print(DONE_MESSAGE_GOOD_MAX % (str(min_blink_rev), str(max_blink_rev))) |
[email protected] | 3bdaa475 | 2013-09-30 20:13:36 | [diff] [blame] | 1293 | else: |
Raul Tambre | 57e09d6 | 2019-09-22 17:18:52 | [diff] [blame] | 1294 | print(DONE_MESSAGE_GOOD_MIN % (str(min_blink_rev), str(max_blink_rev))) |
[email protected] | eadd95d | 2012-11-02 22:42:09 | [diff] [blame] | 1295 | |
Raul Tambre | 57e09d6 | 2019-09-22 17:18:52 | [diff] [blame] | 1296 | print('BLINK CHANGELOG URL:') |
| 1297 | print(' ' + BLINK_CHANGELOG_URL % (max_blink_rev, min_blink_rev)) |
[email protected] | 3bdaa475 | 2013-09-30 20:13:36 | [diff] [blame] | 1298 | |
[email protected] | d0149c5c | 2012-05-29 21:12:11 | [diff] [blame] | 1299 | else: |
[email protected] | 3bdaa475 | 2013-09-30 20:13:36 | [diff] [blame] | 1300 | # We're done. Let the user know the results in an official manner. |
| 1301 | if good_rev > bad_rev: |
Raul Tambre | 57e09d6 | 2019-09-22 17:18:52 | [diff] [blame] | 1302 | print(DONE_MESSAGE_GOOD_MAX % (str(min_chromium_rev), |
| 1303 | str(max_chromium_rev))) |
[email protected] | 3bdaa475 | 2013-09-30 20:13:36 | [diff] [blame] | 1304 | else: |
Raul Tambre | 57e09d6 | 2019-09-22 17:18:52 | [diff] [blame] | 1305 | print(DONE_MESSAGE_GOOD_MIN % (str(min_chromium_rev), |
| 1306 | str(max_chromium_rev))) |
[email protected] | 3bdaa475 | 2013-09-30 20:13:36 | [diff] [blame] | 1307 | if min_blink_rev != max_blink_rev: |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 1308 | print ('NOTE: There is a Blink roll in the range, ' |
| 1309 | 'you might also want to do a Blink bisect.') |
[email protected] | 3bdaa475 | 2013-09-30 20:13:36 | [diff] [blame] | 1310 | |
Raul Tambre | 57e09d6 | 2019-09-22 17:18:52 | [diff] [blame] | 1311 | print('CHANGELOG URL:') |
Jason Kersey | 97bb027a | 2016-05-11 20:10:43 | [diff] [blame] | 1312 | PrintChangeLog(min_chromium_rev, max_chromium_rev) |
[email protected] | cb155a8 | 2011-11-29 17:25:34 | [diff] [blame] | 1313 | |
[email protected] | 4df583c | 2014-07-31 17:11:55 | [diff] [blame] | 1314 | |
[email protected] | 67e0bc6 | 2009-09-03 22:06:09 | [diff] [blame] | 1315 | if __name__ == '__main__': |
[email protected] | 7ad66a7 | 2009-09-04 17:52:33 | [diff] [blame] | 1316 | sys.exit(main()) |