Bug 783551 - Get tooltool running on the b2g on OS X builds. r=respindola
[gecko.git] / client.py
blob0d26bbe74385e366a2ab6f273e84187c99770ccf
1 #!/usr/bin/python
2 # This Source Code Form is subject to the terms of the Mozilla Public
3 # License, v. 2.0. If a copy of the MPL was not distributed with this
4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 NSPR_DIRS = (('nsprpub', 'mozilla/nsprpub'),)
8 NSS_DIRS = (('dbm', 'mozilla/dbm'),
9 ('security/nss', 'mozilla/security/nss'),
10 ('security/coreconf', 'mozilla/security/coreconf'),
11 ('security/dbm', 'mozilla/security/dbm'))
12 NSSCKBI_DIRS = (('security/nss/lib/ckfw/builtins', 'mozilla/security/nss/lib/ckfw/builtins'),)
13 LIBFFI_DIRS = (('js/ctypes/libffi', 'libffi'),)
14 WEBIDLPARSER_DIR = 'dom/bindings/parser'
15 WEBIDLPARSER_REPO = 'https://hg.mozilla.org/users/khuey_mozilla.com/webidl-parser'
16 WEBIDLPARSER_EXCLUSIONS = ['.hgignore', '.gitignore', '.hg', 'ply']
18 CVSROOT_MOZILLA = ':pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot'
19 CVSROOT_LIBFFI = ':pserver:anoncvs@sources.redhat.com:/cvs/libffi'
21 import os
22 import sys
23 import datetime
24 import shutil
25 import glob
26 from optparse import OptionParser
27 from subprocess import check_call
29 topsrcdir = os.path.dirname(__file__)
30 if topsrcdir == '':
31 topsrcdir = '.'
33 def check_call_noisy(cmd, *args, **kwargs):
34 print "Executing command:", cmd
35 check_call(cmd, *args, **kwargs)
37 def do_hg_pull(dir, repository, hg):
38 fulldir = os.path.join(topsrcdir, dir)
39 # clone if the dir doesn't exist, pull if it does
40 if not os.path.exists(fulldir):
41 check_call_noisy([hg, 'clone', repository, fulldir])
42 else:
43 cmd = [hg, 'pull', '-u', '-R', fulldir]
44 if repository is not None:
45 cmd.append(repository)
46 check_call_noisy(cmd)
47 check_call([hg, 'parent', '-R', fulldir,
48 '--template=Updated to revision {node}.\n'])
50 def do_hg_replace(dir, repository, tag, exclusions, hg):
51 """
52 Replace the contents of dir with the contents of repository, except for
53 files matching exclusions.
54 """
55 fulldir = os.path.join(topsrcdir, dir)
56 if os.path.exists(fulldir):
57 shutil.rmtree(fulldir)
59 assert not os.path.exists(fulldir)
60 check_call_noisy([hg, 'clone', '-u', tag, repository, fulldir])
62 for thing in exclusions:
63 for excluded in glob.iglob(os.path.join(fulldir, thing)):
64 if os.path.isdir(excluded):
65 shutil.rmtree(excluded)
66 else:
67 os.remove(excluded)
69 def do_cvs_export(modules, tag, cvsroot, cvs):
70 """Check out a CVS directory without CVS metadata, using "export"
71 modules is a list of directories to check out and the corresponding
72 cvs module, e.g. (('nsprpub', 'mozilla/nsprpub'))
73 """
74 for module_tuple in modules:
75 module = module_tuple[0]
76 cvs_module = module_tuple[1]
77 fullpath = os.path.join(topsrcdir, module)
78 if os.path.exists(fullpath):
79 print "Removing '%s'" % fullpath
80 shutil.rmtree(fullpath)
82 (parent, leaf) = os.path.split(module)
83 print "CVS export begin: " + datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC")
84 check_call_noisy([cvs, '-d', cvsroot,
85 'export', '-r', tag, '-d', leaf, cvs_module],
86 cwd=os.path.join(topsrcdir, parent))
87 print "CVS export end: " + datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC")
89 def toggle_trailing_blank_line(depname):
90 """If the trailing line is empty, then we'll delete it.
91 Otherwise we'll add a blank line."""
92 lines = open(depname, "r").readlines()
93 if not lines:
94 print >>sys.stderr, "unexpected short file"
95 return
97 if not lines[-1].strip():
98 # trailing line is blank, removing it
99 open(depname, "w").writelines(lines[:-1])
100 else:
101 # adding blank line
102 open(depname, "a").write("\n")
104 o = OptionParser(usage="client.py [options] update_nspr tagname | update_nss tagname | update_libffi tagname | update_webidlparser tagname")
105 o.add_option("--skip-mozilla", dest="skip_mozilla",
106 action="store_true", default=False,
107 help="Obsolete")
109 o.add_option("--cvs", dest="cvs", default=os.environ.get('CVS', 'cvs'),
110 help="The location of the cvs binary")
111 o.add_option("--cvsroot", dest="cvsroot",
112 help="The CVSROOT (default for mozilla checkouts: %s)" % CVSROOT_MOZILLA)
113 o.add_option("--hg", dest="hg", default=os.environ.get('HG', 'hg'),
114 help="The location of the hg binary")
116 try:
117 options, args = o.parse_args()
118 action = args[0]
119 except IndexError:
120 o.print_help()
121 sys.exit(2)
123 if action in ('checkout', 'co'):
124 print >>sys.stderr, "Warning: client.py checkout is obsolete."
125 pass
126 elif action in ('update_nspr'):
127 tag, = args[1:]
128 if not options.cvsroot:
129 options.cvsroot = os.environ.get('CVSROOT', CVSROOT_MOZILLA)
130 do_cvs_export(NSPR_DIRS, tag, options.cvsroot, options.cvs)
131 print >>file("nsprpub/TAG-INFO", "w"), tag
132 toggle_trailing_blank_line("nsprpub/config/prdepend.h")
133 elif action in ('update_nss'):
134 tag, = args[1:]
135 if not options.cvsroot:
136 options.cvsroot = os.environ.get('CVSROOT', CVSROOT_MOZILLA)
137 do_cvs_export(NSS_DIRS, tag, options.cvsroot, options.cvs)
138 print >>file("security/nss/TAG-INFO", "w"), tag
139 print >>file("security/nss/TAG-INFO-CKBI", "w"), tag
140 toggle_trailing_blank_line("security/coreconf/coreconf.dep")
141 elif action in ('update_nssckbi'):
142 tag, = args[1:]
143 if not options.cvsroot:
144 options.cvsroot = os.environ.get('CVSROOT', CVSROOT_MOZILLA)
145 do_cvs_export(NSSCKBI_DIRS, tag, options.cvsroot, options.cvs)
146 print >>file("security/nss/TAG-INFO-CKBI", "w"), tag
147 elif action in ('update_libffi'):
148 tag, = args[1:]
149 if not options.cvsroot:
150 options.cvsroot = CVSROOT_LIBFFI
151 do_cvs_export(LIBFFI_DIRS, tag, options.cvsroot, options.cvs)
152 elif action in ('update_webidlparser'):
153 tag, = args[1:]
154 do_hg_replace(WEBIDLPARSER_DIR, WEBIDLPARSER_REPO, tag, WEBIDLPARSER_EXCLUSIONS, options.hg)
155 else:
156 o.print_help()
157 sys.exit(2)