annotate contrib/packaging/hgpackaging/inno.py @ 45752:d270b9b797a7 stable

contrib: split Windows requirements into multiple files Package support for Python 2 has diverged significantly. It is no longer trivial to maintain a single requirements file that supports both Python 2 and 3 because the set of packages and versions varies wildly. This commit split up the Windows requirements files so we have variants for Python 2 and 3. As part of this, I also renamed the files to have what I believe to be more reasonable naming ("win32" felt like a weird identifier to me). We can see that some package versions decreated on 2.7. This is because the old pinned versions weren't compatible with Python 2.
author Gregory Szorc <gregory.szorc@gmail.com>
date Wed, 21 Oct 2020 21:53:19 -0700
parents 9ade217b550d
children 89a2afe31e82
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
41911
dc7827a9ba64 packaging: move Inno Setup core logic into a module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41910
diff changeset
1 # inno.py - Inno Setup functionality.
41853
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
2 #
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
3 # Copyright 2019 Gregory Szorc <gregory.szorc@gmail.com>
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
4 #
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
5 # This software may be used and distributed according to the terms of the
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
6 # GNU General Public License version 2 or any later version.
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
7
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
8 # no-check-code because Python 3 native.
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
9
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
10 import os
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
11 import pathlib
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
12 import shutil
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
13 import subprocess
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
14
43515
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
15 import jinja2
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
16
43516
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
17 from .py2exe import (
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
18 build_py2exe,
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
19 stage_install,
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
20 )
44763
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44762
diff changeset
21 from .pyoxidizer import run_pyoxidizer
43518
7c9f63a5cb14 packaging: always pass VERSION into Inno invocation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43517
diff changeset
22 from .util import (
44763
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44762
diff changeset
23 find_legacy_vc_runtime_files,
44221
f37971c31067 packaging: set the FileVersion field in the Inno installer executable
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
24 normalize_windows_version,
44222
a8786727e478 packaging: bundle the default mercurial.ini template with Inno also
Matt Harbison <matt_harbison@yahoo.com>
parents: 44221
diff changeset
25 process_install_rules,
43518
7c9f63a5cb14 packaging: always pass VERSION into Inno invocation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43517
diff changeset
26 read_version_py,
7c9f63a5cb14 packaging: always pass VERSION into Inno invocation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43517
diff changeset
27 )
41911
dc7827a9ba64 packaging: move Inno Setup core logic into a module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41910
diff changeset
28
41916
260305e8ddbd setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41915
diff changeset
29 EXTRA_PACKAGES = {
260305e8ddbd setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41915
diff changeset
30 'dulwich',
260305e8ddbd setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41915
diff changeset
31 'keyring',
260305e8ddbd setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41915
diff changeset
32 'pygments',
260305e8ddbd setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41915
diff changeset
33 'win32ctypes',
260305e8ddbd setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41915
diff changeset
34 }
260305e8ddbd setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41915
diff changeset
35
44222
a8786727e478 packaging: bundle the default mercurial.ini template with Inno also
Matt Harbison <matt_harbison@yahoo.com>
parents: 44221
diff changeset
36 EXTRA_INSTALL_RULES = [
a8786727e478 packaging: bundle the default mercurial.ini template with Inno also
Matt Harbison <matt_harbison@yahoo.com>
parents: 44221
diff changeset
37 ('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: 44221
diff changeset
38 ]
a8786727e478 packaging: bundle the default mercurial.ini template with Inno also
Matt Harbison <matt_harbison@yahoo.com>
parents: 44221
diff changeset
39
43516
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
40 PACKAGE_FILES_METADATA = {
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
41 'ReadMe.html': 'Flags: isreadme',
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
42 }
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
43
41916
260305e8ddbd setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41915
diff changeset
44
44763
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44762
diff changeset
45 def build_with_py2exe(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41916
diff changeset
46 source_dir: pathlib.Path,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41916
diff changeset
47 build_dir: pathlib.Path,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41916
diff changeset
48 python_exe: pathlib.Path,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41916
diff changeset
49 iscc_exe: pathlib.Path,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41916
diff changeset
50 version=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41916
diff changeset
51 ):
44763
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44762
diff changeset
52 """Build the Inno installer using py2exe.
41853
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
53
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
54 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
55
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
56 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
57 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
58 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
59 """
41911
dc7827a9ba64 packaging: move Inno Setup core logic into a module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41910
diff changeset
60 if not iscc_exe.exists():
dc7827a9ba64 packaging: move Inno Setup core logic into a module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41910
diff changeset
61 raise Exception('%s does not exist' % iscc_exe)
41853
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
62
41915
a2e191a937a9 packaging: extract py2exe functionality to own module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41914
diff changeset
63 vc_x64 = r'\x64' in os.environ.get('LIB', '')
43514
10454e788111 packaging: install and run Inno files in a build directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
64 arch = 'x64' if vc_x64 else 'x86'
44762
eec66d9c9e50 packaging: split Inno installer building from Mercurial building
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44224
diff changeset
65 inno_build_dir = build_dir / ('inno-py2exe-%s' % arch)
43516
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
66 staging_dir = inno_build_dir / 'stage'
41853
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: 41916
diff changeset
68 requirements_txt = (
45752
d270b9b797a7 contrib: split Windows requirements into multiple files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44769
diff changeset
69 source_dir / 'contrib' / 'packaging' / 'requirements-windows-py2.txt'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41916
diff changeset
70 )
41853
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
71
43514
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: 41916
diff changeset
74 build_py2exe(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41916
diff changeset
75 source_dir,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41916
diff changeset
76 build_dir,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41916
diff changeset
77 python_exe,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41916
diff changeset
78 'inno',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41916
diff changeset
79 requirements_txt,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41916
diff changeset
80 extra_packages=EXTRA_PACKAGES,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41916
diff changeset
81 )
41853
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
82
43516
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
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: 43515
diff changeset
84 # pristine.
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
85 if staging_dir.exists():
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
86 print('purging %s' % staging_dir)
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
87 shutil.rmtree(staging_dir)
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
88
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
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: 43515
diff changeset
90 stage_install(source_dir, staging_dir)
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
91
44222
a8786727e478 packaging: bundle the default mercurial.ini template with Inno also
Matt Harbison <matt_harbison@yahoo.com>
parents: 44221
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: 44221
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: 44221
diff changeset
94
41913
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41912
diff changeset
95 # hg.exe depends on VC9 runtime DLLs. Copy those into place.
44763
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44762
diff changeset
96 for f in find_legacy_vc_runtime_files(vc_x64):
41913
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41912
diff changeset
97 if f.name.endswith('.manifest'):
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41912
diff changeset
98 basename = 'Microsoft.VC90.CRT.manifest'
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41912
diff changeset
99 else:
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41912
diff changeset
100 basename = f.name
41853
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
101
43516
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
102 dest_path = staging_dir / basename
41853
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
103
41913
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41912
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: 41912
diff changeset
105 shutil.copyfile(f, dest_path)
41853
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
106
44762
eec66d9c9e50 packaging: split Inno installer building from Mercurial building
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44224
diff changeset
107 build_installer(
eec66d9c9e50 packaging: split Inno installer building from Mercurial building
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44224
diff changeset
108 source_dir,
eec66d9c9e50 packaging: split Inno installer building from Mercurial building
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44224
diff changeset
109 inno_build_dir,
eec66d9c9e50 packaging: split Inno installer building from Mercurial building
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44224
diff changeset
110 staging_dir,
eec66d9c9e50 packaging: split Inno installer building from Mercurial building
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44224
diff changeset
111 iscc_exe,
eec66d9c9e50 packaging: split Inno installer building from Mercurial building
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44224
diff changeset
112 version,
eec66d9c9e50 packaging: split Inno installer building from Mercurial building
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44224
diff changeset
113 arch="x64" if vc_x64 else None,
44769
9ade217b550d packaging: add -python2 to Windows installer filenames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44763
diff changeset
114 suffix="-python2",
44762
eec66d9c9e50 packaging: split Inno installer building from Mercurial building
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44224
diff changeset
115 )
eec66d9c9e50 packaging: split Inno installer building from Mercurial building
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44224
diff changeset
116
eec66d9c9e50 packaging: split Inno installer building from Mercurial building
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44224
diff changeset
117
44763
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44762
diff changeset
118 def build_with_pyoxidizer(
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44762
diff changeset
119 source_dir: pathlib.Path,
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44762
diff changeset
120 build_dir: pathlib.Path,
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44762
diff changeset
121 target_triple: str,
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44762
diff changeset
122 iscc_exe: pathlib.Path,
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44762
diff changeset
123 version=None,
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44762
diff changeset
124 ):
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44762
diff changeset
125 """Build the Inno installer using PyOxidizer."""
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44762
diff changeset
126 if not iscc_exe.exists():
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44762
diff changeset
127 raise Exception("%s does not exist" % iscc_exe)
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44762
diff changeset
128
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44762
diff changeset
129 inno_build_dir = build_dir / ("inno-pyoxidizer-%s" % target_triple)
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44762
diff changeset
130 staging_dir = inno_build_dir / "stage"
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44762
diff changeset
131
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44762
diff changeset
132 inno_build_dir.mkdir(parents=True, exist_ok=True)
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44762
diff changeset
133 run_pyoxidizer(source_dir, inno_build_dir, staging_dir, target_triple)
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44762
diff changeset
134
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44762
diff changeset
135 process_install_rules(EXTRA_INSTALL_RULES, source_dir, staging_dir)
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44762
diff changeset
136
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44762
diff changeset
137 build_installer(
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44762
diff changeset
138 source_dir,
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44762
diff changeset
139 inno_build_dir,
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44762
diff changeset
140 staging_dir,
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44762
diff changeset
141 iscc_exe,
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44762
diff changeset
142 version,
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44762
diff changeset
143 arch="x64" if "x86_64" in target_triple else None,
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44762
diff changeset
144 )
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44762
diff changeset
145
94f4f2ec7dee packaging: support building Inno installer with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44762
diff changeset
146
44762
eec66d9c9e50 packaging: split Inno installer building from Mercurial building
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44224
diff changeset
147 def build_installer(
eec66d9c9e50 packaging: split Inno installer building from Mercurial building
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44224
diff changeset
148 source_dir: pathlib.Path,
eec66d9c9e50 packaging: split Inno installer building from Mercurial building
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44224
diff changeset
149 inno_build_dir: pathlib.Path,
eec66d9c9e50 packaging: split Inno installer building from Mercurial building
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44224
diff changeset
150 staging_dir: pathlib.Path,
eec66d9c9e50 packaging: split Inno installer building from Mercurial building
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44224
diff changeset
151 iscc_exe: pathlib.Path,
eec66d9c9e50 packaging: split Inno installer building from Mercurial building
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44224
diff changeset
152 version,
eec66d9c9e50 packaging: split Inno installer building from Mercurial building
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44224
diff changeset
153 arch=None,
44769
9ade217b550d packaging: add -python2 to Windows installer filenames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44763
diff changeset
154 suffix="",
44762
eec66d9c9e50 packaging: split Inno installer building from Mercurial building
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44224
diff changeset
155 ):
eec66d9c9e50 packaging: split Inno installer building from Mercurial building
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44224
diff changeset
156 """Build an Inno installer from staged Mercurial files.
eec66d9c9e50 packaging: split Inno installer building from Mercurial building
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44224
diff changeset
157
eec66d9c9e50 packaging: split Inno installer building from Mercurial building
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44224
diff changeset
158 This function is agnostic about how to build Mercurial. It just
eec66d9c9e50 packaging: split Inno installer building from Mercurial building
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44224
diff changeset
159 cares that Mercurial files are in ``staging_dir``.
eec66d9c9e50 packaging: split Inno installer building from Mercurial building
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44224
diff changeset
160 """
eec66d9c9e50 packaging: split Inno installer building from Mercurial building
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44224
diff changeset
161 inno_source_dir = source_dir / "contrib" / "packaging" / "inno"
eec66d9c9e50 packaging: split Inno installer building from Mercurial building
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44224
diff changeset
162
43516
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
163 # The final package layout is simply a mirror of the staging directory.
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
164 package_files = []
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
165 for root, dirs, files in os.walk(staging_dir):
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
166 dirs.sort()
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
167
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
168 root = pathlib.Path(root)
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
169
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
170 for f in sorted(files):
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
171 full = root / f
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
172 rel = full.relative_to(staging_dir)
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
173 if str(rel.parent) == '.':
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
174 dest_dir = '{app}'
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
175 else:
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
176 dest_dir = '{app}\\%s' % rel.parent
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
177
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
178 package_files.append(
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
179 {
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
180 'source': rel,
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
181 'dest_dir': dest_dir,
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
182 'metadata': PACKAGE_FILES_METADATA.get(str(rel), None),
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
183 }
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
184 )
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
185
41913
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41912
diff changeset
186 print('creating installer')
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41912
diff changeset
187
43515
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
188 # Install Inno files by rendering a template.
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
189 jinja_env = jinja2.Environment(
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
190 loader=jinja2.FileSystemLoader(str(inno_source_dir)),
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
191 # Need to change these to prevent conflict with Inno Setup.
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
192 comment_start_string='{##',
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
193 comment_end_string='##}',
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
194 )
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
195
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
196 try:
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
197 template = jinja_env.get_template('mercurial.iss')
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
198 except jinja2.TemplateSyntaxError as e:
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
199 raise Exception(
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
200 'template syntax error at %s:%d: %s'
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
201 % (e.name, e.lineno, e.message,)
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
202 )
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
203
43516
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
204 content = template.render(package_files=package_files)
43515
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
205
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
206 with (inno_build_dir / 'mercurial.iss').open('w', encoding='utf-8') as fh:
7bd88d0d6a82 packaging: process Inno Setup files with Jinja2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43514
diff changeset
207 fh.write(content)
43514
10454e788111 packaging: install and run Inno files in a build directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
208
43516
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
209 # Copy additional files used by Inno.
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
210 for p in ('mercurial.ico', 'postinstall.txt'):
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
211 shutil.copyfile(
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
212 source_dir / 'contrib' / 'win32' / p, inno_build_dir / p
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
213 )
d053d3f10b6a packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43515
diff changeset
214
41913
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41912
diff changeset
215 args = [str(iscc_exe)]
41853
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
216
44762
eec66d9c9e50 packaging: split Inno installer building from Mercurial building
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44224
diff changeset
217 if arch:
eec66d9c9e50 packaging: split Inno installer building from Mercurial building
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44224
diff changeset
218 args.append('/dARCH=%s' % arch)
44769
9ade217b550d packaging: add -python2 to Windows installer filenames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44763
diff changeset
219 args.append('/dSUFFIX=-%s%s' % (arch, suffix))
9ade217b550d packaging: add -python2 to Windows installer filenames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44763
diff changeset
220 else:
9ade217b550d packaging: add -python2 to Windows installer filenames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44763
diff changeset
221 args.append('/dSUFFIX=-x86%s' % suffix)
41853
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
222
43518
7c9f63a5cb14 packaging: always pass VERSION into Inno invocation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43517
diff changeset
223 if not version:
7c9f63a5cb14 packaging: always pass VERSION into Inno invocation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43517
diff changeset
224 version = read_version_py(source_dir)
7c9f63a5cb14 packaging: always pass VERSION into Inno invocation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43517
diff changeset
225
7c9f63a5cb14 packaging: always pass VERSION into Inno invocation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43517
diff changeset
226 args.append('/dVERSION=%s' % version)
44221
f37971c31067 packaging: set the FileVersion field in the Inno installer executable
Matt Harbison <matt_harbison@yahoo.com>
parents: 43518
diff changeset
227 args.append('/dQUAD_VERSION=%s' % normalize_windows_version(version))
41853
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
228
41913
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41912
diff changeset
229 args.append('/Odist')
43514
10454e788111 packaging: install and run Inno files in a build directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
230 args.append(str(inno_build_dir / 'mercurial.iss'))
41853
d7dc4ac1ff84 inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
231
41913
5e923355c595 packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41912
diff changeset
232 subprocess.run(args, cwd=str(source_dir), check=True)