contrib/packaging/hgpackaging/inno.py
author Gregory Szorc <gregory.szorc@gmail.com>
Wed, 23 Oct 2019 18:39:28 -0700
changeset 43516 d053d3f10b6a
parent 43515 7bd88d0d6a82
child 43517 24633444ff32
permissions -rw-r--r--
packaging: stage installed files for Inno Previously, the Inno installer maintained its own mapping of source files to install location. (We have to maintain a similar mapping in the WiX installer.) Managing the explicit file layout for Windows packages is cumbersome and redundant. Every time you want to change the layout you need to change N locations. We frequently forget to do this and we only find out when people install Mercurial from our packages at release time. This commit starts the process of consolidating and simplifying the logic for managing the install layout on Windows. We introduce a list of install layout rules. These are simply source filenames (which can contain wildcards) and destination paths. The Inno packaging code has been updated to assemble all files into a staging directory that mirrors the final install layout. The list of files to add to the installer is derived by walking this staging directory and dynamically emitting the proper entries for the Inno Setup script. I diffed the file layout before and after this commit and there is no difference. Another benefit of this change is that it facilitates easier testing of the Windows install layout. Before, in order to test the final install layout, you needed to build an installer and run it. Now, you can stage files into the final layout and test from there, without running the installer. This should cut down on overhead when changing Windows code. Differential Revision: https://phab.mercurial-scm.org/D7159
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41911
dc7827a9ba64 packaging: move Inno Setup core logic into a module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41910
diff changeset
     1
# inno.py - Inno Setup functionality.
41853
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
43515
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
    15
import jinja2
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
    16
43516
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
    17
from .py2exe import (
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
    18
    build_py2exe,
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
    19
    stage_install,
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
    20
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41916
diff changeset
    21
from .util import find_vc_runtime_files
41911
dc7827a9ba64 packaging: move Inno Setup core logic into a module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41910
diff changeset
    22
41916
260305e8ddbd setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41915
diff changeset
    23
EXTRA_PACKAGES = {
260305e8ddbd setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41915
diff changeset
    24
    'dulwich',
260305e8ddbd setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41915
diff changeset
    25
    'keyring',
260305e8ddbd setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41915
diff changeset
    26
    'pygments',
260305e8ddbd setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41915
diff changeset
    27
    'win32ctypes',
260305e8ddbd setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41915
diff changeset
    28
}
260305e8ddbd setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41915
diff changeset
    29
43516
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
    30
PACKAGE_FILES_METADATA = {
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
    31
    'ReadMe.html': 'Flags: isreadme',
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
    32
    'hg.exe': "AfterInstall: Touch('{app}\\hg.exe.local')",
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
    33
}
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
    34
41916
260305e8ddbd setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41915
diff changeset
    35
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41916
diff changeset
    36
def build(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41916
diff changeset
    37
    source_dir: pathlib.Path,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41916
diff changeset
    38
    build_dir: pathlib.Path,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41916
diff changeset
    39
    python_exe: pathlib.Path,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41916
diff changeset
    40
    iscc_exe: pathlib.Path,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41916
diff changeset
    41
    version=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41916
diff changeset
    42
):
41853
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    43
    """Build the Inno installer.
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    44
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    45
    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
    46
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    47
    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
    48
    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
    49
    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
    50
    """
41911
dc7827a9ba64 packaging: move Inno Setup core logic into a module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41910
diff changeset
    51
    if not iscc_exe.exists():
dc7827a9ba64 packaging: move Inno Setup core logic into a module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41910
diff changeset
    52
        raise Exception('%s does not exist' % iscc_exe)
41853
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    53
41915
a2e191a937a9 packaging: extract py2exe functionality to own module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41914
diff changeset
    54
    vc_x64 = r'\x64' in os.environ.get('LIB', '')
43514
10454e788111 packaging: install and run Inno files in a build directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
    55
    arch = 'x64' if vc_x64 else 'x86'
10454e788111 packaging: install and run Inno files in a build directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
    56
    inno_source_dir = source_dir / 'contrib' / 'packaging' / 'inno'
10454e788111 packaging: install and run Inno files in a build directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
    57
    inno_build_dir = build_dir / ('inno-%s' % arch)
43516
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
    58
    staging_dir = inno_build_dir / 'stage'
41853
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    59
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41916
diff changeset
    60
    requirements_txt = (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41916
diff changeset
    61
        source_dir / 'contrib' / 'packaging' / 'inno' / 'requirements.txt'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41916
diff changeset
    62
    )
41853
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    63
43514
10454e788111 packaging: install and run Inno files in a build directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
    64
    inno_build_dir.mkdir(parents=True, exist_ok=True)
10454e788111 packaging: install and run Inno files in a build directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
    65
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41916
diff changeset
    66
    build_py2exe(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41916
diff changeset
    67
        source_dir,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41916
diff changeset
    68
        build_dir,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41916
diff changeset
    69
        python_exe,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41916
diff changeset
    70
        'inno',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41916
diff changeset
    71
        requirements_txt,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41916
diff changeset
    72
        extra_packages=EXTRA_PACKAGES,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41916
diff changeset
    73
    )
41853
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    74
43516
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
    75
    # Purge the staging directory for every build so packaging is
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
    76
    # pristine.
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
    77
    if staging_dir.exists():
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
    78
        print('purging %s' % staging_dir)
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
    79
        shutil.rmtree(staging_dir)
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
    80
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
    81
    # Now assemble all the packaged files into the staging directory.
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
    82
    stage_install(source_dir, staging_dir)
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
    83
41913
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41912
diff changeset
    84
    # 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: 41912
diff changeset
    85
    for f in find_vc_runtime_files(vc_x64):
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41912
diff changeset
    86
        if f.name.endswith('.manifest'):
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41912
diff changeset
    87
            basename = 'Microsoft.VC90.CRT.manifest'
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41912
diff changeset
    88
        else:
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41912
diff changeset
    89
            basename = f.name
41853
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    90
43516
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
    91
        dest_path = staging_dir / basename
41853
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    92
41913
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41912
diff changeset
    93
        print('copying %s to %s' % (f, dest_path))
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41912
diff changeset
    94
        shutil.copyfile(f, dest_path)
41853
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    95
43516
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
    96
    # The final package layout is simply a mirror of the staging directory.
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
    97
    package_files = []
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
    98
    for root, dirs, files in os.walk(staging_dir):
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
    99
        dirs.sort()
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
   100
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
   101
        root = pathlib.Path(root)
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
   102
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
   103
        for f in sorted(files):
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
   104
            full = root / f
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
   105
            rel = full.relative_to(staging_dir)
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
   106
            if str(rel.parent) == '.':
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
   107
                dest_dir = '{app}'
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
   108
            else:
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
   109
                dest_dir = '{app}\\%s' % rel.parent
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
   110
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
   111
            package_files.append(
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
   112
                {
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
   113
                    'source': rel,
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
   114
                    'dest_dir': dest_dir,
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
   115
                    'metadata': PACKAGE_FILES_METADATA.get(str(rel), None),
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
   116
                }
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
   117
            )
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
   118
41913
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41912
diff changeset
   119
    print('creating installer')
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41912
diff changeset
   120
43515
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
   121
    # Install Inno files by rendering a template.
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
   122
    jinja_env = jinja2.Environment(
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
   123
        loader=jinja2.FileSystemLoader(str(inno_source_dir)),
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
   124
        # Need to change these to prevent conflict with Inno Setup.
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
   125
        comment_start_string='{##',
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
   126
        comment_end_string='##}',
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
   127
    )
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
   128
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
   129
    try:
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
   130
        template = jinja_env.get_template('mercurial.iss')
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
   131
    except jinja2.TemplateSyntaxError as e:
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
   132
        raise Exception(
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
   133
            'template syntax error at %s:%d: %s'
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
   134
            % (e.name, e.lineno, e.message,)
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
   135
        )
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
   136
43516
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
   137
    content = template.render(package_files=package_files)
43515
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
   138
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
   139
    with (inno_build_dir / 'mercurial.iss').open('w', encoding='utf-8') as fh:
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
   140
        fh.write(content)
43514
10454e788111 packaging: install and run Inno files in a build directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   141
43516
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
   142
    # Copy additional files used by Inno.
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
   143
    for p in ('mercurial.ico', 'postinstall.txt'):
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
   144
        shutil.copyfile(
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
   145
            source_dir / 'contrib' / 'win32' / p, inno_build_dir / p
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
   146
        )
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
   147
41913
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41912
diff changeset
   148
    args = [str(iscc_exe)]
41853
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   149
41913
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41912
diff changeset
   150
    if vc_x64:
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41912
diff changeset
   151
        args.append('/dARCH=x64')
41853
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   152
41913
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41912
diff changeset
   153
    if version:
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41912
diff changeset
   154
        args.append('/dVERSION=%s' % version)
41853
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   155
41913
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41912
diff changeset
   156
    args.append('/Odist')
43514
10454e788111 packaging: install and run Inno files in a build directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   157
    args.append(str(inno_build_dir / 'mercurial.iss'))
41853
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   158
41913
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41912
diff changeset
   159
    subprocess.run(args, cwd=str(source_dir), check=True)