Fix freezing of quick access sub-bundle

This commit is contained in:
Kovid Goyal 2025-04-25 21:10:19 +05:30
parent 50b044f8a2
commit f270a17c70
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C

View file

@ -1286,7 +1286,7 @@ def kitty_cli_boolean_options() -> Tuple[str, ...]:
return tuple(sorted(set(read_bool_options()) | set(read_bool_options('kittens/panel/main.py'))))
def build_launcher(args: Options, launcher_dir: str = '.', bundle_type: str = 'source') -> None:
def build_launcher(args: Options, launcher_dir: str = '.', bundle_type: str = 'source') -> str:
werror = '' if args.ignore_compiler_warnings else '-pedantic-errors -Werror'
cflags = f'-Wall {werror} -fpie'.split()
cppflags = [define(f'WRAPPED_KITTENS=" {wrapped_kittens()} "')]
@ -1351,7 +1351,7 @@ def build_launcher(args: Options, launcher_dir: str = '.', bundle_type: str = 's
cmd = env.cc + cppflags + cflags + ['-c', src, '-o', obj]
key = CompileKey(src, os.path.basename(obj))
args.compilation_database.add_command(f'Compiling {emphasis(src)} ...', cmd, partial(newer, obj, src), key=key, keyfile=src)
dest = os.path.join(launcher_dir, 'kitty')
dest = kitty_exe = os.path.join(launcher_dir, 'kitty')
link_targets.append(os.path.abspath(dest))
desc = f'Linking {emphasis("launcher")} ...'
cmd = env.cc + ldflags + objects + libs + pylib + ['-o', dest]
@ -1361,6 +1361,7 @@ def build_launcher(args: Options, launcher_dir: str = '.', bundle_type: str = 's
dsym = f'{dest}.dSYM/Contents/Resources/DWARF/{os.path.basename(dest)}'
args.compilation_database.add_command(desc, ['dsymutil', dest], partial(newer, dsym, dest), key=LinkKey(dsym), is_post_link=True)
args.compilation_database.build_all()
return kitty_exe
# Packaging {{{
@ -1630,7 +1631,7 @@ def macos_info_plist(for_quake: bool = False, quake_desc: str = f'Quick access t
CFBundleSignature='????',
LSApplicationCategoryType='public.app-category.utilities',
# App Execution
CFBundleExecutable='kitty-quick-access' if for_quake else appname,
CFBundleExecutable=quake_name if for_quake else appname,
LSEnvironment={'KITTY_LAUNCHED_BY_LAUNCH_SERVICES': '1'},
LSRequiresNativeExecution=True,
NSSupportsSuddenTermination=False,
@ -1703,8 +1704,11 @@ def create_macos_app_icon(where: str = 'Resources') -> None:
]])
quake_name = f'{appname}-quick-access'
def create_quick_access_bundle(kapp: str) -> None:
qapp = os.path.join(kapp, 'Contents', 'kitty-quick-access.app')
qapp = os.path.join(kapp, 'Contents', f'{quake_name}.app')
base_exe_dir = os.path.join(kapp, 'Contents/MacOS')
if os.path.exists(qapp):
shutil.rmtree(qapp)
@ -1714,7 +1718,9 @@ def create_quick_access_bundle(kapp: str) -> None:
f.write(macos_info_plist(for_quake=True, quake_desc=f'Quick access to {appname} built from source'))
for exe in os.listdir(base_exe_dir):
os.symlink(f'../../../MacOS/{exe}', os.path.join(bin_dir, exe))
shutil.copy2(os.path.join(base_exe_dir, 'kitty'), os.path.join(bin_dir, 'kitty-quick-access'))
base_exe = os.path.join(base_exe_dir, 'kitty')
if os.path.exists(base_exe): # during freeze launcher is built after bundle is created
shutil.copy2(base_exe, os.path.join(bin_dir, quake_name))
for x in ('Frameworks', 'Resources'):
os.symlink(f'../../{x}', os.path.join(qapp, 'Contents', x))
@ -2172,7 +2178,7 @@ def macos_freeze(args: Options, launcher_dir: str, only_frozen_launcher: bool =
args.compilation_database = cdb
init_env_from_args(args, native_optimizations=False)
if only_frozen_launcher:
build_launcher(args, launcher_dir=launcher_dir, bundle_type=bundle_type)
kitty_exe_path = build_launcher(args, launcher_dir=launcher_dir, bundle_type=bundle_type)
else:
build_launcher(args, launcher_dir=launcher_dir)
build(args, native_optimizations=False, call_init=False)
@ -2183,7 +2189,10 @@ def macos_freeze(args: Options, launcher_dir: str, only_frozen_launcher: bool =
os.rename(x, arch_specific)
build_dir = orig_build_dir
lipo(link_target_map)
if not only_frozen_launcher:
if only_frozen_launcher:
if is_macos:
shutil.copy2(kitty_exe_path, os.path.dirname(kitty_exe_path) + f'/../Contents/{quake_name}.app/Contents/MacOS/{quake_name}')
else:
package(args, bundle_type=bundle_type, do_build_all=False)