D7161: packaging: always pass VERSION into Inno invocation
indygreg (Gregory Szorc)
phabricator at mercurial-scm.org
Thu Oct 24 01:56:20 UTC 2019
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
REVISION SUMMARY
The code in the Inno file was a holdover from before we had
Python driving execution.
With Python in the driver's seat, we can now have it resolve
the version string and pass it into Inno, making the code
easier to understand for people who aren't packaging gurus.
REPOSITORY
rHG Mercurial
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
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'))
To: indygreg, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list