/brz/remove-bazaar

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