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

Side by Side Diff: nacl_deps_bump_cronjob.py

Issue 872813004: Switching nacl_deps_bump to git. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/parasite/
Patch Set: Created 5 years, 10 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 | Annotate | Revision Log
« nacl_deps_bump.py ('K') | « nacl_deps_bump.py ('k') | 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 (c) 2012 The Native Client Authors. All rights reserved. 2 # Copyright (c) 2012 The Native Client 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 """ 6 """
7 This tool is a wrapper around nacl_deps_bump.py that is intended to be 7 This tool is a wrapper around nacl_deps_bump.py that is intended to be
8 run from a cron job. 8 run from a cron job.
9 9
10 This tool kicks off try jobs for updating nacl_revision in Chromium's 10 This tool kicks off try jobs for updating nacl_revision in Chromium's
11 DEPS file. To reduce load on the try servers, it kicks off a new try 11 DEPS file. To reduce load on the try servers, it kicks off a new try
12 job when a sufficient number of new NaCl revisions have appeared, or a 12 job when a sufficient number of new NaCl revisions have appeared, or a
13 sufficient time has elapsed, since its last try job. 13 sufficient time has elapsed, since its last try job.
14 14
15 Like nacl_deps_bump.py, this tool should be run from a Git checkout of 15 Like nacl_deps_bump.py, this tool should be run from a Git checkout of
16 Chromium. 16 Chromium.
17 """ 17 """
18 18
19 import optparse 19 import optparse
20 import re 20 import re
21 import subprocess 21 import subprocess
22 import time 22 import time
23 23
24 import pysvn
25
26 import nacl_deps_bump 24 import nacl_deps_bump
27 25
28 26
29 # When this number of new revisions accumulates, we kick off a new build. 27 # When this number of new revisions accumulates, we kick off a new build.
30 REVS_THRESHOLD = 10 28 REVS_THRESHOLD = 10
31 29
32 # When the last revision is this old, we kick off a new build. 30 # When the last revision is this old, we kick off a new build.
33 TIME_THRESHOLD = 60 * 60 * 12 # 12 hours 31 TIME_THRESHOLD = 60 * 60 * 12 # 12 hours
34 32
35 33
36 # Returns a list of NaCl SVN revision numbers that we have already 34 # Returns a list of NaCl SVN revision numbers that we have already
37 # kicked off try jobs for. This is based on the branch names in the 35 # kicked off try jobs for. This is based on the branch names in the
38 # current Git repo. This is imperfect because we might have created a 36 # current Git repo. This is imperfect because we might have created a
39 # branch before but failed to send a try job for it. We err on the 37 # branch before but failed to send a try job for it. We err on the
40 # side of not spamming the trybots. 38 # side of not spamming the trybots.
41 def GetExistingJobs(): 39 def GetExistingJobs():
42 proc = subprocess.Popen(['git', 'for-each-ref', 40 proc = subprocess.Popen(['git', 'for-each-ref',
43 '--format', '%(refname:short)', 41 '--format', '%(refname:short)',
44 'refs/heads/*'], stdout=subprocess.PIPE) 42 'refs/heads/*'], stdout=subprocess.PIPE)
45 revs = [] 43 revs = []
46 for line in proc.stdout: 44 for line in proc.stdout:
47 match = re.match('nacl-deps-r(\d+)$', line.strip()) 45 match = re.match('nacl-deps-(.*)$', line.strip())
48 if match is not None: 46 if match is not None:
49 revs.append(int(match.group(1))) 47 revs.append(match.group(1))
50 assert proc.wait() == 0, proc.wait() 48 assert proc.wait() == 0, proc.wait()
51 return revs 49 return revs
52 50
53 51
54 # Returns the time that the given SVN revision was committed, as a 52 # Returns the time that the given GIT revision was committed, as a
Mark Seaborn 2015/01/28 16:34:21 "Git"
bradn 2015/01/28 17:37:33 Done.
55 # Unix timestamp. 53 # Unix timestamp.
56 def GetRevTime(svn_root, rev_num): 54 def GetRevTime(git_dir, rev):
57 rev = pysvn.Revision(pysvn.opt_revision_kind.number, rev_num) 55 return int(subprocess.check_output(
58 rev_info_list = pysvn.Client().log(svn_root, 56 ['git', 'log', '--pretty=format:%ct', '-n1', rev], cwd=git_dir))
59 revision_start=rev, revision_end=rev)
60 assert len(rev_info_list) == 1, rev_info_list
61 return rev_info_list[0].date
62 57
63 58
64 def Main(): 59 def Main():
60 nacl_git_dir = nacl_deps_bump.NACL_GIT_ROOT
61
65 parser = optparse.OptionParser('%prog\n\n' + __doc__.strip()) 62 parser = optparse.OptionParser('%prog\n\n' + __doc__.strip())
66 options, args = parser.parse_args() 63 options, args = parser.parse_args()
67 if len(args) != 0: 64 if len(args) != 0:
68 parser.error('Got unexpected arguments') 65 parser.error('Got unexpected arguments')
69 66
70 do_build = False 67 do_build = False
71 68
72 last_tried_rev = max([1] + GetExistingJobs()) 69 last_tried_time, last_tried_rev = max(
73 print 'Last tried NaCl revision is r%i' % last_tried_rev 70 [(1, '')] +
74 age = time.time() - GetRevTime(nacl_deps_bump.NACL_SVN_ROOT, last_tried_rev) 71 [(GetRevTime(nacl_git_dir, i), i) for i in GetExistingJobs()])
Mark Seaborn 2015/01/28 16:34:21 "i" -> "rev"
bradn 2015/01/28 17:37:33 Done.
75 print 'Age of r%i is %.1f hours' % (last_tried_rev, age / (60 * 60)) 72 print 'Last tried NaCl revision is %s' % last_tried_rev
73 age = time.time() - last_tried_time
74 print 'Age of %s is %.1f hours' % (last_tried_rev, age / (60 * 60))
76 if age > TIME_THRESHOLD: 75 if age > TIME_THRESHOLD:
77 print 'Time threshold passed: trigger new build' 76 print 'Time threshold passed: trigger new build'
78 do_build = True 77 do_build = True
79 else: 78 else:
80 print 'Time threshold not passed' 79 print 'Time threshold not passed'
81 80
82 newest_rev = nacl_deps_bump.GetNaClRev() 81 newest_rev = nacl_deps_bump.GetNaClRev(nacl_git_dir)
83 rev_diff = newest_rev - last_tried_rev 82 rev_diff = len(nacl_deps_bump.GetLog(
83 nacl_git_dir, last_tried_rev, newest_rev)) - 1
Mark Seaborn 2015/01/28 16:34:21 I don't think the "- 1" is right. Remove that?
bradn 2015/01/28 17:37:33 Ah, you're correct, didn't actually check the beha
84 print 'There have been %i NaCl revisions since our last try job' % rev_diff 84 print 'There have been %i NaCl revisions since our last try job' % rev_diff
85 # Note that this comparison ignores that the commits might be to 85 # Note that this comparison ignores that the commits might be to
86 # branches rather the trunk. 86 # branches rather the trunk.
87 if rev_diff > REVS_THRESHOLD: 87 if rev_diff > REVS_THRESHOLD:
88 print 'Revision count threshold passed: trigger new build' 88 print 'Revision count threshold passed: trigger new build'
89 do_build = True 89 do_build = True
90 else: 90 else:
91 print 'Revision count threshold not passed' 91 print 'Revision count threshold not passed'
92 92
93 if do_build: 93 if do_build:
94 print 'Running nacl_deps_bump' 94 print 'Running nacl_deps_bump'
95 nacl_deps_bump.Main(['--revision', str(newest_rev)]) 95 nacl_deps_bump.Main(['--revision', str(newest_rev)])
96 else: 96 else:
97 print 'Not running nacl_deps_bump' 97 print 'Not running nacl_deps_bump'
98 98
99 99
100 if __name__ == '__main__': 100 if __name__ == '__main__':
101 Main() 101 Main()
OLDNEW
« nacl_deps_bump.py ('K') | « nacl_deps_bump.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698