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

Side by Side Diff: tools/update_ddc_dep.py

Issue 2200973002: Script to automate keeping ddc dep in sync. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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
(Empty)
1 #!/usr/bin/python
2
3 # Update ddc dep automatically.
4
5 import optparse
6 import os
7 import re
8 from subprocess import Popen, PIPE
9 import sys
10
11 # Instructions:
12 #
13 # To run locally:
14 # (a) Create and change to a directory to run the updater in:
15 # mkdir /usr/local/google/home/$USER/ddc_deps_updater
16 #
17 # (b) Test by running (Ctrl-C to quit):
18 # > ./update_ddc_deps.py
19 #
20 # (c) Run periodical update:
21 # > while true; do ./update_ddc_deps.py --force ; sleep 300 ; done
22
23 ########################################################################
24 # Actions
25 ########################################################################
26
27 def write_file(filename, content):
28 f = open(filename, "w")
29 f.write(content)
30 f.close()
31
32 def run_cmd(cmd):
33 print "\n[%s]\n$ %s" % (os.getcwd(), " ".join(cmd))
34 pipe = Popen(cmd, stdout=PIPE, stderr=PIPE)
35 output = pipe.communicate()
36 if pipe.returncode == 0:
37 return output[0]
38 else:
39 print output[1]
40 print "FAILED. RET_CODE=%d" % pipe.returncode
41 sys.exit(pipe.returncode)
42
43 def main():
44 option_parser = optparse.OptionParser()
45 option_parser.add_option(
46 '',
47 '--force',
48 help="Push DEPS update to server without prompting",
49 action="store_true",
50 dest="force")
51 options, args = option_parser.parse_args()
52
53 target = 'ddc'
54 repo = 'dev_compiler'
55 repo_name = 'git@github.com:dart-lang/sdk.git'
56 ddc_repo_name = 'git@github.com:dart-lang/%s.git' % (repo)
57 repo_branch = 'origin/master'
58 repo_branch_parts = repo_branch.split('/')
59
60 root_dir = "/usr/local/google/home/%s/ddc_deps_updater" % (os.environ["USER"])
61 src_dir = "%s/sdk" % (root_dir)
62 ddc_dir = "%s/%s" % (root_dir, repo)
63 deps_file = src_dir + '/DEPS'
64
65 os.putenv("GIT_PAGER", "")
66
67 if not os.path.exists(src_dir):
68 print run_cmd(['git', 'clone', repo_name])
69
70 if not os.path.exists(ddc_dir):
71 print run_cmd(['git', 'clone', ddc_repo_name])
72
73 os.chdir(ddc_dir)
74 run_cmd(['git', 'fetch'])
75
76 os.chdir(src_dir)
77 run_cmd(['git', 'fetch'])
78 run_cmd(['git', 'stash'])
79 run_cmd(['git', 'checkout', '-B', repo_branch_parts[1], repo_branch])
80
81 # parse DEPS
82 deps = run_cmd(['cat', deps_file])
83 rev_num = {}
84 revision = '%s_rev":\s*"@(.+)"' % (repo)
85 rev_num = re.search(revision, deps).group(1)
86
87 # update repos
88 all_revs = []
89 os.chdir(ddc_dir)
90
91 output = run_cmd(["git", "log", "--pretty=%H", "%s..HEAD" % (rev_num),
92 "origin/master"])
93 commits = output.split('\n')
94 if not commits or len(commits[0]) < 10:
95 print "DEPS is up-to-date."
96 sys.exit(0)
97
98 revision = commits[0]
99
100 history = run_cmd(["git", "log", "--format=short", "%s..HEAD" % (rev_num),
101 "origin/master"])
102
103 print "Pending DEPS update: %s" % (revision)
104
105 # make the next DEPS update
106 os.chdir(src_dir)
107 run_cmd(['rm', deps_file])
108
109 pattern = re.compile('%s_rev":\s*"@(.+)"' % (repo))
110 new_deps = pattern.sub('%s_rev": "@%s"' % (repo, revision), deps)
111 write_file(deps_file, new_deps)
112
113 commit_log = 'DEPS AutoUpdate: %s\n\n' % (repo)
114 commit_log += history
115
116 write_file('commit_log.txt', commit_log)
117 run_cmd(['git', 'add', deps_file])
118
119 print run_cmd(['git', 'diff', 'HEAD'])
120 print
121 print "Commit log:"
122 print "---------------------------------------------"
123 print commit_log
124 print "---------------------------------------------"
125
126 if not options.force:
127 print "Ready to push; press Enter to continue or Control-C to abort..."
128 sys.stdin.readline()
129 print run_cmd(['git', 'commit', '-F', 'commit_log.txt'])
130 print run_cmd(['git', 'push', repo_branch_parts[0], repo_branch_parts[1]])
131 print "Done."
132
133
134 if '__main__' == __name__:
135 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