Source

thg-winbuild / setup.py

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
"""Generate binary installer for Mercurial or TortoiseHg

Usage: setup.py [OPTIONS]

Options:
  -h --help         Print this message and exit
     --pull         Pull from upstream, implied by stable and unstable targets
     --nopull       Disable pull for all targets
     --config       Show build configuration and exit
  -f --force-hg     Force the build-hg directory to be recloned
  -F --force-thg    Force the build-thg directory to be recloned
  -c --clean        Clean all build remnants
     --thg-release  Build a TortoiseHg release package
     --thg-stable   Build a TortoiseHg nightly stable package
     --thg-unstable Build a TortoiseHg nightly unstable package
     --thg-doc      Only build TortoiseHg documentation in tortoisehg/
     --hg-release   Build a Mercurial release package
     --hg-stable    Build a Mercurial nightly stable package
     --hg-unstable  Build a Mercurial nightly unstable package
     --all          Build all four nightly targets
     --cert <file>  Sign output using the specified cert file (pfx)
"""

#### Package Respins ####
# TortoiseHg 0.9.2-1 used mercurial.iss from changeset 275690997c5f

import os
import sys
import datetime
import subprocess
import fileinput
import getopt
import re
import shutil
import uuid
import getpass

installenv = os.environ
gtkpath = os.environ.get('GTK_PATH', 'C:\GTK')

# default to TortoiseHg nightly stable build config
hgbranch = 'stable'
hgtag = 'tip'
thgbranch = 'stable'
thgtag = 'tip'
forcehg = False
forcethg = False
buildhg = False
builddoc = False
buildthg = False
dopull = None
showconfig = False
cert = None
all = False

URL = {
  'hg-main'   : 'http://selenic.com/repo/hg/',
  'tortoisehg': 'http://bitbucket.org/tortoisehg/stable/',
  'hgfold'    : 'http://bitbucket.org/bradobro/hgfold/',
  'hgcr-gui'  : 'http://bitbucket.org/glimchb/hgcr-gui/',
  'perfarce'  : 'http://www.kingswood-consulting.co.uk/hg/perfarce/',
  'hgeol'     : 'http://bitbucket.org/mg/hg-eol/',
  'keyring'   : 'http://bitbucket.org/sborho/python-keyring-lib/',
  'hgkeyring' : 'http://bitbucket.org/Mekk/mercurial_keyring/',
  'dulwich'   : 'http://bitbucket.org/abderrahim/dulwich/',
  }

extensions = ['hgfold', 'hgcr-gui', 'perfarce', 'hgeol',
              'keyring', 'hgkeyring', 'dulwich']
thg_source_repos = ['tortoisehg', 'hg-main'] + extensions

def checkrepo(name, ver=''):
    if os.path.isdir(name):
        return
    run(r'hg clone -U %s %s' % (URL[name], name))
    run(r'hg update -R %s %s' % (name, ver))


def run(cmd, cwd='.', hide=False):
    global installenv
    if not hide:
        print cwd + "> " + cmd
    try:
        subprocess.check_call(cmd, shell=True, cwd=cwd, env=installenv)
    except subprocess.CalledProcessError:
        if hide:
            raise StandardError("subprocess.CalledProcessError was raised")
        else:
            raise


def lasttag(reponame):
    p = subprocess.Popen( ('hg', '-R', reponame, 'tags', '-q'), 
                          stdin=subprocess.PIPE, 
                          stdout=subprocess.PIPE,
                          shell=False)
    stdout_text, stderr_text = p.communicate('') 
    return stdout_text.splitlines()[1]

def repoversion(verfile):
    globals = {}
    execfile(verfile, globals)
    return globals.get('version', 'unknown')

def windowsversion(name, longversion):
    if '+' in longversion:
        version, extra = longversion.split('+', 1)
        major, minor, periodic = version.split('.')
        tagdistance = int(extra.split('-', 1)[0])
        periodic = int(periodic) * 10000
        if 'unstable' in name:
            periodic += tagdistance + 5000
        else:
            periodic += tagdistance + 1000
        return '.'.join([major, minor, str(periodic)])
    else:
        return longversion

def pipetofile(cmdlist, outfile, cwd):
    print '> ', ' '.join(cmdlist), '>', outfile
    p = subprocess.Popen( cmdlist,
                          stdin=subprocess.PIPE,
                          stdout=subprocess.PIPE,
                          shell=False,
                          cwd=cwd)
    out, err = p.communicate('')
    fp = open(outfile, 'wb')
    fp.write(out)
    fp.close

def build_hg(force, branch, tag):
    if force or not os.path.exists('build-hg'):
        run(r'if exist build-hg rmdir /s /q build-hg')
        run(r'hg clone hg-main -u %s build-hg' % branch)
    else:
        run(r'hg -R build-hg pull')
        run(r'hg -R build-hg update ' + branch)
    if tag == 'tip':
        run(r'hg -R build-hg update')
    else:
        run(r'hg -R build-hg update ' + tag)

    # Clear files added by previous installer runs
    run(r'hg -R build-hg --config extensions.purge= purge --all')
    run(r'copy misc\setup.cfg build-hg')
    run(r'python setup.py --version', 'build-hg')
    run(r'python setup.py build_py -c -d . build_ext -i build_mo', 'build-hg')
    # Build man pages
    pipetofile((sys.executable, 'gendoc.py'),
               'build-hg/doc/hg.1.gendoc.txt',
               'build-hg/doc')
    rst2html = os.path.dirname(sys.executable) + r'\Scripts\rst2html.py'
    for man in ('hg.1.txt', 'hgignore.5.txt', 'hgrc.5.txt'):
        outfile = man[:-3] + 'html'
        run(r'python %s --link-stylesheet --stylesheet-path style.css %s %s' % (
            rst2html, man, outfile), 'build-hg/doc')

def build_hg_installer(name):
    run(r'python setup.py py2exe -b2', 'build-hg')
    if cert is not None:
        print "signing using cert '%s'" % (cert,)
        exe = r'dist\hg.exe'
        run(r'..\misc\sign.cmd %s %s %s' % (cert, pwd, exe), 'build-hg', hide=True)
    version = repoversion('build-hg/mercurial/__version__.py')
    comments = 'Installs Mercurial version %s' % version
    version = windowsversion(name, version)
    package = r'..\output\%s-%s.msi' % (name, version)
    run(r'..\misc\build-mercurial-msi.bat %s "%s" %s' % (version, comments, package), 'build-hg')
    if cert is not None:
        print "signing using cert '%s'" % (cert,)
        run(r'..\misc\sign.cmd %s %s %s' % (cert, pwd, package), 'build-hg', hide=True)

def build_thg(force, branch, tag, name, productid):
    if force or not os.path.exists('build-thg'):
        run(r'if exist build-thg rmdir /s /q build-thg')
        run(r'hg clone tortoisehg -u %s build-thg' % branch)
    else:
        run(r'hg pull', 'build-thg')
        run(r'hg update ' + branch, 'build-thg')
    if tag == 'tip':
        run(r'hg update', 'build-thg')
    else:
        run(r'hg update ' + tag, 'build-thg')

    # Clear files added by previous installer runs
    run(r'hg -R build-thg --config extensions.purge= purge --all')

    run(r'python setup.py --version', 'build-thg')
    # Build locales
    run(r'python setup.py build_mo', 'build-thg')
    # Build cmenu translation registry files
    run(r'python reggen.py', 'build-thg/win32')
    # Use build helpers from contrib\win32
    run(r'copy contrib\win32\config.py tortoisehg\util', 'build-thg')
    run(r'copy contrib\win32\setup.cfg .', 'build-thg')
    # Copy bundled Mercurial extensions into build-hg/hgext
    for ext in ('hgfold/fold.py', 'hgcr-gui/hgcr-gui.py', 'hgeol/eol.py',
            'perfarce/perfarce.py', 'hgkeyring/mercurial_keyring.py'):
        if os.path.exists(ext):
            shutil.copy(ext, 'build-hg/hgext')
    # Build docs
    os.environ['hhc_compiler'] = 'hhc.exe'
    run(r'build chm', 'build-thg/doc')
    run(r'build pdf', 'build-thg/doc')

    # Build x64 and x86 shell extensions
    thgversion = repoversion('build-thg/tortoisehg/util/__version__.py')
    thgversion = windowsversion(name, thgversion)
    v = [int(x) for x in thgversion.split('.')]
    while len(v) < 3:
        v.append(0)
    a, b, c = v
    cmd = r'cmd.exe /e:on /v:on /c contrib\wix\sdk_build_extensions.cmd %i %i %i %s %s'
    for platform in ('x86', 'x64'):
        run(cmd % (a, b, c, platform, productid), 'build-thg')
        if cert is not None:
            print "signing using cert '%s'" % (cert,)
            package = r'win32\ThgShell%s.dll' % platform
            run(r'..\misc\sign.cmd %s %s %s' % (cert, pwd, package), 'build-thg', hide=True)


def build_thg_docs():
    os.environ['hhc_compiler'] = 'hhc.exe'
    run(r'build clean', r'tortoisehg\doc')
    run(r'build chm', r'tortoisehg\doc')
    run(r'build pdf', r'tortoisehg\doc')

def build_thg_installer(name, productid):
    run(r'if exist dist rmdir /s /q dist', 'build-thg')

    # copy selected GTK runtime files
    for dir in (r'\share\themes\MS-Windows', r'\etc', r'\lib\gtk-2.0'):
        shutil.copytree(gtkpath + dir, r'build-thg\dist\gtk' + dir,
                        ignore=shutil.ignore_patterns('include'))
    run(r'copy %s\bin\*.dll build-thg\dist\gtk' % gtkpath)
    run(r'copy misc\gtkrc build-thg\dist\gtk\etc\gtk-2.0')
    for locale in ('cs', 'da', 'de', 'es', 'fr', 'it', 'ja', 'pt',
                   'pt_BR', 'ru', 'uk', 'zh_CN'):
        shutil.copytree(gtkpath + '\share\locale\\' + locale,
                        r'build-thg\dist\gtk\share\locale\\' + locale,
                        ignore=shutil.ignore_patterns('atk10.mo', 'gettext*.mo',
                                                      'gtk20-properties.mo'))

    run(r'python setup.py py2exe -b2', 'build-thg')

    if cert is not None:
        print "signing using cert '%s'" % (cert,)
        for exe in ('hg', 'hgtk', 'thgtaskbar'):
            package = r'dist\%s.exe' % exe
            run(r'..\misc\sign.cmd %s %s %s' % (cert, pwd, package), 'build-thg', hide=True)

    run(r'..\misc\build-tortoisehg-wixobj.bat', 'build-thg')

    hgversion = repoversion('build-hg/mercurial/__version__.py')
    longthgversion = repoversion('build-thg/tortoisehg/util/__version__.py')
    thgversion = windowsversion(name, longthgversion)
    package = "..\output\%s-%s" % (name, thgversion)
    commentsfmt = 'Installs TortoiseHg %s, Mercurial %s on %s'
    cmd = r'..\misc\build-tortoisehg-msi.bat %s "%s" %s %s %s'
    productid = productid.lower()
    for platform in ('x86', 'x64'):
        comments = commentsfmt % (longthgversion, hgversion, platform)
        params = (thgversion, comments, package, platform, productid)
        run(cmd % params, 'build-thg')
        if cert is not None:
            msifile = '%s-%s-%s.msi' % (package, platform, productid)
            print "signing using cert '%s'" % (cert,)
            run(r'..\misc\sign.cmd %s %s %s' % (cert, pwd, msifile), 'build-thg', hide=True)


def try_paths(paths):
    for env in ('ProgramFiles', 'ProgramFiles(x86)', 'ProgramW6432'):
        if env not in installenv: continue
        prefix = installenv[env]
        for file in paths:
            candidate = prefix + file
            if os.path.exists(candidate):
                return candidate
    else:
        return None


def verify_hg_env():
    global installenv

    win7sdk = try_paths([r'\Microsoft SDKs\Windows\v7.0\Bin'])
    if not win7sdk:
        print 'Unable to find Microsoft Windows SDK 7.0, please install'
        sys.exit(1)

    if 'VCINSTALLDIR' not in os.environ:
        print 'Please run setup.py from a Microsoft Windows SDK 7.0 command window'
        print 'to properly setup environment variables for compiling C++ code'
        sys.exit(1)

    # Verify x86 target
    if r'\Lib\X64' in installenv['Lib']:
        print '\nPlease run setenv.bat /x86 before running setup.py'
        sys.exit(1)

    try:
        from mercurial import hg, ui, util
    except ImportError:
        print 'Mercurial must be installed as Python source.'
        print 'You can get this from http://bitbucket.org/tortoisehg/thg-winbuild/downloads/'
        print 'Look for a package like: mercurial-1.4.3.win32-py2.6.exe\n'
        print 'Or simply build it yourself.'
        sys.exit(1)

    try:
        import py2exe
    except ImportError:
        print 'Unable to find py2exe'
        print 'http://sourceforge.net/projects/py2exe/'
        sys.exit(1)

    try:
        import win32api
    except ImportError:
        print 'Unable to find pywin32'
        print 'http://sourceforge.net/projects/pywin32/'
        sys.exit(1)

    path = installenv.get('PATH', '').split(os.pathsep)
    scrpath = os.path.dirname(sys.executable) + os.sep + 'Scripts'
    path.append(scrpath)

    if not os.path.exists(os.path.join(scrpath, 'rst2html.py')):
        print 'Unable to find rst2html'
        print 'easy_install docutils'
        sys.exit(1)

    msgfmt = util.find_exe('msgfmt')
    if not msgfmt:
        found = try_paths([r'\GnuWin32\bin\msgfmt.exe'])
        if found:
            path.append(os.path.dirname(found))
        else:
            print 'Unable to find msgfmt.  Please download from'
            print 'http://gnuwin32.sourceforge.net/packages/gettext.htm'
            sys.exit(1)

    if 'WIX' in installenv:
        path.append(installenv['WIX'] + 'bin')
    else:
        print 'Unable to find WIX.  Please download from'
        print 'http://sourceforge.net/projects/wix/files/'
        sys.exit(1)

    installenv['PATH'] = os.pathsep.join(path)
    installenv['DISTUTILS_USE_SDK'] = '1'


def verify_doc_env():
    global installenv

    try:
        from mercurial import hg, ui, util
    except ImportError:
        print 'Mercurial must be installed as Python source.'
        print 'You can get this from http://bitbucket.org/tortoisehg/thg-winbuild/downloads/'
        print 'Look for a package like: mercurial-1.4.3.win32-py2.6.exe\n'
        print 'Or simply build it yourself.'
        sys.exit(1)

    path = installenv.get('PATH', '').split(os.pathsep)
    scrpath = os.path.dirname(sys.executable) + os.sep + 'Scripts'
    path.append(scrpath)

    # Find HTML Help compiler, add to path
    hhc = util.find_exe('hhc')
    if not hhc:
        found = try_paths([r'\HTML Help Workshop\hhc.exe'])
        if found:
            path.append(os.path.dirname(found))
        else:
            print 'Unable to find HTML Help Workshop'
            print 'http://gnuwin32.sourceforge.net/packages/gettext.htm'
            sys.exit(1)
    # Find MiKTex, add to path
    pdflatex = util.find_exe('pdflatex')
    if not pdflatex:
        found = try_paths([r'\MiKTeX 2.7\miktex\bin\Pdflatex.exe',
                           r'\MiKTeX 2.8\miktex\bin\Pdflatex.exe'])
        if found:
            path.append(os.path.dirname(found))
        else:
            print 'Unable to find MiKTeX'
            print 'http://miktex.org/2.8/setup'
            sys.exit(1)
    # Verify sphinx
    if not os.path.exists(os.path.join(scrpath, 'sphinx-build.exe')):
        print 'Unable to find sphinx'
        print 'easy_install sphinx'
        sys.exit(1)
    installenv['PATH'] = os.pathsep.join(path)


def verify_thg_env():
    global installenv

    try:
        from mercurial import hg, ui, util
    except ImportError:
        print 'Mercurial must be installed as Python source.'
        print 'You can get this from http://bitbucket.org/tortoisehg/thg-winbuild/downloads/'
        print 'Look for a package like: mercurial-1.4.3.win32-py2.6.exe\n'
        print 'Or simply build it yourself.'
        sys.exit(1)

    # Verify GTK
    if not os.path.exists(os.path.join(gtkpath, 'bin', '')):
        print 'Unable to find GTK, please install and/or set GTK_PATH'
        sys.exit(1)

    # Verify iniparse
    try:
        import iniparse
    except ImportError:
        print 'iniparse not found:'
        print 'easy_install --always-unzip iniparse'
        sys.exit(1)

    oldpath = os.environ.get('PYTHONPATH', '')
    installenv['PYTHONPATH'] = '../build-hg;../keyring;../dulwich;'+oldpath

def usage(code, msg=''):
    print >> sys.stderr, __doc__
    if msg:
        print >> sys.stderr, msg
    sys.exit(code)

if len(sys.argv) < 2:
    usage(0)

try:
    opts, args = getopt.getopt(sys.argv[1:], 'hcfF',
          ['clean', 'forcehg', 'forcethg',
           'thg-release', 'thg-stable', 'thg-unstable', 'thg-doc',
           'hg-release', 'hg-stable', 'hg-unstable',
           'pull', 'nopull', 'config', 'all', 'cert='])
except getopt.error, msg:
    usage(1, msg)

# parse options
for opt, arg in opts:
    if opt in ('-h', '--help'):
        usage(0)
    elif opt in ('-f', '--force-hg'):
        forcehg = True
    elif opt in ('-F', '--force-thg'):
        forcethg = True
    elif opt in ('-c', '--clean'):
        run(r'if exist build-hg rmdir /s /q build-hg')
        run(r'if exist build-thg rmdir /s /q build-thg')
        sys.exit(0)
    elif opt == '--thg-doc':
        checkrepo('tortoisehg')
        builddoc = True
    elif opt == '--thg-release':
        for r in thg_source_repos:
            checkrepo(r)
        if dopull is None:
            dopull = True
        buildthg = True
        thgbranch = 'stable'
        thgtag = lasttag('tortoisehg')
        hgbranch = 'stable'
        hgtag = lasttag('hg-main')
        packagename = 'tortoisehg'
    elif opt == '--thg-stable':
        for r in thg_source_repos:
            checkrepo(r)
        if dopull is None:
            dopull = True
        buildthg = True
        thgbranch = 'stable'
        thgtag = 'tip'
        hgbranch = 'stable'
        hgtag = 'tip'
        packagename = 'tortoisehg-stable'
    elif opt == '--thg-unstable':
        for r in thg_source_repos:
            checkrepo(r)
        if dopull is None:
            dopull = True
        buildthg = True
        thgbranch = 'default'
        thgtag = 'tip'
        hgbranch = 'default'
        hgtag = 'tip'
        packagename = 'tortoisehg-unstable'
    elif opt == '--hg-release':
        checkrepo('hg-main')
        buildhg = True
        hgbranch = 'stable'
        hgtag = lasttag('hg-main')
        packagename = 'mercurial'
    elif opt == '--hg-stable':
        checkrepo('hg-main')
        if dopull is None:
            dopull = True
        buildhg = True
        hgbranch = 'stable'
        hgtag = 'tip'
        packagename = 'mercurial-stable'
    elif opt == '--hg-unstable':
        checkrepo('hg-main')
        if dopull is None:
            dopull = True
        buildhg = True
        hgbranch = 'default'
        hgtag = 'tip'
        packagename = 'mercurial-unstable'
    elif opt == '--pull':
        dopull = True
    elif opt == '--nopull':
        dopull = False
    elif opt == '--config':
        showconfig = True
    elif opt == '--cert':
        cert = os.path.abspath(arg)
    elif opt == '--all':
        all = True
        if dopull is None:
            dopull = True

print 'Build config:'
print '[tortoisehg] branch=%s, tag=%s' % (thgbranch, thgtag)
print '[mercurial]  branch=%s, tag=%s\n' % (hgbranch, hgtag)

if showconfig:
    sys.exit(0)

if cert is not None:
    pwd = getpass.getpass('password for signing: ')

if dopull:
    run(r'hg -R hg-main pull')
    if buildthg or all:
        run(r'hg -R tortoisehg pull')
        from mercurial import ui, hg
        out = 'extension-versions.txt'
        f = open(out, 'w')
        f.write('Extensions/modules included in this TortoiseHg package:\n\n')
        for ext in extensions:
            run(r'hg -R %s pull -u' % ext)
            if ext == 'dulwich':
                # We need a specific version of dulwich, which is
                # currently untagged
                run(r'hg -R dulwich update aed0e4ad31f4')
            repo = hg.repository(ui.ui(), path=ext)
            f.write('%12s:\t%s\t%s\n' % (ext, str(repo['.']), URL[ext]))
        try:
            from svn import core
            ver = '%d.%d.%d' % (core.SVN_VER_MAJOR, core.SVN_VER_MINOR, core.SVN_VER_MICRO)
            url = 'http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=8100'
            f.write('%12s:\t%-12s\t%s\n' % ('python-svn', ver, url))
        except ImportError:
            pass
        try:
            import pygments
            ver = pygments.__version__
            url = 'http://pygments.org/download/'
            f.write('%12s:\t%-12s\t%s\n' % ('pygments', ver, url))
        except ImportError:
            pass
        pywin32file = sys.prefix + r'\lib\site-packages\pywin32.version.txt'
        if os.path.exists(pywin32file):
            ver = open(pywin32file, 'r').read().strip()
            url = 'http://sourceforge.net/projects/pywin32/'
            f.write('%12s:\t%-12s\t%s\n' % ('pywin32', ver, url))
        f.close()

if not os.path.isdir('output'):
    run(r'mkdir output')

if all:
    verify_hg_env()
    verify_doc_env()
    verify_thg_env()
    run(r'title Building hg-stable...')
    build_hg(True, 'stable', 'tip')
    build_hg_installer('mercurial-stable')
    run(r'title Building hg-unstable...')
    build_hg(False, 'default', 'tip')
    build_hg_installer('mercurial-unstable')
    run(r'title Building thg-stable...')
    productid = str(uuid.uuid4()).upper()
    build_hg(False, 'stable', 'tip')
    build_thg(True, 'stable', 'tip', 'tortoisehg-stable', productid)
    build_thg_installer('tortoisehg-stable', productid)
    run(r'title Building thg-unstable...')
    productid = str(uuid.uuid4()).upper()
    build_hg(False, 'default', 'tip')
    build_thg(True, 'default', 'tip', 'tortoisehg-unstable', productid)
    build_thg_installer('tortoisehg-unstable', productid)
elif builddoc:
    verify_doc_env()
    build_thg_docs()
elif buildhg:
    verify_hg_env()
    build_hg(forcehg, hgbranch, hgtag)
    build_hg_installer(packagename)
elif buildthg:
    verify_hg_env()
    verify_doc_env()
    verify_thg_env()
    build_hg(forcehg, hgbranch, hgtag)
    productid = str(uuid.uuid4()).upper()
    build_thg(forcethg, thgbranch, thgtag, packagename, productid)
    build_thg_installer(packagename, productid)