Patchwork D7158: packaging: process Inno Setup files with Jinja2

login
register
mail settings
Submitter phabricator
Date Nov. 9, 2019, 12:04 a.m.
Message ID <848e09e8b42e81afcbf85d4d3d06aeb8@localhost.localdomain>
Download mbox | patch
Permalink /patch/42989/
State Not Applicable
Headers show

Comments

phabricator - Nov. 9, 2019, 12:04 a.m.
Closed by commit rHG04b862675439: packaging: process Inno Setup files with Jinja2 (authored by indygreg).
This revision was automatically updated to reflect the committed changes.
This revision was not accepted when it landed; it landed in state "Needs Review".

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7158?vs=17379&id=17809

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7158/new/

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)]