Mercurial > hg
changeset 43515:7bd88d0d6a82
packaging: process Inno Setup files with Jinja2
I want to make the Inno Setup files dynamically generated.
This will enable us to do things like automatically derive the
set of files to be packaged instead of having to manually
keep lists of files in sync across installers.
As the first step towards this, we process the Inno Setup
files with Jinja2.
As part of this conversion, we had to escape syntax in
mercurial.iss that conflicts with Jinja2. I also took the
opportunity to include modpath.iss via Jinja2 instead of
using Inno's preprocessor. This keeps the Python code a
bit simpler.
Differential Revision: https://phab.mercurial-scm.org/D7158
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 23 Oct 2019 18:39:17 -0700 |
parents | 10454e788111 |
children | d053d3f10b6a |
files | contrib/packaging/hgpackaging/inno.py contrib/packaging/inno/mercurial.iss |
diffstat | 2 files changed, 25 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/contrib/packaging/hgpackaging/inno.py Wed Oct 23 18:39:08 2019 -0700 +++ b/contrib/packaging/hgpackaging/inno.py Wed Oct 23 18:39:17 2019 -0700 @@ -12,6 +12,8 @@ import shutil import subprocess +import jinja2 + from .py2exe import build_py2exe from .util import find_vc_runtime_files @@ -75,9 +77,26 @@ print('creating installer') - # Copy Inno files into place. - for p in ('mercurial.iss', 'modpath.iss'): - shutil.copyfile(inno_source_dir / p, inno_build_dir / p) + # 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' + % (e.name, e.lineno, e.message,) + ) + + content = template.render() + + with (inno_build_dir / 'mercurial.iss').open('w', encoding='utf-8') as fh: + fh.write(content) args = [str(iscc_exe)]
--- a/contrib/packaging/inno/mercurial.iss Wed Oct 23 18:39:08 2019 -0700 +++ b/contrib/packaging/inno/mercurial.iss Wed Oct 23 18:39:17 2019 -0700 @@ -40,7 +40,7 @@ AppPublisherURL=https://mercurial-scm.org/ AppSupportURL=https://mercurial-scm.org/ AppUpdatesURL=https://mercurial-scm.org/ -AppID={{4B95A5F1-EF59-4B08-BED8-C891C46121B3} +{{ 'AppID={{4B95A5F1-EF59-4B08-BED8-C891C46121B3}' }} AppContact=mercurial@mercurial-scm.org DefaultDirName={pf}\Mercurial SourceDir=..\.. @@ -121,4 +121,5 @@ setArrayLength(Result, 1) Result[0] := ExpandConstant('{app}'); end; -#include "modpath.iss" + +{% include 'modpath.iss' %}