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_libs = pkgconfig_libs('freetype2', '', '')
sw = os.environ.get('SW', os.path.expanduser('~/sw'))
podofo_inc = os.path.join(sw, 'include', 'podofo')
podofo_lib = os.path.join(sw, 'lib')
podofo_inc = '/usr/include/podofo'
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

View File

@ -15,10 +15,9 @@ from setup.build_environment import BUILD_HOST, PROJECT
BASE_RSYNC = ['rsync', '-av', '--delete', '--force']
EXCLUDES = []
for x in [
'src/calibre/plugins', 'manual', 'translations',
'.bzr', '.git', '.build', '.svn', 'build', 'dist', 'imgsrc', '*.pyc', '*.pyo', '*.swp',
'*.swo', 'format_docs', 'translations']:
EXCLUDES.extend(['--exclude', x])
'/src/calibre/plugins', '/manual', '/translations', '/build', '/dist', '/imgsrc', '/format_docs'
'.bzr', '.git', '.build', '.svn', '*.pyc', '*.pyo', '*.swp', '*.swo',]:
EXCLUDES.extend(['--exclude', ('/calibre' + x) if x.startswith('/') else x])
SAFE_EXCLUDES = ['"%s"'%x if '*' in x else x for x in EXCLUDES]
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
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 (
'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 (
'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]
@ -89,27 +89,28 @@ arch = 'x86_64' if is64bit else 'i686'
def ignore_in_lib(base, items):
ans = []
for y in items:
x = os.path.join(base, y)
if (os.path.isfile(x) and os.path.splitext(x)[1] in ('.so',
'.py')) or \
(os.path.isdir(x) and x not in ('.svn', '.bzr', '.git', 'test', 'tests',
'testing')):
continue
ans.append(y)
for name in items:
path = os.path.join(base, name)
if os.path.isdir(path):
if name in {'.svn', '.bzr', '.git', 'test', 'tests', 'testing'} or not os.path.exists(j(path, '__init__.py')):
if name != 'plugins':
ans.append(name)
else:
if name.rpartition('.')[-1] not in ('so', 'py'):
ans.append(name)
return ans
def import_site_packages(srcdir, dest):
if not os.path.exists(dest):
os.mkdir(dest)
for x in os.listdir(srcdir):
ext = x.rpartition('.')
ext = x.rpartition('.')[-1]
f = j(srcdir, x)
if ext in ('py', 'so'):
shutil.copy2(f, dest)
elif ext == 'pth' and x != 'setuptools.pth':
for line in open(f, 'rb').readlines():
src = j(srcdir, line)
for line in open(f, 'rb').read().splitlines():
src = os.path.abspath(j(srcdir, line))
if os.path.exists(src) and os.path.isdir(src):
import_site_packages(src, dest)
elif os.path.exists(j(f, '__init__.py')):
@ -176,7 +177,7 @@ class LinuxFreeze(Command):
im = glob.glob(SW + '/lib/ImageMagick-*')[-1]
self.magick_base = os.path.basename(im)
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):
self.info('Copying python...')
@ -207,11 +208,11 @@ class LinuxFreeze(Command):
os.remove(self.j(pyqt, x))
for x in os.listdir(self.SRC):
if os.path.isdir(self.j(self.SRC, x)):
shutil.copytree(self.j(self.SRC, x), self.j(dest, x),
ignore=ignore_in_lib)
else:
shutil.copy2(self.j(self.SRC, x), self.j(dest, x))
c = self.j(self.SRC, x)
if os.path.exists(self.j(c, '__init__.py')):
shutil.copytree(c, self.j(dest, x), ignore=ignore_in_lib)
elif os.path.isfile(c):
shutil.copy2(c, self.j(dest, x))
shutil.copytree(self.j(self.src_root, 'resources'), self.j(self.base,
'resources'))
@ -349,7 +350,7 @@ class LinuxFreeze(Command):
with open(self.j(self.py_dir, 'site.py'), 'wb') as f:
f.write(textwrap.dedent('''\
import sys
import encodings
import encodings # noqa
import __builtin__
import locale
import os
@ -359,7 +360,7 @@ class LinuxFreeze(Command):
try:
locale.setlocale(locale.LC_ALL, '')
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')
enc = locale.getdefaultlocale()[1]
if not enc:
@ -389,15 +390,6 @@ class LinuxFreeze(Command):
def set_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():
try:
sys.argv[0] = sys.calibre_basename
@ -406,7 +398,6 @@ class LinuxFreeze(Command):
sys.path.insert(0, os.path.abspath(dfv))
set_default_encoding()
set_helper()
set_qt_plugin_path()
mod = __import__(sys.calibre_module, fromlist=[1])
func = getattr(mod, sys.calibre_function)
return func()

View File

@ -13,6 +13,8 @@
#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) {
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);
/* qt-at-spi causes crashes and performance issues in various distros, so disable it */
if (setenv("QT_ACCESSIBILITY", "0", 1) != 0) {
fprintf(stderr, "Failed to set environment variable with error: %s\n", strerror(errno));
return 1;
}
SET("QT_ACCESSIBILITY", "0")
memset(buf, 0, PATHLEN);
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);
if (setenv("MAGICK_CODER_MODULE_PATH", buf, 1) != 0) {
fprintf(stderr, "Failed to set environment variable with error: %s\n", strerror(errno));
return 1;
}
SET("MAGICK_CODER_MODULE_PATH", buf)
memset(buf, 0, PATHLEN); snprintf(buf, PATHLEN, "%s/%s/modules-Q16/filters", lib, MAGICK_BASE);
if (setenv("MAGICK_CODER_FILTER_PATH", buf, 1) != 0) {
fprintf(stderr, "Failed to set environment variable with error: %s\n", strerror(errno));
return 1;
}
SET("MAGICK_CODER_FILTER_PATH", buf)
memset(buf, 0, PATHLEN);
ldp = getenv("LD_LIBRARY_PATH");
if (ldp == NULL) strncpy(buf, lib, PATHLEN);
else snprintf(buf, PATHLEN, "%s:%s", lib, ldp);
if (setenv("LD_LIBRARY_PATH", buf, 1) != 0) {
fprintf(stderr, "Failed to set environment variable with error: %s\n", strerror(errno));
return 1;
}
SET("LD_LIBRARY_PATH", buf)
argv[0] = exe;
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']
os.environ['LD_LIBRARY_PATH'] = os.pathsep.join(npaths)
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):
if self.changed:
os.environ['LD_LIBRARY_PATH'] = self.orig
if self.changed2:
os.environ['QT_PLUGIN_PATH'] = self.orig2
def open_url(qurl):
if isinstance(qurl, basestring):