author | Kyle Lippincott <spectral@google.com> |
Tue, 30 Mar 2021 13:05:22 -0700 | |
changeset 46871 | 887f89b100ac |
parent 46363 | d6cfe45afb18 |
permissions | -rw-r--r-- |
41915
a2e191a937a9
packaging: extract py2exe functionality to own module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41914
diff
changeset
|
1 |
# py2exe.py - Functionality for performing py2exe builds. |
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 subprocess |
d7dc4ac1ff84
inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
13 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
14 |
from .downloads import download_entry |
41911
dc7827a9ba64
packaging: move Inno Setup core logic into a module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41910
diff
changeset
|
15 |
from .util import ( |
dc7827a9ba64
packaging: move Inno Setup core logic into a module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41910
diff
changeset
|
16 |
extract_tar_to_directory, |
dc7827a9ba64
packaging: move Inno Setup core logic into a module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41910
diff
changeset
|
17 |
extract_zip_to_directory, |
43516
d053d3f10b6a
packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
18 |
process_install_rules, |
41914
7d1211168863
packaging: extract python exe info to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41913
diff
changeset
|
19 |
python_exe_info, |
41911
dc7827a9ba64
packaging: move Inno Setup core logic into a module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41910
diff
changeset
|
20 |
) |
dc7827a9ba64
packaging: move Inno Setup core logic into a module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41910
diff
changeset
|
21 |
|
41853
d7dc4ac1ff84
inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
22 |
|
43516
d053d3f10b6a
packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
23 |
STAGING_RULES = [ |
44225
4aedef6d51ad
packaging: lowercase the `contrib` and `templates` directories with Inno
Matt Harbison <matt_harbison@yahoo.com>
parents:
44153
diff
changeset
|
24 |
('contrib/bash_completion', 'contrib/'), |
4aedef6d51ad
packaging: lowercase the `contrib` and `templates` directories with Inno
Matt Harbison <matt_harbison@yahoo.com>
parents:
44153
diff
changeset
|
25 |
('contrib/hgk', 'contrib/hgk.tcl'), |
4aedef6d51ad
packaging: lowercase the `contrib` and `templates` directories with Inno
Matt Harbison <matt_harbison@yahoo.com>
parents:
44153
diff
changeset
|
26 |
('contrib/hgweb.fcgi', 'contrib/'), |
4aedef6d51ad
packaging: lowercase the `contrib` and `templates` directories with Inno
Matt Harbison <matt_harbison@yahoo.com>
parents:
44153
diff
changeset
|
27 |
('contrib/hgweb.wsgi', 'contrib/'), |
4aedef6d51ad
packaging: lowercase the `contrib` and `templates` directories with Inno
Matt Harbison <matt_harbison@yahoo.com>
parents:
44153
diff
changeset
|
28 |
('contrib/logo-droplets.svg', 'contrib/'), |
4aedef6d51ad
packaging: lowercase the `contrib` and `templates` directories with Inno
Matt Harbison <matt_harbison@yahoo.com>
parents:
44153
diff
changeset
|
29 |
('contrib/mercurial.el', 'contrib/'), |
4aedef6d51ad
packaging: lowercase the `contrib` and `templates` directories with Inno
Matt Harbison <matt_harbison@yahoo.com>
parents:
44153
diff
changeset
|
30 |
('contrib/mq.el', 'contrib/'), |
4aedef6d51ad
packaging: lowercase the `contrib` and `templates` directories with Inno
Matt Harbison <matt_harbison@yahoo.com>
parents:
44153
diff
changeset
|
31 |
('contrib/tcsh_completion', 'contrib/'), |
4aedef6d51ad
packaging: lowercase the `contrib` and `templates` directories with Inno
Matt Harbison <matt_harbison@yahoo.com>
parents:
44153
diff
changeset
|
32 |
('contrib/tcsh_completion_build.sh', 'contrib/'), |
4aedef6d51ad
packaging: lowercase the `contrib` and `templates` directories with Inno
Matt Harbison <matt_harbison@yahoo.com>
parents:
44153
diff
changeset
|
33 |
('contrib/vim/*', 'contrib/vim/'), |
43516
d053d3f10b6a
packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
34 |
('contrib/win32/postinstall.txt', 'ReleaseNotes.txt'), |
d053d3f10b6a
packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
35 |
('contrib/win32/ReadMe.html', 'ReadMe.html'), |
44225
4aedef6d51ad
packaging: lowercase the `contrib` and `templates` directories with Inno
Matt Harbison <matt_harbison@yahoo.com>
parents:
44153
diff
changeset
|
36 |
('contrib/xml.rnc', 'contrib/'), |
4aedef6d51ad
packaging: lowercase the `contrib` and `templates` directories with Inno
Matt Harbison <matt_harbison@yahoo.com>
parents:
44153
diff
changeset
|
37 |
('contrib/zsh_completion', 'contrib/'), |
43516
d053d3f10b6a
packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
38 |
('dist/hg.exe', './'), |
d053d3f10b6a
packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
39 |
('dist/lib/*.dll', 'lib/'), |
d053d3f10b6a
packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
40 |
('dist/lib/*.pyd', 'lib/'), |
d053d3f10b6a
packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
41 |
('dist/lib/library.zip', 'lib/'), |
d053d3f10b6a
packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
42 |
('dist/Microsoft.VC*.CRT.manifest', './'), |
d053d3f10b6a
packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
43 |
('dist/msvc*.dll', './'), |
d053d3f10b6a
packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
44 |
('dist/python*.dll', './'), |
43519
2aaf245639bf
packaging: install documentation to doc/ directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43516
diff
changeset
|
45 |
('doc/*.html', 'doc/'), |
2aaf245639bf
packaging: install documentation to doc/ directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43516
diff
changeset
|
46 |
('doc/style.css', 'doc/'), |
43736
640bae94f2f3
cleanup: update references to /help/ that should now be /helptext/
Augie Fackler <augie@google.com>
parents:
43623
diff
changeset
|
47 |
('mercurial/helptext/**/*.txt', 'helptext/'), |
44153
e4344e463c0c
packaging: rename hgrc.d to defaultrc for Windows config files next to the exe
Matt Harbison <matt_harbison@yahoo.com>
parents:
43749
diff
changeset
|
48 |
('mercurial/defaultrc/*.rc', 'defaultrc/'), |
43516
d053d3f10b6a
packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
49 |
('mercurial/locale/**/*', 'locale/'), |
44225
4aedef6d51ad
packaging: lowercase the `contrib` and `templates` directories with Inno
Matt Harbison <matt_harbison@yahoo.com>
parents:
44153
diff
changeset
|
50 |
('mercurial/templates/**/*', 'templates/'), |
43516
d053d3f10b6a
packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
51 |
('COPYING', 'Copying.txt'), |
d053d3f10b6a
packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
52 |
] |
d053d3f10b6a
packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
53 |
|
43607
a2f28a8746bf
packaging: remove hg-ssh.8.html from Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43606
diff
changeset
|
54 |
# List of paths to exclude from the staging area. |
a2f28a8746bf
packaging: remove hg-ssh.8.html from Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43606
diff
changeset
|
55 |
STAGING_EXCLUDES = [ |
a2f28a8746bf
packaging: remove hg-ssh.8.html from Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43606
diff
changeset
|
56 |
'doc/hg-ssh.8.html', |
a2f28a8746bf
packaging: remove hg-ssh.8.html from Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43606
diff
changeset
|
57 |
] |
a2f28a8746bf
packaging: remove hg-ssh.8.html from Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43606
diff
changeset
|
58 |
|
43516
d053d3f10b6a
packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
59 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
60 |
def build_py2exe( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
61 |
source_dir: pathlib.Path, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
62 |
build_dir: pathlib.Path, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
63 |
python_exe: pathlib.Path, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
64 |
build_name: str, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
65 |
venv_requirements_txt: pathlib.Path, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
66 |
extra_packages=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
67 |
extra_excludes=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
68 |
extra_dll_excludes=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
69 |
extra_packages_script=None, |
46363
d6cfe45afb18
packaging: allow specifying modules to include with py2exe
Matt Harbison <matt_harbison@yahoo.com>
parents:
44225
diff
changeset
|
70 |
extra_includes=None, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
71 |
): |
41915
a2e191a937a9
packaging: extract py2exe functionality to own module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41914
diff
changeset
|
72 |
"""Build Mercurial with py2exe. |
41853
d7dc4ac1ff84
inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
73 |
|
d7dc4ac1ff84
inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
74 |
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
|
75 |
|
d7dc4ac1ff84
inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
76 |
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
|
77 |
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
|
78 |
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
|
79 |
""" |
d7dc4ac1ff84
inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
80 |
if 'VCINSTALLDIR' not in os.environ: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
81 |
raise Exception( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
82 |
'not running from a Visual C++ build environment; ' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
83 |
'execute the "Visual C++ <version> Command Prompt" ' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
84 |
'application shortcut or a vcsvarsall.bat file' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
85 |
) |
41853
d7dc4ac1ff84
inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
86 |
|
d7dc4ac1ff84
inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
87 |
# Identity x86/x64 and validate the environment matches the Python |
d7dc4ac1ff84
inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
88 |
# architecture. |
d7dc4ac1ff84
inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
89 |
vc_x64 = r'\x64' in os.environ['LIB'] |
d7dc4ac1ff84
inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
90 |
|
41914
7d1211168863
packaging: extract python exe info to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41913
diff
changeset
|
91 |
py_info = python_exe_info(python_exe) |
41853
d7dc4ac1ff84
inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
92 |
|
d7dc4ac1ff84
inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
93 |
if vc_x64: |
41914
7d1211168863
packaging: extract python exe info to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41913
diff
changeset
|
94 |
if py_info['arch'] != '64bit': |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
95 |
raise Exception( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
96 |
'architecture mismatch: Visual C++ environment ' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
97 |
'is configured for 64-bit but Python is 32-bit' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
98 |
) |
41853
d7dc4ac1ff84
inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
99 |
else: |
41914
7d1211168863
packaging: extract python exe info to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41913
diff
changeset
|
100 |
if py_info['arch'] != '32bit': |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
101 |
raise Exception( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
102 |
'architecture mismatch: Visual C++ environment ' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
103 |
'is configured for 32-bit but Python is 64-bit' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
104 |
) |
41853
d7dc4ac1ff84
inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
105 |
|
41914
7d1211168863
packaging: extract python exe info to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41913
diff
changeset
|
106 |
if py_info['py3']: |
41853
d7dc4ac1ff84
inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
107 |
raise Exception('Only Python 2 is currently supported') |
d7dc4ac1ff84
inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
108 |
|
d7dc4ac1ff84
inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
109 |
build_dir.mkdir(exist_ok=True) |
d7dc4ac1ff84
inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
110 |
|
41909
1e8fb6522fee
packaging: move DOWNLOADS dict to hgpackaging.downloads
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41908
diff
changeset
|
111 |
gettext_pkg, gettext_entry = download_entry('gettext', build_dir) |
1e8fb6522fee
packaging: move DOWNLOADS dict to hgpackaging.downloads
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41908
diff
changeset
|
112 |
gettext_dep_pkg = download_entry('gettext-dep', build_dir)[0] |
1e8fb6522fee
packaging: move DOWNLOADS dict to hgpackaging.downloads
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41908
diff
changeset
|
113 |
virtualenv_pkg, virtualenv_entry = download_entry('virtualenv', build_dir) |
1e8fb6522fee
packaging: move DOWNLOADS dict to hgpackaging.downloads
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41908
diff
changeset
|
114 |
py2exe_pkg, py2exe_entry = download_entry('py2exe', build_dir) |
41853
d7dc4ac1ff84
inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
115 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
116 |
venv_path = build_dir / ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
117 |
'venv-%s-%s' % (build_name, 'x64' if vc_x64 else 'x86') |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
118 |
) |
41853
d7dc4ac1ff84
inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
119 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
120 |
gettext_root = build_dir / ('gettext-win-%s' % gettext_entry['version']) |
41853
d7dc4ac1ff84
inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
121 |
|
d7dc4ac1ff84
inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
122 |
if not gettext_root.exists(): |
d7dc4ac1ff84
inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
123 |
extract_zip_to_directory(gettext_pkg, gettext_root) |
d7dc4ac1ff84
inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
124 |
extract_zip_to_directory(gettext_dep_pkg, gettext_root) |
d7dc4ac1ff84
inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
125 |
|
41912
d4bf73ea06de
packaging: extract virtualenv and py2exe to build directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41911
diff
changeset
|
126 |
# This assumes Python 2. We don't need virtualenv on Python 3. |
d4bf73ea06de
packaging: extract virtualenv and py2exe to build directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41911
diff
changeset
|
127 |
virtualenv_src_path = build_dir / ( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
128 |
'virtualenv-%s' % virtualenv_entry['version'] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
129 |
) |
41912
d4bf73ea06de
packaging: extract virtualenv and py2exe to build directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41911
diff
changeset
|
130 |
virtualenv_py = virtualenv_src_path / 'virtualenv.py' |
d4bf73ea06de
packaging: extract virtualenv and py2exe to build directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41911
diff
changeset
|
131 |
|
d4bf73ea06de
packaging: extract virtualenv and py2exe to build directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41911
diff
changeset
|
132 |
if not virtualenv_src_path.exists(): |
d4bf73ea06de
packaging: extract virtualenv and py2exe to build directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41911
diff
changeset
|
133 |
extract_tar_to_directory(virtualenv_pkg, build_dir) |
d4bf73ea06de
packaging: extract virtualenv and py2exe to build directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41911
diff
changeset
|
134 |
|
d4bf73ea06de
packaging: extract virtualenv and py2exe to build directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41911
diff
changeset
|
135 |
py2exe_source_path = build_dir / ('py2exe-%s' % py2exe_entry['version']) |
d4bf73ea06de
packaging: extract virtualenv and py2exe to build directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41911
diff
changeset
|
136 |
|
d4bf73ea06de
packaging: extract virtualenv and py2exe to build directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41911
diff
changeset
|
137 |
if not py2exe_source_path.exists(): |
d4bf73ea06de
packaging: extract virtualenv and py2exe to build directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41911
diff
changeset
|
138 |
extract_zip_to_directory(py2exe_pkg, build_dir) |
d4bf73ea06de
packaging: extract virtualenv and py2exe to build directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41911
diff
changeset
|
139 |
|
41913
5e923355c595
packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41912
diff
changeset
|
140 |
if not venv_path.exists(): |
5e923355c595
packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41912
diff
changeset
|
141 |
print('creating virtualenv with dependencies') |
5e923355c595
packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41912
diff
changeset
|
142 |
subprocess.run( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
143 |
[str(python_exe), str(virtualenv_py), str(venv_path)], check=True |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
144 |
) |
41913
5e923355c595
packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41912
diff
changeset
|
145 |
|
5e923355c595
packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41912
diff
changeset
|
146 |
venv_python = venv_path / 'Scripts' / 'python.exe' |
5e923355c595
packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41912
diff
changeset
|
147 |
venv_pip = venv_path / 'Scripts' / 'pip.exe' |
41853
d7dc4ac1ff84
inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
148 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
149 |
subprocess.run( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
150 |
[str(venv_pip), 'install', '-r', str(venv_requirements_txt)], check=True |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
151 |
) |
41853
d7dc4ac1ff84
inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
152 |
|
41913
5e923355c595
packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41912
diff
changeset
|
153 |
# Force distutils to use VC++ settings from environment, which was |
5e923355c595
packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41912
diff
changeset
|
154 |
# validated above. |
5e923355c595
packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41912
diff
changeset
|
155 |
env = dict(os.environ) |
5e923355c595
packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41912
diff
changeset
|
156 |
env['DISTUTILS_USE_SDK'] = '1' |
5e923355c595
packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41912
diff
changeset
|
157 |
env['MSSdk'] = '1' |
41853
d7dc4ac1ff84
inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
158 |
|
42047
715d3220ac4f
wix: add a hook for a prebuild script to inject extra libraries
Augie Fackler <augie@google.com>
parents:
41953
diff
changeset
|
159 |
if extra_packages_script: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
160 |
more_packages = set( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
161 |
subprocess.check_output(extra_packages_script, cwd=build_dir) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
162 |
.split(b'\0')[-1] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
163 |
.strip() |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
164 |
.decode('utf-8') |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
165 |
.splitlines() |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
166 |
) |
42047
715d3220ac4f
wix: add a hook for a prebuild script to inject extra libraries
Augie Fackler <augie@google.com>
parents:
41953
diff
changeset
|
167 |
if more_packages: |
715d3220ac4f
wix: add a hook for a prebuild script to inject extra libraries
Augie Fackler <augie@google.com>
parents:
41953
diff
changeset
|
168 |
if not extra_packages: |
715d3220ac4f
wix: add a hook for a prebuild script to inject extra libraries
Augie Fackler <augie@google.com>
parents:
41953
diff
changeset
|
169 |
extra_packages = more_packages |
715d3220ac4f
wix: add a hook for a prebuild script to inject extra libraries
Augie Fackler <augie@google.com>
parents:
41953
diff
changeset
|
170 |
else: |
715d3220ac4f
wix: add a hook for a prebuild script to inject extra libraries
Augie Fackler <augie@google.com>
parents:
41953
diff
changeset
|
171 |
extra_packages |= more_packages |
715d3220ac4f
wix: add a hook for a prebuild script to inject extra libraries
Augie Fackler <augie@google.com>
parents:
41953
diff
changeset
|
172 |
|
41916
260305e8ddbd
setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41915
diff
changeset
|
173 |
if extra_packages: |
260305e8ddbd
setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41915
diff
changeset
|
174 |
env['HG_PY2EXE_EXTRA_PACKAGES'] = ' '.join(sorted(extra_packages)) |
42054
399ed3e86a49
py2exe: add workaround to allow bundling of hgext3rd.* extensions
Augie Fackler <augie@google.com>
parents:
42047
diff
changeset
|
175 |
hgext3rd_extras = sorted( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
176 |
e for e in extra_packages if e.startswith('hgext3rd.') |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
177 |
) |
42054
399ed3e86a49
py2exe: add workaround to allow bundling of hgext3rd.* extensions
Augie Fackler <augie@google.com>
parents:
42047
diff
changeset
|
178 |
if hgext3rd_extras: |
399ed3e86a49
py2exe: add workaround to allow bundling of hgext3rd.* extensions
Augie Fackler <augie@google.com>
parents:
42047
diff
changeset
|
179 |
env['HG_PY2EXE_EXTRA_INSTALL_PACKAGES'] = ' '.join(hgext3rd_extras) |
46363
d6cfe45afb18
packaging: allow specifying modules to include with py2exe
Matt Harbison <matt_harbison@yahoo.com>
parents:
44225
diff
changeset
|
180 |
if extra_includes: |
d6cfe45afb18
packaging: allow specifying modules to include with py2exe
Matt Harbison <matt_harbison@yahoo.com>
parents:
44225
diff
changeset
|
181 |
env['HG_PY2EXE_EXTRA_INCLUDES'] = ' '.join(sorted(extra_includes)) |
41916
260305e8ddbd
setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41915
diff
changeset
|
182 |
if extra_excludes: |
260305e8ddbd
setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41915
diff
changeset
|
183 |
env['HG_PY2EXE_EXTRA_EXCLUDES'] = ' '.join(sorted(extra_excludes)) |
260305e8ddbd
setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41915
diff
changeset
|
184 |
if extra_dll_excludes: |
260305e8ddbd
setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41915
diff
changeset
|
185 |
env['HG_PY2EXE_EXTRA_DLL_EXCLUDES'] = ' '.join( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
186 |
sorted(extra_dll_excludes) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
187 |
) |
41916
260305e8ddbd
setup: configure py2exe config via environment variables
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41915
diff
changeset
|
188 |
|
41913
5e923355c595
packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41912
diff
changeset
|
189 |
py2exe_py_path = venv_path / 'Lib' / 'site-packages' / 'py2exe' |
5e923355c595
packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41912
diff
changeset
|
190 |
if not py2exe_py_path.exists(): |
5e923355c595
packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41912
diff
changeset
|
191 |
print('building py2exe') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
192 |
subprocess.run( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
193 |
[str(venv_python), 'setup.py', 'install'], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
194 |
cwd=py2exe_source_path, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
195 |
env=env, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
196 |
check=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
197 |
) |
41853
d7dc4ac1ff84
inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
198 |
|
41913
5e923355c595
packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41912
diff
changeset
|
199 |
# Register location of msgfmt and other binaries. |
5e923355c595
packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41912
diff
changeset
|
200 |
env['PATH'] = '%s%s%s' % ( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
201 |
env['PATH'], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
202 |
os.pathsep, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
203 |
str(gettext_root / 'bin'), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
204 |
) |
41853
d7dc4ac1ff84
inno: script to automate building Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
205 |
|
41913
5e923355c595
packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41912
diff
changeset
|
206 |
print('building Mercurial') |
5e923355c595
packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41912
diff
changeset
|
207 |
subprocess.run( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
208 |
[str(venv_python), 'setup.py', 'py2exe', 'build_doc', '--html'], |
41913
5e923355c595
packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41912
diff
changeset
|
209 |
cwd=str(source_dir), |
5e923355c595
packaging: don't use temporary directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41912
diff
changeset
|
210 |
env=env, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
211 |
check=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42054
diff
changeset
|
212 |
) |
43516
d053d3f10b6a
packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
213 |
|
d053d3f10b6a
packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
214 |
|
43623
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43609
diff
changeset
|
215 |
def stage_install( |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43609
diff
changeset
|
216 |
source_dir: pathlib.Path, staging_dir: pathlib.Path, lower_case=False |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43609
diff
changeset
|
217 |
): |
43516
d053d3f10b6a
packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
218 |
"""Copy all files to be installed to a directory. |
d053d3f10b6a
packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
219 |
|
d053d3f10b6a
packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
220 |
This allows packaging to simply walk a directory tree to find source |
d053d3f10b6a
packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
221 |
files. |
d053d3f10b6a
packaging: stage installed files for Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
222 |
""" |
43623
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43609
diff
changeset
|
223 |
if lower_case: |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43609
diff
changeset
|
224 |
rules = [] |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43609
diff
changeset
|
225 |
for source, dest in STAGING_RULES: |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43609
diff
changeset
|
226 |
# Only lower directory names. |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43609
diff
changeset
|
227 |
if '/' in dest: |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43609
diff
changeset
|
228 |
parent, leaf = dest.rsplit('/', 1) |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43609
diff
changeset
|
229 |
dest = '%s/%s' % (parent.lower(), leaf) |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43609
diff
changeset
|
230 |
rules.append((source, dest)) |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43609
diff
changeset
|
231 |
else: |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43609
diff
changeset
|
232 |
rules = STAGING_RULES |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43609
diff
changeset
|
233 |
|
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43609
diff
changeset
|
234 |
process_install_rules(rules, source_dir, staging_dir) |
43607
a2f28a8746bf
packaging: remove hg-ssh.8.html from Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43606
diff
changeset
|
235 |
|
43609
8aa6aa9b7843
packaging: write out editor.rc in Python
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43608
diff
changeset
|
236 |
# Write out a default editor.rc file to configure notepad as the |
8aa6aa9b7843
packaging: write out editor.rc in Python
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43608
diff
changeset
|
237 |
# default editor. |
44153
e4344e463c0c
packaging: rename hgrc.d to defaultrc for Windows config files next to the exe
Matt Harbison <matt_harbison@yahoo.com>
parents:
43749
diff
changeset
|
238 |
with (staging_dir / 'defaultrc' / 'editor.rc').open( |
43609
8aa6aa9b7843
packaging: write out editor.rc in Python
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43608
diff
changeset
|
239 |
'w', encoding='utf-8' |
8aa6aa9b7843
packaging: write out editor.rc in Python
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43608
diff
changeset
|
240 |
) as fh: |
8aa6aa9b7843
packaging: write out editor.rc in Python
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43608
diff
changeset
|
241 |
fh.write('[ui]\neditor = notepad\n') |
8aa6aa9b7843
packaging: write out editor.rc in Python
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43608
diff
changeset
|
242 |
|
43607
a2f28a8746bf
packaging: remove hg-ssh.8.html from Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43606
diff
changeset
|
243 |
# Purge any files we don't want to be there. |
a2f28a8746bf
packaging: remove hg-ssh.8.html from Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43606
diff
changeset
|
244 |
for f in STAGING_EXCLUDES: |
a2f28a8746bf
packaging: remove hg-ssh.8.html from Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43606
diff
changeset
|
245 |
p = staging_dir / f |
a2f28a8746bf
packaging: remove hg-ssh.8.html from Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43606
diff
changeset
|
246 |
if p.exists(): |
a2f28a8746bf
packaging: remove hg-ssh.8.html from Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43606
diff
changeset
|
247 |
print('removing %s' % p) |
a2f28a8746bf
packaging: remove hg-ssh.8.html from Inno installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43606
diff
changeset
|
248 |
p.unlink() |