diff --git a/setup.py b/setup.py index d9317e05b..6b7d41386 100755 --- a/setup.py +++ b/setup.py @@ -1396,10 +1396,20 @@ def wrapped_kittens() -> str: raise Exception('Failed to read wrapped kittens from kitty wrapper script') -def build_shaders(args: Options, kitty_exe: str, for_freeze: bool) -> None: +def build_shaders(args: Options, kitty_exe: str, shaders_dest: str = '') -> None: if args.skip_code_generation: print('Skipping building of shaders due to command line option', flush=True) - return + else: + generate_shaders(kitty_exe) + if shaders_dest: + if not os.path.isdir('shaders'): + raise SystemExit( + 'The shaders directory does not exist. When using --skip-code-generation the shaders must have been generated by a previous build.' + ) + shutil.copytree('shaders', shaders_dest, dirs_exist_ok=True) + + +def generate_shaders(kitty_exe: str) -> None: env = os.environ.copy() env['ASAN_OPTIONS'] = 'detect_leaks=0' cp = subprocess.run( @@ -1417,9 +1427,6 @@ def build_shaders(args: Options, kitty_exe: str, for_freeze: bool) -> None: if os.environ.get('CI') == 'true' and cp.returncode < 0 and shutil.which('coredumpctl'): subprocess.run(['sh', '-c', 'echo bt | coredumpctl debug']) raise SystemExit(f'Generating shaders failed with exit code: {cp.returncode}') - if for_freeze: - libdir = os.path.join(os.path.dirname(kitty_exe), '..', 'Resources' if is_macos else 'lib', 'kitty') - shutil.copytree('shaders', os.path.join(libdir, 'shaders'), dirs_exist_ok=True) def build(args: Options, native_optimizations: bool = True, call_init: bool = True) -> None: @@ -1484,7 +1491,12 @@ def go_cmd() -> list[str]: def build_static_kittens( - args: Options, launcher_dir: str, destination_dir: str = '', for_freeze: bool = False, for_platform: Optional[Tuple[str, str]] = None + args: Options, + launcher_dir: str, + destination_dir: str = '', + for_freeze: bool = False, + for_platform: Optional[Tuple[str, str]] = None, + shaders_dest: str = '', ) -> str: sys.stdout.flush() sys.stderr.flush() @@ -1501,7 +1513,9 @@ def build_static_kittens( raise SystemExit(f'The version of go on this system ({current_go_version}) is too old. go >= {required_go_version} is needed') if not for_platform: update_go_generated_files(args, os.path.join(launcher_dir, appname)) - build_shaders(args, os.path.join(launcher_dir, appname), for_freeze) + if for_freeze and not shaders_dest: + shaders_dest = os.path.join(launcher_dir, '..', 'Resources' if is_macos else 'lib', 'kitty', 'shaders') + build_shaders(args, os.path.join(launcher_dir, appname), shaders_dest) if args.skip_building_kitten: print('Skipping building of the kitten binary because of a command line option. Build is incomplete', file=sys.stderr) @@ -2096,7 +2110,7 @@ def create_macos_bundle_gunk(dest: str, for_freeze: bool, args: Options) -> str: os.symlink(os.path.relpath(kitty_exe, os.path.dirname(in_src_launcher)), in_src_launcher) create_macos_app_icon(os.path.join(ddir, 'Contents', 'Resources')) if not for_freeze: - kitten_exe = build_static_kittens(args, launcher_dir=os.path.dirname(kitty_exe)) + kitten_exe = build_static_kittens(args, launcher_dir=os.path.dirname(kitty_exe), shaders_dest=str(ddir / 'Contents/Resources/kitty/shaders')) if not kitten_exe: raise SystemExit('kitten not built cannot create macOS bundle') os.symlink(os.path.relpath(kitten_exe, os.path.dirname(in_src_launcher)), os.path.join(os.path.dirname(in_src_launcher), os.path.basename(kitten_exe))) @@ -2179,8 +2193,7 @@ def package(args: Options, bundle_type: str, do_build_all: bool = True) -> None: os.chmod(path, 0o755 if should_be_executable(path) else 0o644) if not for_freeze: if not bundle_type.startswith('macos-'): - build_static_kittens(args, launcher_dir=launcher_dir) - shutil.copytree('shaders', os.path.join(libdir, 'shaders'), dirs_exist_ok=True) + build_static_kittens(args, launcher_dir=launcher_dir, shaders_dest=os.path.join(libdir, 'shaders')) if not is_macos and not is_windows: create_linux_bundle_gunk(ddir, args)