Patchwork D7161: packaging: always pass VERSION into Inno invocation

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

Comments

phabricator - Nov. 9, 2019, 12:05 a.m.
Closed by commit rHGcf5eaf24577f: packaging: always pass VERSION into Inno invocation (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/D7161?vs=17382&id=17813

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

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

AFFECTED FILES
  contrib/packaging/hgpackaging/inno.py
  contrib/packaging/hgpackaging/util.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
@@ -1,21 +1,6 @@ 
 ; Script generated by the Inno Setup Script Wizard.
 ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
 
-#ifndef VERSION
-#define FileHandle
-#define FileLine
-#define VERSION = "unknown"
-#if FileHandle = FileOpen(SourcePath + "\..\..\mercurial\__version__.py")
-  #expr FileLine = FileRead(FileHandle)
-  #expr FileLine = FileRead(FileHandle)
-  #define VERSION = Copy(FileLine, Pos('"', FileLine)+1, Len(FileLine)-Pos('"', FileLine)-1)
-#endif
-#if FileHandle
-  #expr FileClose(FileHandle)
-#endif
-#pragma message "Detected Version: " + VERSION
-#endif
-
 #ifndef ARCH
 #define ARCH = "x86"
 #endif
diff --git a/contrib/packaging/hgpackaging/util.py b/contrib/packaging/hgpackaging/util.py
--- a/contrib/packaging/hgpackaging/util.py
+++ b/contrib/packaging/hgpackaging/util.py
@@ -12,6 +12,7 @@ 
 import glob
 import os
 import pathlib
+import re
 import shutil
 import subprocess
 import tarfile
@@ -210,3 +211,16 @@ 
             full_dest_path.parent.mkdir(parents=True, exist_ok=True)
             shutil.copy(full_source_path, full_dest_path)
             print('copying %s to %s' % (full_source_path, full_dest_path))
+
+
+def read_version_py(source_dir):
+    """Read the mercurial/__version__.py file to resolve the version string."""
+    p = source_dir / 'mercurial' / '__version__.py'
+
+    with p.open('r', encoding='utf-8') as fh:
+        m = re.search('version = b"([^"]+)"', fh.read(), re.MULTILINE)
+
+        if not m:
+            raise Exception('could not parse %s' % p)
+
+        return m.group(1)
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
@@ -18,7 +18,10 @@ 
     build_py2exe,
     stage_install,
 )
-from .util import find_vc_runtime_files
+from .util import (
+    find_vc_runtime_files,
+    read_version_py,
+)
 
 EXTRA_PACKAGES = {
     'dulwich',
@@ -149,8 +152,10 @@ 
     if vc_x64:
         args.append('/dARCH=x64')
 
-    if version:
-        args.append('/dVERSION=%s' % version)
+    if not version:
+        version = read_version_py(source_dir)
+
+    args.append('/dVERSION=%s' % version)
 
     args.append('/Odist')
     args.append(str(inno_build_dir / 'mercurial.iss'))