mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
OSX Build: Fix output to stdout/stderr not being redirected to Console.app in newer OS X version (>= 10.8)
This commit is contained in:
parent
e262f916b3
commit
79c029c15f
@ -12,6 +12,6 @@ static const char PYVER[] = "**PYVER**";
|
|||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, const char **argv, const char **envp) {
|
main(int argc, const char **argv, const char **envp) {
|
||||||
return run(ENV_VARS, ENV_VAR_VALS, PROGRAM, MODULE, FUNCTION, PYVER, argc, argv, envp);
|
return run(ENV_VARS, ENV_VAR_VALS, PROGRAM, MODULE, FUNCTION, PYVER, **IS_GUI**, argc, argv, envp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ import sys, os, shutil, plistlib, subprocess, glob, zipfile, tempfile, \
|
|||||||
py_compile, stat, operator, time
|
py_compile, stat, operator, time
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
from itertools import repeat
|
||||||
|
|
||||||
abspath, join, basename = os.path.abspath, os.path.join, os.path.basename
|
abspath, join, basename = os.path.abspath, os.path.join, os.path.basename
|
||||||
|
|
||||||
@ -92,8 +93,8 @@ def compile_launchers(contents_dir, xprograms, pyver):
|
|||||||
src = src.replace('/*ENV_VARS*/', env)
|
src = src.replace('/*ENV_VARS*/', env)
|
||||||
src = src.replace('/*ENV_VAR_VALS*/', env_vals)
|
src = src.replace('/*ENV_VAR_VALS*/', env_vals)
|
||||||
programs = [lib]
|
programs = [lib]
|
||||||
for program, x in xprograms.items():
|
for program, x in xprograms.iteritems():
|
||||||
module, func = x
|
module, func, ptype = x
|
||||||
info('\tCompiling', program)
|
info('\tCompiling', program)
|
||||||
out = join(contents_dir, 'MacOS', program)
|
out = join(contents_dir, 'MacOS', program)
|
||||||
programs.append(out)
|
programs.append(out)
|
||||||
@ -101,6 +102,7 @@ def compile_launchers(contents_dir, xprograms, pyver):
|
|||||||
psrc = psrc.replace('**MODULE**', module)
|
psrc = psrc.replace('**MODULE**', module)
|
||||||
psrc = psrc.replace('**FUNCTION**', func)
|
psrc = psrc.replace('**FUNCTION**', func)
|
||||||
psrc = psrc.replace('**PYVER**', pyver)
|
psrc = psrc.replace('**PYVER**', pyver)
|
||||||
|
psrc = psrc.replace('**IS_GUI**', ('1' if ptype == 'gui' else '0'))
|
||||||
fsrc = '/tmp/%s.c'%program
|
fsrc = '/tmp/%s.c'%program
|
||||||
with open(fsrc, 'wb') as f:
|
with open(fsrc, 'wb') as f:
|
||||||
f.write(psrc)
|
f.write(psrc)
|
||||||
@ -230,9 +232,9 @@ class Py2App(object):
|
|||||||
programs = {}
|
programs = {}
|
||||||
progs = []
|
progs = []
|
||||||
for x in ('console', 'gui'):
|
for x in ('console', 'gui'):
|
||||||
progs += list(zip(basenames[x], main_modules[x], main_functions[x]))
|
progs += list(zip(basenames[x], main_modules[x], main_functions[x], repeat(x)))
|
||||||
for program, module, func in progs:
|
for program, module, func, ptype in progs:
|
||||||
programs[program] = (module, func)
|
programs[program] = (module, func, ptype)
|
||||||
programs = compile_launchers(self.contents_dir, programs,
|
programs = compile_launchers(self.contents_dir, programs,
|
||||||
self.version_info)
|
self.version_info)
|
||||||
for out in programs:
|
for out in programs:
|
||||||
|
@ -31,7 +31,7 @@ for dir in sys.path:
|
|||||||
# if they only differ in case); turn relative paths into absolute
|
# if they only differ in case); turn relative paths into absolute
|
||||||
# paths.
|
# paths.
|
||||||
dir, dircase = makepath(dir)
|
dir, dircase = makepath(dir)
|
||||||
if not dircase in _dirs_in_sys_path:
|
if dircase not in _dirs_in_sys_path:
|
||||||
L.append(dir)
|
L.append(dir)
|
||||||
_dirs_in_sys_path[dircase] = 1
|
_dirs_in_sys_path[dircase] = 1
|
||||||
sys.path[:] = L
|
sys.path[:] = L
|
||||||
@ -55,7 +55,7 @@ def addsitedir(sitedir):
|
|||||||
else:
|
else:
|
||||||
reset = 0
|
reset = 0
|
||||||
sitedir, sitedircase = makepath(sitedir)
|
sitedir, sitedircase = makepath(sitedir)
|
||||||
if not sitedircase in _dirs_in_sys_path:
|
if sitedircase not in _dirs_in_sys_path:
|
||||||
sys.path.append(sitedir) # Add path component
|
sys.path.append(sitedir) # Add path component
|
||||||
try:
|
try:
|
||||||
names = os.listdir(sitedir)
|
names = os.listdir(sitedir)
|
||||||
@ -92,7 +92,7 @@ def addpackage(sitedir, name):
|
|||||||
if dir[-1] == '\n':
|
if dir[-1] == '\n':
|
||||||
dir = dir[:-1]
|
dir = dir[:-1]
|
||||||
dir, dircase = makepath(sitedir, dir)
|
dir, dircase = makepath(sitedir, dir)
|
||||||
if not dircase in _dirs_in_sys_path and os.path.exists(dir):
|
if dircase not in _dirs_in_sys_path and os.path.exists(dir):
|
||||||
sys.path.append(dir)
|
sys.path.append(dir)
|
||||||
_dirs_in_sys_path[dircase] = 1
|
_dirs_in_sys_path[dircase] = 1
|
||||||
if reset:
|
if reset:
|
||||||
@ -184,8 +184,15 @@ def setup_asl():
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
global __file__
|
global __file__
|
||||||
base = sys.resourcepath
|
|
||||||
|
|
||||||
|
if sys.calibre_is_gui_app and not (
|
||||||
|
sys.stdout.isatty() or sys.stderr.isatty() or sys.stdin.isatty()):
|
||||||
|
try:
|
||||||
|
setup_asl()
|
||||||
|
except:
|
||||||
|
pass # Failure to log to Console.app is not critical
|
||||||
|
|
||||||
|
base = sys.resourcepath
|
||||||
sys.frozen = 'macosx_app'
|
sys.frozen = 'macosx_app'
|
||||||
sys.new_app_bundle = True
|
sys.new_app_bundle = True
|
||||||
abs__file__()
|
abs__file__()
|
||||||
@ -193,16 +200,4 @@ def main():
|
|||||||
add_calibre_vars(base)
|
add_calibre_vars(base)
|
||||||
addsitedir(sys.site_packages)
|
addsitedir(sys.site_packages)
|
||||||
|
|
||||||
launched_by_launch_services = False
|
|
||||||
|
|
||||||
for arg in tuple(sys.argv[1:]):
|
|
||||||
if arg.startswith('-psn_'):
|
|
||||||
sys.argv.remove(arg)
|
|
||||||
launched_by_launch_services = True
|
|
||||||
if launched_by_launch_services:
|
|
||||||
try:
|
|
||||||
setup_asl()
|
|
||||||
except:
|
|
||||||
pass # Failure to log to Console.app is not critical
|
|
||||||
|
|
||||||
return run_entry_point()
|
return run_entry_point()
|
||||||
|
@ -46,7 +46,7 @@ set_env_vars(const char **ENV_VARS, const char **ENV_VAR_VALS, const char* exe_p
|
|||||||
}
|
}
|
||||||
|
|
||||||
void initialize_interpreter(const char **ENV_VARS, const char **ENV_VAR_VALS,
|
void initialize_interpreter(const char **ENV_VARS, const char **ENV_VAR_VALS,
|
||||||
char *PROGRAM, const char *MODULE, const char *FUNCTION, const char *PYVER,
|
char *PROGRAM, const char *MODULE, const char *FUNCTION, const char *PYVER, int IS_GUI,
|
||||||
const char* exe_path, const char *rpath, int argc, const char **argv) {
|
const char* exe_path, const char *rpath, int argc, const char **argv) {
|
||||||
PyObject *pargv, *v;
|
PyObject *pargv, *v;
|
||||||
int i;
|
int i;
|
||||||
@ -83,6 +83,7 @@ void initialize_interpreter(const char **ENV_VARS, const char **ENV_VAR_VALS,
|
|||||||
PySys_SetObject("calibre_basename", PyBytes_FromString(PROGRAM));
|
PySys_SetObject("calibre_basename", PyBytes_FromString(PROGRAM));
|
||||||
PySys_SetObject("calibre_module", PyBytes_FromString(MODULE));
|
PySys_SetObject("calibre_module", PyBytes_FromString(MODULE));
|
||||||
PySys_SetObject("calibre_function", PyBytes_FromString(FUNCTION));
|
PySys_SetObject("calibre_function", PyBytes_FromString(FUNCTION));
|
||||||
|
PySys_SetObject("calibre_is_gui_app", ((IS_GUI) ? Py_True : Py_False));
|
||||||
PySys_SetObject("resourcepath", PyBytes_FromString(rpath));
|
PySys_SetObject("resourcepath", PyBytes_FromString(rpath));
|
||||||
snprintf(path, 3000, "%s/site-packages", pyhome);
|
snprintf(path, 3000, "%s/site-packages", pyhome);
|
||||||
PySys_SetObject("site_packages", PyBytes_FromString(pyhome));
|
PySys_SetObject("site_packages", PyBytes_FromString(pyhome));
|
||||||
@ -154,7 +155,7 @@ EXPORT
|
|||||||
int
|
int
|
||||||
run(const char **ENV_VARS, const char **ENV_VAR_VALS, char *PROGRAM,
|
run(const char **ENV_VARS, const char **ENV_VAR_VALS, char *PROGRAM,
|
||||||
const char *MODULE, const char *FUNCTION, const char *PYVER,
|
const char *MODULE, const char *FUNCTION, const char *PYVER,
|
||||||
int argc, const char **argv, const char **envp) {
|
int IS_GUI, int argc, const char **argv, const char **envp) {
|
||||||
char *pathPtr = NULL, *t = NULL;
|
char *pathPtr = NULL, *t = NULL;
|
||||||
char buf[3*PATH_MAX];
|
char buf[3*PATH_MAX];
|
||||||
int ret = 0, i;
|
int ret = 0, i;
|
||||||
@ -190,7 +191,7 @@ run(const char **ENV_VARS, const char **ENV_VAR_VALS, char *PROGRAM,
|
|||||||
char rpath[PATH_MAX+1], exe_path[PATH_MAX+1];
|
char rpath[PATH_MAX+1], exe_path[PATH_MAX+1];
|
||||||
snprintf(exe_path, PATH_MAX+1, "%s/Contents", pathPtr);
|
snprintf(exe_path, PATH_MAX+1, "%s/Contents", pathPtr);
|
||||||
snprintf(rpath, PATH_MAX+1, "%s/Resources", exe_path);
|
snprintf(rpath, PATH_MAX+1, "%s/Resources", exe_path);
|
||||||
initialize_interpreter(ENV_VARS, ENV_VAR_VALS, PROGRAM, MODULE, FUNCTION, PYVER,
|
initialize_interpreter(ENV_VARS, ENV_VAR_VALS, PROGRAM, MODULE, FUNCTION, PYVER, IS_GUI,
|
||||||
exe_path, rpath, argc, argv);
|
exe_path, rpath, argc, argv);
|
||||||
|
|
||||||
site = PyImport_ImportModule("site");
|
site = PyImport_ImportModule("site");
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
int run(const char **ENV_VARS, const char **ENV_VAR_VALS, char *PROGRAM,
|
int run(const char **ENV_VARS, const char **ENV_VAR_VALS, char *PROGRAM,
|
||||||
const char *MODULE, const char *FUNCTION, const char *PYVER,
|
const char *MODULE, const char *FUNCTION, const char *PYVER, int IS_GUI,
|
||||||
int argc, const char **argv, const char **envp);
|
int argc, const char **argv, const char **envp);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user