From 313136803c12b3235ff646996e451998e9329077 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 2 Jun 2022 10:21:34 +0530 Subject: [PATCH] DRYer --- setup.py | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/setup.py b/setup.py index 84c4db9bb..e4c2496fd 100755 --- a/setup.py +++ b/setup.py @@ -368,30 +368,18 @@ def init_env( cflags.append('-g3') ldflags.append('-lprofiler') - library_paths = {} + library_paths: Dict[str, List[str]] = {} - if egl_library is not None: - assert('"' not in egl_library) - library_paths['glfw/egl_context.c'] = [f'_GLFW_EGL_LIBRARY="{egl_library}"'] + def add_lpath(which: str, name: str, val: Optional[str]) -> None: + if val: + if '"' in val: + raise SystemExit(f'Cannot have quotes in library paths: {val}') + library_paths.setdefault(which, []).append(f'{name}="{val}"') - desktop_libs = [] - fc_libs = [] - if startup_notification_library is not None: - assert('"' not in startup_notification_library) - desktop_libs = [f'_KITTY_STARTUP_NOTIFICATION_LIBRARY="{startup_notification_library}"'] - - if canberra_library is not None: - assert('"' not in canberra_library) - desktop_libs += [f'_KITTY_CANBERRA_LIBRARY="{canberra_library}"'] - - if fontconfig_library is not None: - assert('"' not in fontconfig_library) - fc_libs += [f'_KITTY_FONTCONFIG_LIBRARY="{fontconfig_library}"'] - - if desktop_libs: - library_paths['kitty/desktop.c'] = desktop_libs - if fc_libs: - library_paths['kitty/fontconfig.c'] = fc_libs + add_lpath('glfw/egl_context.c', '_GLFW_EGL_LIBRARY', egl_library) + add_lpath('kitty/desktop.c', '_KITTY_STARTUP_NOTIFICATION_LIBRARY', startup_notification_library) + add_lpath('kitty/desktop.c', '_KITTY_CANBERRA_LIBRARY', canberra_library) + add_lpath('kitty/fontconfig.c', '_KITTY_FONTCONFIG_LIBRARY', fontconfig_library) for path in extra_include_dirs: cflags.append(f'-I{path}')