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
13
# This will be passed to 'make' to ensure we build with the right python
14
PYTHON='/cygdrive/c/Python25/python'
16
# Create the final build in this directory
19
DEBUG_SUBPROCESS = True
31
if BZR_EXE is not None:
34
subprocess.call(['bzr', '--version'], stdout=subprocess.PIPE,
35
stderr=subprocess.PIPE)
39
subprocess.call(['bzr.bat', '--version'], stdout=subprocess.PIPE,
40
stderr=subprocess.PIPE)
43
raise RuntimeError('Could not find bzr or bzr.bat on your path.')
47
def call_or_fail(*args, **kwargs):
48
"""Call a subprocess, and fail if the return code is not 0."""
50
print ' calling: "%s"' % (' '.join(args[0]),)
51
p = subprocess.Popen(*args, **kwargs)
52
(out, err) = p.communicate()
54
raise RuntimeError('Failed to run: %s, %s' % (args, kwargs))
61
if TARGET is not None:
63
out = call_or_fail([sys.executable, get_bzr_dir() + '/bzr',
64
'version', '--short'], stdout=subprocess.PIPE)
66
TARGET = os.path.abspath(TARGET_ROOT + '-' + version)
71
"""Nuke the target directory so we know we are starting from scratch."""
73
if os.path.isdir(target):
74
print "Deleting: %s" % (target,)
78
return 'bzr.' + VERSIONS['bzr']
82
"""Make sure we have the latest bzr in play."""
83
bzr_dir = get_bzr_dir()
84
if not os.path.isdir(bzr_dir):
85
bzr_version = VERSIONS['bzr']
86
bzr_url = 'http://bazaar-vcs.org/bzr/bzr' + bzr_version
87
print "Getting bzr release %s from %s" % (bzr_version, bzr_url)
88
call_or_fail([bzr(), 'co', bzr_url])
90
print "Ensuring %s is up-to-date" % (bzr_dir,)
91
call_or_fail([bzr(), 'update', bzr_dir])
96
print "Creating target dir: %s" % (target,)
97
call_or_fail([bzr(), 'co', get_bzr_dir(), target])
100
def get_plugin_trunk_dir(plugin_name):
101
return '%s/trunk' % (plugin_name,)
104
def get_plugin_release_dir(plugin_name):
105
return '%s/%s' % (plugin_name, VERSIONS[plugin_name])
108
def get_plugin_trunk_branch(plugin_name):
109
if plugin_name == 'bzr-svn':
110
# For some reason bzr-svn doesn't have the latest tags on its 'trunk'
111
# branch, but only exist in the 0.4 releases.
112
return 'lp:bzr-svn/0.4'
113
return 'lp:%s' % (plugin_name,)
116
def update_plugin_trunk(plugin_name):
117
trunk_dir = get_plugin_trunk_dir(plugin_name)
118
if not os.path.isdir(trunk_dir):
119
plugin_trunk = get_plugin_trunk_branch()
120
print "Getting latest %s trunk" % (plugin_name,)
121
call_or_fail([bzr(), 'co', plugin_trunk,
124
print "Ensuring %s is up-to-date" % (trunk_dir,)
125
call_or_fail([bzr(), 'update', trunk_dir])
129
def _plugin_tag_name(plugin_name):
130
if plugin_name == 'bzr-svn':
131
return 'bzr-svn-' + VERSIONS['bzr-svn']
132
# bzrtools and qbzr use 'release-X.Y.Z'
133
return 'release-' + VERSIONS[plugin_name]
136
def update_plugin(plugin_name):
137
release_dir = get_plugin_release_dir(plugin_name)
138
if not os.path.isdir(plugin_name):
139
if plugin_name == 'bzr-svn':
140
# bzr-svn uses a different repo format
141
call_or_fail([bzr(), 'init-repo', '--rich-root-pack', plugin_name])
143
os.mkdir(plugin_name)
144
if os.path.isdir(release_dir):
145
print "Removing existing dir: %s" % (release_dir,)
146
shutil.rmtree(release_dir)
148
trunk_dir = update_plugin_trunk(plugin_name)
149
# Now create the tagged directory
150
tag_name = _plugin_tag_name(plugin_name)
151
print "Creating the branch %s" % (release_dir,)
152
call_or_fail([bzr(), 'co', '-rtag:%s' % (tag_name,),
153
trunk_dir, release_dir])
157
def install_plugin(plugin_name):
158
release_dir = update_plugin(plugin_name)
159
# at least bzrtools doesn't like you to call 'setup.py' unless you are in
160
# that directory specifically, so we cd, rather than calling it from
162
print "Installing %s" % (release_dir,)
163
call_or_fail([sys.executable, 'setup.py', 'install', '-O1',
164
'--install-lib=%s' % (get_target(),)],
169
tbzr_loc = os.environ.get('TBZR', None)
171
raise ValueError('You must set TBZR to the location of tortoisebzr.')
172
print 'Updating %s' % (tbzr_loc,)
173
call_or_fail([bzr(), 'update', tbzr_loc])
176
def build_installer():
177
target = get_target()
181
print 'Building standalone installer'
182
call_or_fail(['make', 'PYTHON=%s' % (PYTHON,), 'installer'],
189
p = optparse.OptionParser(usage='%prog [OPTIONS]')
190
opts, args = p.parse_args(args)
196
install_plugin('bzrtools')
197
install_plugin('qbzr')
198
install_plugin('bzr-svn')
203
if __name__ == '__main__':
206
# vim: ts=4 sw=4 sts=4 et ai