wix: add functionality to inject additional Features into installer
authorAugie Fackler <raf@durin42.com>
Mon, 01 Apr 2019 20:01:48 -0400
changeset 42049 1711f5813a63
parent 42048 978b03d5f66e
child 42050 03f6480bfdda
wix: add functionality to inject additional Features into installer This is the last bit required to be able to glue extra configs etc into the installer. Differential Revision: https://phab.mercurial-scm.org/D6180
contrib/packaging/hgpackaging/wix.py
contrib/packaging/wix/build.py
contrib/packaging/wix/mercurial.wxs
--- a/contrib/packaging/hgpackaging/wix.py	Mon Apr 01 16:21:47 2019 -0400
+++ b/contrib/packaging/hgpackaging/wix.py	Mon Apr 01 20:01:48 2019 -0400
@@ -179,8 +179,9 @@
 
 def build_installer(source_dir: pathlib.Path, python_exe: pathlib.Path,
                     msi_name='mercurial', version=None, post_build_fn=None,
-                    extra_packages_script: typing.Optional[str]=None,
-                    extra_wxs:typing.Optional[typing.Dict[str,str]]=None):
+                    extra_packages_script=None,
+                    extra_wxs:typing.Optional[typing.Dict[str,str]]=None,
+                    extra_features:typing.Optional[typing.List[str]]=None):
     """Build a WiX MSI installer.
 
     ``source_dir`` is the path to the Mercurial source tree to use.
@@ -197,6 +198,8 @@
     print a null byte followed by a newline-separated list of packages that
     should be included in the exe.
     ``extra_wxs`` is a dict of {wxs_name: working_dir_for_wxs_build}.
+    ``extra_features`` is a list of additional named Features to include in
+    the build. These must match Feature names in one of the wxs scripts.
     """
     arch = 'x64' if r'\x64' in os.environ.get('LIB', '') else 'x86'
 
@@ -256,6 +259,9 @@
     defines['Version'] = version
     defines['Comments'] = 'Installs Mercurial version %s' % version
     defines['VCRedistSrcDir'] = str(hg_build_dir)
+    if extra_features:
+        assert all(';' not in f for f in extra_features)
+        defines['MercurialExtraFeatures'] = ';'.join(extra_features)
 
     run_candle(wix_path, build_dir, source, source_build_rel, defines=defines)
 
@@ -298,7 +304,7 @@
                            name: str, version=None, subject_name=None,
                            cert_path=None, cert_password=None,
                            timestamp_url=None, extra_packages_script=None,
-                           extra_wxs=None):
+                           extra_wxs=None, extra_features=None):
     """Build an installer with signed executables."""
 
     post_build_fn = make_post_build_signing_fn(
@@ -312,7 +318,7 @@
                            msi_name=name.lower(), version=version,
                            post_build_fn=post_build_fn,
                            extra_packages_script=extra_packages_script,
-                           extra_wxs=extra_wxs)
+                           extra_wxs=extra_wxs, extra_features=extra_features)
 
     description = '%s %s' % (name, version)
 
--- a/contrib/packaging/wix/build.py	Mon Apr 01 16:21:47 2019 -0400
+++ b/contrib/packaging/wix/build.py	Mon Apr 01 20:01:48 2019 -0400
@@ -39,6 +39,9 @@
                               'py2exe binary.'))
     parser.add_argument('--extra-wxs',
                         help='CSV of path_to_wxs_file=working_dir_for_wxs_file')
+    parser.add_argument('--extra-features',
+                        help=('CSV of extra feature names to include '
+                              'in the installer from the extra wxs files'))
 
     args = parser.parse_args()
 
@@ -64,6 +67,8 @@
     if args.extra_wxs:
         kwargs['extra_wxs'] = dict(
             thing.split("=") for thing in args.extra_wxs.split(','))
+    if args.extra_features:
+        kwargs['extra_features'] = args.extra_features.split(',')
 
     if args.sign_sn or args.sign_cert:
         fn = build_signed_installer
--- a/contrib/packaging/wix/mercurial.wxs	Mon Apr 01 16:21:47 2019 -0400
+++ b/contrib/packaging/wix/mercurial.wxs	Mon Apr 01 20:01:48 2019 -0400
@@ -129,6 +129,11 @@
         <MergeRef Id='VCRuntime' />
         <MergeRef Id='VCRuntimePolicy' />
       </Feature>
+      <?if $(var.MercurialExtraFeatures)?>
+        <?foreach EXTRAFEAT in $(var.MercurialExtraFeatures)?>
+          <FeatureRef Id="$(var.EXTRAFEAT)" />
+        <?endforeach?>
+      <?endif?>
       <Feature Id='Locales' Title='Translations' Description='Translations' Level='1'>
         <ComponentGroupRef Id='localeFolder' />
         <ComponentRef Id='i18nFolder' />