Patchwork D7158: packaging: process Inno Setup files with Jinja2

login
register
mail settings
Submitter phabricator
Date Oct. 24, 2019, 1:56 a.m.
Message ID <differential-rev-PHID-DREV-unurwdjuns2nr3kl2mqk-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/42546/
State Superseded
Headers show

Comments

phabricator - Oct. 24, 2019, 1:56 a.m.
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D7158

AFFECTED FILES
  contrib/packaging/hgpackaging/inno.py
  contrib/packaging/inno/mercurial.iss

CHANGE DETAILS




To: indygreg, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/contrib/packaging/inno/mercurial.iss b/contrib/packaging/inno/mercurial.iss
--- a/contrib/packaging/inno/mercurial.iss
+++ b/contrib/packaging/inno/mercurial.iss
@@ -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' %}
diff --git a/contrib/packaging/hgpackaging/inno.py b/contrib/packaging/hgpackaging/inno.py
--- a/contrib/packaging/hgpackaging/inno.py
+++ b/contrib/packaging/hgpackaging/inno.py
@@ -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)]