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

Side by Side Diff: tools/roll_pdfium.py

Issue 1289873005: for discussion: add tools/roll_pdfium.py (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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 | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2015 The Chromium Authors. All rights reserved. 2 # Copyright 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import argparse 6 import argparse
7 import collections 7 import collections
8 import logging 8 import logging
9 import os 9 import os
10 import re 10 import re
11 import subprocess 11 import subprocess
12 import sys 12 import sys
13 import time 13 import time
14 14
15 15
16 SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) 16 SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
17 SRC_DIR = os.path.abspath(os.path.join(SCRIPT_DIR, os.pardir)) 17 SRC_DIR = os.path.abspath(os.path.join(SCRIPT_DIR, os.pardir))
18 import find_depot_tools 18 import find_depot_tools
19 find_depot_tools.add_depot_tools_to_path() 19 find_depot_tools.add_depot_tools_to_path()
20 import roll_dep_svn 20 import roll_dep_svn
21 from gclient import GClientKeywords 21 from gclient import GClientKeywords
22 from third_party import upload 22 from third_party import upload
23 23
24 # Avoid depot_tools/third_party/upload.py print verbose messages. 24 # Avoid depot_tools/third_party/upload.py print verbose messages.
25 upload.verbosity = 0 # Errors only. 25 upload.verbosity = 0 # Errors only.
26 26
27 CHROMIUM_GIT_URL = 'https://chromium.googlesource.com/chromium/src.git' 27 CHROMIUM_GIT_URL = 'https://chromium.googlesource.com/chromium/src.git'
28 CL_ISSUE_RE = re.compile('^Issue number: ([0-9]+) \((.*)\)$') 28 CL_ISSUE_RE = re.compile('^Issue number: ([0-9]+) \((.*)\)$')
29 RIETVELD_URL_RE = re.compile('^https?://(.*)/(.*)') 29 RIETVELD_URL_RE = re.compile('^https?://(.*)/(.*)')
30 ROLL_BRANCH_NAME = 'special_angle_roll_branch' 30 ROLL_BRANCH_NAME = 'special_pdfium_roll_branch'
31 TRYJOB_STATUS_SLEEP_SECONDS = 30 31 TRYJOB_STATUS_SLEEP_SECONDS = 30
32 32
33 # Use a shell for subcommands on Windows to get a PATH search. 33 # Use a shell for subcommands on Windows to get a PATH search.
34 IS_WIN = sys.platform.startswith('win') 34 IS_WIN = sys.platform.startswith('win')
35 ANGLE_PATH = os.path.join('third_party', 'angle') 35 PDFIUM_PATH = os.path.join('third_party', 'pdfium')
36 36
37 CommitInfo = collections.namedtuple('CommitInfo', ['git_commit', 37 CommitInfo = collections.namedtuple('CommitInfo', ['git_commit',
38 'git_repo_url']) 38 'git_repo_url'])
39 CLInfo = collections.namedtuple('CLInfo', ['issue', 'url', 'rietveld_server']) 39 CLInfo = collections.namedtuple('CLInfo', ['issue', 'url', 'rietveld_server'])
40 40
41 def _PosixPath(path): 41 def _PosixPath(path):
42 """Convert a possibly-Windows path to a posix-style path.""" 42 """Convert a possibly-Windows path to a posix-style path."""
43 (_, path) = os.path.splitdrive(path) 43 (_, path) = os.path.splitdrive(path)
44 return path.replace(os.sep, '/') 44 return path.replace(os.sep, '/')
45 45
(...skipping 18 matching lines...) Expand all
64 global_scope = { 64 global_scope = {
65 'File': GClientKeywords.FileImpl, 65 'File': GClientKeywords.FileImpl,
66 'From': GClientKeywords.FromImpl, 66 'From': GClientKeywords.FromImpl,
67 'Var': var.Lookup, 67 'Var': var.Lookup,
68 'deps_os': {}, 68 'deps_os': {},
69 } 69 }
70 exec(deps_content, global_scope, local_scope) 70 exec(deps_content, global_scope, local_scope)
71 return local_scope 71 return local_scope
72 72
73 73
74 def _GenerateCLDescriptionCommand(angle_current, angle_new, bugs): 74 def _GenerateCLDescriptionCommand(pdfium_current, pdfium_new, bugs):
75 def GetChangeString(current_hash, new_hash): 75 def GetChangeString(current_hash, new_hash):
76 return '%s..%s' % (current_hash[0:7], new_hash[0:7]); 76 return '%s..%s' % (current_hash[0:7], new_hash[0:7]);
77 77
78 def GetChangeLogURL(git_repo_url, change_string): 78 def GetChangeLogURL(git_repo_url, change_string):
79 return '%s/+log/%s' % (git_repo_url, change_string) 79 return '%s/+log/%s' % (git_repo_url, change_string)
80 80
81 def GetBugString(bugs): 81 def GetBugString(bugs):
82 bug_str = 'BUG=' 82 bug_str = 'BUG='
83 for bug in bugs: 83 for bug in bugs:
84 bug_str += str(bug) + ',' 84 bug_str += str(bug) + ','
85 return bug_str.rstrip(',') 85 return bug_str.rstrip(',')
86 86
87 if angle_current.git_commit != angle_new.git_commit: 87 if pdfium_current.git_commit != pdfium_new.git_commit:
88 change_str = GetChangeString(angle_current.git_commit, 88 change_str = GetChangeString(pdfium_current.git_commit,
89 angle_new.git_commit) 89 pdfium_new.git_commit)
90 changelog_url = GetChangeLogURL(angle_current.git_repo_url, 90 changelog_url = GetChangeLogURL(pdfium_current.git_repo_url,
91 change_str) 91 change_str)
92 92
93 return [ 93 return [
94 '-m', 'Roll ANGLE ' + change_str, 94 '-m', 'Roll PDFium ' + change_str,
95 '-m', '%s' % changelog_url, 95 '-m', '%s' % changelog_url,
96 '-m', GetBugString(bugs), 96 '-m', GetBugString(bugs),
97 '-m', 'TEST=bots', 97 '-m', 'TEST=bots',
98 ] 98 ]
99 99
100 100
101 class AutoRoller(object): 101 class AutoRoller(object):
102 def __init__(self, chromium_src): 102 def __init__(self, chromium_src):
103 self._chromium_src = chromium_src 103 self._chromium_src = chromium_src
104 104
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 166
167 def _IsTreeClean(self): 167 def _IsTreeClean(self):
168 lines = self._RunCommand( 168 lines = self._RunCommand(
169 ['git', 'status', '--porcelain', '-uno']).splitlines() 169 ['git', 'status', '--porcelain', '-uno']).splitlines()
170 if len(lines) == 0: 170 if len(lines) == 0:
171 return True 171 return True
172 172
173 logging.debug('Dirty/unversioned files:\n%s', '\n'.join(lines)) 173 logging.debug('Dirty/unversioned files:\n%s', '\n'.join(lines))
174 return False 174 return False
175 175
176 def _GetBugList(self, path_below_src, angle_current, angle_new): 176 def _GetBugList(self, path_below_src, pdfium_current, pdfium_new):
177 working_dir = os.path.join(self._chromium_src, path_below_src) 177 working_dir = os.path.join(self._chromium_src, path_below_src)
178 lines = self._RunCommand( 178 lines = self._RunCommand(
179 ['git','log', 179 ['git','log',
180 '%s..%s' % (angle_current.git_commit, angle_new.git_commit)], 180 '%s..%s' % (pdfium_current.git_commit, pdfium_new.git_commit)],
181 working_dir=working_dir).split('\n') 181 working_dir=working_dir).split('\n')
182 bugs = set() 182 bugs = set()
183 for line in lines: 183 for line in lines:
184 line = line.strip() 184 line = line.strip()
185 bug_prefix = 'BUG=' 185 bug_prefix = 'BUG='
186 if line.startswith(bug_prefix): 186 if line.startswith(bug_prefix):
187 bugs_strings = line[len(bug_prefix):].split(',') 187 bugs_strings = line[len(bug_prefix):].split(',')
188 for bug_string in bugs_strings: 188 for bug_string in bugs_strings:
189 try: 189 try:
190 bugs.add(int(bug_string)) 190 bugs.add(int(bug_string))
191 except: 191 except:
192 # skip this, it may be a project specific bug such as 192 # skip this, it may be a project specific bug such as
193 # "angleproject:X" or an ill-formed BUG= message 193 # "pdfium:X" or an ill-formed BUG= message
194 pass 194 pass
195 return bugs 195 return bugs
196 196
197 def _UpdateReadmeFile(self, readme_path, new_revision): 197 def _UpdateReadmeFile(self, readme_path, new_revision):
198 readme = open(os.path.join(self._chromium_src, readme_path), 'r+') 198 readme = open(os.path.join(self._chromium_src, readme_path), 'r+')
199 txt = readme.read() 199 txt = readme.read()
200 m = re.sub(re.compile('.*^Revision\: ([0-9]*).*', re.MULTILINE), 200 m = re.sub(re.compile('.*^Revision\: ([0-9]*).*', re.MULTILINE),
201 ('Revision: %s' % new_revision), txt) 201 ('Revision: %s' % new_revision), txt)
202 readme.seek(0) 202 readme.seek(0)
203 readme.write(m) 203 readme.write(m)
(...skipping 18 matching lines...) Expand all
222 if not ignore_checks: 222 if not ignore_checks:
223 self._RunCommand(['git', 'pull']) 223 self._RunCommand(['git', 'pull'])
224 224
225 self._RunCommand(['git', 'checkout', '-b', ROLL_BRANCH_NAME]) 225 self._RunCommand(['git', 'checkout', '-b', ROLL_BRANCH_NAME])
226 226
227 # Modify Chromium's DEPS file. 227 # Modify Chromium's DEPS file.
228 228
229 # Parse current hashes. 229 # Parse current hashes.
230 deps_filename = os.path.join(self._chromium_src, 'DEPS') 230 deps_filename = os.path.join(self._chromium_src, 'DEPS')
231 deps = _ParseDepsFile(deps_filename) 231 deps = _ParseDepsFile(deps_filename)
232 angle_current = self._GetDepsCommitInfo(deps, ANGLE_PATH) 232 pdfium_current = self._GetDepsCommitInfo(deps, PDFIUM_PATH)
233 233
234 # Find ToT revisions. 234 # Find ToT revisions.
235 angle_latest = self._GetCommitInfo(ANGLE_PATH) 235 pdfium_latest = self._GetCommitInfo(PDFIUM_PATH)
236 236
237 if IS_WIN: 237 if IS_WIN:
238 # Make sure the roll script doesn't use windows line endings 238 # Make sure the roll script doesn't use windows line endings
239 self._RunCommand(['git', 'config', 'core.autocrlf', 'true']) 239 self._RunCommand(['git', 'config', 'core.autocrlf', 'true'])
240 240
241 self._UpdateDep(deps_filename, ANGLE_PATH, angle_latest) 241 self._UpdateDep(deps_filename, PDFIUM_PATH, pdfium_latest)
242 242
243 if self._IsTreeClean(): 243 if self._IsTreeClean():
244 logging.debug('Tree is clean - no changes detected.') 244 logging.debug('Tree is clean - no changes detected.')
245 self._DeleteRollBranch() 245 self._DeleteRollBranch()
246 else: 246 else:
247 bugs = self._GetBugList(ANGLE_PATH, angle_current, angle_latest) 247 bugs = self._GetBugList(PDFIUM_PATH, pdfium_current, pdfium_latest)
248 description = _GenerateCLDescriptionCommand( 248 description = _GenerateCLDescriptionCommand(
249 angle_current, angle_latest, bugs) 249 pdfium_current, pdfium_latest, bugs)
250 logging.debug('Committing changes locally.') 250 logging.debug('Committing changes locally.')
251 self._RunCommand(['git', 'add', '--update', '.']) 251 self._RunCommand(['git', 'add', '--update', '.'])
252 self._RunCommand(['git', 'commit'] + description) 252 self._RunCommand(['git', 'commit'] + description)
253 logging.debug('Uploading changes...') 253 logging.debug('Uploading changes...')
254 self._RunCommand(['git', 'cl', 'upload'], 254 self._RunCommand(['git', 'cl', 'upload'],
255 extra_env={'EDITOR': 'true'}) 255 extra_env={'EDITOR': 'true'})
256 self._RunCommand(['git', 'cl', 'try']) 256 self._RunCommand(['git', 'cl', 'try'])
257 cl_info = self._GetCLInfo() 257 cl_info = self._GetCLInfo()
258 print 'Issue: %d URL: %s' % (cl_info.issue, cl_info.url) 258 print 'Issue: %d URL: %s' % (cl_info.issue, cl_info.url)
259 259
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 self._RunCommand(['git', 'checkout', ROLL_BRANCH_NAME]) 308 self._RunCommand(['git', 'checkout', ROLL_BRANCH_NAME])
309 # Ignore an error here in case an issue wasn't created for some reason. 309 # Ignore an error here in case an issue wasn't created for some reason.
310 self._RunCommand(['git', 'cl', 'set_close'], ignore_exit_code=True) 310 self._RunCommand(['git', 'cl', 'set_close'], ignore_exit_code=True)
311 self._RunCommand(['git', 'checkout', active_branch]) 311 self._RunCommand(['git', 'checkout', active_branch])
312 self._RunCommand(['git', 'branch', '-D', ROLL_BRANCH_NAME]) 312 self._RunCommand(['git', 'branch', '-D', ROLL_BRANCH_NAME])
313 return 0 313 return 0
314 314
315 315
316 def main(): 316 def main():
317 parser = argparse.ArgumentParser( 317 parser = argparse.ArgumentParser(
318 description='Auto-generates a CL containing an ANGLE roll.') 318 description='Auto-generates a CL containing an PDFium roll.')
319 parser.add_argument('--abort', 319 parser.add_argument('--abort',
320 help=('Aborts a previously prepared roll. ' 320 help=('Aborts a previously prepared roll. '
321 'Closes any associated issues and deletes the roll branches'), 321 'Closes any associated issues and deletes the roll branches'),
322 action='store_true') 322 action='store_true')
323 parser.add_argument('--ignore-checks', action='store_true', default=False, 323 parser.add_argument('--ignore-checks', action='store_true', default=False,
324 help=('Skips checks for being on the master branch, dirty workspaces and ' 324 help=('Skips checks for being on the master branch, dirty workspaces and '
325 'the updating of the checkout. Will still delete and create local ' 325 'the updating of the checkout. Will still delete and create local '
326 'Git branches.')) 326 'Git branches.'))
327 parser.add_argument('-v', '--verbose', action='store_true', default=False, 327 parser.add_argument('-v', '--verbose', action='store_true', default=False,
328 help='Be extra verbose in printing of log messages.') 328 help='Be extra verbose in printing of log messages.')
329 args = parser.parse_args() 329 args = parser.parse_args()
330 330
331 if args.verbose: 331 if args.verbose:
332 logging.basicConfig(level=logging.DEBUG) 332 logging.basicConfig(level=logging.DEBUG)
333 else: 333 else:
334 logging.basicConfig(level=logging.ERROR) 334 logging.basicConfig(level=logging.ERROR)
335 335
336 autoroller = AutoRoller(SRC_DIR) 336 autoroller = AutoRoller(SRC_DIR)
337 if args.abort: 337 if args.abort:
338 return autoroller.Abort() 338 return autoroller.Abort()
339 else: 339 else:
340 return autoroller.PrepareRoll(args.ignore_checks) 340 return autoroller.PrepareRoll(args.ignore_checks)
341 341
342 if __name__ == '__main__': 342 if __name__ == '__main__':
343 sys.exit(main()) 343 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698