D6164: wix: add a hook for a prebuild script to inject extra libraries

durin42 (Augie Fackler) phabricator at mercurial-scm.org
Thu Mar 21 08:55:30 EDT 2019


durin42 created this revision.
durin42 added a reviewer: indygreg.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  I need this to build packages for Google so we can bundle some
  extensions in the installed image. My assumption is that this is most
  interesting for the .msi images so I only wired it up there. I'm not
  thrilled with the interface this provides, but it was an easy way to
  retain debug messages on Windows while also having enough structure to
  know what lines are actually module names for py2exe.
  
  Still pending on my end: I need to bundle a couple of config files,
  and at least one data file. I'm open to advice on how to do those
  things, and how to do this better.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  contrib/packaging/hgpackaging/py2exe.py
  contrib/packaging/hgpackaging/wix.py
  contrib/packaging/wix/build.py

CHANGE DETAILS

diff --git a/contrib/packaging/wix/build.py b/contrib/packaging/wix/build.py
--- a/contrib/packaging/wix/build.py
+++ b/contrib/packaging/wix/build.py
@@ -34,6 +34,8 @@
                         help='URL of timestamp server to use for signing')
     parser.add_argument('--version',
                         help='Version string to use')
+    parser.add_argument('--extra-prebuild-script',
+                        help='Extra script to run after creating virtualenv.')
 
     args = parser.parse_args()
 
@@ -54,6 +56,9 @@
         'version': args.version,
     }
 
+    if args.extra_prebuild_script:
+        kwargs['extra_prebuild_script'] = args.extra_prebuild_script
+
     if args.sign_sn or args.sign_cert:
         fn = build_signed_installer
         kwargs['name'] = args.name
diff --git a/contrib/packaging/hgpackaging/wix.py b/contrib/packaging/hgpackaging/wix.py
--- a/contrib/packaging/hgpackaging/wix.py
+++ b/contrib/packaging/hgpackaging/wix.py
@@ -177,7 +177,8 @@
 
 
 def build_installer(source_dir: pathlib.Path, python_exe: pathlib.Path,
-                    msi_name='mercurial', version=None, post_build_fn=None):
+                    msi_name='mercurial', version=None, post_build_fn=None,
+                    extra_prebuild_script=None):
     """Build a WiX MSI installer.
 
     ``source_dir`` is the path to the Mercurial source tree to use.
@@ -200,7 +201,8 @@
 
     build_py2exe(source_dir, hg_build_dir,
                  python_exe, 'wix', requirements_txt,
-                 extra_packages=EXTRA_PACKAGES)
+                 extra_packages=EXTRA_PACKAGES,
+                 extra_prebuild_script=extra_prebuild_script)
 
     version = version or normalize_version(find_version(source_dir))
     print('using version string: %s' % version)
@@ -280,7 +282,7 @@
 def build_signed_installer(source_dir: pathlib.Path, python_exe: pathlib.Path,
                            name: str, version=None, subject_name=None,
                            cert_path=None, cert_password=None,
-                           timestamp_url=None):
+                           timestamp_url=None, extra_prebuild_script=None):
     """Build an installer with signed executables."""
 
     post_build_fn = make_post_build_signing_fn(
@@ -292,7 +294,8 @@
 
     info = build_installer(source_dir, python_exe=python_exe,
                            msi_name=name.lower(), version=version,
-                           post_build_fn=post_build_fn)
+                           post_build_fn=post_build_fn,
+                           extra_prebuild_script=extra_prebuild_script)
 
     description = '%s %s' % (name, version)
 
diff --git a/contrib/packaging/hgpackaging/py2exe.py b/contrib/packaging/hgpackaging/py2exe.py
--- a/contrib/packaging/hgpackaging/py2exe.py
+++ b/contrib/packaging/hgpackaging/py2exe.py
@@ -25,7 +25,8 @@
                  python_exe: pathlib.Path, build_name: str,
                  venv_requirements_txt: pathlib.Path,
                  extra_packages=None, extra_excludes=None,
-                 extra_dll_excludes=None):
+                 extra_dll_excludes=None,
+                 extra_prebuild_script=None):
     """Build Mercurial with py2exe.
 
     Build files will be placed in ``build_dir``.
@@ -105,6 +106,16 @@
     env['DISTUTILS_USE_SDK'] = '1'
     env['MSSdk'] = '1'
 
+    if extra_prebuild_script:
+        more_packages = set(subprocess.check_output(
+            extra_prebuild_script,
+            cwd=build_dir).split(b'\0')[-1].strip().decode('utf-8').splitlines())
+        if more_packages:
+            if not extra_packages:
+                extra_packages = more_packages
+            else:
+                extra_packages |= more_packages
+
     if extra_packages:
         env['HG_PY2EXE_EXTRA_PACKAGES'] = ' '.join(sorted(extra_packages))
     if extra_excludes:



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


More information about the Mercurial-devel mailing list