Implement building OS X bundle
In order for @executable_path resolution to work the launcher has to link against the python dll rather than running the python executable.
This commit is contained in:
parent
0427f30c2a
commit
543af0dd89
@ -17,14 +17,18 @@
|
|||||||
#else
|
#else
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <Python.h>
|
||||||
|
|
||||||
#define MIN(x, y) ((x) < (y)) ? (x) : (y)
|
#define MIN(x, y) ((x) < (y)) ? (x) : (y)
|
||||||
#define MAX_ARGC 1024
|
#define MAX_ARGC 1024
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
int num, num_args, i, ret=0;
|
||||||
char exe[PATH_MAX+1] = {0};
|
char exe[PATH_MAX+1] = {0};
|
||||||
char lib[PATH_MAX+1] = {0};
|
char lib[PATH_MAX+1] = {0};
|
||||||
char *final_argv[MAX_ARGC + 1] = {0};
|
char *final_argv[MAX_ARGC + 1] = {0};
|
||||||
|
wchar_t *argvw[MAX_ARGC + 1] = {0};
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
uint32_t size = PATH_MAX;
|
uint32_t size = PATH_MAX;
|
||||||
char apple[PATH_MAX+1] = {0};
|
char apple[PATH_MAX+1] = {0};
|
||||||
@ -33,17 +37,31 @@ int main(int argc, char *argv[]) {
|
|||||||
#else
|
#else
|
||||||
if (realpath("/proc/self/exe", exe) == NULL) { fprintf(stderr, "Failed to read /proc/self/exe\n"); return 1; }
|
if (realpath("/proc/self/exe", exe) == NULL) { fprintf(stderr, "Failed to read /proc/self/exe\n"); return 1; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
char *exe_dir = dirname(exe);
|
char *exe_dir = dirname(exe);
|
||||||
int num = snprintf(lib, PATH_MAX, "%s%s", exe_dir, "/../lib/kitty");
|
|
||||||
|
#ifdef FOR_BUNDLE
|
||||||
|
num = snprintf(lib, PATH_MAX, "%s%s", exe_dir, "/../Frameworks/kitty");
|
||||||
|
#else
|
||||||
|
num = snprintf(lib, PATH_MAX, "%s%s", exe_dir, "/../lib/kitty");
|
||||||
|
#endif
|
||||||
|
|
||||||
if (num < 0 || num >= PATH_MAX) { fprintf(stderr, "Failed to create path to /../lib/kitty\n"); return 1; }
|
if (num < 0 || num >= PATH_MAX) { fprintf(stderr, "Failed to create path to /../lib/kitty\n"); return 1; }
|
||||||
final_argv[0] = "python3";
|
final_argv[0] = exe;
|
||||||
final_argv[1] = lib;
|
final_argv[1] = lib;
|
||||||
for (int i = 1; i < argc && i + 1 <= MAX_ARGC; i++) {
|
for (i = 1, num_args=2; i < argc && i + 1 <= MAX_ARGC; i++) {
|
||||||
final_argv[i+1] = argv[i];
|
final_argv[i+1] = argv[i];
|
||||||
|
num_args++;
|
||||||
}
|
}
|
||||||
execvp(final_argv[0], final_argv);
|
for (i = 0; i < num_args; i++) {
|
||||||
fprintf(stderr, "Failed to run %s: %s\n", final_argv[0], strerror(errno));
|
argvw[i] = Py_DecodeLocale(final_argv[i], NULL);
|
||||||
return 0;
|
if (argvw[i] == NULL) {
|
||||||
|
fprintf(stderr, "Fatal error: cannot decode argv[%d]\n", i);
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ret = Py_Main(num_args, argvw);
|
||||||
|
end:
|
||||||
|
for (i = 0; i < num_args; i++) { if(argvw[i]) PyMem_RawFree(argvw[i]); }
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
26
setup.py
26
setup.py
@ -176,7 +176,7 @@ def compile_c_extension(module, incremental, sources, headers):
|
|||||||
|
|
||||||
def option_parser():
|
def option_parser():
|
||||||
p = argparse.ArgumentParser()
|
p = argparse.ArgumentParser()
|
||||||
p.add_argument('action', nargs='?', default='build', choices='build test linux-package'.split(), help='Action to perform (default is build)')
|
p.add_argument('action', nargs='?', default='build', choices='build test linux-package osx-bundle'.split(), help='Action to perform (default is build)')
|
||||||
p.add_argument('--debug', default=False, action='store_true',
|
p.add_argument('--debug', default=False, action='store_true',
|
||||||
help='Build extension modules with debugging symbols')
|
help='Build extension modules with debugging symbols')
|
||||||
p.add_argument('--asan', default=False, action='store_true',
|
p.add_argument('--asan', default=False, action='store_true',
|
||||||
@ -214,7 +214,7 @@ def safe_makedirs(path):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def package(args): # {{{
|
def package(args, for_bundle=False): # {{{
|
||||||
ddir = args.prefix
|
ddir = args.prefix
|
||||||
libdir = os.path.join(ddir, 'lib', 'kitty')
|
libdir = os.path.join(ddir, 'lib', 'kitty')
|
||||||
if os.path.exists(libdir):
|
if os.path.exists(libdir):
|
||||||
@ -239,8 +239,13 @@ def package(args): # {{{
|
|||||||
os.chmod(path, 0o755 if f.endswith('.so') else 0o644)
|
os.chmod(path, 0o755 if f.endswith('.so') else 0o644)
|
||||||
launcher_dir = os.path.join(ddir, 'bin')
|
launcher_dir = os.path.join(ddir, 'bin')
|
||||||
safe_makedirs(launcher_dir)
|
safe_makedirs(launcher_dir)
|
||||||
run_tool([cc, '-O3', 'linux-launcher.c', '-o', os.path.join(launcher_dir, 'kitty')])
|
cflags = '-O3'.split()
|
||||||
if not isosx:
|
if for_bundle:
|
||||||
|
cflags.append('-DFOR_BUNDLE')
|
||||||
|
pylib = get_python_flags(cflags)
|
||||||
|
cmd = [cc] + cflags + ['linux-launcher.c', '-o', os.path.join(launcher_dir, 'kitty')] + pylib
|
||||||
|
run_tool(cmd)
|
||||||
|
if not isosx: # {{{ linux desktop gunk
|
||||||
icdir = os.path.join(ddir, 'share', 'icons', 'hicolor', '256x256')
|
icdir = os.path.join(ddir, 'share', 'icons', 'hicolor', '256x256')
|
||||||
safe_makedirs(icdir)
|
safe_makedirs(icdir)
|
||||||
shutil.copy2('logo/kitty.png', icdir)
|
shutil.copy2('logo/kitty.png', icdir)
|
||||||
@ -261,6 +266,16 @@ Categories=System;
|
|||||||
''')
|
''')
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
if for_bundle: # OS X bundle gunk {{{
|
||||||
|
os.chdir(ddir)
|
||||||
|
os.mkdir('Contents')
|
||||||
|
os.chdir('Contents')
|
||||||
|
os.rename('../share', 'Resources')
|
||||||
|
os.rename('../bin', 'MacOS')
|
||||||
|
os.rename('../lib', 'Frameworks')
|
||||||
|
# }}}
|
||||||
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if sys.version_info < (3, 5):
|
if sys.version_info < (3, 5):
|
||||||
@ -275,6 +290,9 @@ def main():
|
|||||||
elif args.action == 'linux-package':
|
elif args.action == 'linux-package':
|
||||||
build(args)
|
build(args)
|
||||||
package(args)
|
package(args)
|
||||||
|
elif args.action == 'osx-bundle':
|
||||||
|
build(args)
|
||||||
|
package(args, for_bundle=True)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user