view contrib/win32/win32-build.txt @ 20742:3681de20b0a7

parsers: fail fast if Python has wrong minor version (issue4110) This change causes an informative ImportError to be raised when importing the parsers extension module if the minor version of the currently-running Python interpreter doesn't match that of the Python used when compiling the extension module. This change also exposes a parsers.versionerrortext constant in the C implementation of the module. Its presence can be used to determine whether this behavior is present in a version of the module. The value of the constant is the leading text of the ImportError raised and is set to "Python minor version mismatch". Here is an example of what the new error looks like: Traceback (most recent call last): File "test.py", line 1, in <module> import mercurial.parsers ImportError: Python minor version mismatch: The Mercurial extension modules were compiled with Python 2.7.6, but Mercurial is currently using Python with sys.hexversion=33883888: Python 2.5.6 (r256:88840, Nov 18 2012, 05:37:10) [GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] at: /opt/local/Library/Frameworks/Python.framework/Versions/2.5/Resources/ Python.app/Contents/MacOS/Python The reason for raising an error in this scenario is that Python's C API is known not to be compatible from minor version to minor version, even if sys.api_version is the same. See for example this Python bug report about incompatibilities between 2.5 and 2.6+: http://bugs.python.org/issue8118 These incompatibilities can cause Mercurial to break in mysterious, unforeseen ways. For example, when Mercurial compiled with Python 2.7 was run with 2.5, the following crash occurred when running "hg status": http://bz.selenic.com/show_bug.cgi?id=4110 After this crash was fixed, running with Python 2.5 no longer crashes, but the following puzzling behavior still occurs: $ hg status ... File ".../mercurial/changelog.py", line 123, in __init__ revlog.revlog.__init__(self, opener, "00changelog.i") File ".../mercurial/revlog.py", line 251, in __init__ d = self._io.parseindex(i, self._inline) File ".../mercurial/revlog.py", line 158, in parseindex index, cache = parsers.parse_index2(data, inline) TypeError: data is not a string which can be reproduced more simply with: import mercurial.parsers as parsers parsers.parse_index2("", True) Both the crash and the TypeError occurred because the Python C API's PyString_Check() returns the wrong value when the C header files from Python 2.7 are run with Python 2.5. This is an example of an incompatibility of the sort mentioned in the Python bug report above. Failing fast with an informative error message results in a better user experience in cases like the above. The information in the ImportError also simplifies troubleshooting for those on Mercurial mailing lists, the bug tracker, etc. This patch only adds the version check to parsers.c, which is sufficient to affect command-line commands like "hg status" and "hg summary". An idea for a future improvement is to move the version-checking C code to a more central location, and have it run when importing all Mercurial extension modules and not just parsers.c.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Wed, 04 Dec 2013 20:38:27 -0800
parents 170fc0949fb6
children e999ed2192ef
line wrap: on
line source

The standalone Windows installer for Mercurial is built in a somewhat
jury-rigged fashion.

It has the following prerequisites. Ensure to take the packages
matching the mercurial version you want to build (32-bit or 64-bit).

  Python 2.6 for Windows
      http://www.python.org/download/releases/

  A compiler:
    either MinGW
      http://www.mingw.org/
    or Microsoft Visual C++ 2008 SP1 Express Edition
      http://www.microsoft.com/express/Downloads/Download-2008.aspx

  Python for Windows Extensions
      http://sourceforge.net/projects/pywin32/

  mfc71.dll (just download, don't install; not needed for Python 2.6)
      http://starship.python.net/crew/mhammond/win32/

  Visual C++ 2008 redistributable package (needed for >= Python 2.6 or if you compile with MSVC)
    for 32-bit:
      http://www.microsoft.com/downloads/details.aspx?FamilyID=9b2da534-3e03-4391-8a4d-074b9f2bc1bf
    for 64-bit:
      http://www.microsoft.com/downloads/details.aspx?familyid=bd2a6171-e2d6-4230-b809-9a8d7548c1b6

  The py2exe distutils extension
      http://sourceforge.net/projects/py2exe/

  GnuWin32 gettext utility (if you want to build translations)
      http://gnuwin32.sourceforge.net/packages/gettext.htm

  Inno Setup
      http://www.jrsoftware.org/isdl.php#qsp

      Get and install ispack-5.3.10.exe or later (includes Inno Setup Processor),
      which is necessary to package Mercurial.

  ISTool - optional
      http://www.istool.org/default.aspx/

  add_path (you need only add_path.exe in the zip file)
      http://www.barisione.org/apps.html#add_path

  Docutils
      http://docutils.sourceforge.net/

  CA Certs file
      http://curl.haxx.se/ca/cacert.pem

And, of course, Mercurial itself.

Once you have all this installed and built, clone a copy of the
Mercurial repository you want to package, and name the repo
C:\hg\hg-release.

In a shell, build a standalone copy of the hg.exe program.

Building instructions for MinGW:
  python setup.py build -c mingw32
  python setup.py py2exe -b 2
Note: the previously suggested combined command of "python setup.py build -c
mingw32 py2exe -b 2" doesn't work correctly anymore as it doesn't include the
extensions in the mercurial subdirectory.
If you want to create a file named setup.cfg with the contents:
[build]
compiler=mingw32
you can skip the first build step.

Building instructions with MSVC 2008 Express Edition:
  for 32-bit:
    "C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86
    python setup.py py2exe -b 2
  for 64-bit:
    "C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86_amd64
    python setup.py py2exe -b 3

Copy add_path.exe and cacert.pem files into the dist directory that just got created.

If you are using Python up to version 2.5.4, copy mfc71.dll into the dist
directory that just got created.

If you are using Python 2.6 or later, or if you are using MSVC 2008 to compile
mercurial, you must include the C runtime libraries in the installer. To do so,
install the Visual C++ 2008 redistributable package. Then in your windows\winsxs
folder, locate the folder containing the dlls version 9.0.21022.8.
For x86, it should be named like x86_Microsoft.VC90.CRT_(...)_9.0.21022.8(...).
For x64, it should be named like amd64_Microsoft.VC90.CRT_(...)_9.0.21022.8(...).
Copy the files named msvcm90.dll, msvcp90.dll and msvcr90.dll into the dist
directory.
Then in the windows\winsxs\manifests folder, locate the corresponding manifest
file (x86_Microsoft.VC90.CRT_(...)_9.0.21022.8(...).manifest for x86,
amd64_Microsoft.VC90.CRT_(...)_9.0.21022.8(...).manifest for x64), copy it in the
dist directory and rename it to Microsoft.VC90.CRT.manifest.

Before building the installer, you have to build Mercurial HTML documentation
(or fix mercurial.iss to not reference the doc directory):

  cd doc
  mingw32-make html
  cd ..

If you use ISTool, you open the C:\hg\hg-release\contrib\win32\mercurial.iss
file and type Ctrl-F9 to compile the installer file.

Otherwise you run the Inno Setup compiler.  Assuming it's in the path
you should execute:

  iscc contrib\win32\mercurial.iss /dVERSION=foo

Where 'foo' is the version number you would like to see in the
'Add/Remove Applications' tool.  The installer will be placed into
a directory named Output/ at the root of your repository.
If the /dVERSION=foo parameter is not given in the command line, the
installer will retrieve the version information from the __version__.py file.

If you want to build an installer for a 64-bit mercurial, add /dARCH=x64 to
your command line:
  iscc contrib\win32\mercurial.iss /dARCH=x64

To automate the steps above you may want to create a batchfile based on the
following (MinGW build chain):

  echo [build] > setup.cfg
  echo compiler=mingw32 >> setup.cfg
  python setup.py py2exe -b 2
  cd doc
  mingw32-make html
  cd ..
  iscc contrib\win32\mercurial.iss /dVERSION=snapshot

and run it from the root of the hg repository (c:\hg\hg-release).