Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/w3c/deps_updater.py

Issue 2639213003: Refactoring: Split up "commit_changes_if_needed" method. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Tools/Scripts/webkitpy/w3c/deps_updater_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Fetches a copy of the latest state of a W3C test repository and commits. 5 """Fetches a copy of the latest state of a W3C test repository and commits.
6 6
7 If this script is given the argument --auto-update, it will also attempt to 7 If this script is given the argument --auto-update, it will also attempt to
8 upload a CL, triggery try jobs, and make any changes that are required for 8 upload a CL, triggery try jobs, and make any changes that are required for
9 new failing tests before committing. 9 new failing tests before committing.
10 """ 10 """
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 log_level = logging.DEBUG if self.verbose else logging.INFO 45 log_level = logging.DEBUG if self.verbose else logging.INFO
46 logging.basicConfig(level=log_level, format='%(message)s') 46 logging.basicConfig(level=log_level, format='%(message)s')
47 47
48 if not self.checkout_is_okay(options.allow_local_commits): 48 if not self.checkout_is_okay(options.allow_local_commits):
49 return 1 49 return 1
50 50
51 self.git_cl = GitCL(self.host, auth_refresh_token_json=options.auth_refr esh_token_json) 51 self.git_cl = GitCL(self.host, auth_refresh_token_json=options.auth_refr esh_token_json)
52 52
53 _log.info('Noting the current Chromium commit.') 53 _log.info('Noting the current Chromium commit.')
54 _, show_ref_output = self.run(['git', 'show-ref', 'HEAD']) 54 _, show_ref_output = self.run(['git', 'show-ref', 'HEAD'])
55 chromium_commitish = show_ref_output.split()[0] 55 chromium_commit = show_ref_output.split()[0]
56 56
57 if options.target == 'wpt': 57 if options.target == 'wpt':
58 import_commitish = self.update(WPT_DEST_NAME, WPT_REPO_URL, options. keep_w3c_repos_around, options.revision) 58 import_commit = self.update(WPT_DEST_NAME, WPT_REPO_URL, options.kee p_w3c_repos_around, options.revision)
59 self._copy_resources() 59 self._copy_resources()
60 elif options.target == 'css': 60 elif options.target == 'css':
61 import_commitish = self.update(CSS_DEST_NAME, CSS_REPO_URL, options. keep_w3c_repos_around, options.revision) 61 import_commit = self.update(CSS_DEST_NAME, CSS_REPO_URL, options.kee p_w3c_repos_around, options.revision)
62 else: 62 else:
63 raise AssertionError("Unsupported target %s" % options.target) 63 raise AssertionError("Unsupported target %s" % options.target)
64 64
65 has_changes = self.commit_changes_if_needed(chromium_commitish, import_c ommitish) 65 has_changes = self._has_changes()
66 if options.auto_update and has_changes: 66 if not has_changes:
67 _log.info('Done: no changes to import.')
68 return 0
69
70 commit_message = self._commit_message(chromium_commit, import_commit)
71 self._commit_changes(commit_message)
72 _log.info('Done: changes imported and committed.')
73
74 if options.auto_update:
67 commit_successful = self.do_auto_update() 75 commit_successful = self.do_auto_update()
68 if not commit_successful: 76 if not commit_successful:
69 return 1 77 return 1
70 return 0 78 return 0
71 79
72 def parse_args(self, argv): 80 def parse_args(self, argv):
73 parser = argparse.ArgumentParser() 81 parser = argparse.ArgumentParser()
74 parser.description = __doc__ 82 parser.description = __doc__
75 parser.add_argument('-v', '--verbose', action='store_true', 83 parser.add_argument('-v', '--verbose', action='store_true',
76 help='log what we are doing') 84 help='log what we are doing')
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 226
219 if not keep_w3c_repos_around: 227 if not keep_w3c_repos_around:
220 _log.info('Deleting temp repo directory %s.', temp_repo_path) 228 _log.info('Deleting temp repo directory %s.', temp_repo_path)
221 self.rmtree(temp_repo_path) 229 self.rmtree(temp_repo_path)
222 230
223 _log.info('Updating TestExpectations for any removed or renamed tests.') 231 _log.info('Updating TestExpectations for any removed or renamed tests.')
224 self.update_all_test_expectations_files(self._list_deleted_tests(), self ._list_renamed_tests()) 232 self.update_all_test_expectations_files(self._list_deleted_tests(), self ._list_renamed_tests())
225 233
226 return '%s@%s' % (dest_dir_name, master_commitish) 234 return '%s@%s' % (dest_dir_name, master_commitish)
227 235
228 def commit_changes_if_needed(self, chromium_commitish, import_commitish): 236 def _commit_changes(self, commit_message):
229 if self.run(['git', 'diff', '--quiet', 'HEAD'], exit_on_failure=False)[0 ]: 237 _log.info('Committing changes.')
230 _log.info('Committing changes.') 238 path_to_commit_msg = self.path_from_webkit_base('commit_msg')
231 commit_msg = ('Import %s\n' 239 _log.debug('cat > %s <<EOF', path_to_commit_msg)
232 '\n' 240 _log.debug(commit_message)
233 'Using update-w3c-deps in Chromium %s.\n' 241 _log.debug('EOF')
234 % (import_commitish, chromium_commitish)) 242 self.fs.write_text_file(path_to_commit_msg, commit_message)
235 path_to_commit_msg = self.path_from_webkit_base('commit_msg') 243 self.run(['git', 'commit', '-a', '-F', path_to_commit_msg])
jeffcarp 2017/01/18 19:45:39 Not sure if this is preferable, but you can also p
236 _log.debug('cat > %s <<EOF', path_to_commit_msg) 244 self.remove(path_to_commit_msg)
237 _log.debug(commit_msg) 245
238 _log.debug('EOF') 246 def _has_changes(self):
239 self.fs.write_text_file(path_to_commit_msg, commit_msg) 247 return_code, _ = self.run(['git', 'diff', '--quiet', 'HEAD'], exit_on_fa ilure=False)
240 self.run(['git', 'commit', '-a', '-F', path_to_commit_msg]) 248 return return_code == 1
241 self.remove(path_to_commit_msg) 249
242 _log.info('Done: changes imported and committed.') 250 def _commit_message(self, chromium_commit, import_commit):
243 return True 251 return ('Import %s\n\nUsing update-w3c-deps in Chromium %s.\n\n' %
244 else: 252 (import_commit, chromium_commit))
245 _log.info('Done: no changes to import.')
246 return False
247 253
248 @staticmethod 254 @staticmethod
249 def is_baseline(basename): 255 def is_baseline(basename):
250 return basename.endswith('-expected.txt') 256 return basename.endswith('-expected.txt')
251 257
252 def run(self, cmd, exit_on_failure=True, cwd=None): 258 def run(self, cmd, exit_on_failure=True, cwd=None):
253 _log.debug('Running command: %s', ' '.join(cmd)) 259 _log.debug('Running command: %s', ' '.join(cmd))
254 260
255 cwd = cwd or self.finder.webkit_base() 261 cwd = cwd or self.finder.webkit_base()
256 proc = self.executive.popen(cmd, stdout=self.executive.PIPE, stderr=self .executive.PIPE, cwd=cwd) 262 proc = self.executive.popen(cmd, stdout=self.executive.PIPE, stderr=self .executive.PIPE, cwd=cwd)
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 """Returns a dict mapping source to dest name for layout tests that have been renamed.""" 458 """Returns a dict mapping source to dest name for layout tests that have been renamed."""
453 out = self.check_run(['git', 'diff', 'origin/master', '-M100%', '--diff- filter=R', '--name-status']) 459 out = self.check_run(['git', 'diff', 'origin/master', '-M100%', '--diff- filter=R', '--name-status'])
454 renamed_tests = {} 460 renamed_tests = {}
455 for line in out.splitlines(): 461 for line in out.splitlines():
456 _, source_path, dest_path = line.split() 462 _, source_path, dest_path = line.split()
457 source_test = self.finder.layout_test_name(source_path) 463 source_test = self.finder.layout_test_name(source_path)
458 dest_test = self.finder.layout_test_name(dest_path) 464 dest_test = self.finder.layout_test_name(dest_path)
459 if source_test and dest_test: 465 if source_test and dest_test:
460 renamed_tests[source_test] = dest_test 466 renamed_tests[source_test] = dest_test
461 return renamed_tests 467 return renamed_tests
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Tools/Scripts/webkitpy/w3c/deps_updater_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698