3823.4.1
by John Arbash Meinel
Add the win32 build_release script into tools. |
1 |
#!/cygdrive/C/Python25/python
|
2 |
"""A script to help automate the build process."""
|
|
3 |
||
4 |
# When preparing a new release, make sure to set all of these to the latest
|
|
5 |
# values.
|
|
6 |
VERSIONS = { |
|
7 |
'bzr': '1.9', |
|
8 |
'qbzr': '0.9.5', |
|
9 |
'bzrtools': '1.9.1', |
|
10 |
'bzr-svn': '0.4.14', |
|
11 |
}
|
|
12 |
||
13 |
# This will be passed to 'make' to ensure we build with the right python
|
|
14 |
PYTHON='/cygdrive/c/Python25/python' |
|
15 |
||
16 |
# Create the final build in this directory
|
|
17 |
TARGET_ROOT='release' |
|
18 |
||
19 |
DEBUG_SUBPROCESS = True |
|
20 |
||
21 |
||
22 |
import os |
|
23 |
import shutil |
|
24 |
import subprocess |
|
25 |
import sys |
|
26 |
||
27 |
||
28 |
BZR_EXE = None |
|
29 |
def bzr(): |
|
30 |
global BZR_EXE |
|
31 |
if BZR_EXE is not None: |
|
32 |
return BZR_EXE |
|
33 |
try: |
|
34 |
subprocess.call(['bzr', '--version'], stdout=subprocess.PIPE, |
|
35 |
stderr=subprocess.PIPE) |
|
36 |
BZR_EXE = 'bzr' |
|
37 |
except OSError: |
|
38 |
try: |
|
39 |
subprocess.call(['bzr.bat', '--version'], stdout=subprocess.PIPE, |
|
40 |
stderr=subprocess.PIPE) |
|
41 |
BZR_EXE = 'bzr.bat' |
|
42 |
except OSError: |
|
43 |
raise RuntimeError('Could not find bzr or bzr.bat on your path.') |
|
44 |
return BZR_EXE |
|
45 |
||
46 |
||
47 |
def call_or_fail(*args, **kwargs): |
|
48 |
"""Call a subprocess, and fail if the return code is not 0."""
|
|
49 |
if DEBUG_SUBPROCESS: |
|
50 |
print ' calling: "%s"' % (' '.join(args[0]),) |
|
51 |
p = subprocess.Popen(*args, **kwargs) |
|
52 |
(out, err) = p.communicate() |
|
53 |
if p.returncode != 0: |
|
54 |
raise RuntimeError('Failed to run: %s, %s' % (args, kwargs)) |
|
55 |
return out |
|
56 |
||
57 |
||
58 |
TARGET = None |
|
59 |
def get_target(): |
|
60 |
global TARGET |
|
61 |
if TARGET is not None: |
|
62 |
return TARGET |
|
63 |
out = call_or_fail([sys.executable, get_bzr_dir() + '/bzr', |
|
64 |
'version', '--short'], stdout=subprocess.PIPE) |
|
65 |
version = out.strip() |
|
66 |
TARGET = os.path.abspath(TARGET_ROOT + '-' + version) |
|
67 |
return TARGET |
|
68 |
||
69 |
||
70 |
def clean_target(): |
|
71 |
"""Nuke the target directory so we know we are starting from scratch."""
|
|
72 |
target = get_target() |
|
73 |
if os.path.isdir(target): |
|
74 |
print "Deleting: %s" % (target,) |
|
75 |
shutil.rmtree(target) |
|
76 |
||
77 |
def get_bzr_dir(): |
|
78 |
return 'bzr.' + VERSIONS['bzr'] |
|
79 |
||
80 |
||
81 |
def update_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]) |
|
89 |
else: |
|
90 |
print "Ensuring %s is up-to-date" % (bzr_dir,) |
|
91 |
call_or_fail([bzr(), 'update', bzr_dir]) |
|
92 |
||
93 |
||
94 |
def create_target(): |
|
95 |
target = get_target() |
|
96 |
print "Creating target dir: %s" % (target,) |
|
97 |
call_or_fail([bzr(), 'co', get_bzr_dir(), target]) |
|
98 |
||
99 |
||
100 |
def get_plugin_trunk_dir(plugin_name): |
|
101 |
return '%s/trunk' % (plugin_name,) |
|
102 |
||
103 |
||
104 |
def get_plugin_release_dir(plugin_name): |
|
105 |
return '%s/%s' % (plugin_name, VERSIONS[plugin_name]) |
|
106 |
||
107 |
||
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,) |
|
114 |
||
115 |
||
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, |
|
122 |
trunk_dir]) |
|
123 |
else: |
|
124 |
print "Ensuring %s is up-to-date" % (trunk_dir,) |
|
125 |
call_or_fail([bzr(), 'update', trunk_dir]) |
|
126 |
return trunk_dir |
|
127 |
||
128 |
||
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] |
|
134 |
||
135 |
||
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]) |
|
142 |
else: |
|
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) |
|
147 |
# First update trunk
|
|
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]) |
|
154 |
return release_dir |
|
155 |
||
156 |
||
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
|
|
161 |
# outside
|
|
162 |
print "Installing %s" % (release_dir,) |
|
163 |
call_or_fail([sys.executable, 'setup.py', 'install', '-O1', |
|
164 |
'--install-lib=%s' % (get_target(),)], |
|
165 |
cwd=release_dir) |
|
166 |
||
167 |
||
168 |
def update_tbzr(): |
|
169 |
tbzr_loc = os.environ.get('TBZR', None) |
|
170 |
if tbzr_loc is 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]) |
|
174 |
||
175 |
||
176 |
def build_installer(): |
|
177 |
target = get_target() |
|
178 |
print
|
|
179 |
print
|
|
180 |
print '*' * 60 |
|
181 |
print 'Building standalone installer' |
|
182 |
call_or_fail(['make', 'PYTHON=%s' % (PYTHON,), 'installer'], |
|
183 |
cwd=target) |
|
184 |
||
185 |
||
186 |
def main(args): |
|
187 |
import optparse |
|
188 |
||
189 |
p = optparse.OptionParser(usage='%prog [OPTIONS]') |
|
190 |
opts, args = p.parse_args(args) |
|
191 |
||
192 |
update_bzr() |
|
193 |
update_tbzr() |
|
194 |
clean_target() |
|
195 |
create_target() |
|
196 |
install_plugin('bzrtools') |
|
197 |
install_plugin('qbzr') |
|
198 |
install_plugin('bzr-svn') |
|
199 |
||
200 |
build_installer() |
|
201 |
||
202 |
||
203 |
if __name__ == '__main__': |
|
204 |
main(sys.argv[1:]) |
|
205 |
||
206 |
# vim: ts=4 sw=4 sts=4 et ai
|