/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 = {
3923.2.3 by John Arbash Meinel
VERSIONS for the 1.11rc1 win32 installer.
7
    'bzr': '1.11',
8
    'qbzr': '0.9.6',
9
    'bzrtools': '1.11.0',
3915.2.1 by John Arbash Meinel
Fix up bits of the build_release script.
10
    'bzr-svn': '0.4.16',
3823.4.1 by John Arbash Meinel
Add the win32 build_release script into tools.
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']
3923.2.3 by John Arbash Meinel
VERSIONS for the 1.11rc1 win32 installer.
86
        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.
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
    return 'lp:%s' % (plugin_name,)
110
111
112
def update_plugin_trunk(plugin_name):
113
    trunk_dir = get_plugin_trunk_dir(plugin_name)
114
    if not os.path.isdir(trunk_dir):
3915.2.1 by John Arbash Meinel
Fix up bits of the build_release script.
115
        plugin_trunk = get_plugin_trunk_branch(plugin_name)
3823.4.1 by John Arbash Meinel
Add the win32 build_release script into tools.
116
        print "Getting latest %s trunk" % (plugin_name,)
117
        call_or_fail([bzr(), 'co', plugin_trunk,
118
                      trunk_dir])
119
    else:
120
        print "Ensuring %s is up-to-date" % (trunk_dir,)
121
        call_or_fail([bzr(), 'update', trunk_dir])
122
    return trunk_dir
123
124
125
def _plugin_tag_name(plugin_name):
126
    if plugin_name == 'bzr-svn':
127
        return 'bzr-svn-' + VERSIONS['bzr-svn']
128
    # bzrtools and qbzr use 'release-X.Y.Z'
129
    return 'release-' + VERSIONS[plugin_name]
130
131
132
def update_plugin(plugin_name):
133
    release_dir = get_plugin_release_dir(plugin_name)
134
    if not os.path.isdir(plugin_name):
135
        if plugin_name == 'bzr-svn':
136
            # bzr-svn uses a different repo format
137
            call_or_fail([bzr(), 'init-repo', '--rich-root-pack', plugin_name])
138
        else:
139
            os.mkdir(plugin_name)
140
    if os.path.isdir(release_dir):
141
        print "Removing existing dir: %s" % (release_dir,)
142
        shutil.rmtree(release_dir)
143
    # First update trunk
144
    trunk_dir = update_plugin_trunk(plugin_name)
145
    # Now create the tagged directory
146
    tag_name = _plugin_tag_name(plugin_name)
147
    print "Creating the branch %s" % (release_dir,)
148
    call_or_fail([bzr(), 'co', '-rtag:%s' % (tag_name,),
149
                  trunk_dir, release_dir])
150
    return release_dir
151
152
153
def install_plugin(plugin_name):
154
    release_dir = update_plugin(plugin_name)
155
    # at least bzrtools doesn't like you to call 'setup.py' unless you are in
156
    # that directory specifically, so we cd, rather than calling it from
157
    # outside
158
    print "Installing %s" % (release_dir,)
159
    call_or_fail([sys.executable, 'setup.py', 'install', '-O1',
160
                  '--install-lib=%s' % (get_target(),)],
161
                 cwd=release_dir)
162
163
164
def update_tbzr():
165
    tbzr_loc = os.environ.get('TBZR', None)
166
    if tbzr_loc is None:
167
        raise ValueError('You must set TBZR to the location of tortoisebzr.')
168
    print 'Updating %s' % (tbzr_loc,)
169
    call_or_fail([bzr(), 'update', tbzr_loc])
170
171
172
def build_installer():
173
    target = get_target()
174
    print
175
    print
176
    print '*' * 60
177
    print 'Building standalone installer'
178
    call_or_fail(['make', 'PYTHON=%s' % (PYTHON,), 'installer'],
179
                 cwd=target)
180
181
182
def main(args):
183
    import optparse
184
185
    p = optparse.OptionParser(usage='%prog [OPTIONS]')
186
    opts, args = p.parse_args(args)
187
188
    update_bzr()
189
    update_tbzr()
190
    clean_target()
191
    create_target()
192
    install_plugin('bzrtools')
193
    install_plugin('qbzr')
194
    install_plugin('bzr-svn')
195
196
    build_installer()
197
198
199
if __name__ == '__main__':
200
    main(sys.argv[1:])
201
202
# vim: ts=4 sw=4 sts=4 et ai