IGN:More work on leopard build

This commit is contained in:
Kovid Goyal 2009-09-02 16:16:40 -06:00
parent 0acbb330e9
commit 6ad672ae40
6 changed files with 72 additions and 41 deletions

View File

@ -1,6 +1,5 @@
#!/usr/bin/env python
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
from __future__ import with_statement
__license__ = 'GPL v3'
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
@ -39,13 +38,19 @@ def _run():
import os, sys, site
sys.frozen = 'macosx_app'
base = os.environ['RESOURCEPATH']
sys.frameworks_dir = os.path.join(os.path.dirname(base, 'Frameworks'))
sys.frameworks_dir = os.path.join(os.path.dirname(base), 'Frameworks')
sys.new_app_bundle = True
site.addsitedir(base)
site.addsitedir(os.path.join(base, 'Python', 'site-packages'))
exe = os.environ.get('CALIBRE_LAUNCH_MODULE', 'calibre.gui2.main')
exe = os.path.join(base, 'Python', 'site-packages', *exe.split('.'))
exe += '.py'
sys.argv[0] = __file__ = exe
argv = os.environ.get('CALIBRE_LAUNCH_ARGV', None)
if argv is not None:
import cPickle
argv = cPickle.loads(argv)
sys.argv[1:] = argv
execfile(exe, globals(), globals())
_run()

View File

@ -5,7 +5,7 @@ __copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
import os, sys
import os, sys, cPickle
ENV = {}##ENV##
MODULE = ''##MODULE##
@ -18,13 +18,16 @@ resources_dir = os.path.join(base_dir, 'Resources')
frameworks_dir = os.path.join(base_dir, 'Frameworks')
exe_dir = os.path.join(base_dir, 'MacOS')
base_name = os.path.splitext(name)[0]
python = os.path.join(base_dir, 'MacOS', 'calibre')
python = os.path.join(base_dir, 'MacOS', 'Python')
for key, val in ENV.items():
if val.startswith('@exec'):
ENV[key] = os.path.normpath(val.replace('@executable_path', exe_dir))
ENV['CALIBRE_LAUNCH_MODULE'] = MODULE
ENV['CALIBRE_LAUNCH_ARGV'] = cPickle.dumps(sys.argv[1:], -1)
ENV['RESOURCEPATH'] = resources_dir
os.environ.update(ENV)
args = [path] + sys.argv[1:]
launcher = os.path.join(resources_dir, 'launcher.py')
args = ['-OO', launcher]
os.execv(python, args)

View File

@ -864,9 +864,10 @@ static int py2app_main(int argc, char * const *argv, char * const *envp) {
if (!getApplicationName()) return report_error(ERR_NONAME);
pyLocations = (CFArrayRef)getKey("PyRuntimeLocations");
if (!pyLocations) return report_error(ERR_PYRUNTIMELOCATIONS);
printf("1111111\n;");
pyLocation = findPyLocation(pyLocations);
if (!pyLocation) return report_error(ERR_NOPYTHONRUNTIME);
printf("2222222\n");
setExecutablePath();
setResourcePath();
/* check for ':' in path, not compatible with Python due to Py_GetPath */
@ -895,7 +896,7 @@ static int py2app_main(int argc, char * const *argv, char * const *envp) {
xCFStringGetCString(pyLocation, buf, sizeof(buf), kCFStringEncodingUTF8);
py_dylib = dlopen(buf, PYMACAPP_DYLD_FLAGS);
if (py_dylib == NULL) return report_linkEdit_error();
printf("3333333\n");
#define LOOKUP_SYMBOL(NAME) \
tmpSymbol = dlsym(py_dylib, # NAME)
#define LOOKUP_DEFINEADDRESS(NAME, ADDRESS) \

View File

@ -26,6 +26,7 @@ ENV = dict(
PYTHONIOENCODING='utf-8:replace',
PYTHONPATH='@executable_path/../Resources/Python/site-packages',
PYTHONHOME='@executable_path/../Resources/Python',
PYTHONOPTIMIZE='2',
QT_PLUGIN_PATH='@executable_path'
)
@ -85,6 +86,7 @@ class Py2App(object):
self.contents_dir = join(self.build_dir, 'Contents')
self.resources_dir = join(self.contents_dir, 'Resources')
self.frameworks_dir = join(self.contents_dir, 'Frameworks')
self.version_info = '.'.join(map(str, sys.version_info[:2]))
self.to_strip = []
self.warnings = []
@ -141,6 +143,9 @@ class Py2App(object):
launcher = launcher.replace('{}##ENV##', repr(ENV))
os.mkdir(join(self.resources_dir, 'loaders'))
for basename, module in zip(all_names, all_modules):
py_file = join('src', *module.split('.'))+'.py'
shutil.copy2(py_file, join(self.resources_dir, 'Python',
'site-packages', *module.split('.'))+'.py')
raw = launcher.replace("''##MODULE##", repr(module))
path = join(self.resources_dir, 'loaders', basename)
open(path, 'wb').write(raw)
@ -174,13 +179,10 @@ class Py2App(object):
raw = subprocess.Popen(['otool', '-L', path_to_lib],
stdout=subprocess.PIPE).stdout.read()
for line in raw.splitlines():
if 'compatibility' not in line:
if 'compatibility' not in line or line.strip().endswith(':'):
continue
idx = line.find('(')
path = line[:idx].strip()
bname = os.path.basename(path).partition('.')[0]
if bname in path_to_lib:
continue
yield path
@flush
@ -213,6 +215,7 @@ class Py2App(object):
@flush
def add_python_framework(self):
print '\nAdding Python framework'
src = join(SW, 'python', 'Python.framework')
x = join(self.frameworks_dir, 'Python.framework')
curr = os.path.realpath(join(src, 'Versions', 'Current'))
@ -223,6 +226,10 @@ class Py2App(object):
shutil.copy2(join(curr, 'Python'), currd)
self.set_id(join(currd, 'Python'),
self.FID+'/Python.framework/Versions/%s/Python'%basename(curr))
python = '%s/python/Python.framework/Versions/%s/Resources/Python.app/Contents/MacOS/Python'\
% (SW, self.version_info)
shutil.copy2(python, join(self.contents_dir, 'MacOS'))
self.fix_dependencies_in_lib(join(self.contents_dir, 'MacOS', 'Python'))
@flush
def add_qt_frameworks(self):
@ -264,7 +271,7 @@ class Py2App(object):
os.mkdir(dest)
for f in glob.glob('src/calibre/plugins/*.so'):
shutil.copy2(f, dest)
self.fix_dependencies_in_lib(join(dest, basename(f)))
self.fix_dependencies_in_lib(join(dest, basename(f)))
@flush
@ -279,7 +286,7 @@ class Py2App(object):
CFBundleSignature='????',
CFBundleExecutable='calibre',
LSMinimumSystemVersion='10.5.2',
PyRuntimeLocations=[self.FID+'/Python.framework/Versions/Current/Python'],
PyRuntimeLocations=[self.FID+'/Python.framework/Versions/%s/Python'%self.version_info],
LSRequiresNativeExecution=True,
NSAppleScriptEnabled=False,
NSHumanReadableCopyright='Copyright 2008, Kovid Goyal',
@ -369,7 +376,9 @@ class Py2App(object):
def add_misc_libraries(self):
for x in ('usb', 'unrar'):
print '\nAdding', x
shutil.copy2(join(SW, 'lib', 'lib%s.dylib'%x), self.frameworks_dir)
x = 'lib%s.dylib'%x
shutil.copy2(join(SW, 'lib', x), self.frameworks_dir)
self.set_id(join(self.frameworks_dir, x), self.FID+'/'+x)
@flush
def add_site_packages(self):
@ -436,6 +445,11 @@ class Py2App(object):
dest = join(dest, basename(x))
shutil.copytree(x, dest, symlinks=True, ignore=ignore)
self.postprocess_package(x, dest)
for x in os.walk(dest):
for f in x[-1]:
if f.endswith('.so'):
f = join(x[0], f)
self.fix_dependencies_in_lib(f)
@flush
def filter_package(self, name):
@ -450,20 +464,22 @@ class Py2App(object):
def add_stdlib(self):
print '\nAdding python stdlib'
src = join(SW, 'python/Python.framework/Versions/Current/lib/python')
src += '.'.join(map(str, sys.version_info[:2]))
src += self.version_info
dest = join(self.resources_dir, 'Python', 'lib', 'python')
dest += '.'.join(map(str, sys.version_info[:2]))
dest += self.version_info
os.makedirs(dest)
for x in os.listdir(src):
if x in ('site-packages', 'config', 'test', 'lib2to3', 'lib-tk',
'lib-old', 'idlelib', 'plat-mac', 'plat-darwin', 'site.py'):
continue
x = join(src, x)
if os.path.isdir(x):
self.add_package_dir(join(src, x), dest)
elif os.path.splitext(x) in ('.so', '.py'):
shutil.copy2(join(src, x), dest)
dest = join(dest, basename(x))
if dest.endswith('.so'):
self.fix_dependencies_in_lib(dest)
self.add_package_dir(x, dest)
elif os.path.splitext(x)[1] in ('.so', '.py'):
shutil.copy2(x, dest)
dest2 = join(dest, basename(x))
if dest2.endswith('.so'):
self.fix_dependencies_in_lib(dest2)
self.remove_bytecode(join(self.resources_dir, 'Python', 'lib'))
@flush
@ -509,8 +525,10 @@ class Py2App(object):
@flush
def copy_launcher_and_site(self):
base = os.path.dirname(__file__)
for x in ('launcher', 'site'):
shutil.copy2(join(base, x+'.py'), self.resources_dir)
shutil.copy2(join(base, 'launcher.py'), self.resources_dir)
shutil.copy2(join(base, 'site.py'), join(self.resources_dir, 'Python',
'lib', 'python'+self.version_info))
@flush
def makedmg(self, d, volname,

View File

@ -305,22 +305,25 @@ Device._fields_ = [ \
]
if _libusb is not None:
_libusb.usb_get_busses.restype = POINTER(Bus)
_libusb.usb_open.restype = POINTER(DeviceHandle)
_libusb.usb_open.argtypes = [POINTER(Device)]
_libusb.usb_close.argtypes = [POINTER(DeviceHandle)]
_libusb.usb_claim_interface.argtypes = [POINTER(DeviceHandle), c_int]
_libusb.usb_claim_interface.restype = c_int
_libusb.usb_release_interface.argtypes = [POINTER(DeviceHandle), c_int]
_libusb.usb_release_interface.restype = c_int
_libusb.usb_reset.argtypes = [POINTER(DeviceHandle)]
_libusb.usb_reset.restype = c_int
_libusb.usb_control_msg.restype = c_int
_libusb.usb_bulk_read.restype = c_int
_libusb.usb_bulk_write.restype = c_int
_libusb.usb_set_configuration.argtypes = [POINTER(DeviceHandle), c_int]
_libusb.usb_set_configuration.restype = c_int
_libusb.usb_init()
try:
_libusb.usb_get_busses.restype = POINTER(Bus)
_libusb.usb_open.restype = POINTER(DeviceHandle)
_libusb.usb_open.argtypes = [POINTER(Device)]
_libusb.usb_close.argtypes = [POINTER(DeviceHandle)]
_libusb.usb_claim_interface.argtypes = [POINTER(DeviceHandle), c_int]
_libusb.usb_claim_interface.restype = c_int
_libusb.usb_release_interface.argtypes = [POINTER(DeviceHandle), c_int]
_libusb.usb_release_interface.restype = c_int
_libusb.usb_reset.argtypes = [POINTER(DeviceHandle)]
_libusb.usb_reset.restype = c_int
_libusb.usb_control_msg.restype = c_int
_libusb.usb_bulk_read.restype = c_int
_libusb.usb_bulk_write.restype = c_int
_libusb.usb_set_configuration.argtypes = [POINTER(DeviceHandle), c_int]
_libusb.usb_set_configuration.restype = c_int
_libusb.usb_init()
except:
_libusb = None

View File

@ -523,8 +523,9 @@ class VMInstaller(OptionlessCommand):
--exclude "*.pyc" --exclude "*.pyo" --exclude "*.swp" --exclude "*.swo" \
rsync://%(host)s/work/%(project)s . && \
cd %(project)s && \
rm -rf src/calibre/plugins/* && \
%%s && \
rm -rf build/* dist/* src/calibre/plugins/* && \
rm -rf build/* dist/* && \
%%s %%s
'''%dict(host=HOST, project=__appname__))