contrib/packaging/hgpackaging/inno.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Thu, 14 Mar 2019 09:12:55 +0000
changeset 41968 6386f9a421d2
parent 41921 260305e8ddbd
child 43076 2372284d9457
permissions -rw-r--r--
manifestcache: clear the cache before testing the debug command Right now the cache is empty before this section of the test. However, we are about to improve the persistence of the cache (putting it under `wllock`, intead of `lock`). So we install the cleanup before.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41916
dc7827a9ba64 packaging: move Inno Setup core logic into a module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41915
diff changeset
     1
# inno.py - Inno Setup functionality.
41858
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     2
#
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     3
# Copyright 2019 Gregory Szorc <gregory.szorc@gmail.com>
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     4
#
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     5
# This software may be used and distributed according to the terms of the
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     6
# GNU General Public License version 2 or any later version.
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     7
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     8
# no-check-code because Python 3 native.
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     9
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    10
import os
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    11
import pathlib
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    12
import shutil
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    13
import subprocess
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    14
41920
a2e191a937a9 packaging: extract py2exe functionality to own module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41919
diff changeset
    15
from .py2exe import (
a2e191a937a9 packaging: extract py2exe functionality to own module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41919
diff changeset
    16
    build_py2exe,
41916
dc7827a9ba64 packaging: move Inno Setup core logic into a module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41915
diff changeset
    17
)
dc7827a9ba64 packaging: move Inno Setup core logic into a module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41915
diff changeset
    18
from .util import (
dc7827a9ba64 packaging: move Inno Setup core logic into a module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41915
diff changeset
    19
    find_vc_runtime_files,
dc7827a9ba64 packaging: move Inno Setup core logic into a module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41915
diff changeset
    20
)
dc7827a9ba64 packaging: move Inno Setup core logic into a module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41915
diff changeset
    21
41858
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    22
41921
260305e8ddbd setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41920
diff changeset
    23
EXTRA_PACKAGES = {
260305e8ddbd setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41920
diff changeset
    24
    'dulwich',
260305e8ddbd setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41920
diff changeset
    25
    'keyring',
260305e8ddbd setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41920
diff changeset
    26
    'pygments',
260305e8ddbd setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41920
diff changeset
    27
    'win32ctypes',
260305e8ddbd setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41920
diff changeset
    28
}
260305e8ddbd setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41920
diff changeset
    29
260305e8ddbd setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41920
diff changeset
    30
41858
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    31
def build(source_dir: pathlib.Path, build_dir: pathlib.Path,
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    32
          python_exe: pathlib.Path, iscc_exe: pathlib.Path,
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    33
          version=None):
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    34
    """Build the Inno installer.
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    35
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    36
    Build files will be placed in ``build_dir``.
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    37
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    38
    py2exe's setup.py doesn't use setuptools. It doesn't have modern logic
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    39
    for finding the Python 2.7 toolchain. So, we require the environment
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    40
    to already be configured with an active toolchain.
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    41
    """
41916
dc7827a9ba64 packaging: move Inno Setup core logic into a module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41915
diff changeset
    42
    if not iscc_exe.exists():
dc7827a9ba64 packaging: move Inno Setup core logic into a module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41915
diff changeset
    43
        raise Exception('%s does not exist' % iscc_exe)
41858
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    44
41920
a2e191a937a9 packaging: extract py2exe functionality to own module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41919
diff changeset
    45
    vc_x64 = r'\x64' in os.environ.get('LIB', '')
41858
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    46
41918
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41917
diff changeset
    47
    requirements_txt = (source_dir / 'contrib' / 'packaging' /
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41917
diff changeset
    48
                        'inno' / 'requirements.txt')
41858
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    49
41920
a2e191a937a9 packaging: extract py2exe functionality to own module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41919
diff changeset
    50
    build_py2exe(source_dir, build_dir, python_exe, 'inno',
41921
260305e8ddbd setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41920
diff changeset
    51
                 requirements_txt, extra_packages=EXTRA_PACKAGES)
41858
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    52
41918
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41917
diff changeset
    53
    # hg.exe depends on VC9 runtime DLLs. Copy those into place.
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41917
diff changeset
    54
    for f in find_vc_runtime_files(vc_x64):
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41917
diff changeset
    55
        if f.name.endswith('.manifest'):
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41917
diff changeset
    56
            basename = 'Microsoft.VC90.CRT.manifest'
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41917
diff changeset
    57
        else:
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41917
diff changeset
    58
            basename = f.name
41858
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    59
41918
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41917
diff changeset
    60
        dest_path = source_dir / 'dist' / basename
41858
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    61
41918
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41917
diff changeset
    62
        print('copying %s to %s' % (f, dest_path))
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41917
diff changeset
    63
        shutil.copyfile(f, dest_path)
41858
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    64
41918
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41917
diff changeset
    65
    print('creating installer')
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41917
diff changeset
    66
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41917
diff changeset
    67
    args = [str(iscc_exe)]
41858
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    68
41918
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41917
diff changeset
    69
    if vc_x64:
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41917
diff changeset
    70
        args.append('/dARCH=x64')
41858
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    71
41918
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41917
diff changeset
    72
    if version:
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41917
diff changeset
    73
        args.append('/dVERSION=%s' % version)
41858
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    74
41918
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41917
diff changeset
    75
    args.append('/Odist')
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41917
diff changeset
    76
    args.append('contrib/packaging/inno/mercurial.iss')
41858
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    77
41918
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41917
diff changeset
    78
    subprocess.run(args, cwd=str(source_dir), check=True)