contrib/packaging/hgpackaging/util.py
author Matt Harbison <matt_harbison@yahoo.com>
Sat, 01 Feb 2020 00:32:46 -0500
branchstable
changeset 44220 a70108a3d7cc
parent 43518 7c9f63a5cb14
child 44763 94f4f2ec7dee
permissions -rw-r--r--
packaging: move the version normalization function to the util module This will be used with Inno as well. Since this module isn't platform specific, rename to include that this is meant for Windows. (Mac has a different format.) Differential Revision: https://phab.mercurial-scm.org/D8059
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
     1
# util.py - Common packaging utility code.
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
     2
#
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
     3
# Copyright 2019 Gregory Szorc <gregory.szorc@gmail.com>
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
     4
#
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
     5
# This software may be used and distributed according to the terms of the
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
     6
# GNU General Public License version 2 or any later version.
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
     7
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
     8
# no-check-code because Python 3 native.
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
     9
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    10
import distutils.version
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    11
import getpass
43516
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
    12
import glob
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    13
import os
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    14
import pathlib
43518
7c9f63a5cb14 packaging: always pass VERSION into Inno invocation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43516
diff changeset
    15
import re
43516
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
    16
import shutil
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    17
import subprocess
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    18
import tarfile
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    19
import zipfile
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    20
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    21
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    22
def extract_tar_to_directory(source: pathlib.Path, dest: pathlib.Path):
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    23
    with tarfile.open(source, 'r') as tf:
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    24
        tf.extractall(dest)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    25
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    26
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    27
def extract_zip_to_directory(source: pathlib.Path, dest: pathlib.Path):
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    28
    with zipfile.ZipFile(source, 'r') as zf:
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    29
        zf.extractall(dest)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    30
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    31
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    32
def find_vc_runtime_files(x64=False):
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    33
    """Finds Visual C++ Runtime DLLs to include in distribution."""
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    34
    winsxs = pathlib.Path(os.environ['SYSTEMROOT']) / 'WinSxS'
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    35
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    36
    prefix = 'amd64' if x64 else 'x86'
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    37
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42090
diff changeset
    38
    candidates = sorted(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42090
diff changeset
    39
        p
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42090
diff changeset
    40
        for p in os.listdir(winsxs)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42090
diff changeset
    41
        if p.lower().startswith('%s_microsoft.vc90.crt_' % prefix)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42090
diff changeset
    42
    )
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    43
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    44
    for p in candidates:
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    45
        print('found candidate VC runtime: %s' % p)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    46
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    47
    # Take the newest version.
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    48
    version = candidates[-1]
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    49
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    50
    d = winsxs / version
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    51
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    52
    return [
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    53
        d / 'msvcm90.dll',
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    54
        d / 'msvcp90.dll',
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    55
        d / 'msvcr90.dll',
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    56
        winsxs / 'Manifests' / ('%s.manifest' % version),
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    57
    ]
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    58
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    59
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    60
def windows_10_sdk_info():
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    61
    """Resolves information about the Windows 10 SDK."""
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    62
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    63
    base = pathlib.Path(os.environ['ProgramFiles(x86)']) / 'Windows Kits' / '10'
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    64
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    65
    if not base.is_dir():
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    66
        raise Exception('unable to find Windows 10 SDK at %s' % base)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    67
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    68
    # Find the latest version.
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    69
    bin_base = base / 'bin'
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    70
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    71
    versions = [v for v in os.listdir(bin_base) if v.startswith('10.')]
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    72
    version = sorted(versions, reverse=True)[0]
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    73
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    74
    bin_version = bin_base / version
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    75
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    76
    return {
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    77
        'root': base,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    78
        'version': version,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    79
        'bin_root': bin_version,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    80
        'bin_x86': bin_version / 'x86',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42090
diff changeset
    81
        'bin_x64': bin_version / 'x64',
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    82
    }
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    83
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
    84
44220
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
    85
def normalize_windows_version(version):
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
    86
    """Normalize Mercurial version string so WiX/Inno accepts it.
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
    87
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
    88
    Version strings have to be numeric ``A.B.C[.D]`` to conform with MSI's
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
    89
    requirements.
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
    90
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
    91
    We normalize RC version or the commit count to a 4th version component.
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
    92
    We store this in the 4th component because ``A.B.C`` releases do occur
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
    93
    and we want an e.g. ``5.3rc0`` version to be semantically less than a
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
    94
    ``5.3.1rc2`` version. This requires always reserving the 3rd version
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
    95
    component for the point release and the ``X.YrcN`` release is always
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
    96
    point release 0.
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
    97
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
    98
    In the case of an RC and presence of ``+`` suffix data, we can't use both
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
    99
    because the version format is limited to 4 components. We choose to use
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   100
    RC and throw away the commit count in the suffix. This means we could
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   101
    produce multiple installers with the same normalized version string.
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   102
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   103
    >>> normalize_windows_version("5.3")
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   104
    '5.3.0'
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   105
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   106
    >>> normalize_windows_version("5.3rc0")
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   107
    '5.3.0.0'
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   108
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   109
    >>> normalize_windows_version("5.3rc1")
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   110
    '5.3.0.1'
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   111
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   112
    >>> normalize_windows_version("5.3rc1+2-abcdef")
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   113
    '5.3.0.1'
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   114
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   115
    >>> normalize_windows_version("5.3+2-abcdef")
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   116
    '5.3.0.2'
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   117
    """
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   118
    if '+' in version:
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   119
        version, extra = version.split('+', 1)
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   120
    else:
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   121
        extra = None
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   122
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   123
    # 4.9rc0
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   124
    if version[:-1].endswith('rc'):
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   125
        rc = int(version[-1:])
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   126
        version = version[:-3]
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   127
    else:
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   128
        rc = None
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   129
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   130
    # Ensure we have at least X.Y version components.
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   131
    versions = [int(v) for v in version.split('.')]
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   132
    while len(versions) < 3:
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   133
        versions.append(0)
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   134
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   135
    if len(versions) < 4:
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   136
        if rc is not None:
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   137
            versions.append(rc)
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   138
        elif extra:
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   139
            # <commit count>-<hash>+<date>
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   140
            versions.append(int(extra.split('-')[0]))
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   141
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   142
    return '.'.join('%d' % x for x in versions[0:4])
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   143
a70108a3d7cc packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
   144
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   145
def find_signtool():
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   146
    """Find signtool.exe from the Windows SDK."""
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   147
    sdk = windows_10_sdk_info()
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   148
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   149
    for key in ('bin_x64', 'bin_x86'):
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   150
        p = sdk[key] / 'signtool.exe'
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   151
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   152
        if p.exists():
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   153
            return p
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   154
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   155
    raise Exception('could not find signtool.exe in Windows 10 SDK')
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   156
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   157
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42090
diff changeset
   158
def sign_with_signtool(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42090
diff changeset
   159
    file_path,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42090
diff changeset
   160
    description,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42090
diff changeset
   161
    subject_name=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42090
diff changeset
   162
    cert_path=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42090
diff changeset
   163
    cert_password=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42090
diff changeset
   164
    timestamp_url=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42090
diff changeset
   165
):
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   166
    """Digitally sign a file with signtool.exe.
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   167
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   168
    ``file_path`` is file to sign.
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   169
    ``description`` is text that goes in the signature.
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   170
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   171
    The signing certificate can be specified by ``cert_path`` or
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   172
    ``subject_name``. These correspond to the ``/f`` and ``/n`` arguments
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   173
    to signtool.exe, respectively.
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   174
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   175
    The certificate password can be specified via ``cert_password``. If
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   176
    not provided, you will be prompted for the password.
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   177
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   178
    ``timestamp_url`` is the URL of a RFC 3161 timestamp server (``/tr``
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   179
    argument to signtool.exe).
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   180
    """
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   181
    if cert_path and subject_name:
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   182
        raise ValueError('cannot specify both cert_path and subject_name')
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   183
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   184
    while cert_path and not cert_password:
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   185
        cert_password = getpass.getpass('password for %s: ' % cert_path)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   186
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   187
    args = [
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42090
diff changeset
   188
        str(find_signtool()),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42090
diff changeset
   189
        'sign',
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   190
        '/v',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42090
diff changeset
   191
        '/fd',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42090
diff changeset
   192
        'sha256',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42090
diff changeset
   193
        '/d',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42090
diff changeset
   194
        description,
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   195
    ]
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   196
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   197
    if cert_path:
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   198
        args.extend(['/f', str(cert_path), '/p', cert_password])
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   199
    elif subject_name:
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   200
        args.extend(['/n', subject_name])
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   201
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   202
    if timestamp_url:
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   203
        args.extend(['/tr', timestamp_url, '/td', 'sha256'])
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   204
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   205
    args.append(str(file_path))
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   206
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   207
    print('signing %s' % file_path)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   208
    subprocess.run(args, check=True)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   209
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   210
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   211
PRINT_PYTHON_INFO = '''
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   212
import platform; print("%s:%s" % (platform.architecture()[0], platform.python_version()))
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   213
'''.strip()
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   214
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   215
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   216
def python_exe_info(python_exe: pathlib.Path):
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   217
    """Obtain information about a Python executable."""
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   218
42090
9c07d345fd6d packaging: don't crash building wix with python3.6 and earlier
Matt Harbison <matt_harbison@yahoo.com>
parents: 41952
diff changeset
   219
    res = subprocess.check_output([str(python_exe), '-c', PRINT_PYTHON_INFO])
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   220
42090
9c07d345fd6d packaging: don't crash building wix with python3.6 and earlier
Matt Harbison <matt_harbison@yahoo.com>
parents: 41952
diff changeset
   221
    arch, version = res.decode('utf-8').split(':')
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   222
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   223
    version = distutils.version.LooseVersion(version)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   224
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   225
    return {
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   226
        'arch': arch,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   227
        'version': version,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   228
        'py3': version >= distutils.version.LooseVersion('3'),
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
   229
    }
43516
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   230
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   231
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   232
def process_install_rules(
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   233
    rules: list, source_dir: pathlib.Path, dest_dir: pathlib.Path
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   234
):
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   235
    for source, dest in rules:
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   236
        if '*' in source:
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   237
            if not dest.endswith('/'):
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   238
                raise ValueError('destination must end in / when globbing')
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   239
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   240
            # We strip off the source path component before the first glob
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   241
            # character to construct the relative install path.
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   242
            prefix_end_index = source[: source.index('*')].rindex('/')
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   243
            relative_prefix = source_dir / source[0:prefix_end_index]
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   244
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   245
            for res in glob.glob(str(source_dir / source), recursive=True):
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   246
                source_path = pathlib.Path(res)
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   247
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   248
                if source_path.is_dir():
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   249
                    continue
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   250
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   251
                rel_path = source_path.relative_to(relative_prefix)
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   252
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   253
                dest_path = dest_dir / dest[:-1] / rel_path
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   254
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   255
                dest_path.parent.mkdir(parents=True, exist_ok=True)
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   256
                print('copying %s to %s' % (source_path, dest_path))
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   257
                shutil.copy(source_path, dest_path)
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   258
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   259
        # Simple file case.
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   260
        else:
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   261
            source_path = pathlib.Path(source)
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   262
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   263
            if dest.endswith('/'):
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   264
                dest_path = pathlib.Path(dest) / source_path.name
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   265
            else:
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   266
                dest_path = pathlib.Path(dest)
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   267
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   268
            full_source_path = source_dir / source_path
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   269
            full_dest_path = dest_dir / dest_path
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   270
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   271
            full_dest_path.parent.mkdir(parents=True, exist_ok=True)
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   272
            shutil.copy(full_source_path, full_dest_path)
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
   273
            print('copying %s to %s' % (full_source_path, full_dest_path))
43518
7c9f63a5cb14 packaging: always pass VERSION into Inno invocation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43516
diff changeset
   274
7c9f63a5cb14 packaging: always pass VERSION into Inno invocation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43516
diff changeset
   275
7c9f63a5cb14 packaging: always pass VERSION into Inno invocation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43516
diff changeset
   276
def read_version_py(source_dir):
7c9f63a5cb14 packaging: always pass VERSION into Inno invocation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43516
diff changeset
   277
    """Read the mercurial/__version__.py file to resolve the version string."""
7c9f63a5cb14 packaging: always pass VERSION into Inno invocation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43516
diff changeset
   278
    p = source_dir / 'mercurial' / '__version__.py'
7c9f63a5cb14 packaging: always pass VERSION into Inno invocation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43516
diff changeset
   279
7c9f63a5cb14 packaging: always pass VERSION into Inno invocation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43516
diff changeset
   280
    with p.open('r', encoding='utf-8') as fh:
7c9f63a5cb14 packaging: always pass VERSION into Inno invocation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43516
diff changeset
   281
        m = re.search('version = b"([^"]+)"', fh.read(), re.MULTILINE)
7c9f63a5cb14 packaging: always pass VERSION into Inno invocation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43516
diff changeset
   282
7c9f63a5cb14 packaging: always pass VERSION into Inno invocation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43516
diff changeset
   283
        if not m:
7c9f63a5cb14 packaging: always pass VERSION into Inno invocation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43516
diff changeset
   284
            raise Exception('could not parse %s' % p)
7c9f63a5cb14 packaging: always pass VERSION into Inno invocation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43516
diff changeset
   285
7c9f63a5cb14 packaging: always pass VERSION into Inno invocation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43516
diff changeset
   286
        return m.group(1)