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
3 # found in the LICENSE file.
5 """Pull latest revisions of the W3C test repos and update our DEPS entries."""
10 from webkitpy.common.webkit_finder import WebKitFinder
13 class DepsUpdater(object):
14 def __init__(self, host):
16 self.executive = host.executive
17 self.fs = host.filesystem
18 self.finder = WebKitFinder(self.fs)
20 self.allow_local_blink_commits = False
21 self.keep_w3c_repos_around = False
23 def main(self, argv=None):
27 if not self.checkout_is_okay():
30 self.print_('## noting the current Blink commitish')
31 blink_commitish = self.run(['git', 'show-ref', 'HEAD'])[1].split()[0]
33 wpt_import_text = self.update('web-platform-tests',
34 'https://chromium.googlesource.com/external/w3c/web-platform-tests.git')
36 css_import_text = self.update('csswg-test',
37 'https://chromium.googlesource.com/external/w3c/csswg-test.git')
39 self.commit_changes_if_needed(blink_commitish, css_import_text, wpt_import_text)
43 def parse_args(self, argv):
44 parser = argparse.ArgumentParser()
45 parser.description = __doc__
46 parser.add_argument('-v', '--verbose', action='store_true',
47 help='log what we are doing')
48 parser.add_argument('--allow-local-blink-commits', action='store_true',
49 help='allow script to run even if we have local blink commits')
50 parser.add_argument('--keep-w3c-repos-around', action='store_true',
51 help='leave the w3c repos around that were imported previously.')
53 args = parser.parse_args(argv)
54 self.allow_local_blink_commits = args.allow_local_blink_commits
55 self.keep_w3c_repos_around = args.keep_w3c_repos_around
56 self.verbose = args.verbose
58 def checkout_is_okay(self):
59 if self.run(['git', 'diff', '--quiet', 'HEAD'], exit_on_failure=False)[0]:
60 self.print_('## blink checkout is dirty, aborting')
63 local_blink_commits = self.run(['git', 'log', '--oneline', 'origin/master..HEAD'])[1]
64 if local_blink_commits and not self.allow_local_blink_commits:
65 self.print_('## blink checkout has local commits, aborting')
68 if self.fs.exists(self.path_from_webkit_base('web-platform-tests')):
69 self.print_('## web-platform-tests repo exists, aborting')
72 if self.fs.exists(self.path_from_webkit_base('csswg-test')):
73 self.print_('## csswg-test repo exists, aborting')
78 def update(self, repo, url):
79 self.print_('## cloning %s' % repo)
81 self.run(['git', 'clone', url])
83 self.print_('## noting the revision we are importing')
84 master_commitish = self.run(['git', 'show-ref', 'origin/master'])[1].split()[0]
86 self.print_('## cleaning out tests from LayoutTests/imported/%s' % repo)
87 dest_repo = self.path_from_webkit_base('LayoutTests', 'imported', repo)
88 files_to_delete = self.fs.files_under(dest_repo, file_filter=self.is_not_baseline)
89 for subpath in files_to_delete:
90 self.remove('LayoutTests', 'imported', subpath)
92 self.print_('## importing the tests')
93 src_repo = self.path_from_webkit_base(repo)
94 import_path = self.path_from_webkit_base('Tools', 'Scripts', 'import-w3c-tests')
95 self.run([self.host.executable, import_path, '-d', 'imported', src_repo])
98 self.run(['git', 'add', '--all', 'LayoutTests/imported/%s' % repo])
100 self.print_('## deleting any orphaned baselines')
101 previous_baselines = self.fs.files_under(dest_repo, file_filter=self.is_baseline)
102 for subpath in previous_baselines:
103 full_path = self.fs.join(dest_repo, subpath)
104 if self.fs.glob(full_path.replace('-expected.txt', '*')) == [full_path]:
105 self.fs.remove(full_path)
107 if not self.keep_w3c_repos_around:
108 self.print_('## deleting %s repo' % repo)
112 return 'imported %s@%s' % (repo, master_commitish)
114 def commit_changes_if_needed(self, blink_commitish, css_import_text, wpt_import_text):
115 if self.run(['git', 'diff', '--quiet', 'HEAD'], exit_on_failure=False)[0]:
116 self.print_('## commiting changes')
117 commit_msg = ('update-w3c-deps import using blink %s:\n'
120 '%s\n' % (blink_commitish, css_import_text, wpt_import_text))
121 path_to_commit_msg = self.path_from_webkit_base('commit_msg')
123 self.print_('cat > %s <<EOF' % path_to_commit_msg)
124 self.print_(commit_msg)
126 self.fs.write_text_file(path_to_commit_msg, commit_msg)
127 self.run(['git', 'commit', '-a', '-F', path_to_commit_msg])
128 self.remove(path_to_commit_msg)
129 self.print_('## Done: changes imported and committed')
131 self.print_('## Done: no changes to import')
133 def is_baseline(self, fs, dirname, basename):
134 return basename.endswith('-expected.txt')
136 def is_not_baseline(self, fs, dirname, basename):
137 return not self.is_baseline(fs, dirname, basename)
139 def run(self, cmd, exit_on_failure=True):
141 self.print_(' '.join(cmd))
143 proc = self.executive.popen(cmd, stdout=self.executive.PIPE, stderr=self.executive.PIPE)
144 out, err = proc.communicate()
145 if proc.returncode or self.verbose:
146 self.print_('# ret> %d' % proc.returncode)
148 for line in out.splitlines():
149 self.print_('# out> %s' % line)
151 for line in err.splitlines():
152 self.print_('# err> %s' % line)
153 if exit_on_failure and proc.returncode:
154 self.host.exit(proc.returncode)
155 return proc.returncode, out
157 def cd(self, *comps):
158 dest = self.path_from_webkit_base(*comps)
160 self.print_('cd %s' % dest)
163 def remove(self, *comps):
164 dest = self.path_from_webkit_base(*comps)
166 self.print_('rm %s' % dest)
169 def rmtree(self, *comps):
170 dest = self.path_from_webkit_base(*comps)
172 self.print_('rm -fr %s' % dest)
175 def path_from_webkit_base(self, *comps):
176 return self.finder.path_from_webkit_base(*comps)
178 def print_(self, msg):
179 self.host.print_(msg)