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 LIBFFI_DIRS
= (('js/ctypes/libffi', 'libffi'),)
8 WEBIDLPARSER_DIR
= 'dom/bindings/parser'
9 WEBIDLPARSER_REPO
= 'https://hg.mozilla.org/users/khuey_mozilla.com/webidl-parser'
10 HG_EXCLUSIONS
= ['.hg', '.hgignore', '.hgtags']
11 WEBIDLPARSER_EXCLUSIONS
= HG_EXCLUSIONS
+ ['.gitignore', 'ply']
13 CVSROOT_LIBFFI
= ':pserver:anoncvs@sources.redhat.com:/cvs/libffi'
20 from optparse
import OptionParser
21 from subprocess
import check_call
23 topsrcdir
= os
.path
.dirname(__file__
)
27 def check_call_noisy(cmd
, *args
, **kwargs
):
28 print "Executing command:", cmd
29 check_call(cmd
, *args
, **kwargs
)
31 def do_hg_pull(dir, repository
, hg
):
32 fulldir
= os
.path
.join(topsrcdir
, dir)
33 # clone if the dir doesn't exist, pull if it does
34 if not os
.path
.exists(fulldir
):
35 check_call_noisy([hg
, 'clone', repository
, fulldir
])
37 cmd
= [hg
, 'pull', '-u', '-R', fulldir
]
38 if repository
is not None:
39 cmd
.append(repository
)
41 check_call([hg
, 'parent', '-R', fulldir
,
42 '--template=Updated to revision {node}.\n'])
44 def do_hg_replace(dir, repository
, tag
, exclusions
, hg
):
46 Replace the contents of dir with the contents of repository, except for
47 files matching exclusions.
49 fulldir
= os
.path
.join(topsrcdir
, dir)
50 if os
.path
.exists(fulldir
):
51 shutil
.rmtree(fulldir
)
53 assert not os
.path
.exists(fulldir
)
54 check_call_noisy([hg
, 'clone', '-u', tag
, repository
, fulldir
])
56 for thing
in exclusions
:
57 for excluded
in glob
.iglob(os
.path
.join(fulldir
, thing
)):
58 if os
.path
.isdir(excluded
):
59 shutil
.rmtree(excluded
)
63 def do_cvs_export(modules
, tag
, cvsroot
, cvs
):
64 """Check out a CVS directory without CVS metadata, using "export"
65 modules is a list of directories to check out and the corresponding
66 cvs module, e.g. (('js/ctypes/libffi', 'libffi'),)
68 for module_tuple
in modules
:
69 module
= module_tuple
[0]
70 cvs_module
= module_tuple
[1]
71 fullpath
= os
.path
.join(topsrcdir
, module
)
72 if os
.path
.exists(fullpath
):
73 print "Removing '%s'" % fullpath
74 shutil
.rmtree(fullpath
)
76 (parent
, leaf
) = os
.path
.split(module
)
77 print "CVS export begin: " + datetime
.datetime
.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC")
78 check_call_noisy([cvs
, '-d', cvsroot
,
79 'export', '-r', tag
, '-d', leaf
, cvs_module
],
80 cwd
=os
.path
.join(topsrcdir
, parent
))
81 print "CVS export end: " + datetime
.datetime
.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC")
83 def toggle_trailing_blank_line(depname
):
84 """If the trailing line is empty, then we'll delete it.
85 Otherwise we'll add a blank line."""
86 lines
= open(depname
, "r").readlines()
88 print >>sys
.stderr
, "unexpected short file"
91 if not lines
[-1].strip():
92 # trailing line is blank, removing it
93 open(depname
, "wb").writelines(lines
[:-1])
96 open(depname
, "ab").write("\n")
98 def get_trailing_blank_line_state(depname
):
99 lines
= open(depname
, "r").readlines()
101 print >>sys
.stderr
, "unexpected short file"
102 return "no blank line"
104 if not lines
[-1].strip():
105 return "has blank line"
107 return "no blank line"
109 def update_nspr_or_nss(tag
, depfile
, destination
, hgpath
):
110 print "reverting to HG version of %s to get its blank line state" % depfile
111 check_call_noisy([options
.hg
, 'revert', depfile
])
112 old_state
= get_trailing_blank_line_state(depfile
)
113 print "old state of %s is: %s" % (depfile
, old_state
)
114 do_hg_replace(destination
, hgpath
, tag
, HG_EXCLUSIONS
, options
.hg
)
115 new_state
= get_trailing_blank_line_state(depfile
)
116 print "new state of %s is: %s" % (depfile
, new_state
)
117 if old_state
== new_state
:
118 print "toggling blank line in: ", depfile
119 toggle_trailing_blank_line(depfile
)
120 tag_file
= destination
+ "/TAG-INFO"
121 print >>file(tag_file
, "w"), tag
123 o
= OptionParser(usage
="client.py [options] update_nspr tagname | update_nss tagname | update_libffi tagname | update_webidlparser tagname")
124 o
.add_option("--skip-mozilla", dest
="skip_mozilla",
125 action
="store_true", default
=False,
128 o
.add_option("--cvs", dest
="cvs", default
=os
.environ
.get('CVS', 'cvs'),
129 help="The location of the cvs binary")
130 o
.add_option("--cvsroot", dest
="cvsroot",
131 help="The CVSROOT for libffi (default : %s)" % CVSROOT_LIBFFI
)
132 o
.add_option("--hg", dest
="hg", default
=os
.environ
.get('HG', 'hg'),
133 help="The location of the hg binary")
136 options
, args
= o
.parse_args()
142 if action
in ('checkout', 'co'):
143 print >>sys
.stderr
, "Warning: client.py checkout is obsolete."
145 elif action
in ('update_nspr'):
147 depfile
= "nsprpub/config/prdepend.h"
148 update_nspr_or_nss(tag
, depfile
, 'nsprpub', 'https://hg.mozilla.org/projects/nspr')
149 elif action
in ('update_nss'):
151 depfile
= "security/nss/coreconf/coreconf.dep"
152 update_nspr_or_nss(tag
, depfile
, 'security/nss', 'https://hg.mozilla.org/projects/nss')
153 elif action
in ('update_libffi'):
155 if not options
.cvsroot
:
156 options
.cvsroot
= CVSROOT_LIBFFI
157 do_cvs_export(LIBFFI_DIRS
, tag
, options
.cvsroot
, options
.cvs
)
158 elif action
in ('update_webidlparser'):
160 do_hg_replace(WEBIDLPARSER_DIR
, WEBIDLPARSER_REPO
, tag
, WEBIDLPARSER_EXCLUSIONS
, options
.hg
)