| 1 |
# cli.py - Command line interface for automation |
| 2 |
# |
| 3 |
# Copyright 2019 Gregory Szorc <[email protected]> |
| 4 |
# |
| 5 |
# This software may be used and distributed according to the terms of the |
| 6 |
# GNU General Public License version 2 or any later version. |
| 7 |
|
| 8 |
# no-check-code because Python 3 native. |
| 9 |
|
| 10 |
import argparse |
| 11 |
import os |
| 12 |
import pathlib |
| 13 |
|
| 14 |
from . import ( |
| 15 |
inno, |
| 16 |
wix, |
| 17 |
) |
| 18 |
|
| 19 |
HERE = pathlib.Path(os.path.abspath(os.path.dirname(__file__))) |
| 20 |
SOURCE_DIR = HERE.parent.parent.parent |
| 21 |
|
| 22 |
|
| 23 |
def build_inno(pyoxidizer_target, iscc=None, version=None): |
| 24 |
if iscc: |
| 25 |
iscc = pathlib.Path(iscc) |
| 26 |
else: |
| 27 |
iscc = ( |
| 28 |
pathlib.Path(os.environ["ProgramFiles(x86)"]) |
| 29 |
/ "Inno Setup 5" |
| 30 |
/ "ISCC.exe" |
| 31 |
) |
| 32 |
|
| 33 |
build_dir = SOURCE_DIR / "build" |
| 34 |
|
| 35 |
inno.build_with_pyoxidizer( |
| 36 |
SOURCE_DIR, build_dir, pyoxidizer_target, iscc, version=version |
| 37 |
) |
| 38 |
|
| 39 |
|
| 40 |
def build_wix( |
| 41 |
pyoxidizer_target, |
| 42 |
name=None, |
| 43 |
version=None, |
| 44 |
sign_sn=None, |
| 45 |
sign_cert=None, |
| 46 |
sign_password=None, |
| 47 |
sign_timestamp_url=None, |
| 48 |
extra_wxs=None, |
| 49 |
extra_features=None, |
| 50 |
extra_pyoxidizer_vars=None, |
| 51 |
): |
| 52 |
kwargs = { |
| 53 |
"source_dir": SOURCE_DIR, |
| 54 |
"version": version, |
| 55 |
"target_triple": pyoxidizer_target, |
| 56 |
"extra_pyoxidizer_vars": extra_pyoxidizer_vars, |
| 57 |
} |
| 58 |
|
| 59 |
if extra_wxs: |
| 60 |
kwargs["extra_wxs"] = dict( |
| 61 |
thing.split("=") for thing in extra_wxs.split(",") |
| 62 |
) |
| 63 |
if extra_features: |
| 64 |
kwargs["extra_features"] = extra_features.split(",") |
| 65 |
|
| 66 |
if sign_sn or sign_cert: |
| 67 |
kwargs["signing_info"] = { |
| 68 |
"name": name, |
| 69 |
"subject_name": sign_sn, |
| 70 |
"cert_path": sign_cert, |
| 71 |
"cert_password": sign_password, |
| 72 |
"timestamp_url": sign_timestamp_url, |
| 73 |
} |
| 74 |
|
| 75 |
wix.build_installer_pyoxidizer(**kwargs) |
| 76 |
|
| 77 |
|
| 78 |
def get_parser(): |
| 79 |
parser = argparse.ArgumentParser() |
| 80 |
|
| 81 |
subparsers = parser.add_subparsers() |
| 82 |
|
| 83 |
sp = subparsers.add_parser("inno", help="Build Inno Setup installer") |
| 84 |
sp.add_argument( |
| 85 |
"--pyoxidizer-target", |
| 86 |
choices={"i686-pc-windows-msvc", "x86_64-pc-windows-msvc"}, |
| 87 |
required=True, |
| 88 |
help="Build with PyOxidizer targeting this host triple", |
| 89 |
) |
| 90 |
sp.add_argument("--iscc", help="path to iscc.exe to use") |
| 91 |
sp.add_argument( |
| 92 |
"--version", |
| 93 |
help="Mercurial version string to use " |
| 94 |
"(detected from __version__.py if not defined)", |
| 95 |
) |
| 96 |
sp.set_defaults(func=build_inno) |
| 97 |
|
| 98 |
sp = subparsers.add_parser( |
| 99 |
"wix", help="Build Windows installer with WiX Toolset" |
| 100 |
) |
| 101 |
sp.add_argument("--name", help="Application name", default="Mercurial") |
| 102 |
sp.add_argument( |
| 103 |
"--pyoxidizer-target", |
| 104 |
choices={"i686-pc-windows-msvc", "x86_64-pc-windows-msvc"}, |
| 105 |
required=True, |
| 106 |
help="Build with PyOxidizer targeting this host triple", |
| 107 |
) |
| 108 |
sp.add_argument( |
| 109 |
"--sign-sn", |
| 110 |
help="Subject name (or fragment thereof) of certificate " |
| 111 |
"to use for signing", |
| 112 |
) |
| 113 |
sp.add_argument( |
| 114 |
"--sign-cert", help="Path to certificate to use for signing" |
| 115 |
) |
| 116 |
sp.add_argument("--sign-password", help="Password for signing certificate") |
| 117 |
sp.add_argument( |
| 118 |
"--sign-timestamp-url", |
| 119 |
help="URL of timestamp server to use for signing", |
| 120 |
) |
| 121 |
sp.add_argument("--version", help="Version string to use") |
| 122 |
sp.add_argument( |
| 123 |
"--extra-wxs", help="CSV of path_to_wxs_file=working_dir_for_wxs_file" |
| 124 |
) |
| 125 |
sp.add_argument( |
| 126 |
"--extra-features", |
| 127 |
help=( |
| 128 |
"CSV of extra feature names to include " |
| 129 |
"in the installer from the extra wxs files" |
| 130 |
), |
| 131 |
) |
| 132 |
|
| 133 |
sp.add_argument( |
| 134 |
"--extra-pyoxidizer-vars", |
| 135 |
help="json map of extra variables to pass to pyoxidizer", |
| 136 |
) |
| 137 |
|
| 138 |
sp.set_defaults(func=build_wix) |
| 139 |
|
| 140 |
return parser |
| 141 |
|
| 142 |
|
| 143 |
def main(): |
| 144 |
parser = get_parser() |
| 145 |
args = parser.parse_args() |
| 146 |
|
| 147 |
if not hasattr(args, "func"): |
| 148 |
parser.print_help() |
| 149 |
return |
| 150 |
|
| 151 |
kwargs = dict(vars(args)) |
| 152 |
del kwargs["func"] |
| 153 |
|
| 154 |
args.func(**kwargs) |