contrib/packaging/hgpackaging/inno.py
author Matt Harbison <matt_harbison@yahoo.com>
Sun, 16 Feb 2020 16:13:36 -0500
changeset 44560 bbb170f9396d
parent 44153 e2589b9e4562
child 44747 eec66d9c9e50
permissions -rw-r--r--
phabricator: add a `phabimport` command I've had `alias.phabimport = $hg phabread --stack $1 | $hg import --bypass -` for a while now, and I suspect others do too. That's limited though, in that it can't use the information on Phabricator to restore it in the original location, so I'm making it a first class command. This doesn't do anything ambitious like that- this is mostly a simplification of `hg import` to get the equivalent of the alias mentioned above. The `--bypass` option is hardcoded to be enabled and the message about amending rejects dropped (rejects aren't created with `--bypass`), because editing patches on Phabricator seems like an unusual workflow. This will need other options, like `--obsolete` and `--secret`. I think these would be more useful as config settings, as I imagine the workflows are pretty fixed depending on roles. Reviewers who don't queue patches probably never want `--obsolete`, but may need `--secret`. Reviewers who do will want the former, but not the latter. I left `--stack` as an option, but that should probably be a config knob too (or at least default to on)- if the point of this is to avoid rejects, it doesn't make sense to skip dependencies in most cases. Evolve is going to need a fix to its wrapping of `cmdutil.tryimportone()`, as it currently assumes `opts` has an `obsolete` key. It's worked around for now. Differential Revision: https://phab.mercurial-scm.org/D8136
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
43563
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43562
diff changeset
    15
import jinja2
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43562
diff changeset
    16
43564
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
    17
from .py2exe import (
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
    18
    build_py2exe,
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
    19
    stage_install,
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
    20
)
43566
7c9f63a5cb14 packaging: always pass VERSION into Inno invocation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43565
diff changeset
    21
from .util import (
7c9f63a5cb14 packaging: always pass VERSION into Inno invocation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43565
diff changeset
    22
    find_vc_runtime_files,
44150
f37971c31067 packaging: set the FileVersion field in the Inno installer executable
Matt Harbison <matt_harbison@yahoo.com>
parents: 43566
diff changeset
    23
    normalize_windows_version,
44151
a8786727e478 packaging: bundle the default mercurial.ini template with Inno also
Matt Harbison <matt_harbison@yahoo.com>
parents: 44150
diff changeset
    24
    process_install_rules,
43566
7c9f63a5cb14 packaging: always pass VERSION into Inno invocation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43565
diff changeset
    25
    read_version_py,
7c9f63a5cb14 packaging: always pass VERSION into Inno invocation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43565
diff changeset
    26
)
41916
dc7827a9ba64 packaging: move Inno Setup core logic into a module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41915
diff changeset
    27
41921
260305e8ddbd setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41920
diff changeset
    28
EXTRA_PACKAGES = {
260305e8ddbd setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41920
diff changeset
    29
    'dulwich',
260305e8ddbd setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41920
diff changeset
    30
    'keyring',
260305e8ddbd setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41920
diff changeset
    31
    'pygments',
260305e8ddbd setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41920
diff changeset
    32
    'win32ctypes',
260305e8ddbd setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41920
diff changeset
    33
}
260305e8ddbd setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41920
diff changeset
    34
44151
a8786727e478 packaging: bundle the default mercurial.ini template with Inno also
Matt Harbison <matt_harbison@yahoo.com>
parents: 44150
diff changeset
    35
EXTRA_INSTALL_RULES = [
a8786727e478 packaging: bundle the default mercurial.ini template with Inno also
Matt Harbison <matt_harbison@yahoo.com>
parents: 44150
diff changeset
    36
    ('contrib/win32/mercurial.ini', 'defaultrc/mercurial.rc'),
a8786727e478 packaging: bundle the default mercurial.ini template with Inno also
Matt Harbison <matt_harbison@yahoo.com>
parents: 44150
diff changeset
    37
]
a8786727e478 packaging: bundle the default mercurial.ini template with Inno also
Matt Harbison <matt_harbison@yahoo.com>
parents: 44150
diff changeset
    38
43564
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
    39
PACKAGE_FILES_METADATA = {
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
    40
    'ReadMe.html': 'Flags: isreadme',
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
    41
}
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
    42
41921
260305e8ddbd setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41920
diff changeset
    43
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41921
diff changeset
    44
def build(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41921
diff changeset
    45
    source_dir: pathlib.Path,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41921
diff changeset
    46
    build_dir: pathlib.Path,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41921
diff changeset
    47
    python_exe: pathlib.Path,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41921
diff changeset
    48
    iscc_exe: pathlib.Path,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41921
diff changeset
    49
    version=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41921
diff changeset
    50
):
41858
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    51
    """Build the Inno installer.
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    52
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    53
    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
    54
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    55
    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
    56
    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
    57
    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
    58
    """
41916
dc7827a9ba64 packaging: move Inno Setup core logic into a module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41915
diff changeset
    59
    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
    60
        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
    61
41920
a2e191a937a9 packaging: extract py2exe functionality to own module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41919
diff changeset
    62
    vc_x64 = r'\x64' in os.environ.get('LIB', '')
43562
10454e788111 packaging: install and run Inno files in a build directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
    63
    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
    64
    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
    65
    inno_build_dir = build_dir / ('inno-%s' % arch)
43564
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
    66
    staging_dir = inno_build_dir / 'stage'
41858
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    67
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41921
diff changeset
    68
    requirements_txt = (
44153
e2589b9e4562 packaging: merge the requirements.txt files for WiX and Inno
Matt Harbison <matt_harbison@yahoo.com>
parents: 44151
diff changeset
    69
        source_dir / 'contrib' / 'packaging' / 'requirements_win32.txt'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41921
diff changeset
    70
    )
41858
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    71
43562
10454e788111 packaging: install and run Inno files in a build directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
    72
    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
    73
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41921
diff changeset
    74
    build_py2exe(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41921
diff changeset
    75
        source_dir,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41921
diff changeset
    76
        build_dir,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41921
diff changeset
    77
        python_exe,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41921
diff changeset
    78
        'inno',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41921
diff changeset
    79
        requirements_txt,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41921
diff changeset
    80
        extra_packages=EXTRA_PACKAGES,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41921
diff changeset
    81
    )
41858
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    82
43564
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
    83
    # Purge the staging directory for every build so packaging is
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
    84
    # pristine.
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
    85
    if staging_dir.exists():
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
    86
        print('purging %s' % staging_dir)
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
    87
        shutil.rmtree(staging_dir)
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
    88
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
    89
    # Now assemble all the packaged files into the staging directory.
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
    90
    stage_install(source_dir, staging_dir)
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
    91
44151
a8786727e478 packaging: bundle the default mercurial.ini template with Inno also
Matt Harbison <matt_harbison@yahoo.com>
parents: 44150
diff changeset
    92
    # We also install some extra files.
a8786727e478 packaging: bundle the default mercurial.ini template with Inno also
Matt Harbison <matt_harbison@yahoo.com>
parents: 44150
diff changeset
    93
    process_install_rules(EXTRA_INSTALL_RULES, source_dir, staging_dir)
a8786727e478 packaging: bundle the default mercurial.ini template with Inno also
Matt Harbison <matt_harbison@yahoo.com>
parents: 44150
diff changeset
    94
41918
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41917
diff changeset
    95
    # 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
    96
    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
    97
        if f.name.endswith('.manifest'):
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41917
diff changeset
    98
            basename = 'Microsoft.VC90.CRT.manifest'
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41917
diff changeset
    99
        else:
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41917
diff changeset
   100
            basename = f.name
41858
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   101
43564
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
   102
        dest_path = staging_dir / basename
41858
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   103
41918
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41917
diff changeset
   104
        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
   105
        shutil.copyfile(f, dest_path)
41858
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   106
43564
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
   107
    # 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: 43563
diff changeset
   108
    package_files = []
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
   109
    for root, dirs, files in os.walk(staging_dir):
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
   110
        dirs.sort()
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
   111
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
   112
        root = pathlib.Path(root)
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
   113
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
   114
        for f in sorted(files):
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
   115
            full = root / f
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
   116
            rel = full.relative_to(staging_dir)
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
   117
            if str(rel.parent) == '.':
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
   118
                dest_dir = '{app}'
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
   119
            else:
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
   120
                dest_dir = '{app}\\%s' % rel.parent
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
   121
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
   122
            package_files.append(
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
   123
                {
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
   124
                    'source': rel,
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
   125
                    'dest_dir': dest_dir,
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
   126
                    'metadata': PACKAGE_FILES_METADATA.get(str(rel), None),
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
   127
                }
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
   128
            )
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
   129
41918
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41917
diff changeset
   130
    print('creating installer')
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41917
diff changeset
   131
43563
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43562
diff changeset
   132
    # Install Inno files by rendering a template.
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43562
diff changeset
   133
    jinja_env = jinja2.Environment(
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43562
diff changeset
   134
        loader=jinja2.FileSystemLoader(str(inno_source_dir)),
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43562
diff changeset
   135
        # 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: 43562
diff changeset
   136
        comment_start_string='{##',
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43562
diff changeset
   137
        comment_end_string='##}',
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43562
diff changeset
   138
    )
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43562
diff changeset
   139
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43562
diff changeset
   140
    try:
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43562
diff changeset
   141
        template = jinja_env.get_template('mercurial.iss')
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43562
diff changeset
   142
    except jinja2.TemplateSyntaxError as e:
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43562
diff changeset
   143
        raise Exception(
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43562
diff changeset
   144
            'template syntax error at %s:%d: %s'
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43562
diff changeset
   145
            % (e.name, e.lineno, e.message,)
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43562
diff changeset
   146
        )
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43562
diff changeset
   147
43564
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
   148
    content = template.render(package_files=package_files)
43563
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43562
diff changeset
   149
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43562
diff changeset
   150
    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: 43562
diff changeset
   151
        fh.write(content)
43562
10454e788111 packaging: install and run Inno files in a build directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   152
43564
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
   153
    # Copy additional files used by Inno.
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
   154
    for p in ('mercurial.ico', 'postinstall.txt'):
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
   155
        shutil.copyfile(
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
   156
            source_dir / 'contrib' / 'win32' / p, inno_build_dir / p
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
   157
        )
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43563
diff changeset
   158
41918
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41917
diff changeset
   159
    args = [str(iscc_exe)]
41858
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   160
41918
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41917
diff changeset
   161
    if vc_x64:
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41917
diff changeset
   162
        args.append('/dARCH=x64')
41858
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   163
43566
7c9f63a5cb14 packaging: always pass VERSION into Inno invocation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43565
diff changeset
   164
    if not version:
7c9f63a5cb14 packaging: always pass VERSION into Inno invocation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43565
diff changeset
   165
        version = read_version_py(source_dir)
7c9f63a5cb14 packaging: always pass VERSION into Inno invocation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43565
diff changeset
   166
7c9f63a5cb14 packaging: always pass VERSION into Inno invocation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43565
diff changeset
   167
    args.append('/dVERSION=%s' % version)
44150
f37971c31067 packaging: set the FileVersion field in the Inno installer executable
Matt Harbison <matt_harbison@yahoo.com>
parents: 43566
diff changeset
   168
    args.append('/dQUAD_VERSION=%s' % normalize_windows_version(version))
41858
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   169
41918
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41917
diff changeset
   170
    args.append('/Odist')
43562
10454e788111 packaging: install and run Inno files in a build directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   171
    args.append(str(inno_build_dir / 'mercurial.iss'))
41858
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   172
41918
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41917
diff changeset
   173
    subprocess.run(args, cwd=str(source_dir), check=True)