##// END OF EJS Templates
packaging: extract python exe info to own function...
packaging: extract python exe info to own function This is generic functionality. We'll need it for WIX. As part of the port, we expose the full version and return the data as a dict. Differential Revision: https://phab.mercurial-scm.org/D6090

File last commit:

r42080:7d121116 default
r42080:7d121116 default
Show More
inno.py
158 lines | 5.1 KiB | text/x-python | PythonLexer
Gregory Szorc
packaging: move Inno Setup core logic into a module...
r42077 # inno.py - Inno Setup functionality.
#
# Copyright 2019 Gregory Szorc <gregory.szorc@gmail.com>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
# no-check-code because Python 3 native.
import os
import pathlib
import shutil
import subprocess
from .downloads import (
download_entry,
)
from .util import (
extract_tar_to_directory,
extract_zip_to_directory,
find_vc_runtime_files,
Gregory Szorc
packaging: extract python exe info to own function...
r42080 python_exe_info,
Gregory Szorc
packaging: move Inno Setup core logic into a module...
r42077 )
def build(source_dir: pathlib.Path, build_dir: pathlib.Path,
python_exe: pathlib.Path, iscc_exe: pathlib.Path,
version=None):
"""Build the Inno installer.
Build files will be placed in ``build_dir``.
py2exe's setup.py doesn't use setuptools. It doesn't have modern logic
for finding the Python 2.7 toolchain. So, we require the environment
to already be configured with an active toolchain.
"""
if not iscc_exe.exists():
raise Exception('%s does not exist' % iscc_exe)
if 'VCINSTALLDIR' not in os.environ:
raise Exception('not running from a Visual C++ build environment; '
'execute the "Visual C++ <version> Command Prompt" '
'application shortcut or a vcsvarsall.bat file')
# Identity x86/x64 and validate the environment matches the Python
# architecture.
vc_x64 = r'\x64' in os.environ['LIB']
Gregory Szorc
packaging: extract python exe info to own function...
r42080 py_info = python_exe_info(python_exe)
Gregory Szorc
packaging: move Inno Setup core logic into a module...
r42077
if vc_x64:
Gregory Szorc
packaging: extract python exe info to own function...
r42080 if py_info['arch'] != '64bit':
Gregory Szorc
packaging: move Inno Setup core logic into a module...
r42077 raise Exception('architecture mismatch: Visual C++ environment '
'is configured for 64-bit but Python is 32-bit')
else:
Gregory Szorc
packaging: extract python exe info to own function...
r42080 if py_info['arch'] != '32bit':
Gregory Szorc
packaging: move Inno Setup core logic into a module...
r42077 raise Exception('architecture mismatch: Visual C++ environment '
'is configured for 32-bit but Python is 64-bit')
Gregory Szorc
packaging: extract python exe info to own function...
r42080 if py_info['py3']:
Gregory Szorc
packaging: move Inno Setup core logic into a module...
r42077 raise Exception('Only Python 2 is currently supported')
build_dir.mkdir(exist_ok=True)
gettext_pkg, gettext_entry = download_entry('gettext', build_dir)
gettext_dep_pkg = download_entry('gettext-dep', build_dir)[0]
virtualenv_pkg, virtualenv_entry = download_entry('virtualenv', build_dir)
py2exe_pkg, py2exe_entry = download_entry('py2exe', build_dir)
venv_path = build_dir / ('venv-inno-%s' % ('x64' if vc_x64 else 'x86'))
gettext_root = build_dir / (
'gettext-win-%s' % gettext_entry['version'])
if not gettext_root.exists():
extract_zip_to_directory(gettext_pkg, gettext_root)
extract_zip_to_directory(gettext_dep_pkg, gettext_root)
Gregory Szorc
packaging: extract virtualenv and py2exe to build directory...
r42078 # This assumes Python 2. We don't need virtualenv on Python 3.
virtualenv_src_path = build_dir / (
'virtualenv-%s' % virtualenv_entry['version'])
virtualenv_py = virtualenv_src_path / 'virtualenv.py'
if not virtualenv_src_path.exists():
extract_tar_to_directory(virtualenv_pkg, build_dir)
py2exe_source_path = build_dir / ('py2exe-%s' % py2exe_entry['version'])
if not py2exe_source_path.exists():
extract_zip_to_directory(py2exe_pkg, build_dir)
Gregory Szorc
packaging: don't use temporary directory...
r42079 if not venv_path.exists():
print('creating virtualenv with dependencies')
subprocess.run(
[str(python_exe), str(virtualenv_py), str(venv_path)],
check=True)
venv_python = venv_path / 'Scripts' / 'python.exe'
venv_pip = venv_path / 'Scripts' / 'pip.exe'
Gregory Szorc
packaging: move Inno Setup core logic into a module...
r42077
Gregory Szorc
packaging: don't use temporary directory...
r42079 requirements_txt = (source_dir / 'contrib' / 'packaging' /
'inno' / 'requirements.txt')
subprocess.run([str(venv_pip), 'install', '-r', str(requirements_txt)],
check=True)
Gregory Szorc
packaging: move Inno Setup core logic into a module...
r42077
Gregory Szorc
packaging: don't use temporary directory...
r42079 # Force distutils to use VC++ settings from environment, which was
# validated above.
env = dict(os.environ)
env['DISTUTILS_USE_SDK'] = '1'
env['MSSdk'] = '1'
Gregory Szorc
packaging: move Inno Setup core logic into a module...
r42077
Gregory Szorc
packaging: don't use temporary directory...
r42079 py2exe_py_path = venv_path / 'Lib' / 'site-packages' / 'py2exe'
if not py2exe_py_path.exists():
print('building py2exe')
subprocess.run([str(venv_python), 'setup.py', 'install'],
cwd=py2exe_source_path,
env=env,
Gregory Szorc
packaging: move Inno Setup core logic into a module...
r42077 check=True)
Gregory Szorc
packaging: don't use temporary directory...
r42079 # Register location of msgfmt and other binaries.
env['PATH'] = '%s%s%s' % (
env['PATH'], os.pathsep, str(gettext_root / 'bin'))
Gregory Szorc
packaging: move Inno Setup core logic into a module...
r42077
Gregory Szorc
packaging: don't use temporary directory...
r42079 print('building Mercurial')
subprocess.run(
[str(venv_python), 'setup.py',
'py2exe', '-b', '3' if vc_x64 else '2',
'build_doc', '--html'],
cwd=str(source_dir),
env=env,
check=True)
Gregory Szorc
packaging: move Inno Setup core logic into a module...
r42077
Gregory Szorc
packaging: don't use temporary directory...
r42079 # hg.exe depends on VC9 runtime DLLs. Copy those into place.
for f in find_vc_runtime_files(vc_x64):
if f.name.endswith('.manifest'):
basename = 'Microsoft.VC90.CRT.manifest'
else:
basename = f.name
Gregory Szorc
packaging: move Inno Setup core logic into a module...
r42077
Gregory Szorc
packaging: don't use temporary directory...
r42079 dest_path = source_dir / 'dist' / basename
Gregory Szorc
packaging: move Inno Setup core logic into a module...
r42077
Gregory Szorc
packaging: don't use temporary directory...
r42079 print('copying %s to %s' % (f, dest_path))
shutil.copyfile(f, dest_path)
Gregory Szorc
packaging: move Inno Setup core logic into a module...
r42077
Gregory Szorc
packaging: don't use temporary directory...
r42079 print('creating installer')
args = [str(iscc_exe)]
Gregory Szorc
packaging: move Inno Setup core logic into a module...
r42077
Gregory Szorc
packaging: don't use temporary directory...
r42079 if vc_x64:
args.append('/dARCH=x64')
Gregory Szorc
packaging: move Inno Setup core logic into a module...
r42077
Gregory Szorc
packaging: don't use temporary directory...
r42079 if version:
args.append('/dVERSION=%s' % version)
Gregory Szorc
packaging: move Inno Setup core logic into a module...
r42077
Gregory Szorc
packaging: don't use temporary directory...
r42079 args.append('/Odist')
args.append('contrib/packaging/inno/mercurial.iss')
Gregory Szorc
packaging: move Inno Setup core logic into a module...
r42077
Gregory Szorc
packaging: don't use temporary directory...
r42079 subprocess.run(args, cwd=str(source_dir), check=True)