From b5a166753b02eea1712131ec004adfe2564b8db4 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 6 Jun 2011 11:33:32 -0600 Subject: [PATCH] Windows build: No longer install CRT in the system SxS folder. Makes calibre fully relocatable. --- setup/installer/windows/en-us.xml | 2 +- setup/installer/windows/freeze.py | 33 ++++++++++++++++++++++-- setup/installer/windows/wix-template.xml | 16 ++++++------ setup/installer/windows/wix.py | 1 - src/calibre/test_build.py | 7 +++++ 5 files changed, 47 insertions(+), 12 deletions(-) diff --git a/setup/installer/windows/en-us.xml b/setup/installer/windows/en-us.xml index 89cc25f0a2..d3cdac2a41 100644 --- a/setup/installer/windows/en-us.xml +++ b/setup/installer/windows/en-us.xml @@ -1,6 +1,6 @@ - If you are upgrading from a {app} version older than 0.6.17, please uninstall {app} first. Click Advanced to change installation settings. + Click Advanced to change installation settings. Computing space requirements, this may take upto five minutes... Computing space requirements, this may take upto five minutes... Computing space requirements, this may take upto five minutes... diff --git a/setup/installer/windows/freeze.py b/setup/installer/windows/freeze.py index 59d08cea64..63993c19f0 100644 --- a/setup/installer/windows/freeze.py +++ b/setup/installer/windows/freeze.py @@ -8,8 +8,8 @@ __docformat__ = 'restructuredtext en' import sys, os, shutil, glob, py_compile, subprocess, re, zipfile, time -from setup import Command, modules, functions, basenames, __version__, \ - __appname__ +from setup import (Command, modules, functions, basenames, __version__, + __appname__) from setup.build_environment import msvc, MT, RC from setup.installer.windows.wix import WixMixIn @@ -20,6 +20,7 @@ LIBUNRAR = 'C:\\Program Files\\UnrarDLL\\unrar.dll' SW = r'C:\cygwin\home\kovid\sw' IMAGEMAGICK = os.path.join(SW, 'build', 'ImageMagick-6.6.6', 'VisualMagick', 'bin') +CRT = r'C:\Microsoft.VC90.CRT' VERSION = re.sub('[a-z]\d+', '', __version__) WINVER = VERSION+'.0' @@ -81,8 +82,33 @@ class Win32Freeze(Command, WixMixIn): self.embed_manifests() self.install_site_py() self.archive_lib_dir() + self.remove_CRT_from_manifests() self.create_installer() + def remove_CRT_from_manifests(self): + ''' + The dependency on the CRT is removed from the manifests of all DLLs. + This allows the CRT loaded by the .exe files to be used instead. + ''' + search_pat = re.compile(r'(?is).*Microsoft\.VC\d+\.CRT') + repl_pat = re.compile( + r'(?is).*?Microsoft\.VC\d+\.CRT.*?') + + for dll in glob.glob(self.j(self.dll_dir, '*.dll')): + bn = self.b(dll) + with open(dll, 'rb') as f: + raw = f.read() + match = search_pat.search(raw) + if match is None: + continue + self.info('Removing CRT dependency from manifest of: %s'%bn) + # Blank out the bytes corresponding to the dependency specification + nraw = repl_pat.sub(lambda m: b' '*len(m.group()), raw) + if len(nraw) != len(raw): + raise Exception('Something went wrong with %s'%bn) + with open(dll, 'wb') as f: + f.write(nraw) + def initbase(self): if self.e(self.base): shutil.rmtree(self.base) @@ -103,6 +129,9 @@ class Win32Freeze(Command, WixMixIn): def freeze(self): shutil.copy2(self.j(self.src_root, 'LICENSE'), self.base) + self.info('Adding CRT') + shutil.copytree(CRT, self.j(self.base, os.path.basename(CRT))) + self.info('Adding resources...') tgt = self.j(self.base, 'resources') if os.path.exists(tgt): diff --git a/setup/installer/windows/wix-template.xml b/setup/installer/windows/wix-template.xml index 3ebe0882e0..46b5a07ead 100644 --- a/setup/installer/windows/wix-template.xml +++ b/setup/installer/windows/wix-template.xml @@ -11,6 +11,10 @@ SummaryCodepage='1252' /> + + - @@ -100,10 +103,6 @@ - - - - @@ -149,12 +148,13 @@ Set default folder name and allow only per machine installs. For a per-machine installation, the default installation location will be [ProgramFilesFolder][ApplicationFolderName] and the user - will be able to change it in the setup UI. This is because the installer - has to install the VC90 merge module into the system winsxs folder for python - to work, so per user installs are impossible anyway. + will be able to change it in the setup UI. This is no longer necessary + (i.e. per user installs should work) but left this way as I + dont want to deal with the complications --> + diff --git a/setup/installer/windows/wix.py b/setup/installer/windows/wix.py index 857a667a9e..b43e14a711 100644 --- a/setup/installer/windows/wix.py +++ b/setup/installer/windows/wix.py @@ -35,7 +35,6 @@ class WixMixIn: exe_map = self.smap, main_icon = self.j(self.src_root, 'icons', 'library.ico'), web_icon = self.j(self.src_root, 'icons', 'web.ico'), - crt_msm = self.j(self.SW, 'Microsoft_VC90_CRT_x86.msm') ) template = open(self.j(self.d(__file__), 'en-us.xml'), 'rb').read() diff --git a/src/calibre/test_build.py b/src/calibre/test_build.py index 4d45077b93..b987658d72 100644 --- a/src/calibre/test_build.py +++ b/src/calibre/test_build.py @@ -88,6 +88,12 @@ def test_imaging(): raise RuntimeError('PIL choked!') print ('PIL OK!') +def test_unrar(): + from calibre.libunrar import _libunrar + if not _libunrar: + raise RuntimeError('Failed to load libunrar') + print ('Unrar OK!') + def test(): test_plugins() test_lxml() @@ -98,6 +104,7 @@ def test(): test_win32() test_qt() test_imaging() + test_unrar() if __name__ == '__main__': test()