bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6619.3.3
by Jelmer Vernooij
Apply 2to3 print fix. |
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 = { |
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
7 |
'brz': '1.17', |
6619.3.3
by Jelmer Vernooij
Apply 2to3 print fix. |
8 |
'qbzr': '0.12', |
9 |
'bzrtools': '1.17.0', |
|
10 |
'bzr-svn': '0.6.3', |
|
11 |
'bzr-rewrite': '0.5.2', |
|
12 |
'subvertpy': '0.6.8', |
|
13 |
}
|
|
14 |
||
15 |
# This will be passed to 'make' to ensure we build with the right python
|
|
7143.16.17
by Jelmer Vernooij
Fix E225. |
16 |
PYTHON = '/cygdrive/c/Python25/python' |
6619.3.3
by Jelmer Vernooij
Apply 2to3 print fix. |
17 |
|
18 |
# Create the final build in this directory
|
|
7143.16.17
by Jelmer Vernooij
Fix E225. |
19 |
TARGET_ROOT = 'release' |
6619.3.3
by Jelmer Vernooij
Apply 2to3 print fix. |
20 |
|
21 |
DEBUG_SUBPROCESS = True |
|
22 |
||
23 |
||
24 |
import os |
|
25 |
import shutil |
|
26 |
import subprocess |
|
27 |
import sys |
|
28 |
||
29 |
||
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
30 |
BRZ_EXE = None |
31 |
def brz(): |
|
32 |
global BRZ_EXE |
|
33 |
if BRZ_EXE is not None: |
|
34 |
return BRZ_EXE |
|
6619.3.3
by Jelmer Vernooij
Apply 2to3 print fix. |
35 |
try: |
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
36 |
subprocess.call(['brz', '--version'], stdout=subprocess.PIPE, |
6619.3.3
by Jelmer Vernooij
Apply 2to3 print fix. |
37 |
stderr=subprocess.PIPE) |
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
38 |
BRZ_EXE = 'brz' |
6619.3.3
by Jelmer Vernooij
Apply 2to3 print fix. |
39 |
except OSError: |
40 |
try: |
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
41 |
subprocess.call(['brz.bat', '--version'], stdout=subprocess.PIPE, |
6619.3.3
by Jelmer Vernooij
Apply 2to3 print fix. |
42 |
stderr=subprocess.PIPE) |
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
43 |
BRZ_EXE = 'brz.bat' |
6619.3.3
by Jelmer Vernooij
Apply 2to3 print fix. |
44 |
except OSError: |
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
45 |
raise RuntimeError('Could not find brz or brz.bat on your path.') |
46 |
return BRZ_EXE |
|
6619.3.3
by Jelmer Vernooij
Apply 2to3 print fix. |
47 |
|
48 |
||
49 |
def call_or_fail(*args, **kwargs): |
|
50 |
"""Call a subprocess, and fail if the return code is not 0.""" |
|
51 |
if DEBUG_SUBPROCESS: |
|
52 |
print(' calling: "%s"' % (' '.join(args[0]),)) |
|
53 |
p = subprocess.Popen(*args, **kwargs) |
|
54 |
(out, err) = p.communicate() |
|
55 |
if p.returncode != 0: |
|
56 |
raise RuntimeError('Failed to run: %s, %s' % (args, kwargs)) |
|
57 |
return out |
|
58 |
||
59 |
||
60 |
TARGET = None |
|
61 |
def get_target(): |
|
62 |
global TARGET |
|
63 |
if TARGET is not None: |
|
64 |
return TARGET |
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
65 |
out = call_or_fail([sys.executable, get_brz_dir() + '/brz', |
6619.3.3
by Jelmer Vernooij
Apply 2to3 print fix. |
66 |
'version', '--short'], stdout=subprocess.PIPE) |
67 |
version = out.strip() |
|
68 |
TARGET = os.path.abspath(TARGET_ROOT + '-' + version) |
|
69 |
return TARGET |
|
70 |
||
71 |
||
72 |
def clean_target(): |
|
73 |
"""Nuke the target directory so we know we are starting from scratch.""" |
|
74 |
target = get_target() |
|
75 |
if os.path.isdir(target): |
|
76 |
print("Deleting: %s" % (target,)) |
|
77 |
shutil.rmtree(target) |
|
78 |
||
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
79 |
def get_brz_dir(): |
80 |
return 'brz.' + VERSIONS['brz'] |
|
81 |
||
82 |
||
83 |
def update_brz(): |
|
84 |
"""Make sure we have the latest brz in play.""" |
|
85 |
brz_dir = get_brz_dir() |
|
86 |
if not os.path.isdir(brz_dir): |
|
87 |
brz_version = VERSIONS['brz'] |
|
88 |
brz_url = 'lp:brz/' + brz_version |
|
89 |
print("Getting brz release %s from %s" % (brz_version, brz_url)) |
|
90 |
call_or_fail([brz(), 'co', brz_url, brz_dir]) |
|
6619.3.3
by Jelmer Vernooij
Apply 2to3 print fix. |
91 |
else: |
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
92 |
print("Ensuring %s is up-to-date" % (brz_dir,)) |
93 |
call_or_fail([brz(), 'update', brz_dir]) |
|
6619.3.3
by Jelmer Vernooij
Apply 2to3 print fix. |
94 |
|
95 |
||
96 |
def create_target(): |
|
97 |
target = get_target() |
|
98 |
print("Creating target dir: %s" % (target,)) |
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
99 |
call_or_fail([brz(), 'co', get_brz_dir(), target]) |
6619.3.3
by Jelmer Vernooij
Apply 2to3 print fix. |
100 |
|
101 |
||
102 |
def get_plugin_trunk_dir(plugin_name): |
|
103 |
return '%s/trunk' % (plugin_name,) |
|
104 |
||
105 |
||
106 |
def get_plugin_release_dir(plugin_name): |
|
107 |
return '%s/%s' % (plugin_name, VERSIONS[plugin_name]) |
|
108 |
||
109 |
||
110 |
def get_plugin_trunk_branch(plugin_name): |
|
111 |
return 'lp:%s' % (plugin_name,) |
|
112 |
||
113 |
||
114 |
def update_plugin_trunk(plugin_name): |
|
115 |
trunk_dir = get_plugin_trunk_dir(plugin_name) |
|
116 |
if not os.path.isdir(trunk_dir): |
|
117 |
plugin_trunk = get_plugin_trunk_branch(plugin_name) |
|
118 |
print("Getting latest %s trunk" % (plugin_name,)) |
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
119 |
call_or_fail([brz(), 'co', plugin_trunk, |
6619.3.3
by Jelmer Vernooij
Apply 2to3 print fix. |
120 |
trunk_dir]) |
121 |
else: |
|
122 |
print("Ensuring %s is up-to-date" % (trunk_dir,)) |
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
123 |
call_or_fail([brz(), 'update', trunk_dir]) |
6619.3.3
by Jelmer Vernooij
Apply 2to3 print fix. |
124 |
return trunk_dir |
125 |
||
126 |
||
127 |
def _plugin_tag_name(plugin_name): |
|
128 |
if plugin_name in ('bzr-svn', 'bzr-rewrite', 'subvertpy'): |
|
129 |
return '%s-%s' % (plugin_name, VERSIONS[plugin_name]) |
|
130 |
# bzrtools and qbzr use 'release-X.Y.Z'
|
|
131 |
return 'release-' + VERSIONS[plugin_name] |
|
132 |
||
133 |
||
134 |
def update_plugin(plugin_name): |
|
135 |
release_dir = get_plugin_release_dir(plugin_name) |
|
136 |
if not os.path.isdir(plugin_name): |
|
137 |
if plugin_name in ('bzr-svn', 'bzr-rewrite'): |
|
138 |
# bzr-svn uses a different repo format
|
|
7385.2.1
by Jelmer Vernooij
Rename init-repo to init-shared-repo. |
139 |
call_or_fail( |
140 |
[brz(), 'init-shared-repo', '--rich-root-pack', plugin_name]) |
|
6619.3.3
by Jelmer Vernooij
Apply 2to3 print fix. |
141 |
else: |
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) |
|
146 |
# First update trunk
|
|
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,)) |
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
151 |
call_or_fail([brz(), 'co', '-rtag:%s' % (tag_name,), |
6619.3.3
by Jelmer Vernooij
Apply 2to3 print fix. |
152 |
trunk_dir, release_dir]) |
153 |
return release_dir |
|
154 |
||
155 |
||
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
|
|
160 |
# outside
|
|
161 |
print("Installing %s" % (release_dir,)) |
|
162 |
call_or_fail([sys.executable, 'setup.py', 'install', '-O1', |
|
163 |
'--install-lib=%s' % (get_target(),)], |
|
164 |
cwd=release_dir) |
|
165 |
||
166 |
||
167 |
def update_tbzr(): |
|
168 |
tbzr_loc = os.environ.get('TBZR', None) |
|
169 |
if tbzr_loc is None: |
|
170 |
raise ValueError('You must set TBZR to the location of tortoisebzr.') |
|
171 |
print('Updating %s' % (tbzr_loc,)) |
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
172 |
call_or_fail([brz(), 'update', tbzr_loc]) |
6619.3.3
by Jelmer Vernooij
Apply 2to3 print fix. |
173 |
|
174 |
||
175 |
def build_installer(): |
|
176 |
target = get_target() |
|
177 |
print() |
|
178 |
print() |
|
179 |
print('*' * 60) |
|
180 |
print('Building standalone installer') |
|
181 |
call_or_fail(['make', 'PYTHON=%s' % (PYTHON,), 'installer'], |
|
182 |
cwd=target) |
|
183 |
||
184 |
||
185 |
def main(args): |
|
186 |
import optparse |
|
187 |
||
188 |
p = optparse.OptionParser(usage='%prog [OPTIONS]') |
|
189 |
opts, args = p.parse_args(args) |
|
190 |
||
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
191 |
update_brz() |
6619.3.3
by Jelmer Vernooij
Apply 2to3 print fix. |
192 |
update_tbzr() |
193 |
clean_target() |
|
194 |
create_target() |
|
195 |
install_plugin('subvertpy') |
|
196 |
install_plugin('bzrtools') |
|
197 |
install_plugin('qbzr') |
|
198 |
install_plugin('bzr-svn') |
|
199 |
install_plugin('bzr-rewrite') |
|
200 |
||
201 |
build_installer() |
|
202 |
||
203 |
||
204 |
if __name__ == '__main__': |
|
205 |
main(sys.argv[1:]) |
|
206 |
||
207 |
# vim: ts=4 sw=4 sts=4 et ai
|