Add packager build for macos

This commit is contained in:
Federico Terzi 2019-09-18 11:10:36 +02:00
parent a4a20b492c
commit 2f205605b1
2 changed files with 66 additions and 6 deletions

View File

@ -2,12 +2,11 @@ import subprocess
import sys import sys
import os import os
import platform import platform
from dataclasses import dataclass import hashlib
import click import click
import glob
import shutil import shutil
import toml import toml
from dataclasses import dataclass
PACKAGER_TARGET_DIR = "target/packager" PACKAGER_TARGET_DIR = "target/packager"
@ -28,7 +27,7 @@ def cli():
def build(skipcargo): def build(skipcargo):
"""Build espanso distribution""" """Build espanso distribution"""
# Check operating system # Check operating system
TARGET_OS = "macosx" TARGET_OS = "macos"
if platform.system() == "Windows": if platform.system() == "Windows":
TARGET_OS = "windows" TARGET_OS = "windows"
elif platform.system() == "Linux": elif platform.system() == "Linux":
@ -53,12 +52,14 @@ def build(skipcargo):
if TARGET_OS == "windows": if TARGET_OS == "windows":
build_windows(package_info) build_windows(package_info)
elif TARGET_OS == "macos":
build_mac(package_info)
def build_windows(package_info): def build_windows(package_info):
print("Starting packaging process on windows...") print("Starting packaging process for Windows...")
# Check javapackager # Check Inno Setup
try: try:
subprocess.run(["iscc"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) subprocess.run(["iscc"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
except FileNotFoundError: except FileNotFoundError:
@ -100,6 +101,51 @@ def build_windows(package_info):
print("Compiling installer with Inno setup") print("Compiling installer with Inno setup")
subprocess.run(["iscc", os.path.abspath(os.path.join(TARGET_DIR, "setupscript.iss"))]) subprocess.run(["iscc", os.path.abspath(os.path.join(TARGET_DIR, "setupscript.iss"))])
def build_mac(package_info):
print("Starting packaging process for MacOS...")
print("Clearing target dirs")
# Clearing previous build directory
if os.path.isdir(PACKAGER_TARGET_DIR):
print("Cleaning packager temp directory...")
shutil.rmtree(PACKAGER_TARGET_DIR)
TARGET_DIR = os.path.join(PACKAGER_TARGET_DIR, "mac")
os.makedirs(TARGET_DIR, exist_ok=True)
print("Compressing release to archive...")
target_name = f"espanso-mac-{package_info.version}.tar.gz"
archive_target = os.path.abspath(os.path.join(TARGET_DIR, target_name))
subprocess.run(["tar",
"-C", os.path.abspath("target/release"),
"-cvf",
archive_target,
"espanso",
])
print(f"Created archive: {archive_target}")
print("Processing Homebrew formula template")
with open("packager/mac/espanso.rb", "r") as formula_template:
content = formula_template.read()
# Replace variables
content = content.replace("{{{app_desc}}}", package_info.description)
content = content.replace("{{{app_url}}}", package_info.url)
content = content.replace("{{{app_version}}}", package_info.version)
# Calculate hash
with open(archive_target, "rb") as f:
bytes = f.read()
readable_hash = hashlib.sha256(bytes).hexdigest()
content = content.replace("{{{release_hash}}}", readable_hash)
with open(os.path.join(TARGET_DIR, "espanso.rb"), "w") as output_script:
output_script.write(content)
print("Done!")
if __name__ == '__main__': if __name__ == '__main__':
print("[[ espanso packager ]]") print("[[ espanso packager ]]")

14
packager/mac/espanso.rb Normal file
View File

@ -0,0 +1,14 @@
# Documentation: https://docs.brew.sh/Formula-Cookbook
# https://rubydoc.brew.sh/Formula
# PLEASE REMOVE ALL GENERATED COMMENTS BEFORE SUBMITTING YOUR PULL REQUEST!
class Espanso < Formula
desc "{{{app_desc}}}"
homepage "{{{app_url}}}"
url "{{{app_release_url}}}"
sha256 "{{{release_hash}}}"
version "{{{app_version}}}"
def install
bin.install "espanso"
end
end