##// END OF EJS Templates
rust-matchers: fix quadratic complexity in `FileMatcher`...
rust-matchers: fix quadratic complexity in `FileMatcher` Concretely, this command: ``` $ echo hg up -r <nodeid>; time hg revert dir1 dir2 -r <othernode> --debug hg up -r <nodeid> real 0m14.690s user 0m14.766s sys 0m5.430s ``` was much slower despite using 16 cores before this change. The approach taken here is the same one used in match.py, in exactmatcher. This changeset was originally written by Valentin Gatien-Baron in a private repository. I have redacted the commit message and did a minor clean up of the code.

File last commit:

r49703:17d5e25b default
r52002:687e192d default
Show More
inno.py
154 lines | 4.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
Gregory Szorc
packaging: process Inno Setup files with Jinja2...
r43915 import jinja2
Gregory Szorc
packaging: rename run_pyoxidizer()...
r47979 from .pyoxidizer import create_pyoxidizer_install_layout
Gregory Szorc
packaging: always pass VERSION into Inno invocation...
r43918 from .util import (
Matt Harbison
packaging: set the FileVersion field in the Inno installer executable...
r44708 normalize_windows_version,
Matt Harbison
packaging: bundle the default mercurial.ini template with Inno also...
r44709 process_install_rules,
Gregory Szorc
packaging: always pass VERSION into Inno invocation...
r43918 read_version_py,
)
Gregory Szorc
packaging: move Inno Setup core logic into a module...
r42077
Matt Harbison
packaging: include `windows_curses` when building py2exe...
r47110
Matt Harbison
packaging: bundle the default mercurial.ini template with Inno also...
r44709 EXTRA_INSTALL_RULES = [
('contrib/win32/mercurial.ini', 'defaultrc/mercurial.rc'),
]
Gregory Szorc
packaging: stage installed files for Inno...
r43916 PACKAGE_FILES_METADATA = {
'ReadMe.html': 'Flags: isreadme',
}
Gregory Szorc
setup: configure py2exe config via environment variables...
r42082
Gregory Szorc
packaging: support building Inno installer with PyOxidizer...
r45270 def build_with_pyoxidizer(
source_dir: pathlib.Path,
build_dir: pathlib.Path,
target_triple: str,
iscc_exe: pathlib.Path,
version=None,
):
"""Build the Inno installer using PyOxidizer."""
if not iscc_exe.exists():
raise Exception("%s does not exist" % iscc_exe)
inno_build_dir = build_dir / ("inno-pyoxidizer-%s" % target_triple)
staging_dir = inno_build_dir / "stage"
inno_build_dir.mkdir(parents=True, exist_ok=True)
Gregory Szorc
packaging: rename run_pyoxidizer()...
r47979 create_pyoxidizer_install_layout(
source_dir, inno_build_dir, staging_dir, target_triple
)
Gregory Szorc
packaging: support building Inno installer with PyOxidizer...
r45270
process_install_rules(EXTRA_INSTALL_RULES, source_dir, staging_dir)
build_installer(
source_dir,
inno_build_dir,
staging_dir,
iscc_exe,
version,
arch="x64" if "x86_64" in target_triple else None,
)
Gregory Szorc
packaging: split Inno installer building from Mercurial building...
r45269 def build_installer(
source_dir: pathlib.Path,
inno_build_dir: pathlib.Path,
staging_dir: pathlib.Path,
iscc_exe: pathlib.Path,
version,
arch=None,
Gregory Szorc
packaging: add -python2 to Windows installer filenames...
r45276 suffix="",
Gregory Szorc
packaging: split Inno installer building from Mercurial building...
r45269 ):
"""Build an Inno installer from staged Mercurial files.
This function is agnostic about how to build Mercurial. It just
cares that Mercurial files are in ``staging_dir``.
"""
inno_source_dir = source_dir / "contrib" / "packaging" / "inno"
Gregory Szorc
packaging: stage installed files for Inno...
r43916 # The final package layout is simply a mirror of the staging directory.
package_files = []
for root, dirs, files in os.walk(staging_dir):
dirs.sort()
root = pathlib.Path(root)
for f in sorted(files):
full = root / f
rel = full.relative_to(staging_dir)
if str(rel.parent) == '.':
dest_dir = '{app}'
else:
dest_dir = '{app}\\%s' % rel.parent
package_files.append(
{
'source': rel,
'dest_dir': dest_dir,
'metadata': PACKAGE_FILES_METADATA.get(str(rel), None),
}
)
Gregory Szorc
packaging: don't use temporary directory...
r42079 print('creating installer')
Gregory Szorc
packaging: process Inno Setup files with Jinja2...
r43915 # Install Inno files by rendering a template.
jinja_env = jinja2.Environment(
loader=jinja2.FileSystemLoader(str(inno_source_dir)),
# Need to change these to prevent conflict with Inno Setup.
comment_start_string='{##',
comment_end_string='##}',
)
try:
template = jinja_env.get_template('mercurial.iss')
except jinja2.TemplateSyntaxError as e:
raise Exception(
'template syntax error at %s:%d: %s'
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 % (
e.name,
e.lineno,
e.message,
)
Gregory Szorc
packaging: process Inno Setup files with Jinja2...
r43915 )
Gregory Szorc
packaging: stage installed files for Inno...
r43916 content = template.render(package_files=package_files)
Gregory Szorc
packaging: process Inno Setup files with Jinja2...
r43915
with (inno_build_dir / 'mercurial.iss').open('w', encoding='utf-8') as fh:
fh.write(content)
Gregory Szorc
packaging: install and run Inno files in a build directory...
r43914
Gregory Szorc
packaging: stage installed files for Inno...
r43916 # Copy additional files used by Inno.
for p in ('mercurial.ico', 'postinstall.txt'):
shutil.copyfile(
source_dir / 'contrib' / 'win32' / p, inno_build_dir / p
)
Gregory Szorc
packaging: don't use temporary directory...
r42079 args = [str(iscc_exe)]
Gregory Szorc
packaging: move Inno Setup core logic into a module...
r42077
Gregory Szorc
packaging: split Inno installer building from Mercurial building...
r45269 if arch:
args.append('/dARCH=%s' % arch)
Gregory Szorc
packaging: add -python2 to Windows installer filenames...
r45276 args.append('/dSUFFIX=-%s%s' % (arch, suffix))
else:
args.append('/dSUFFIX=-x86%s' % suffix)
Gregory Szorc
packaging: move Inno Setup core logic into a module...
r42077
Gregory Szorc
packaging: always pass VERSION into Inno invocation...
r43918 if not version:
version = read_version_py(source_dir)
args.append('/dVERSION=%s' % version)
Matt Harbison
packaging: set the FileVersion field in the Inno installer executable...
r44708 args.append('/dQUAD_VERSION=%s' % normalize_windows_version(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')
Gregory Szorc
packaging: install and run Inno files in a build directory...
r43914 args.append(str(inno_build_dir / '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)