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.
6 """Pull latest revisions of the W3C test repos and update our DEPS entries."""
11 from webkitpy.common import version_check
13 from webkitpy.common.host import Host
14 from webkitpy.common.webkit_finder import WebKitFinder
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')
24 options, args = parser.parse_args()
26 parser.error('%prog does not take any arguments')
29 cmd = CommandRunner(Host(), options)
31 update_repo(cmd, 'web-platform-tests')
32 update_repo(cmd, 'csswg-test')
35 def update_repo(cmd, repo):
36 if cmd.options.verbose:
37 print >>sys.stderr, 'updating %s' % repo
38 print >>sys.stderr, ''
41 if cmd.call(['git', 'diff', '--quiet', 'HEAD']):
42 print >>sys.stderr, "blink checkout is dirty, exiting"
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"
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]
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
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.
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]
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'])
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'])
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', '.'])
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']
100 cmd.run(['git', 'commit', '-m', 'import origin/master@%s using blink@%s%s' %
101 (master_commitish, blink_commitish, no_changes)] + allow_empty)
104 class CommandRunner(object):
105 def __init__(self, host, options):
107 self.executive = host.executive
108 self.fs = host.filesystem
109 self.finder = WebKitFinder(self.fs)
110 self.options = options
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)
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
123 proc = self.executive.popen(cmd, stdout=self.executive.PIPE,
124 stderr=self.executive.PIPE, **args)
125 out, err = proc.communicate()
127 print >> sys.stderr, "'%s' failed:\n%s\%s" % (cmd_str, out, err)
128 sys.exit(proc.returncode)
129 if self.options.verbose:
133 print >>sys.stderr, err
136 def cd(self, *comps):
137 dest = self.path_from_webkit_base(*comps)
138 if self.options.verbose:
142 def path_from_webkit_base(self, *comps):
143 return self.finder.path_from_webkit_base(*comps)
146 if __name__ == '__main__':