OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 |
| 6 """Pull latest revisions of the W3C test repos and update our DEPS entries.""" |
| 7 import optparse |
| 8 import subprocess |
| 9 import sys |
| 10 |
| 11 from webkitpy.common import version_check |
| 12 |
| 13 from webkitpy.common.host import Host |
| 14 from webkitpy.common.webkit_finder import WebKitFinder |
| 15 |
| 16 def main(): |
| 17 parser = optparse.OptionParser() |
| 18 parser.description = __doc__ |
| 19 parser.add_option('-v', '--verbose', action='store_true', |
| 20 help='log what we are doing') |
| 21 parser.add_option('--allow-local-blink-commits', action='store_true', |
| 22 help='allow script to run even if we have local blink comm
its') |
| 23 |
| 24 options, args = parser.parse_args() |
| 25 if args: |
| 26 parser.error('%prog does not take any arguments') |
| 27 sys.exit(1) |
| 28 |
| 29 cmd = CommandRunner(Host(), options) |
| 30 |
| 31 update_repo(cmd, 'web-platform-tests') |
| 32 update_repo(cmd, 'csswg-test') |
| 33 |
| 34 |
| 35 def update_repo(cmd, repo): |
| 36 if cmd.options.verbose: |
| 37 print >>sys.stderr, 'updating %s' % repo |
| 38 print >>sys.stderr, '' |
| 39 |
| 40 if cmd.call(['git', 'diff', '--quiet', 'HEAD']): |
| 41 print >>sys.stderr, "blink checkout is dirty, exiting" |
| 42 sys.exit(1) |
| 43 |
| 44 local_blink_commits = cmd.run(['git', 'log', '--oneline', 'origin/master..HE
AD']) |
| 45 if local_blink_commits and not cmd.options.allow_local_blink_commits: |
| 46 print >>sys.stderr, "blink checkout has local commits, exiting" |
| 47 sys.exit(1) |
| 48 |
| 49 # Find the Blink rev we are currently sync'ed to, so we can include |
| 50 # it in the commit message. |
| 51 blink_commitish = cmd.run(['git', 'show-ref', 'HEAD']).split()[0] |
| 52 |
| 53 # Check to make sure we don't have any local changes to the repo. |
| 54 cmd.cd('LayoutTests', 'w3c', repo) |
| 55 if cmd.call(['git', 'diff', '--quiet', 'HEAD']): |
| 56 print >> sys.stderr, "%s is not clean, exiting" % repo |
| 57 sys.exit(1) |
| 58 |
| 59 # Check to make sure that there is something to merge. |
| 60 cmd.run(['git', 'fetch', 'origin']) |
| 61 new_commits = cmd.run(['git', 'log', '--oneline', 'origin/blink..origin/mast
er']) |
| 62 if not new_commits and cmd.options.verbose: |
| 63 print >>sys.stderr, 'No new commits found in %s' % repo |
| 64 # FIXME: We also need to see if there were any changes to |
| 65 # W3CImportExpectations since the last time this ran. |
| 66 return |
| 67 |
| 68 # Find the rev we're merging in, so we can include it in the commit message. |
| 69 master_commitish = cmd.run(['git', 'show-ref', 'origin/master']).split()[0] |
| 70 |
| 71 # Create a new local branch to track origin/blink. |
| 72 if cmd.run(['git', 'branch', '--list', 'blink']): |
| 73 cmd.run(['git', 'checkout', 'origin/master']) |
| 74 cmd.run(['git', 'branch', '-D', 'blink']) |
| 75 cmd.run(['git', 'checkout', '--track', '-b', 'blink', 'origin/blink']) |
| 76 |
| 77 # FIXME: Ideally, at this point we'd record an empty merge commit |
| 78 # so that we have a record in git of doing the merge. However, Gerrit |
| 79 # is refusing to let me push a merge commit back to the repo. |
| 80 # See crbug.com/329096. |
| 81 # cmd.run(['git', 'merge', '--no-commit', '-s', 'ours', 'origin/master']) |
| 82 |
| 83 # Actually manually merge in origin/master. |
| 84 cmd.run(['git', 'rm', '-fr', '*']) |
| 85 cmd.run(['git', 'checkout', 'origin/blink', 'README.blink']) |
| 86 cmd.run(['git', 'checkout', 'origin/master', '--', '.']) |
| 87 cmd.run([sys.executable, cmd.path_from_webkit_base('Tools', 'Scripts', 'impo
rt-w3c-tests')]) |
| 88 cmd.run(['git', 'add', '--all', '.']) |
| 89 |
| 90 # Now commit the changes. |
| 91 # We wouldn't need the --allow-empty flag if we could do merge commits. |
| 92 if not cmd.call(['git', 'diff', '--quiet', 'HEAD']): |
| 93 no_changes = ' (no changes resulted)' |
| 94 allow_empty = ['--allow-empty'] |
| 95 else: |
| 96 no_changes = '' |
| 97 allow_empty = [] |
| 98 |
| 99 cmd.run(['git', 'commit', '-m', 'import origin/master@%s using blink@%s%s' % |
| 100 (master_commitish, blink_commitish, no_changes)] + allow_empty) |
| 101 |
| 102 |
| 103 class CommandRunner(object): |
| 104 def __init__(self, host, options): |
| 105 host = host |
| 106 self.executive = host.executive |
| 107 self.fs = host.filesystem |
| 108 self.finder = WebKitFinder(self.fs) |
| 109 self.options = options |
| 110 |
| 111 def call(self, cmd, **args): |
| 112 cmd_str = ' '.join([arg for arg in cmd]) |
| 113 if self.options.verbose: |
| 114 print >>sys.stderr, cmd_str |
| 115 return self.executive.call(cmd) |
| 116 |
| 117 def run(self, cmd, **args): |
| 118 cmd_str = ' '.join([arg for arg in cmd]) |
| 119 if self.options.verbose: |
| 120 print >>sys.stderr, cmd_str |
| 121 |
| 122 proc = self.executive.popen(cmd, stdout=self.executive.PIPE, |
| 123 stderr=self.executive.PIPE, **args) |
| 124 out, err = proc.communicate() |
| 125 if proc.returncode: |
| 126 print >> sys.stderr, "'%s' failed:\n%s\%s" % (cmd_str, out, err) |
| 127 sys.exit(proc.returncode) |
| 128 if self.options.verbose: |
| 129 if out: |
| 130 print out |
| 131 if err: |
| 132 print >>sys.stderr, err |
| 133 return out |
| 134 |
| 135 def cd(self, *comps): |
| 136 dest = self.path_from_webkit_base(*comps) |
| 137 if self.options.verbose: |
| 138 print "cd %s" % dest |
| 139 self.fs.chdir(dest) |
| 140 |
| 141 def path_from_webkit_base(self, *comps): |
| 142 return self.finder.path_from_webkit_base(*comps) |
| 143 |
| 144 |
| 145 if __name__ == '__main__': |
| 146 main() |
OLD | NEW |