Various fixed for linux binary. Also performance improvement by not importing PyQt in site.py

This commit is contained in:
Kovid Goyal 2014-06-30 07:35:42 +05:30
parent 8f9fa74586
commit db449ebb71
5 changed files with 51 additions and 63 deletions

View File

@ -196,8 +196,11 @@ else:
ft_lib_dirs = pkgconfig_lib_dirs('freetype2', 'FT_LIB_DIR', '/usr/lib') ft_lib_dirs = pkgconfig_lib_dirs('freetype2', 'FT_LIB_DIR', '/usr/lib')
ft_libs = pkgconfig_libs('freetype2', '', '') ft_libs = pkgconfig_libs('freetype2', '', '')
sw = os.environ.get('SW', os.path.expanduser('~/sw')) sw = os.environ.get('SW', os.path.expanduser('~/sw'))
podofo_inc = os.path.join(sw, 'include', 'podofo') podofo_inc = '/usr/include/podofo'
podofo_lib = os.path.join(sw, 'lib') podofo_lib = '/usr/lib'
if not os.path.exists(podofo_inc + '/podofo.h'):
podofo_inc = os.path.join(sw, 'include', 'podofo')
podofo_lib = os.path.join(sw, 'lib')
magick_error = None magick_error = None

View File

@ -15,10 +15,9 @@ from setup.build_environment import BUILD_HOST, PROJECT
BASE_RSYNC = ['rsync', '-av', '--delete', '--force'] BASE_RSYNC = ['rsync', '-av', '--delete', '--force']
EXCLUDES = [] EXCLUDES = []
for x in [ for x in [
'src/calibre/plugins', 'manual', 'translations', '/src/calibre/plugins', '/manual', '/translations', '/build', '/dist', '/imgsrc', '/format_docs'
'.bzr', '.git', '.build', '.svn', 'build', 'dist', 'imgsrc', '*.pyc', '*.pyo', '*.swp', '.bzr', '.git', '.build', '.svn', '*.pyc', '*.pyo', '*.swp', '*.swo',]:
'*.swo', 'format_docs', 'translations']: EXCLUDES.extend(['--exclude', ('/calibre' + x) if x.startswith('/') else x])
EXCLUDES.extend(['--exclude', x])
SAFE_EXCLUDES = ['"%s"'%x if '*' in x else x for x in EXCLUDES] SAFE_EXCLUDES = ['"%s"'%x if '*' in x else x for x in EXCLUDES]
def get_rsync_pw(): def get_rsync_pw():

View File

@ -52,7 +52,6 @@ path=(~/bin "$path[@]")
''' '''
import sys, os, shutil, platform, subprocess, stat, py_compile, glob, textwrap, tarfile import sys, os, shutil, platform, subprocess, stat, py_compile, glob, textwrap, tarfile
from setup import Command, modules, basenames, functions, __version__, __appname__ from setup import Command, modules, basenames, functions, __version__, __appname__
@ -77,11 +76,12 @@ def binary_includes():
)] + [ )] + [
glob.glob('/lib/*/lib' + x)[-1] for x in ( glob.glob('/lib/*/lib' + x)[-1] for x in (
'glib-2.0.so.0', 'gcrypt.so.11', 'gpg-error.so.0', 'dbus-1.so.3', 'pcre.so.3', 'glib-2.0.so.0', 'gcrypt.so.11', 'gpg-error.so.0', 'dbus-1.so.3', 'pcre.so.3', 'selinux.so.1',
)] + [ )] + [
glob.glob('/usr/lib/*/lib' + x)[-1] for x in ( glob.glob('/usr/lib/*/lib' + x)[-1] for x in (
'gthread-2.0.so.0', 'ffi.so.5', 'stdc++.so.6', 'gobject-2.0.so.0', 'gthread-2.0.so.0', 'gmodule-2.0.so.0', 'gstreamer-0.10.so.0', 'gstbase-0.10.so.0', 'gstpbutils-0.10.so.0', 'gio-2.0.so.0',
'ffi.so.5', 'stdc++.so.6',
)] + [ )] + [
j(qt['libs'], 'lib%s.so.5' % x) for x in QT_DLLS] j(qt['libs'], 'lib%s.so.5' % x) for x in QT_DLLS]
@ -89,27 +89,28 @@ arch = 'x86_64' if is64bit else 'i686'
def ignore_in_lib(base, items): def ignore_in_lib(base, items):
ans = [] ans = []
for y in items: for name in items:
x = os.path.join(base, y) path = os.path.join(base, name)
if (os.path.isfile(x) and os.path.splitext(x)[1] in ('.so', if os.path.isdir(path):
'.py')) or \ if name in {'.svn', '.bzr', '.git', 'test', 'tests', 'testing'} or not os.path.exists(j(path, '__init__.py')):
(os.path.isdir(x) and x not in ('.svn', '.bzr', '.git', 'test', 'tests', if name != 'plugins':
'testing')): ans.append(name)
continue else:
ans.append(y) if name.rpartition('.')[-1] not in ('so', 'py'):
ans.append(name)
return ans return ans
def import_site_packages(srcdir, dest): def import_site_packages(srcdir, dest):
if not os.path.exists(dest): if not os.path.exists(dest):
os.mkdir(dest) os.mkdir(dest)
for x in os.listdir(srcdir): for x in os.listdir(srcdir):
ext = x.rpartition('.') ext = x.rpartition('.')[-1]
f = j(srcdir, x) f = j(srcdir, x)
if ext in ('py', 'so'): if ext in ('py', 'so'):
shutil.copy2(f, dest) shutil.copy2(f, dest)
elif ext == 'pth' and x != 'setuptools.pth': elif ext == 'pth' and x != 'setuptools.pth':
for line in open(f, 'rb').readlines(): for line in open(f, 'rb').read().splitlines():
src = j(srcdir, line) src = os.path.abspath(j(srcdir, line))
if os.path.exists(src) and os.path.isdir(src): if os.path.exists(src) and os.path.isdir(src):
import_site_packages(src, dest) import_site_packages(src, dest)
elif os.path.exists(j(f, '__init__.py')): elif os.path.exists(j(f, '__init__.py')):
@ -176,7 +177,7 @@ class LinuxFreeze(Command):
im = glob.glob(SW + '/lib/ImageMagick-*')[-1] im = glob.glob(SW + '/lib/ImageMagick-*')[-1]
self.magick_base = os.path.basename(im) self.magick_base = os.path.basename(im)
dest = self.j(self.lib_dir, self.magick_base) dest = self.j(self.lib_dir, self.magick_base)
shutil.copytree(im, dest, ignore=shutil.ignore_patterns('*.a', '*.la')) shutil.copytree(im, dest, ignore=shutil.ignore_patterns('*.a'))
def copy_python(self): def copy_python(self):
self.info('Copying python...') self.info('Copying python...')
@ -207,11 +208,11 @@ class LinuxFreeze(Command):
os.remove(self.j(pyqt, x)) os.remove(self.j(pyqt, x))
for x in os.listdir(self.SRC): for x in os.listdir(self.SRC):
if os.path.isdir(self.j(self.SRC, x)): c = self.j(self.SRC, x)
shutil.copytree(self.j(self.SRC, x), self.j(dest, x), if os.path.exists(self.j(c, '__init__.py')):
ignore=ignore_in_lib) shutil.copytree(c, self.j(dest, x), ignore=ignore_in_lib)
else: elif os.path.isfile(c):
shutil.copy2(self.j(self.SRC, x), self.j(dest, x)) shutil.copy2(c, self.j(dest, x))
shutil.copytree(self.j(self.src_root, 'resources'), self.j(self.base, shutil.copytree(self.j(self.src_root, 'resources'), self.j(self.base,
'resources')) 'resources'))
@ -349,7 +350,7 @@ class LinuxFreeze(Command):
with open(self.j(self.py_dir, 'site.py'), 'wb') as f: with open(self.j(self.py_dir, 'site.py'), 'wb') as f:
f.write(textwrap.dedent('''\ f.write(textwrap.dedent('''\
import sys import sys
import encodings import encodings # noqa
import __builtin__ import __builtin__
import locale import locale
import os import os
@ -359,7 +360,7 @@ class LinuxFreeze(Command):
try: try:
locale.setlocale(locale.LC_ALL, '') locale.setlocale(locale.LC_ALL, '')
except: except:
print 'WARNING: Failed to set default libc locale, using en_US.UTF-8' print ('WARNING: Failed to set default libc locale, using en_US.UTF-8')
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
enc = locale.getdefaultlocale()[1] enc = locale.getdefaultlocale()[1]
if not enc: if not enc:
@ -389,15 +390,6 @@ class LinuxFreeze(Command):
def set_helper(): def set_helper():
__builtin__.help = _Helper() __builtin__.help = _Helper()
def set_qt_plugin_path():
import uuid
uuid.uuid4() # Workaround for libuuid/PyQt conflict
from PyQt5.Qt import QCoreApplication
paths = list(map(unicode, QCoreApplication.libraryPaths()))
paths.insert(0, sys.frozen_path + '/lib/qt_plugins')
QCoreApplication.setLibraryPaths(paths)
def main(): def main():
try: try:
sys.argv[0] = sys.calibre_basename sys.argv[0] = sys.calibre_basename
@ -406,7 +398,6 @@ class LinuxFreeze(Command):
sys.path.insert(0, os.path.abspath(dfv)) sys.path.insert(0, os.path.abspath(dfv))
set_default_encoding() set_default_encoding()
set_helper() set_helper()
set_qt_plugin_path()
mod = __import__(sys.calibre_module, fromlist=[1]) mod = __import__(sys.calibre_module, fromlist=[1])
func = getattr(mod, sys.calibre_function) func = getattr(mod, sys.calibre_function)
return func() return func()

View File

@ -13,6 +13,8 @@
#define PATHLEN 1023 #define PATHLEN 1023
#define SET(x, y) if (setenv(x, y, 1) != 0) { fprintf(stderr, "Failed to set environment variable with error: %s\n", strerror(errno)); return 1; }
int main(int argc, char **argv) { int main(int argc, char **argv) {
static char buf[PATHLEN+1] = {0}, lib[PATHLEN+1] = {0}, base[PATHLEN+1] = {0}, exe[PATHLEN+1] = {0}, *ldp = NULL; static char buf[PATHLEN+1] = {0}, lib[PATHLEN+1] = {0}, base[PATHLEN+1] = {0}, exe[PATHLEN+1] = {0}, *ldp = NULL;
@ -27,39 +29,23 @@ int main(int argc, char **argv) {
snprintf(lib, PATHLEN, "%s/lib", base); snprintf(lib, PATHLEN, "%s/lib", base);
/* qt-at-spi causes crashes and performance issues in various distros, so disable it */ /* qt-at-spi causes crashes and performance issues in various distros, so disable it */
if (setenv("QT_ACCESSIBILITY", "0", 1) != 0) { SET("QT_ACCESSIBILITY", "0")
fprintf(stderr, "Failed to set environment variable with error: %s\n", strerror(errno)); memset(buf, 0, PATHLEN);
return 1; ldp = getenv("QT_PLUGIN_PATH");
} if (ldp == NULL) snprintf(buf, PATHLEN, "%s/qt_plugins", lib);
else snprintf(buf, PATHLEN, "%s/qt_plugins:%s", lib, ldp);
SET("QT_PLUGIN_PATH", buf);
if (setenv("MAGICK_HOME", base, 1) != 0) {
fprintf(stderr, "Failed to set environment variable with error: %s\n", strerror(errno));
return 1;
}
memset(buf, 0, PATHLEN); snprintf(buf, PATHLEN, "%s/%s/config", lib, MAGICK_BASE);
if (setenv("MAGICK_CONFIGURE_PATH", buf, 1) != 0) {
fprintf(stderr, "Failed to set environment variable with error: %s\n", strerror(errno));
return 1;
}
memset(buf, 0, PATHLEN); snprintf(buf, PATHLEN, "%s/%s/modules-Q16/coders", lib, MAGICK_BASE); memset(buf, 0, PATHLEN); snprintf(buf, PATHLEN, "%s/%s/modules-Q16/coders", lib, MAGICK_BASE);
if (setenv("MAGICK_CODER_MODULE_PATH", buf, 1) != 0) { SET("MAGICK_CODER_MODULE_PATH", buf)
fprintf(stderr, "Failed to set environment variable with error: %s\n", strerror(errno));
return 1;
}
memset(buf, 0, PATHLEN); snprintf(buf, PATHLEN, "%s/%s/modules-Q16/filters", lib, MAGICK_BASE); memset(buf, 0, PATHLEN); snprintf(buf, PATHLEN, "%s/%s/modules-Q16/filters", lib, MAGICK_BASE);
if (setenv("MAGICK_CODER_FILTER_PATH", buf, 1) != 0) { SET("MAGICK_CODER_FILTER_PATH", buf)
fprintf(stderr, "Failed to set environment variable with error: %s\n", strerror(errno));
return 1;
}
memset(buf, 0, PATHLEN); memset(buf, 0, PATHLEN);
ldp = getenv("LD_LIBRARY_PATH"); ldp = getenv("LD_LIBRARY_PATH");
if (ldp == NULL) strncpy(buf, lib, PATHLEN); if (ldp == NULL) strncpy(buf, lib, PATHLEN);
else snprintf(buf, PATHLEN, "%s:%s", lib, ldp); else snprintf(buf, PATHLEN, "%s:%s", lib, ldp);
if (setenv("LD_LIBRARY_PATH", buf, 1) != 0) { SET("LD_LIBRARY_PATH", buf)
fprintf(stderr, "Failed to set environment variable with error: %s\n", strerror(errno));
return 1;
}
argv[0] = exe; argv[0] = exe;
if (execv(exe, argv) == -1) { if (execv(exe, argv) == -1) {

View File

@ -1009,10 +1009,19 @@ class SanitizeLibraryPath(object):
npaths = [x for x in paths if x != sys.frozen_path+'/lib'] npaths = [x for x in paths if x != sys.frozen_path+'/lib']
os.environ['LD_LIBRARY_PATH'] = os.pathsep.join(npaths) os.environ['LD_LIBRARY_PATH'] = os.pathsep.join(npaths)
self.changed = True self.changed = True
self.orig2 = os.environ.get('QT_PLUGIN_PATH', '')
self.changed2 = False
paths = [x for x in self.orig2.split(os.pathsep) if x]
if isfrozen and islinux and paths:
npaths = [x for x in paths if x != sys.frozen_path+'/lib/qt_plugins']
os.environ['QT_PLUGIN_PATH'] = os.pathsep.join(npaths)
self.changed2 = True
def __exit__(self, *args): def __exit__(self, *args):
if self.changed: if self.changed:
os.environ['LD_LIBRARY_PATH'] = self.orig os.environ['LD_LIBRARY_PATH'] = self.orig
if self.changed2:
os.environ['QT_PLUGIN_PATH'] = self.orig2
def open_url(qurl): def open_url(qurl):
if isinstance(qurl, basestring): if isinstance(qurl, basestring):