contrib/packaging/hgpackaging/cli.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Mon, 06 Dec 2021 10:23:51 +0100
branchstable
changeset 48434 d4c084160434
parent 47881 39ab4c2f38b4
child 48848 17d5e25b8e78
permissions -rw-r--r--
test-upgrade: narrow the `debugformat` call when upgrading to dirstate-v2 This will make the test less noisy when new requirement are added. Differential Revision: https://phab.mercurial-scm.org/D11864
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
43513
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     1
# cli.py - Command line interface for automation
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     2
#
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     3
# Copyright 2019 Gregory Szorc <gregory.szorc@gmail.com>
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     4
#
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     5
# This software may be used and distributed according to the terms of the
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     6
# GNU General Public License version 2 or any later version.
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     7
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     8
# no-check-code because Python 3 native.
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     9
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    10
import argparse
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    11
import os
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    12
import pathlib
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    13
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    14
from . import (
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    15
    inno,
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    16
    wix,
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    17
)
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    18
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    19
HERE = pathlib.Path(os.path.abspath(os.path.dirname(__file__)))
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    20
SOURCE_DIR = HERE.parent.parent.parent
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    21
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    22
44763
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43513
diff changeset
    23
def build_inno(pyoxidizer_target=None, python=None, iscc=None, version=None):
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43513
diff changeset
    24
    if not pyoxidizer_target and not python:
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43513
diff changeset
    25
        raise Exception("--python required unless building with PyOxidizer")
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43513
diff changeset
    26
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43513
diff changeset
    27
    if python and not os.path.isabs(python):
43513
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    28
        raise Exception("--python arg must be an absolute path")
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    29
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    30
    if iscc:
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    31
        iscc = pathlib.Path(iscc)
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    32
    else:
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    33
        iscc = (
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    34
            pathlib.Path(os.environ["ProgramFiles(x86)"])
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    35
            / "Inno Setup 5"
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    36
            / "ISCC.exe"
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    37
        )
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    38
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    39
    build_dir = SOURCE_DIR / "build"
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    40
44763
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43513
diff changeset
    41
    if pyoxidizer_target:
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43513
diff changeset
    42
        inno.build_with_pyoxidizer(
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43513
diff changeset
    43
            SOURCE_DIR, build_dir, pyoxidizer_target, iscc, version=version
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43513
diff changeset
    44
        )
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43513
diff changeset
    45
    else:
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43513
diff changeset
    46
        inno.build_with_py2exe(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44767
diff changeset
    47
            SOURCE_DIR,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44767
diff changeset
    48
            build_dir,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44767
diff changeset
    49
            pathlib.Path(python),
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44767
diff changeset
    50
            iscc,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44767
diff changeset
    51
            version=version,
44763
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43513
diff changeset
    52
        )
43513
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    53
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    54
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    55
def build_wix(
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    56
    name=None,
44767
234882d17814 packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44765
diff changeset
    57
    pyoxidizer_target=None,
43513
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    58
    python=None,
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    59
    version=None,
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    60
    sign_sn=None,
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    61
    sign_cert=None,
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    62
    sign_password=None,
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    63
    sign_timestamp_url=None,
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    64
    extra_packages_script=None,
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    65
    extra_wxs=None,
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    66
    extra_features=None,
47644
be37bb8d0c7c packaging: add command line flag to add extra vars to pyoxidizer
Augie Fackler <augie@google.com>
parents: 45942
diff changeset
    67
    extra_pyoxidizer_vars=None,
43513
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    68
):
44767
234882d17814 packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44765
diff changeset
    69
    if not pyoxidizer_target and not python:
234882d17814 packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44765
diff changeset
    70
        raise Exception("--python required unless building with PyOxidizer")
234882d17814 packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44765
diff changeset
    71
234882d17814 packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44765
diff changeset
    72
    if python and not os.path.isabs(python):
234882d17814 packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44765
diff changeset
    73
        raise Exception("--python arg must be an absolute path")
234882d17814 packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44765
diff changeset
    74
43513
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    75
    kwargs = {
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    76
        "source_dir": SOURCE_DIR,
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    77
        "version": version,
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    78
    }
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    79
44767
234882d17814 packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44765
diff changeset
    80
    if pyoxidizer_target:
234882d17814 packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44765
diff changeset
    81
        fn = wix.build_installer_pyoxidizer
234882d17814 packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44765
diff changeset
    82
        kwargs["target_triple"] = pyoxidizer_target
47881
39ab4c2f38b4 packaging: pass extra_pyoxidizer_vars only to pyoxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 47644
diff changeset
    83
        kwargs["extra_pyoxidizer_vars"] = extra_pyoxidizer_vars
44767
234882d17814 packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44765
diff changeset
    84
    else:
234882d17814 packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44765
diff changeset
    85
        fn = wix.build_installer_py2exe
234882d17814 packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44765
diff changeset
    86
        kwargs["python_exe"] = pathlib.Path(python)
43513
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    87
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    88
    if extra_packages_script:
44767
234882d17814 packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44765
diff changeset
    89
        if pyoxidizer_target:
234882d17814 packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44765
diff changeset
    90
            raise Exception(
234882d17814 packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44765
diff changeset
    91
                "pyoxidizer does not support --extra-packages-script"
234882d17814 packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44765
diff changeset
    92
            )
43513
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    93
        kwargs["extra_packages_script"] = extra_packages_script
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    94
    if extra_wxs:
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    95
        kwargs["extra_wxs"] = dict(
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    96
            thing.split("=") for thing in extra_wxs.split(",")
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    97
        )
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    98
    if extra_features:
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    99
        kwargs["extra_features"] = extra_features.split(",")
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   100
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   101
    if sign_sn or sign_cert:
44765
a39984091380 packaging: integrate signing into run_wix_packaging()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44763
diff changeset
   102
        kwargs["signing_info"] = {
a39984091380 packaging: integrate signing into run_wix_packaging()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44763
diff changeset
   103
            "name": name,
a39984091380 packaging: integrate signing into run_wix_packaging()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44763
diff changeset
   104
            "subject_name": sign_sn,
a39984091380 packaging: integrate signing into run_wix_packaging()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44763
diff changeset
   105
            "cert_path": sign_cert,
a39984091380 packaging: integrate signing into run_wix_packaging()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44763
diff changeset
   106
            "cert_password": sign_password,
a39984091380 packaging: integrate signing into run_wix_packaging()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44763
diff changeset
   107
            "timestamp_url": sign_timestamp_url,
a39984091380 packaging: integrate signing into run_wix_packaging()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44763
diff changeset
   108
        }
43513
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   109
47881
39ab4c2f38b4 packaging: pass extra_pyoxidizer_vars only to pyoxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 47644
diff changeset
   110
    fn(**kwargs)
43513
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   111
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   112
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   113
def get_parser():
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   114
    parser = argparse.ArgumentParser()
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   115
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   116
    subparsers = parser.add_subparsers()
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   117
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   118
    sp = subparsers.add_parser("inno", help="Build Inno Setup installer")
44763
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43513
diff changeset
   119
    sp.add_argument(
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43513
diff changeset
   120
        "--pyoxidizer-target",
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43513
diff changeset
   121
        choices={"i686-pc-windows-msvc", "x86_64-pc-windows-msvc"},
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43513
diff changeset
   122
        help="Build with PyOxidizer targeting this host triple",
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43513
diff changeset
   123
    )
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43513
diff changeset
   124
    sp.add_argument("--python", help="path to python.exe to use")
43513
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   125
    sp.add_argument("--iscc", help="path to iscc.exe to use")
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   126
    sp.add_argument(
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   127
        "--version",
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   128
        help="Mercurial version string to use "
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   129
        "(detected from __version__.py if not defined",
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   130
    )
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   131
    sp.set_defaults(func=build_inno)
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   132
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   133
    sp = subparsers.add_parser(
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   134
        "wix", help="Build Windows installer with WiX Toolset"
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   135
    )
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   136
    sp.add_argument("--name", help="Application name", default="Mercurial")
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   137
    sp.add_argument(
44767
234882d17814 packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44765
diff changeset
   138
        "--pyoxidizer-target",
234882d17814 packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44765
diff changeset
   139
        choices={"i686-pc-windows-msvc", "x86_64-pc-windows-msvc"},
234882d17814 packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44765
diff changeset
   140
        help="Build with PyOxidizer targeting this host triple",
43513
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   141
    )
44767
234882d17814 packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44765
diff changeset
   142
    sp.add_argument("--python", help="Path to Python executable to use")
43513
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   143
    sp.add_argument(
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   144
        "--sign-sn",
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   145
        help="Subject name (or fragment thereof) of certificate "
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   146
        "to use for signing",
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   147
    )
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   148
    sp.add_argument(
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   149
        "--sign-cert", help="Path to certificate to use for signing"
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   150
    )
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   151
    sp.add_argument("--sign-password", help="Password for signing certificate")
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   152
    sp.add_argument(
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   153
        "--sign-timestamp-url",
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   154
        help="URL of timestamp server to use for signing",
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   155
    )
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   156
    sp.add_argument("--version", help="Version string to use")
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   157
    sp.add_argument(
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   158
        "--extra-packages-script",
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   159
        help=(
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   160
            "Script to execute to include extra packages in " "py2exe binary."
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   161
        ),
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   162
    )
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   163
    sp.add_argument(
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   164
        "--extra-wxs", help="CSV of path_to_wxs_file=working_dir_for_wxs_file"
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   165
    )
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   166
    sp.add_argument(
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   167
        "--extra-features",
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   168
        help=(
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   169
            "CSV of extra feature names to include "
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   170
            "in the installer from the extra wxs files"
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   171
        ),
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   172
    )
47644
be37bb8d0c7c packaging: add command line flag to add extra vars to pyoxidizer
Augie Fackler <augie@google.com>
parents: 45942
diff changeset
   173
be37bb8d0c7c packaging: add command line flag to add extra vars to pyoxidizer
Augie Fackler <augie@google.com>
parents: 45942
diff changeset
   174
    sp.add_argument(
be37bb8d0c7c packaging: add command line flag to add extra vars to pyoxidizer
Augie Fackler <augie@google.com>
parents: 45942
diff changeset
   175
        "--extra-pyoxidizer-vars",
be37bb8d0c7c packaging: add command line flag to add extra vars to pyoxidizer
Augie Fackler <augie@google.com>
parents: 45942
diff changeset
   176
        help="json map of extra variables to pass to pyoxidizer",
be37bb8d0c7c packaging: add command line flag to add extra vars to pyoxidizer
Augie Fackler <augie@google.com>
parents: 45942
diff changeset
   177
    )
be37bb8d0c7c packaging: add command line flag to add extra vars to pyoxidizer
Augie Fackler <augie@google.com>
parents: 45942
diff changeset
   178
43513
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   179
    sp.set_defaults(func=build_wix)
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   180
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   181
    return parser
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   182
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   183
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   184
def main():
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   185
    parser = get_parser()
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   186
    args = parser.parse_args()
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   187
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   188
    if not hasattr(args, "func"):
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   189
        parser.print_help()
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   190
        return
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   191
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   192
    kwargs = dict(vars(args))
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   193
    del kwargs["func"]
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   194
081a77df7bc6 packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   195
    args.func(**kwargs)