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..be26390 100644 --- a/makelove/config.py +++ b/makelove/config.py @@ -77,6 +77,7 @@ "love_binaries": val.Path(), "shared_libraries": val.List(val.Path()), "artifacts": val.ValueOrList(val.Choice("directory", "archive")), + "archive_files": val.Dict(val.Path(), val.Path()), } ), "linux": val.Section( @@ -87,6 +88,7 @@ "source_appimage": val.Path(), "shared_libraries": val.List(val.Path()), "artifacts": val.ValueOrList(val.Choice("appdir", "appimage")), + "archive_files": val.Dict(val.Path(), val.Path()), } ), "macos": val.Section( @@ -94,6 +96,7 @@ "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()), } ), 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 d3b75a8..b613136 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(): @@ -143,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: @@ -174,6 +177,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( @@ -226,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")): @@ -234,6 +261,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." diff --git a/makelove/macos.py b/makelove/macos.py index 97bbfc9..6b3dca8 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): @@ -243,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 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) + os.remove(dst) + \ No newline at end of file diff --git a/makelove/windows.py b/makelove/windows.py index 1ae4177..2c634b5 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): @@ -233,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)