mirror of
https://github.com/dortania/OpenCore-Legacy-Patcher.git
synced 2026-04-13 20:28:21 +10:00
CI: Standardize Build Script
This commit is contained in:
5
.github/workflows/build-app-wxpython.yml
vendored
5
.github/workflows/build-app-wxpython.yml
vendored
@@ -16,10 +16,7 @@ jobs:
|
||||
commitdate: ${{ github.event.head_commit.timestamp }}
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- run: python3 create_offline_build.py
|
||||
- run: hdiutil create ./payloads.dmg -megabytes 32000 -format UDZO -ov -volname "payloads" -fs HFS+ -srcfolder ./payloads -passphrase password -encryption
|
||||
- run: /Library/Frameworks/Python.framework/Versions/3.9/bin/pyinstaller OpenCore-Patcher-GUI.spec
|
||||
- run: python3 ./payloads/binary.py $branch $commiturl $commitdate
|
||||
- run: python3 Build-Binary.command --branch ${{ env.branch }} --commit ${{ env.commiturl }} --commit_date ${{ env.commitdate }}
|
||||
- run: 'codesign -s "Developer ID Application: Mykola Grymalyuk (S74BDJXQMD)" -v --force --deep --timestamp --entitlements ./payloads/entitlements.plist -o runtime "dist/OpenCore-Patcher.app"'
|
||||
- run: cd dist; ditto -c -k --sequesterRsrc --keepParent OpenCore-Patcher.app ../OpenCore-Patcher-wxPython.app.zip
|
||||
- run: ./../sign-wxpython.sh
|
||||
|
||||
5
.github/workflows/build-app.yml
vendored
5
.github/workflows/build-app.yml
vendored
@@ -16,10 +16,7 @@ jobs:
|
||||
commitdate: ${{ github.event.head_commit.timestamp }}
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- run: python3 create_offline_build.py
|
||||
- run: /Library/Frameworks/Python.framework/Versions/3.9/bin/pyinstaller OpenCore-Patcher.spec
|
||||
- run: ./after_pyinstaller.sh
|
||||
- run: python3 ./payloads/binary.py $branch $commiturl $commitdate
|
||||
- run: python3 Build-Binary.command --build_tui --branch ${{ env.branch }} --commit ${{ env.commiturl }} --commit_date ${{ env.commitdate }}
|
||||
- run: 'codesign -s "Developer ID Application: Mykola Grymalyuk (S74BDJXQMD)" -v --force --deep --timestamp --entitlements ./payloads/entitlements.plist -o runtime "dist/OpenCore-Patcher.app"'
|
||||
- run: cd dist; zip -r ../OpenCore-Patcher-TUI.app.zip OpenCore-Patcher.app
|
||||
- run: ./../sign-tui.sh
|
||||
|
||||
211
Build-Binary.command
Executable file
211
Build-Binary.command
Executable file
@@ -0,0 +1,211 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# This script's main purpose is to handle the following:
|
||||
# - Download PatcherSupportPkg resources
|
||||
# - Convert payloads directory into DMG (GUI only)
|
||||
# - Build Binary via Pyinstaller
|
||||
# - Add Launcher.sh (TUI only)
|
||||
# - Patch 'LC_VERSION_MIN_MACOSX' to OS X 10.10
|
||||
# - Add commit data to Info.plist
|
||||
|
||||
# Copyright (C) 2022 - Mykola Grymalyuk
|
||||
|
||||
from pathlib import Path
|
||||
import argparse
|
||||
import os
|
||||
import subprocess
|
||||
import plistlib
|
||||
import time
|
||||
import sys
|
||||
|
||||
from resources import constants
|
||||
|
||||
class create_binary:
|
||||
|
||||
def __init__(self):
|
||||
start = time.time()
|
||||
print("- Starting build script")
|
||||
self.set_cwd()
|
||||
self.args = self.parse_arguments()
|
||||
|
||||
self.preflight_processes()
|
||||
self.build_binary()
|
||||
self.postflight_processes()
|
||||
print(f"- Build script completed in {str(round(time.time() - start, 2))} seconds")
|
||||
|
||||
def set_cwd(self):
|
||||
os.chdir(Path(__file__).resolve().parent)
|
||||
print(f"- Current Working Directory: \n\t{os.getcwd()}")
|
||||
|
||||
def parse_arguments(self):
|
||||
parser = argparse.ArgumentParser(description='Builds OpenCore-Patcher binary')
|
||||
parser.add_argument('--build_tui', action='store_true', help='Builds TUI binary, if ommited GUI binary is built')
|
||||
parser.add_argument('--branch', type=str, help='Git branch name')
|
||||
parser.add_argument('--commit', type=str, help='Git commit URL')
|
||||
parser.add_argument('--commit_date', type=str, help='Git commit date')
|
||||
args = parser.parse_args()
|
||||
return args
|
||||
|
||||
def setup_pathing(self):
|
||||
# /Library/Frameworks/Python.framework/Versions/3.9/bin/python3
|
||||
python_path = sys.executable
|
||||
python_binary = python_path.split("/")[-1]
|
||||
python_bin_dir = python_path.strip(python_binary)
|
||||
pyinstaller_path = f"{python_bin_dir}pyinstaller"
|
||||
|
||||
if not Path(pyinstaller_path).exists():
|
||||
print(f" - pyinstaller not found:\n\t{pyinstaller_path}")
|
||||
raise Exception("pyinstaller not found")
|
||||
print(f" - pyinstaller found:\n\t{pyinstaller_path}")
|
||||
|
||||
self.pyinstaller_path = pyinstaller_path
|
||||
|
||||
def preflight_processes(self):
|
||||
print("- Starting preflight processes")
|
||||
self.setup_pathing()
|
||||
self.download_resources()
|
||||
if not self.args.build_tui:
|
||||
# payloads.dmg is only needed for GUI builds
|
||||
self.generate_paylods_dmg()
|
||||
|
||||
def postflight_processes(self):
|
||||
print("- Starting postflight processes")
|
||||
if self.args.build_tui:
|
||||
self.move_launcher()
|
||||
self.patch_load_command()
|
||||
self.add_commit_data()
|
||||
|
||||
def build_binary(self):
|
||||
if Path(f"./dist/OpenCore-Patcher.app").exists():
|
||||
print("- Found OpenCore-Patcher.app, removing...")
|
||||
rm_output = subprocess.run(
|
||||
["rm", "-rf", "./dist/OpenCore-Patcher.app"],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
||||
)
|
||||
if rm_output.returncode != 0:
|
||||
print("- Remove failed")
|
||||
print(rm_output.stderr.decode('utf-8'))
|
||||
raise Exception("Remove failed")
|
||||
|
||||
|
||||
if self.args.build_tui:
|
||||
print("- Building TUI binary...")
|
||||
build_args = [self.pyinstaller_path, "./OpenCore-Patcher.spec", "--noconfirm"]
|
||||
else:
|
||||
print("- Building GUI binary...")
|
||||
build_args = [self.pyinstaller_path, "./OpenCore-Patcher-GUI.spec", "--noconfirm"]
|
||||
|
||||
build_result = subprocess.run(build_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
if build_result.returncode != 0:
|
||||
print("- Build failed")
|
||||
print(build_result.stderr.decode('utf-8'))
|
||||
raise Exception("Build failed")
|
||||
|
||||
|
||||
def download_resources(self):
|
||||
patcher_support_pkg_version = constants.Constants().patcher_support_pkg_version
|
||||
required_resources = [
|
||||
"Universal-Binaries.zip"
|
||||
]
|
||||
|
||||
for resource in required_resources:
|
||||
if Path(f"./payloads/{resource}").exists():
|
||||
print(f" - {resource} already exists, skipping download")
|
||||
continue
|
||||
print(f" - Downloading {resource}...")
|
||||
|
||||
download_result = subprocess.run(
|
||||
[
|
||||
"curl", "-LO",
|
||||
f"https://github.com/dortania/PatcherSupportPkg/releases/download/{patcher_support_pkg_version}/{resource}"
|
||||
],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
||||
)
|
||||
|
||||
if download_result.returncode != 0:
|
||||
print(" - Download failed")
|
||||
print(download_result.stderr.decode('utf-8'))
|
||||
raise Exception("Download failed")
|
||||
if not Path(f"./{resource}").exists():
|
||||
print(f" - {resource} not found")
|
||||
raise Exception(f"{resource} not found")
|
||||
|
||||
print(" - Moving into payloads")
|
||||
mv_output = subprocess.run(["mv", resource, "./payloads/"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
if mv_output.returncode != 0:
|
||||
print(" - Move failed")
|
||||
print(mv_output.stderr.decode('utf-8'))
|
||||
raise Exception("Move failed")
|
||||
|
||||
def generate_paylods_dmg(self):
|
||||
if Path("./payloads.dmg").exists():
|
||||
print(" - payloads.dmg already exists, skipping creation")
|
||||
return
|
||||
print(" - Generating DMG...")
|
||||
dmg_output = subprocess.run([
|
||||
'hdiutil', 'create', './payloads.dmg',
|
||||
'-megabytes', '32000',
|
||||
'-format', 'UDZO', '-ov',
|
||||
'-volname', 'payloads',
|
||||
'-fs', 'HFS+',
|
||||
'-srcfolder', './payloads',
|
||||
'-passphrase', 'password', '-encryption'
|
||||
], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
if dmg_output.returncode != 0:
|
||||
print(" - DMG generation failed")
|
||||
print(dmg_output.stderr.decode('utf-8'))
|
||||
raise Exception("DMG generation failed")
|
||||
|
||||
print(" - DMG generation complete")
|
||||
|
||||
def add_commit_data(self):
|
||||
if not self.args.branch and not self.args.commit and not self.args.commit_date:
|
||||
print(" - No commit data provided, skipping")
|
||||
return
|
||||
print(" - Adding commit data to Info.plist")
|
||||
plist_path = Path("./dist/OpenCore-Patcher.app/Contents/Info.plist")
|
||||
plist = plistlib.load(Path(plist_path).open("rb"))
|
||||
plist["Github"] = {
|
||||
"Branch": self.args.branch,
|
||||
"Commit URL": self.args.commit,
|
||||
"Commit Date": self.args.commit_date
|
||||
}
|
||||
plistlib.dump(plist, Path(plist_path).open("wb"), sort_keys=True)
|
||||
|
||||
def patch_load_command(self):
|
||||
# Patches LC_VERSION_MIN_MACOSX in Load Command to report 10.10
|
||||
#
|
||||
# By default Pyinstaller will create binaries supporting 10.13+
|
||||
# However this limitation is entirely arbitrary for our libraries
|
||||
# and instead we're able to support 10.10 without issues.
|
||||
#
|
||||
# To verify set version:
|
||||
# otool -l ./dist/OpenCore-Patcher.app/Contents/MacOS/OpenCore-Patcher
|
||||
#
|
||||
# cmd LC_VERSION_MIN_MACOSX
|
||||
# cmdsize 16
|
||||
# version 10.13
|
||||
# sdk 10.9
|
||||
print(" - Patching LC_VERSION_MIN_MACOSX")
|
||||
path = './dist/OpenCore-Patcher.app/Contents/MacOS/OpenCore-Patcher'
|
||||
find = b'\x00\x0D\x0A\x00' # 10.13 (0xA0D)
|
||||
replace = b'\x00\x0A\x0A\x00' # 10.10 (0xA0A)
|
||||
with open(path, 'rb') as f:
|
||||
data = f.read()
|
||||
data = data.replace(find, replace, 1)
|
||||
with open(path, 'wb') as f:
|
||||
f.write(data)
|
||||
|
||||
def move_launcher(self):
|
||||
print(" - Adding TUI launcher")
|
||||
mv_output = subprocess.run(
|
||||
["cp", "./payloads/launcher.sh", "./dist/OpenCore-Patcher.app/Contents/MacOS/Launcher"],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
||||
)
|
||||
if mv_output.returncode != 0:
|
||||
print(" - Move failed")
|
||||
print(mv_output.stderr.decode('utf-8'))
|
||||
raise Exception("Move failed")
|
||||
|
||||
if __name__ == "__main__":
|
||||
create_binary()
|
||||
@@ -1,2 +0,0 @@
|
||||
#!/bin/sh
|
||||
cp payloads/launcher.sh dist/OpenCore-Patcher.app/Contents/MacOS/Launcher
|
||||
@@ -1,14 +0,0 @@
|
||||
import subprocess
|
||||
from resources import constants
|
||||
|
||||
patcher_support_pkg_version = constants.Constants().patcher_support_pkg_version
|
||||
binary_packages = ["Universal-Binaries"]
|
||||
|
||||
for binary_package in binary_packages:
|
||||
print(f"- Downloading {binary_package}...")
|
||||
download_cmd = f"curl -LO https://github.com/dortania/PatcherSupportPkg/releases/download/{patcher_support_pkg_version}/{binary_package}.zip"
|
||||
subprocess.run(download_cmd, shell=True)
|
||||
print("- Moving into payloads")
|
||||
move_cmd = f"mv {binary_package}.zip ./payloads/"
|
||||
subprocess.run(move_cmd, shell=True)
|
||||
print("- Download complete")
|
||||
@@ -745,7 +745,7 @@ class wx_python_gui:
|
||||
self.install_button.Centre(wx.HORIZONTAL)
|
||||
|
||||
|
||||
self.reload_button = wx.Button(self.frame, label="Search for Disks Again", size=(150,-1))
|
||||
self.reload_button = wx.Button(self.frame, label="Search for Disks Again", size=(170,-1))
|
||||
self.reload_button.SetPosition(
|
||||
wx.Point(
|
||||
self.install_button.GetPosition().x,
|
||||
@@ -755,7 +755,7 @@ class wx_python_gui:
|
||||
self.reload_button.Bind(wx.EVT_BUTTON, self.install_menu)
|
||||
self.reload_button.Centre(wx.HORIZONTAL)
|
||||
|
||||
self.return_to_main_menu = wx.Button(self.frame, label="Return to Main Menu", size=(150,-1))
|
||||
self.return_to_main_menu = wx.Button(self.frame, label="Return to Main Menu", size=(170,-1))
|
||||
self.return_to_main_menu.SetPosition(
|
||||
wx.Point(
|
||||
self.reload_button.GetPosition().x,
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
# Handle Misc patching for binaries during commit
|
||||
# This includes Load Command Patching as well as Info.plist patching
|
||||
# Copyright (C) 2022 - Mykola Grymalyuk
|
||||
import sys
|
||||
import plistlib
|
||||
from pathlib import Path
|
||||
|
||||
def main():
|
||||
patch_load_command()
|
||||
patch_info_plist()
|
||||
|
||||
def patch_load_command():
|
||||
# Patches LC_VERSION_MIN_MACOSX in Load Command to report 10.10
|
||||
#
|
||||
# By default Pyinstaller will create binaries supporting 10.13+
|
||||
# However this limitation is entirely arbitrary for our libraries
|
||||
# and instead we're able to support 10.10 without issues.
|
||||
#
|
||||
# To verify set version:
|
||||
# otool -l ./dist/OpenCore-Patcher.app/Contents/MacOS/OpenCore-Patcher
|
||||
#
|
||||
# cmd LC_VERSION_MIN_MACOSX
|
||||
# cmdsize 16
|
||||
# version 10.13
|
||||
# sdk 10.9
|
||||
print("- Patching LC_VERSION_MIN_MACOSX")
|
||||
path = './dist/OpenCore-Patcher.app/Contents/MacOS/OpenCore-Patcher'
|
||||
find = b'\x00\x0D\x0A\x00' # 10.13 (0xA0D)
|
||||
replace = b'\x00\x0A\x0A\x00' # 10.10 (0xA0A)
|
||||
with open(path, 'rb') as f:
|
||||
data = f.read()
|
||||
data = data.replace(find, replace, 1)
|
||||
with open(path, 'wb') as f:
|
||||
f.write(data)
|
||||
|
||||
def patch_info_plist():
|
||||
# Add Commit Data to Info.plist
|
||||
print("- Updating Info.plist")
|
||||
argsv = sys.argv
|
||||
argsv.pop(0)
|
||||
if argsv:
|
||||
plist_path = './dist/OpenCore-Patcher.app/Contents/Info.plist'
|
||||
plist = plistlib.load(Path(plist_path).open("rb"))
|
||||
print("- Adding Github Dictionary")
|
||||
plist["Github"] = {
|
||||
"Branch": argsv[0],
|
||||
"Commit URL": argsv[1],
|
||||
"Commit Date": argsv[2],
|
||||
}
|
||||
print("- Writing Plist")
|
||||
plistlib.dump(plist, Path(plist_path).open("wb"), sort_keys=True)
|
||||
else:
|
||||
print("- No commit data supplied, skipping")
|
||||
main()
|
||||
Reference in New Issue
Block a user