1
#!/cygdrive/C/Python25/python
2
"""A script to help automate the build process."""
4
# When preparing a new release, make sure to set all of these to the latest
11
'bzr-rewrite': '0.5.2',
15
# This will be passed to 'make' to ensure we build with the right python
16
PYTHON='/cygdrive/c/Python25/python'
18
# Create the final build in this directory
21
DEBUG_SUBPROCESS = True
33
if BZR_EXE is not None:
36
subprocess.call(['bzr', '--version'], stdout=subprocess.PIPE,
37
stderr=subprocess.PIPE)
41
subprocess.call(['bzr.bat', '--version'], stdout=subprocess.PIPE,
42
stderr=subprocess.PIPE)
45
raise RuntimeError('Could not find bzr or bzr.bat on your path.')
49
def call_or_fail(*args, **kwargs):
50
"""Call a subprocess, and fail if the return code is not 0."""
52
print ' calling: "%s"' % (' '.join(args[0]),)
53
p = subprocess.Popen(*args, **kwargs)
54
(out, err) = p.communicate()
56
raise RuntimeError('Failed to run: %s, %s' % (args, kwargs))
63
if TARGET is not None:
65
out = call_or_fail([sys.executable, get_bzr_dir() + '/bzr',
66
'version', '--short'], stdout=subprocess.PIPE)
68
TARGET = os.path.abspath(TARGET_ROOT + '-' + version)
73
"""Nuke the target directory so we know we are starting from scratch."""
75
if os.path.isdir(target):
76
print "Deleting: %s" % (target,)
80
return 'bzr.' + VERSIONS['bzr']
84
"""Make sure we have the latest bzr in play."""
85
bzr_dir = get_bzr_dir()
86
if not os.path.isdir(bzr_dir):
87
bzr_version = VERSIONS['bzr']
88
# bzr_url = 'http://bazaar-vcs.org/bzr/bzr.' + bzr_version
89
bzr_url = 'lp:bzr/' + bzr_version
90
print "Getting bzr release %s from %s" % (bzr_version, bzr_url)
91
call_or_fail([bzr(), 'co', bzr_url, bzr_dir])
93
print "Ensuring %s is up-to-date" % (bzr_dir,)
94
call_or_fail([bzr(), 'update', bzr_dir])
99
print "Creating target dir: %s" % (target,)
100
call_or_fail([bzr(), 'co', get_bzr_dir(), target])
103
def get_plugin_trunk_dir(plugin_name):
104
return '%s/trunk' % (plugin_name,)
107
def get_plugin_release_dir(plugin_name):
108
return '%s/%s' % (plugin_name, VERSIONS[plugin_name])
111
def get_plugin_trunk_branch(plugin_name):
112
return 'lp:%s' % (plugin_name,)
115
def update_plugin_trunk(plugin_name):
116
trunk_dir = get_plugin_trunk_dir(plugin_name)
117
if not os.path.isdir(trunk_dir):
118
plugin_trunk = get_plugin_trunk_branch(plugin_name)
119
print "Getting latest %s trunk" % (plugin_name,)
120
call_or_fail([bzr(), 'co', plugin_trunk,
123
print "Ensuring %s is up-to-date" % (trunk_dir,)
124
call_or_fail([bzr(), 'update', trunk_dir])
128
def _plugin_tag_name(plugin_name):
129
if plugin_name in ('bzr-svn', 'bzr-rewrite', 'subvertpy'):
130
return '%s-%s' % (plugin_name, VERSIONS[plugin_name])
131
# bzrtools and qbzr use 'release-X.Y.Z'
132
return 'release-' + VERSIONS[plugin_name]
135
def update_plugin(plugin_name):
136
release_dir = get_plugin_release_dir(plugin_name)
137
if not os.path.isdir(plugin_name):
138
if plugin_name in ('bzr-svn', 'bzr-rewrite'):
139
# bzr-svn uses a different repo format
140
call_or_fail([bzr(), 'init-repo', '--rich-root-pack', plugin_name])
142
os.mkdir(plugin_name)
143
if os.path.isdir(release_dir):
144
print "Removing existing dir: %s" % (release_dir,)
145
shutil.rmtree(release_dir)
147
trunk_dir = update_plugin_trunk(plugin_name)
148
# Now create the tagged directory
149
tag_name = _plugin_tag_name(plugin_name)
150
print "Creating the branch %s" % (release_dir,)
151
call_or_fail([bzr(), 'co', '-rtag:%s' % (tag_name,),
152
trunk_dir, release_dir])
156
def install_plugin(plugin_name):
157
release_dir = update_plugin(plugin_name)
158
# at least bzrtools doesn't like you to call 'setup.py' unless you are in
159
# that directory specifically, so we cd, rather than calling it from
161
print "Installing %s" % (release_dir,)
162
call_or_fail([sys.executable, 'setup.py', 'install', '-O1',
163
'--install-lib=%s' % (get_target(),)],
168
tbzr_loc = os.environ.get('TBZR', None)
170
raise ValueError('You must set TBZR to the location of tortoisebzr.')
171
print 'Updating %s' % (tbzr_loc,)
172
call_or_fail([bzr(), 'update', tbzr_loc])
175
def build_installer():
176
target = get_target()
180
print 'Building standalone installer'
181
call_or_fail(['make', 'PYTHON=%s' % (PYTHON,), 'installer'],
188
p = optparse.OptionParser(usage='%prog [OPTIONS]')
189
opts, args = p.parse_args(args)
195
install_plugin('subvertpy')
196
install_plugin('bzrtools')
197
install_plugin('qbzr')
198
install_plugin('bzr-svn')
199
install_plugin('bzr-rewrite')
204
if __name__ == '__main__':
207
# vim: ts=4 sw=4 sts=4 et ai