senorblanco@chromium.org | 782f3b4 | 2012-10-29 18:06:26 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | ''' |
| 4 | Copyright 2012 Google Inc. |
| 5 | |
| 6 | Use of this source code is governed by a BSD-style license that can be |
| 7 | found in the LICENSE file. |
| 8 | ''' |
| 9 | |
| 10 | ''' |
senorblanco@chromium.org | 123a0b5 | 2012-11-29 21:50:34 +0000 | [diff] [blame] | 11 | Rebaselines the given GM tests, on all bots and all configurations. |
| 12 | Must be run from the gm-expected directory. If run from a git or SVN |
| 13 | checkout, the files will be added to the staging area for commit. |
senorblanco@chromium.org | 782f3b4 | 2012-10-29 18:06:26 +0000 | [diff] [blame] | 14 | ''' |
| 15 | |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 16 | # System-level imports |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 17 | import argparse |
epoger@google.com | ec3397b | 2013-05-29 17:09:43 +0000 | [diff] [blame] | 18 | import os |
epoger@google.com | e78d207 | 2013-06-12 17:44:14 +0000 | [diff] [blame] | 19 | import re |
epoger@google.com | ec3397b | 2013-05-29 17:09:43 +0000 | [diff] [blame] | 20 | import sys |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 21 | import urllib2 |
| 22 | |
epoger@google.com | 99a8ec9 | 2013-06-19 18:56:59 +0000 | [diff] [blame] | 23 | # Imports from local directory |
| 24 | import rebaseline_imagefiles |
| 25 | |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 26 | # Imports from within Skia |
| 27 | # |
epoger@google.com | dad5310 | 2013-06-12 14:25:30 +0000 | [diff] [blame] | 28 | # We need to add the 'gm' directory, so that we can import gm_json.py within |
| 29 | # that directory. That script allows us to parse the actual-results.json file |
| 30 | # written out by the GM tool. |
| 31 | # Make sure that the 'gm' dir is in the PYTHONPATH, but add it at the *end* |
| 32 | # so any dirs that are already in the PYTHONPATH will be preferred. |
| 33 | # |
| 34 | # This assumes that the 'gm' directory has been checked out as a sibling of |
| 35 | # the 'tools' directory containing this script, which will be the case if |
| 36 | # 'trunk' was checked out as a single unit. |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 37 | GM_DIRECTORY = os.path.realpath( |
| 38 | os.path.join(os.path.dirname(os.path.dirname(__file__)), 'gm')) |
| 39 | if GM_DIRECTORY not in sys.path: |
| 40 | sys.path.append(GM_DIRECTORY) |
| 41 | import gm_json |
| 42 | |
epoger@google.com | ec3397b | 2013-05-29 17:09:43 +0000 | [diff] [blame] | 43 | # Mapping of gm-expectations subdir (under |
| 44 | # https://skia.googlecode.com/svn/gm-expected/ ) |
| 45 | # to builder name (see list at http://108.170.217.252:10117/builders ) |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 46 | SUBDIR_MAPPING = { |
epoger@google.com | ec3397b | 2013-05-29 17:09:43 +0000 | [diff] [blame] | 47 | 'base-shuttle-win7-intel-float': |
| 48 | 'Test-Win7-ShuttleA-HD2000-x86-Release', |
| 49 | 'base-shuttle-win7-intel-angle': |
| 50 | 'Test-Win7-ShuttleA-HD2000-x86-Release-ANGLE', |
| 51 | 'base-shuttle-win7-intel-directwrite': |
| 52 | 'Test-Win7-ShuttleA-HD2000-x86-Release-DirectWrite', |
| 53 | 'base-shuttle_ubuntu12_ati5770': |
| 54 | 'Test-Ubuntu12-ShuttleA-ATI5770-x86_64-Release', |
| 55 | 'base-macmini': |
| 56 | 'Test-Mac10.6-MacMini4.1-GeForce320M-x86-Release', |
| 57 | 'base-macmini-lion-float': |
| 58 | 'Test-Mac10.7-MacMini4.1-GeForce320M-x86-Release', |
| 59 | 'base-android-galaxy-nexus': |
| 60 | 'Test-Android-GalaxyNexus-SGX540-Arm7-Debug', |
| 61 | 'base-android-nexus-7': |
| 62 | 'Test-Android-Nexus7-Tegra3-Arm7-Release', |
| 63 | 'base-android-nexus-s': |
| 64 | 'Test-Android-NexusS-SGX540-Arm7-Release', |
| 65 | 'base-android-xoom': |
| 66 | 'Test-Android-Xoom-Tegra2-Arm7-Release', |
| 67 | 'base-android-nexus-10': |
| 68 | 'Test-Android-Nexus10-MaliT604-Arm7-Release', |
robertphillips@google.com | 63e9627 | 2013-07-02 12:54:37 +0000 | [diff] [blame] | 69 | 'base-android-nexus-4': |
| 70 | 'Test-Android-Nexus4-Adreno320-Arm7-Release', |
epoger@google.com | ec3397b | 2013-05-29 17:09:43 +0000 | [diff] [blame] | 71 | } |
| 72 | |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 73 | |
epoger@google.com | 66ba9f9 | 2013-07-11 19:20:30 +0000 | [diff] [blame] | 74 | class _InternalException(Exception): |
epoger@google.com | db29a31 | 2013-06-04 14:58:47 +0000 | [diff] [blame] | 75 | pass |
| 76 | |
epoger@google.com | ffcbdbf | 2013-07-16 17:35:39 +0000 | [diff] [blame^] | 77 | # Object that handles exceptions, either raising them immediately or collecting |
| 78 | # them to display later on. |
| 79 | class ExceptionHandler(object): |
| 80 | |
| 81 | # params: |
| 82 | # keep_going_on_failure: if False, report failures and quit right away; |
| 83 | # if True, collect failures until |
| 84 | # ReportAllFailures() is called |
| 85 | def __init__(self, keep_going_on_failure=False): |
| 86 | self._keep_going_on_failure = keep_going_on_failure |
| 87 | self._failures_encountered = [] |
| 88 | self._exiting = False |
| 89 | |
| 90 | # Exit the program with the given status value. |
| 91 | def _Exit(self, status=1): |
| 92 | self._exiting = True |
| 93 | sys.exit(status) |
| 94 | |
| 95 | # We have encountered an exception; either collect the info and keep going, |
| 96 | # or exit the program right away. |
| 97 | def RaiseExceptionOrContinue(self, e): |
| 98 | # If we are already quitting the program, propagate any exceptions |
| 99 | # so that the proper exit status will be communicated to the shell. |
| 100 | if self._exiting: |
| 101 | raise e |
| 102 | |
| 103 | if self._keep_going_on_failure: |
| 104 | print >> sys.stderr, 'WARNING: swallowing exception %s' % e |
| 105 | self._failures_encountered.append(e) |
| 106 | else: |
| 107 | print >> sys.stderr, e |
| 108 | print >> sys.stderr, ( |
| 109 | 'Halting at first exception; to keep going, re-run ' + |
| 110 | 'with the --keep-going-on-failure option set.') |
| 111 | self._Exit() |
| 112 | |
| 113 | def ReportAllFailures(self): |
| 114 | if self._failures_encountered: |
| 115 | print >> sys.stderr, ('Encountered %d failures (see above).' % |
| 116 | len(self._failures_encountered)) |
| 117 | self._Exit() |
| 118 | |
| 119 | |
epoger@google.com | 99a8ec9 | 2013-06-19 18:56:59 +0000 | [diff] [blame] | 120 | # Object that rebaselines a JSON expectations file (not individual image files). |
epoger@google.com | 99a8ec9 | 2013-06-19 18:56:59 +0000 | [diff] [blame] | 121 | class JsonRebaseliner(object): |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 122 | |
| 123 | # params: |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 124 | # expectations_root: root directory of all expectations JSON files |
| 125 | # expectations_filename: filename (under expectations_root) of JSON |
| 126 | # expectations file; typically |
| 127 | # "expected-results.json" |
| 128 | # actuals_base_url: base URL from which to read actual-result JSON files |
| 129 | # actuals_filename: filename (under actuals_base_url) from which to read a |
| 130 | # summary of results; typically "actual-results.json" |
epoger@google.com | ffcbdbf | 2013-07-16 17:35:39 +0000 | [diff] [blame^] | 131 | # exception_handler: reference to rebaseline.ExceptionHandler object |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 132 | # tests: list of tests to rebaseline, or None if we should rebaseline |
| 133 | # whatever files the JSON results summary file tells us to |
epoger@google.com | 9de25e3 | 2013-07-10 15:27:18 +0000 | [diff] [blame] | 134 | # configs: which configs to run for each test, or None if we should |
| 135 | # rebaseline whatever configs the JSON results summary file tells |
| 136 | # us to |
epoger@google.com | dad5310 | 2013-06-12 14:25:30 +0000 | [diff] [blame] | 137 | # add_new: if True, add expectations for tests which don't have any yet |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 138 | def __init__(self, expectations_root, expectations_filename, |
epoger@google.com | ffcbdbf | 2013-07-16 17:35:39 +0000 | [diff] [blame^] | 139 | actuals_base_url, actuals_filename, exception_handler, |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 140 | tests=None, configs=None, add_new=False): |
epoger@google.com | 99a8ec9 | 2013-06-19 18:56:59 +0000 | [diff] [blame] | 141 | self._expectations_root = expectations_root |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 142 | self._expectations_filename = expectations_filename |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 143 | self._tests = tests |
| 144 | self._configs = configs |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 145 | self._actuals_base_url = actuals_base_url |
| 146 | self._actuals_filename = actuals_filename |
epoger@google.com | ffcbdbf | 2013-07-16 17:35:39 +0000 | [diff] [blame^] | 147 | self._exception_handler = exception_handler |
epoger@google.com | dad5310 | 2013-06-12 14:25:30 +0000 | [diff] [blame] | 148 | self._add_new = add_new |
epoger@google.com | e78d207 | 2013-06-12 17:44:14 +0000 | [diff] [blame] | 149 | self._testname_pattern = re.compile('(\S+)_(\S+).png') |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 150 | |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 151 | # Returns the full contents of filepath, as a single string. |
| 152 | # If filepath looks like a URL, try to read it that way instead of as |
| 153 | # a path on local storage. |
epoger@google.com | 66ba9f9 | 2013-07-11 19:20:30 +0000 | [diff] [blame] | 154 | # |
| 155 | # Raises _InternalException if there is a problem. |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 156 | def _GetFileContents(self, filepath): |
| 157 | if filepath.startswith('http:') or filepath.startswith('https:'): |
epoger@google.com | 66ba9f9 | 2013-07-11 19:20:30 +0000 | [diff] [blame] | 158 | try: |
| 159 | return urllib2.urlopen(filepath).read() |
| 160 | except urllib2.HTTPError as e: |
| 161 | raise _InternalException('unable to read URL %s: %s' % ( |
| 162 | filepath, e)) |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 163 | else: |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 164 | return open(filepath, 'r').read() |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 165 | |
epoger@google.com | e78d207 | 2013-06-12 17:44:14 +0000 | [diff] [blame] | 166 | # Returns a dictionary of actual results from actual-results.json file. |
| 167 | # |
| 168 | # The dictionary returned has this format: |
| 169 | # { |
| 170 | # u'imageblur_565.png': [u'bitmap-64bitMD5', 3359963596899141322], |
| 171 | # u'imageblur_8888.png': [u'bitmap-64bitMD5', 4217923806027861152], |
| 172 | # u'shadertext3_8888.png': [u'bitmap-64bitMD5', 3713708307125704716] |
| 173 | # } |
| 174 | # |
epoger@google.com | 66ba9f9 | 2013-07-11 19:20:30 +0000 | [diff] [blame] | 175 | # If the JSON actual result summary file cannot be loaded, logs a warning |
| 176 | # message and returns None. |
| 177 | # If the JSON actual result summary file can be loaded, but we have |
| 178 | # trouble parsing it, raises an Exception. |
epoger@google.com | e78d207 | 2013-06-12 17:44:14 +0000 | [diff] [blame] | 179 | # |
| 180 | # params: |
| 181 | # json_url: URL pointing to a JSON actual result summary file |
| 182 | # sections: a list of section names to include in the results, e.g. |
| 183 | # [gm_json.JSONKEY_ACTUALRESULTS_FAILED, |
| 184 | # gm_json.JSONKEY_ACTUALRESULTS_NOCOMPARISON] ; |
| 185 | # if None, then include ALL sections. |
| 186 | def _GetActualResults(self, json_url, sections=None): |
epoger@google.com | 66ba9f9 | 2013-07-11 19:20:30 +0000 | [diff] [blame] | 187 | try: |
| 188 | json_contents = self._GetFileContents(json_url) |
| 189 | except _InternalException: |
| 190 | print >> sys.stderr, ( |
| 191 | 'could not read json_url %s ; skipping this platform.' % |
| 192 | json_url) |
| 193 | return None |
epoger@google.com | e78d207 | 2013-06-12 17:44:14 +0000 | [diff] [blame] | 194 | json_dict = gm_json.LoadFromString(json_contents) |
| 195 | results_to_return = {} |
| 196 | actual_results = json_dict[gm_json.JSONKEY_ACTUALRESULTS] |
| 197 | if not sections: |
| 198 | sections = actual_results.keys() |
| 199 | for section in sections: |
| 200 | section_results = actual_results[section] |
| 201 | if section_results: |
| 202 | results_to_return.update(section_results) |
| 203 | return results_to_return |
| 204 | |
epoger@google.com | 99a8ec9 | 2013-06-19 18:56:59 +0000 | [diff] [blame] | 205 | # Rebaseline all tests/types we specified in the constructor, |
| 206 | # within this gm-expectations subdir. |
| 207 | # |
| 208 | # params: |
| 209 | # subdir : e.g. 'base-shuttle-win7-intel-float' |
| 210 | # builder : e.g. 'Test-Win7-ShuttleA-HD2000-x86-Release' |
| 211 | def RebaselineSubdir(self, subdir, builder): |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 212 | # Read in the actual result summary, and extract all the tests whose |
| 213 | # results we need to update. |
| 214 | actuals_url = '/'.join([self._actuals_base_url, |
| 215 | subdir, builder, subdir, |
| 216 | self._actuals_filename]) |
| 217 | sections = [gm_json.JSONKEY_ACTUALRESULTS_FAILED] |
| 218 | if self._add_new: |
| 219 | sections.append(gm_json.JSONKEY_ACTUALRESULTS_NOCOMPARISON) |
| 220 | results_to_update = self._GetActualResults(json_url=actuals_url, |
| 221 | sections=sections) |
epoger@google.com | e78d207 | 2013-06-12 17:44:14 +0000 | [diff] [blame] | 222 | |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 223 | # Read in current expectations. |
| 224 | expectations_json_filepath = os.path.join( |
| 225 | self._expectations_root, subdir, self._expectations_filename) |
| 226 | expectations_dict = gm_json.LoadFromFile(expectations_json_filepath) |
| 227 | |
| 228 | # Update the expectations in memory, skipping any tests/configs that |
| 229 | # the caller asked to exclude. |
| 230 | skipped_images = [] |
| 231 | if results_to_update: |
| 232 | for (image_name, image_results) in results_to_update.iteritems(): |
| 233 | (test, config) = self._testname_pattern.match(image_name).groups() |
| 234 | if self._tests: |
| 235 | if test not in self._tests: |
| 236 | skipped_images.append(image_name) |
| 237 | continue |
| 238 | if self._configs: |
| 239 | if config not in self._configs: |
| 240 | skipped_images.append(image_name) |
| 241 | continue |
| 242 | expectations_dict[gm_json.JSONKEY_EXPECTEDRESULTS] \ |
| 243 | [image_name] \ |
| 244 | [gm_json.JSONKEY_EXPECTEDRESULTS_ALLOWEDDIGESTS] = \ |
| 245 | [image_results] |
| 246 | |
| 247 | # Write out updated expectations. |
| 248 | gm_json.WriteToFile(expectations_dict, expectations_json_filepath) |
| 249 | |
epoger@google.com | ec3397b | 2013-05-29 17:09:43 +0000 | [diff] [blame] | 250 | |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 251 | # main... |
epoger@google.com | ec3397b | 2013-05-29 17:09:43 +0000 | [diff] [blame] | 252 | |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 253 | parser = argparse.ArgumentParser() |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 254 | parser.add_argument('--actuals-base-url', |
| 255 | help='base URL from which to read files containing JSON ' + |
| 256 | 'summaries of actual GM results; defaults to %(default)s', |
| 257 | default='http://skia-autogen.googlecode.com/svn/gm-actual') |
| 258 | parser.add_argument('--actuals-filename', |
| 259 | help='filename (within platform-specific subdirectories ' + |
| 260 | 'of ACTUALS_BASE_URL) to read a summary of results from; ' + |
| 261 | 'defaults to %(default)s', |
| 262 | default='actual-results.json') |
| 263 | # TODO(epoger): Add test that exercises --add-new argument. |
epoger@google.com | dad5310 | 2013-06-12 14:25:30 +0000 | [diff] [blame] | 264 | parser.add_argument('--add-new', action='store_true', |
| 265 | help='in addition to the standard behavior of ' + |
| 266 | 'updating expectations for failing tests, add ' + |
| 267 | 'expectations for tests which don\'t have expectations ' + |
| 268 | 'yet.') |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 269 | # TODO(epoger): Add test that exercises --configs argument. |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 270 | parser.add_argument('--configs', metavar='CONFIG', nargs='+', |
| 271 | help='which configurations to rebaseline, e.g. ' + |
epoger@google.com | 9de25e3 | 2013-07-10 15:27:18 +0000 | [diff] [blame] | 272 | '"--configs 565 8888", as a filter over the full set of ' + |
| 273 | 'results in ACTUALS_FILENAME; if unspecified, rebaseline ' + |
| 274 | '*all* configs that are available.') |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 275 | # TODO(epoger): The --dry-run argument will no longer be needed once we |
| 276 | # are only rebaselining JSON files. |
epoger@google.com | 82f3178 | 2013-06-11 15:45:46 +0000 | [diff] [blame] | 277 | parser.add_argument('--dry-run', action='store_true', |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 278 | help='instead of actually downloading files or adding ' + |
| 279 | 'files to checkout, display a list of operations that ' + |
| 280 | 'we would normally perform') |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 281 | parser.add_argument('--expectations-filename', |
| 282 | help='filename (under EXPECTATIONS_ROOT) to read ' + |
| 283 | 'current expectations from, and to write new ' + |
| 284 | 'expectations into; defaults to %(default)s', |
| 285 | default='expected-results.json') |
epoger@google.com | 99a8ec9 | 2013-06-19 18:56:59 +0000 | [diff] [blame] | 286 | parser.add_argument('--expectations-root', |
| 287 | help='root of expectations directory to update-- should ' + |
| 288 | 'contain one or more base-* subdirectories. Defaults to ' + |
| 289 | '%(default)s', |
| 290 | default='.') |
epoger@google.com | ffcbdbf | 2013-07-16 17:35:39 +0000 | [diff] [blame^] | 291 | parser.add_argument('--keep-going-on-failure', action='store_true', |
| 292 | help='instead of halting at the first error encountered, ' + |
| 293 | 'keep going and rebaseline as many tests as possible, ' + |
| 294 | 'and then report the full set of errors at the end') |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 295 | parser.add_argument('--subdirs', metavar='SUBDIR', nargs='+', |
| 296 | help='which platform subdirectories to rebaseline; ' + |
| 297 | 'if unspecified, rebaseline all subdirs, same as ' + |
| 298 | '"--subdirs %s"' % ' '.join(sorted(SUBDIR_MAPPING.keys()))) |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 299 | # TODO(epoger): Add test that exercises --tests argument. |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 300 | parser.add_argument('--tests', metavar='TEST', nargs='+', |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 301 | help='which tests to rebaseline, e.g. ' + |
epoger@google.com | 9de25e3 | 2013-07-10 15:27:18 +0000 | [diff] [blame] | 302 | '"--tests aaclip bigmatrix", as a filter over the full ' + |
| 303 | 'set of results in ACTUALS_FILENAME; if unspecified, ' + |
| 304 | 'rebaseline *all* tests that are available.') |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 305 | args = parser.parse_args() |
epoger@google.com | ffcbdbf | 2013-07-16 17:35:39 +0000 | [diff] [blame^] | 306 | exception_handler = ExceptionHandler( |
| 307 | keep_going_on_failure=args.keep_going_on_failure) |
epoger@google.com | 99a8ec9 | 2013-06-19 18:56:59 +0000 | [diff] [blame] | 308 | if args.subdirs: |
| 309 | subdirs = args.subdirs |
| 310 | missing_json_is_fatal = True |
| 311 | else: |
| 312 | subdirs = sorted(SUBDIR_MAPPING.keys()) |
| 313 | missing_json_is_fatal = False |
| 314 | for subdir in subdirs: |
| 315 | if not subdir in SUBDIR_MAPPING.keys(): |
| 316 | raise Exception(('unrecognized platform subdir "%s"; ' + |
| 317 | 'should be one of %s') % ( |
| 318 | subdir, SUBDIR_MAPPING.keys())) |
| 319 | builder = SUBDIR_MAPPING[subdir] |
| 320 | |
| 321 | # We instantiate different Rebaseliner objects depending |
| 322 | # on whether we are rebaselining an expected-results.json file, or |
| 323 | # individual image files. Different gm-expected subdirectories may move |
| 324 | # from individual image files to JSON-format expectations at different |
| 325 | # times, so we need to make this determination per subdirectory. |
| 326 | # |
| 327 | # See https://goto.google.com/ChecksumTransitionDetail |
| 328 | expectations_json_file = os.path.join(args.expectations_root, subdir, |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 329 | args.expectations_filename) |
epoger@google.com | 99a8ec9 | 2013-06-19 18:56:59 +0000 | [diff] [blame] | 330 | if os.path.isfile(expectations_json_file): |
epoger@google.com | 99a8ec9 | 2013-06-19 18:56:59 +0000 | [diff] [blame] | 331 | rebaseliner = JsonRebaseliner( |
| 332 | expectations_root=args.expectations_root, |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 333 | expectations_filename=args.expectations_filename, |
epoger@google.com | 99a8ec9 | 2013-06-19 18:56:59 +0000 | [diff] [blame] | 334 | tests=args.tests, configs=args.configs, |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 335 | actuals_base_url=args.actuals_base_url, |
| 336 | actuals_filename=args.actuals_filename, |
epoger@google.com | ffcbdbf | 2013-07-16 17:35:39 +0000 | [diff] [blame^] | 337 | exception_handler=exception_handler, |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 338 | add_new=args.add_new) |
epoger@google.com | 99a8ec9 | 2013-06-19 18:56:59 +0000 | [diff] [blame] | 339 | else: |
epoger@google.com | 89fa4b9 | 2013-07-10 16:54:10 +0000 | [diff] [blame] | 340 | # TODO(epoger): When we get rid of the ImageRebaseliner implementation, |
| 341 | # we should raise an Exception in this case (no JSON expectations file |
| 342 | # found to update), to prevent a recurrence of |
| 343 | # https://code.google.com/p/skia/issues/detail?id=1403 ('rebaseline.py |
| 344 | # script fails with misleading output when run outside of gm-expected |
| 345 | # dir') |
epoger@google.com | 99a8ec9 | 2013-06-19 18:56:59 +0000 | [diff] [blame] | 346 | rebaseliner = rebaseline_imagefiles.ImageRebaseliner( |
| 347 | expectations_root=args.expectations_root, |
| 348 | tests=args.tests, configs=args.configs, |
| 349 | dry_run=args.dry_run, |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 350 | json_base_url=args.actuals_base_url, |
| 351 | json_filename=args.actuals_filename, |
epoger@google.com | ffcbdbf | 2013-07-16 17:35:39 +0000 | [diff] [blame^] | 352 | exception_handler=exception_handler, |
epoger@google.com | 99a8ec9 | 2013-06-19 18:56:59 +0000 | [diff] [blame] | 353 | add_new=args.add_new, |
| 354 | missing_json_is_fatal=missing_json_is_fatal) |
epoger@google.com | ffcbdbf | 2013-07-16 17:35:39 +0000 | [diff] [blame^] | 355 | |
epoger@google.com | 3e7399f | 2013-07-10 17:23:47 +0000 | [diff] [blame] | 356 | try: |
| 357 | rebaseliner.RebaselineSubdir(subdir=subdir, builder=builder) |
| 358 | except BaseException as e: |
epoger@google.com | ffcbdbf | 2013-07-16 17:35:39 +0000 | [diff] [blame^] | 359 | exception_handler.RaiseExceptionOrContinue(e) |
| 360 | |
| 361 | exception_handler.ReportAllFailures() |