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 commits') 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 cmd.cd('') 41 if cmd.call(['git', 'diff', '--quiet', 'HEAD']): 42 print >>sys.stderr, "blink checkout is dirty, exiting" 43 sys.exit(1) 44 45 local_blink_commits = cmd.run(['git', 'log', '--oneline', 'origin/master..HEAD']) 46 if local_blink_commits and not cmd.options.allow_local_blink_commits: 47 print >>sys.stderr, "blink checkout has local commits, exiting" 48 sys.exit(1) 49 50 # Find the Blink rev we are currently sync'ed to, so we can include 51 # it in the commit message. 52 blink_commitish = cmd.run(['git', 'show-ref', 'HEAD']).split()[0] 53 54 # Check to make sure we don't have any local changes to the repo. 55 cmd.cd('LayoutTests', 'w3c', repo) 56 if cmd.call(['git', 'diff', '--quiet', 'HEAD']): 57 print >> sys.stderr, "%s is not clean, exiting" % repo 58 sys.exit(1) 59 60 # Check to make sure that there is something to merge. 61 cmd.run(['git', 'fetch', 'origin']) 62 new_commits = cmd.run(['git', 'log', '--oneline', 'origin/blink..origin/master']) 63 if not new_commits and cmd.options.verbose: 64 print >>sys.stderr, 'No new commits found in %s' % repo 65 # FIXME: We also need to see if there were any changes to 66 # W3CImportExpectations since the last time this ran. 67 return 68 69 # Find the rev we're merging in, so we can include it in the commit message. 70 master_commitish = cmd.run(['git', 'show-ref', 'origin/master']).split()[0] 71 72 # Create a new local branch to track origin/blink. 73 if cmd.run(['git', 'branch', '--list', 'blink']): 74 cmd.run(['git', 'checkout', 'origin/master']) 75 cmd.run(['git', 'branch', '-D', 'blink']) 76 cmd.run(['git', 'checkout', '--track', '-b', 'blink', 'origin/blink']) 77 78 # FIXME: Ideally, at this point we'd record an empty merge commit 79 # so that we have a record in git of doing the merge. However, Gerrit 80 # is refusing to let me push a merge commit back to the repo. 81 # See crbug.com/329096. 82 # cmd.run(['git', 'merge', '--no-commit', '-s', 'ours', 'origin/master']) 83 84 # Actually manually merge in origin/master. 85 cmd.run(['git', 'rm', '-fr', '*']) 86 cmd.run(['git', 'checkout', 'origin/blink', 'README.blink']) 87 cmd.run(['git', 'checkout', 'origin/master', '--', '.']) 88 cmd.run([sys.executable, cmd.path_from_webkit_base('Tools', 'Scripts', 'import-w3c-tests')]) 89 cmd.run(['git', 'add', '--all', '.']) 90 91 # Now commit the changes. 92 # We wouldn't need the --allow-empty flag if we could do merge commits. 93 if not cmd.call(['git', 'diff', '--quiet', 'HEAD']): 94 no_changes = ' (no changes resulted)' 95 allow_empty = ['--allow-empty'] 96 else: 97 no_changes = '' 98 allow_empty = [] 99 100 cmd.run(['git', 'commit', '-m', 'import origin/master@%s using blink@%s%s' % 101 (master_commitish, blink_commitish, no_changes)] + allow_empty) 102 103 104 class CommandRunner(object): 105 def __init__(self, host, options): 106 host = host 107 self.executive = host.executive 108 self.fs = host.filesystem 109 self.finder = WebKitFinder(self.fs) 110 self.options = options 111 112 def call(self, cmd, **args): 113 cmd_str = ' '.join([arg for arg in cmd]) 114 if self.options.verbose: 115 print >>sys.stderr, cmd_str 116 return self.executive.call(cmd) 117 118 def run(self, cmd, **args): 119 cmd_str = ' '.join([arg for arg in cmd]) 120 if self.options.verbose: 121 print >>sys.stderr, cmd_str 122 123 proc = self.executive.popen(cmd, stdout=self.executive.PIPE, 124 stderr=self.executive.PIPE, **args) 125 out, err = proc.communicate() 126 if proc.returncode: 127 print >> sys.stderr, "'%s' failed:\n%s\%s" % (cmd_str, out, err) 128 sys.exit(proc.returncode) 129 if self.options.verbose: 130 if out: 131 print out 132 if err: 133 print >>sys.stderr, err 134 return out 135 136 def cd(self, *comps): 137 dest = self.path_from_webkit_base(*comps) 138 if self.options.verbose: 139 print "cd %s" % dest 140 self.fs.chdir(dest) 141 142 def path_from_webkit_base(self, *comps): 143 return self.finder.path_from_webkit_base(*comps) 144 145 146 if __name__ == '__main__': 147 main() 148