From f11036a88ad75afc6dedc1547dfc3a41dd7496b3 Mon Sep 17 00:00:00 2001 From: Kostas Georgiadis Date: Sat, 8 Jun 2024 19:54:07 +0300 Subject: [PATCH 1/5] fix appimage build for linux --- makelove/linux.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/makelove/linux.py b/makelove/linux.py index d3b75a8..fa0c789 100644 --- a/makelove/linux.py +++ b/makelove/linux.py @@ -174,6 +174,12 @@ def build_linux(config, version, target, target_directory, love_file_path): fuse_files(fused_exe_path, appdir("bin/love"), love_file_path) os.chmod(fused_exe_path, 0o755) os.remove(appdir("bin/love")) + + # rename back to bin/love so love.sh can pick it up + parsed_version = parse_love_version(config["love_version"]) + if (parsed_version[0], parsed_version[1]) >= (11, 4): + os.rename(fused_exe_path, appdir("bin/love")) + desktop_exec = f"{game_name} %f" else: sys.exit( From c798c4ca5c15a6b5939b8815538a63c440b895e3 Mon Sep 17 00:00:00 2001 From: Kostas Georgiadis Date: Sun, 8 Sep 2024 22:24:40 +0300 Subject: [PATCH 2/5] hook support for individual targets --- .gitignore | 1 + makelove/config.py | 4 ++++ makelove/hooks.py | 11 +++++++++++ makelove/linux.py | 9 +++++++++ makelove/macos.py | 4 ++++ makelove/windows.py | 6 ++++++ 6 files changed, 35 insertions(+) diff --git a/.gitignore b/.gitignore index cd7f39e..e8930c1 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ __pycache__/ *.egg-info build/ dist/ +.python-version diff --git a/makelove/config.py b/makelove/config.py index f10468b..3c20ed2 100644 --- a/makelove/config.py +++ b/makelove/config.py @@ -70,6 +70,7 @@ "love_binaries": val.Path(), "shared_libraries": val.List(val.Path()), "artifacts": val.ValueOrList(val.Choice("directory", "archive")), + "hook": val.String(), } ), "win64": val.Section( @@ -77,6 +78,7 @@ "love_binaries": val.Path(), "shared_libraries": val.List(val.Path()), "artifacts": val.ValueOrList(val.Choice("directory", "archive")), + "hook": val.String(), } ), "linux": val.Section( @@ -87,6 +89,7 @@ "source_appimage": val.Path(), "shared_libraries": val.List(val.Path()), "artifacts": val.ValueOrList(val.Choice("appdir", "appimage")), + "hook": val.String(), } ), "macos": val.Section( @@ -95,6 +98,7 @@ "icon_file": val.Path(), "app_metadata": val.Dict(val.String(), val.String()), "archive_files": val.Dict(val.Path(), val.Path()), + "hook": val.String(), } ), "lovejs": val.Section( diff --git a/makelove/hooks.py b/makelove/hooks.py index 1b00836..e80af9e 100644 --- a/makelove/hooks.py +++ b/makelove/hooks.py @@ -37,3 +37,14 @@ def execute_hook(command, config, version, targets, build_directory): new_config = get_config(tmp_config_path) os.remove(tmp_config_path) return new_config + +def execute_target_hook(command, target): + env = os.environ.copy() + env.update({ + "MAKELOVE_TARGET": target, + }) + + try: + subprocess.run(command, shell=True, check=True, env=env) + except Exception as e: + sys.exit("Build target hook '{}' failed: {}".format(command, e)) \ No newline at end of file diff --git a/makelove/linux.py b/makelove/linux.py index fa0c789..9120fa4 100644 --- a/makelove/linux.py +++ b/makelove/linux.py @@ -12,6 +12,7 @@ from .util import fuse_files, tmpfile, parse_love_version, ask_yes_no from .config import all_love_versions, should_build_artifact +from .hooks import execute_target_hook def get_appimagetool_path(): @@ -240,6 +241,9 @@ def build_linux(config, version, target, target_directory, love_file_path): elif os.path.isfile(appdir("lib/liblove.so")): # Official AppImages (since 11.4) so_target_dir = appdir("lib/") + elif os.path.isfile(appdir("lib/liblove-{}.so".format(config["love_version"]))): + # Support for >= 11.5 + so_target_dir = appdir("lib/") else: sys.exit( "Could not find liblove.so in AppDir. The AppImage has an unknown format." @@ -248,6 +252,11 @@ def build_linux(config, version, target, target_directory, love_file_path): for f in config[target]["shared_libraries"]: shutil.copy(f, so_target_dir) + # A hook to execute before bundling AppImage again + if target in config and config[target]["hook"]: + print("Executing hook {} for target {}".format(config[target]["hook"], target)) + execute_target_hook(config[target]["hook"], target) + # Rebuild AppImage if should_build_artifact(config, target, "appimage", True): print("Creating new AppImage..") diff --git a/makelove/macos.py b/makelove/macos.py index 97bbfc9..8aae310 100644 --- a/makelove/macos.py +++ b/makelove/macos.py @@ -11,6 +11,7 @@ from PIL import Image from .util import eprint, get_default_love_binary_dir, get_download_url +from .hooks import execute_target_hook def download_love(version, platform): @@ -157,6 +158,9 @@ def get_info_plist_content(config, version): def build_macos(config, version, target, target_directory, love_file_path): + if target in config and config[target]["hook"]: + print("Executing hook {} for target {}".format(config[target]["hook"], target)) + execute_target_hook(config[target]["hook"], target) if target in config and "love_binaries" in config[target]: love_binaries = config[target]["love_binaries"] else: diff --git a/makelove/windows.py b/makelove/windows.py index 1ae4177..796f220 100644 --- a/makelove/windows.py +++ b/makelove/windows.py @@ -11,6 +11,7 @@ from .util import get_default_love_binary_dir, get_download_url, tmpfile, eprint from .config import should_build_artifact +from .hooks import execute_target_hook def common_prefix(l): @@ -248,6 +249,11 @@ def build_windows(config, version, target, target_directory, love_file_path): for f in config[target]["shared_libraries"]: shutil.copyfile(f, dest(os.path.basename(f))) + # A hook to execute before building the zip file + if target in config and config[target]["hook"]: + print("Executing hook {} for target {}".format(config[target]["hook"], target)) + execute_target_hook(config[target]["hook"], target) + if should_build_artifact(config, target, "archive", True): archive_path = os.path.join( target_directory, "{}-{}".format(config["name"], target) From 56a8cc1c9197030d7f97eed9829f92ff11f8805b Mon Sep 17 00:00:00 2001 From: Kostas Georgiadis Date: Sat, 14 Sep 2024 16:13:09 +0300 Subject: [PATCH 3/5] switch to archive files --- makelove/config.py | 7 +++---- makelove/linux.py | 25 ++++++++++++++++++++----- makelove/macos.py | 11 ++++++++--- makelove/windows.py | 8 +++----- 4 files changed, 34 insertions(+), 17 deletions(-) diff --git a/makelove/config.py b/makelove/config.py index 3c20ed2..be26390 100644 --- a/makelove/config.py +++ b/makelove/config.py @@ -70,7 +70,6 @@ "love_binaries": val.Path(), "shared_libraries": val.List(val.Path()), "artifacts": val.ValueOrList(val.Choice("directory", "archive")), - "hook": val.String(), } ), "win64": val.Section( @@ -78,7 +77,7 @@ "love_binaries": val.Path(), "shared_libraries": val.List(val.Path()), "artifacts": val.ValueOrList(val.Choice("directory", "archive")), - "hook": val.String(), + "archive_files": val.Dict(val.Path(), val.Path()), } ), "linux": val.Section( @@ -89,7 +88,7 @@ "source_appimage": val.Path(), "shared_libraries": val.List(val.Path()), "artifacts": val.ValueOrList(val.Choice("appdir", "appimage")), - "hook": val.String(), + "archive_files": val.Dict(val.Path(), val.Path()), } ), "macos": val.Section( @@ -97,8 +96,8 @@ "love_binaries": val.Path(), "icon_file": val.Path(), "app_metadata": val.Dict(val.String(), val.String()), + "artifacts": val.ValueOrList(val.Choice("directory", "archive")), "archive_files": val.Dict(val.Path(), val.Path()), - "hook": val.String(), } ), "lovejs": val.Section( diff --git a/makelove/linux.py b/makelove/linux.py index 9120fa4..b613136 100644 --- a/makelove/linux.py +++ b/makelove/linux.py @@ -144,6 +144,8 @@ def build_linux(config, version, target, target_directory, love_file_path): appdir_path = os.path.join(target_directory, "squashfs-root") appdir = lambda x: os.path.join(appdir_path, x) + appdirbin_path = os.path.join(appdir_path, "bin") + appdirbin = lambda x: os.path.join(appdirbin_path, x) game_name = config["name"] if " " in game_name: @@ -233,6 +235,24 @@ def build_linux(config, version, target, target_directory, love_file_path): for k, v in desktop_file_fields.items(): f.write("{}={}\n".format(k, v)) + # archive files + archive_files = {} + if "archive_files" in config: + archive_files.update(config["archive_files"]) + if target in config and "archive_files" in config[target]: + archive_files.update(config[target]["archive_files"]) + + for k, v in archive_files.items(): + path = appdirbin(v) + os.makedirs(os.path.dirname(path), exist_ok=True) + if os.path.isfile(k): + shutil.copyfile(k, path) + elif os.path.isdir(k): + shutil.copytree(k, path) + else: + sys.exit("Cannot copy archive file '{}'".format(k)) + + # Shared libraries if target in config and "shared_libraries" in config[target]: if os.path.isfile(appdir("usr/lib/liblove.so")): @@ -252,11 +272,6 @@ def build_linux(config, version, target, target_directory, love_file_path): for f in config[target]["shared_libraries"]: shutil.copy(f, so_target_dir) - # A hook to execute before bundling AppImage again - if target in config and config[target]["hook"]: - print("Executing hook {} for target {}".format(config[target]["hook"], target)) - execute_target_hook(config[target]["hook"], target) - # Rebuild AppImage if should_build_artifact(config, target, "appimage", True): print("Creating new AppImage..") diff --git a/makelove/macos.py b/makelove/macos.py index 8aae310..2b96b60 100644 --- a/makelove/macos.py +++ b/makelove/macos.py @@ -158,9 +158,6 @@ def get_info_plist_content(config, version): def build_macos(config, version, target, target_directory, love_file_path): - if target in config and config[target]["hook"]: - print("Executing hook {} for target {}".format(config[target]["hook"], target)) - execute_target_hook(config[target]["hook"], target) if target in config and "love_binaries" in config[target]: love_binaries = config[target]["love_binaries"] else: @@ -247,3 +244,11 @@ def build_macos(config, version, target, target_directory, love_file_path): loveZipKey = f"{config['name']}.app/Contents/Resources/{config['name']}.love" app_zip.writestr(loveZipKey, love_zip.read()) + + # default behavior is to create an archive + if "directory" in config[target]["artifacts"]: + unzip_dst = os.path.join(target_directory, f"{config['name']}-{target}") + with ZipFile(dst, "r") as zip_ref: + zip_ref.extractall(unzip_dst) + os.remove(dst) + \ No newline at end of file diff --git a/makelove/windows.py b/makelove/windows.py index 796f220..2c634b5 100644 --- a/makelove/windows.py +++ b/makelove/windows.py @@ -234,6 +234,9 @@ def build_windows(config, version, target, target_directory, love_file_path): archive_files.update(config["archive_files"]) if "windows" in config and "archive_files" in config["windows"]: archive_files.update(config["windows"]["archive_files"]) + # also add win32/win64 files + if target in config and "archive_files" in config[target]: + archive_files.update(config[target]["archive_files"]) for k, v in archive_files.items(): path = dest(v) @@ -249,11 +252,6 @@ def build_windows(config, version, target, target_directory, love_file_path): for f in config[target]["shared_libraries"]: shutil.copyfile(f, dest(os.path.basename(f))) - # A hook to execute before building the zip file - if target in config and config[target]["hook"]: - print("Executing hook {} for target {}".format(config[target]["hook"], target)) - execute_target_hook(config[target]["hook"], target) - if should_build_artifact(config, target, "archive", True): archive_path = os.path.join( target_directory, "{}-{}".format(config["name"], target) From 36e0ad41687c8cbc95ccecb71e1b0ebedf30950b Mon Sep 17 00:00:00 2001 From: Kostas Georgiadis Date: Sat, 14 Sep 2024 16:17:59 +0300 Subject: [PATCH 4/5] fix check --- makelove/macos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makelove/macos.py b/makelove/macos.py index 2b96b60..3e00e90 100644 --- a/makelove/macos.py +++ b/makelove/macos.py @@ -246,7 +246,7 @@ def build_macos(config, version, target, target_directory, love_file_path): app_zip.writestr(loveZipKey, love_zip.read()) # default behavior is to create an archive - if "directory" in config[target]["artifacts"]: + if "artifacts" in config[target] and "directory" in config[target]["artifacts"]: unzip_dst = os.path.join(target_directory, f"{config['name']}-{target}") with ZipFile(dst, "r") as zip_ref: zip_ref.extractall(unzip_dst) From 696e4f75a5bdcfa6d173f3630f9866553047ec92 Mon Sep 17 00:00:00 2001 From: Kostas Georgiadis Date: Sat, 16 Nov 2024 12:22:00 +0200 Subject: [PATCH 5/5] fix macos default build --- makelove/macos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makelove/macos.py b/makelove/macos.py index 3e00e90..6b3dca8 100644 --- a/makelove/macos.py +++ b/makelove/macos.py @@ -246,7 +246,7 @@ def build_macos(config, version, target, target_directory, love_file_path): app_zip.writestr(loveZipKey, love_zip.read()) # default behavior is to create an archive - if "artifacts" in config[target] and "directory" in config[target]["artifacts"]: + if target in config and "artifacts" in config[target] and "directory" in config[target]["artifacts"]: unzip_dst = os.path.join(target_directory, f"{config['name']}-{target}") with ZipFile(dst, "r") as zip_ref: zip_ref.extractall(unzip_dst)