Bug 771588: don't PGO asm_enc_offsets.c in libvpx - fix for MSVC2010 r=bsmedberg
[gecko.git] / client.py
blob34684b9dddf6f5f06e9c355c1d7317f09cfdb72e
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 o = OptionParser(usage="client.py [options] update_nspr tagname | update_nss tagname | update_libffi tagname | update_webidlparser tagname")
90 o.add_option("--skip-mozilla", dest="skip_mozilla",
91 action="store_true", default=False,
92 help="Obsolete")
94 o.add_option("--cvs", dest="cvs", default=os.environ.get('CVS', 'cvs'),
95 help="The location of the cvs binary")
96 o.add_option("--cvsroot", dest="cvsroot",
97 help="The CVSROOT (default for mozilla checkouts: %s)" % CVSROOT_MOZILLA)
98 o.add_option("--hg", dest="hg", default=os.environ.get('HG', 'hg'),
99 help="The location of the hg binary")
101 try:
102 options, args = o.parse_args()
103 action = args[0]
104 except IndexError:
105 o.print_help()
106 sys.exit(2)
108 if action in ('checkout', 'co'):
109 print >>sys.stderr, "Warning: client.py checkout is obsolete."
110 pass
111 elif action in ('update_nspr'):
112 tag, = args[1:]
113 if not options.cvsroot:
114 options.cvsroot = os.environ.get('CVSROOT', CVSROOT_MOZILLA)
115 do_cvs_export(NSPR_DIRS, tag, options.cvsroot, options.cvs)
116 print >>file("nsprpub/TAG-INFO", "w"), tag
117 elif action in ('update_nss'):
118 tag, = args[1:]
119 if not options.cvsroot:
120 options.cvsroot = os.environ.get('CVSROOT', CVSROOT_MOZILLA)
121 do_cvs_export(NSS_DIRS, tag, options.cvsroot, options.cvs)
122 print >>file("security/nss/TAG-INFO", "w"), tag
123 print >>file("security/nss/TAG-INFO-CKBI", "w"), tag
124 elif action in ('update_nssckbi'):
125 tag, = args[1:]
126 if not options.cvsroot:
127 options.cvsroot = os.environ.get('CVSROOT', CVSROOT_MOZILLA)
128 do_cvs_export(NSSCKBI_DIRS, tag, options.cvsroot, options.cvs)
129 print >>file("security/nss/TAG-INFO-CKBI", "w"), tag
130 elif action in ('update_libffi'):
131 tag, = args[1:]
132 if not options.cvsroot:
133 options.cvsroot = CVSROOT_LIBFFI
134 do_cvs_export(LIBFFI_DIRS, tag, options.cvsroot, options.cvs)
135 elif action in ('update_webidlparser'):
136 tag, = args[1:]
137 do_hg_replace(WEBIDLPARSER_DIR, WEBIDLPARSER_REPO, tag, WEBIDLPARSER_EXCLUSIONS, options.hg)
138 else:
139 o.print_help()
140 sys.exit(2)