gb-emu/scripts/mac/patch.py

83 lines
2 KiB
Python
Raw Normal View History

import argparse
import glob
import os
import shutil
from os.path import isdir, isfile, join
parser = argparse.ArgumentParser(description="Patch imports")
parser.add_argument("bundle", type=str)
parser.add_argument("--executable", help="executable name", required=False)
args = parser.parse_args()
bundle_path = args.bundle
if not isdir(bundle_path):
print(bundle_path + " is not a directory")
exit()
if not isfile(join(bundle_path, "Contents/Info.plist")):
print("Contents/Info.plist not found")
exit()
executable_dir = join(bundle_path, "Contents/MacOS")
executable = ""
if args.executable is not None:
executable = join(executable_dir, args.executable)
else:
executable = glob.glob(join(executable_dir, "**"), recursive=False)[0]
if not os.path.exists(executable):
print("error with executable path " + executable)
exit()
frameworks_dir = join(bundle_path, "Contents/Frameworks")
if not os.path.exists(frameworks_dir):
os.makedirs(frameworks_dir)
SHADERC_DYLIB_NAME = "libshaderc_shared.1.dylib"
2023-10-05 18:27:52 +11:00
SHADERC_OUT = join(frameworks_dir, SHADERC_DYLIB_NAME)
VULKAN_DYLIB_NAME = "libvulkan.1.dylib"
2023-10-05 18:27:52 +11:00
VULKAN_OUT = join(frameworks_dir, VULKAN_DYLIB_NAME)
DYLIB_PATH = join(os.environ["VULKAN_SDK"], "lib")
2023-10-05 18:27:52 +11:00
print("Patching " + executable)
shutil.copyfile(
join(DYLIB_PATH, SHADERC_DYLIB_NAME),
2023-10-05 18:27:52 +11:00
SHADERC_OUT,
follow_symlinks=True,
)
shutil.copyfile(
join(DYLIB_PATH, VULKAN_DYLIB_NAME),
2023-10-05 18:27:52 +11:00
VULKAN_OUT,
follow_symlinks=True,
)
os.system(
2023-10-05 21:38:38 +11:00
'install_name_tool -add_rpath "@loader_path/../Frameworks/" "' + executable + '"'
)
2023-10-05 18:27:52 +11:00
2023-10-05 21:38:38 +11:00
# os.system(
# 'install_name_tool -change "@rpath/'
# + SHADERC_DYLIB_NAME
# + '" "@executable_path/../Frameworks/'
# + SHADERC_DYLIB_NAME
# + '" '
# + executable
# )
# os.system(
# 'install_name_tool -change "@rpath/'
# + VULKAN_DYLIB_NAME
# + '" "@executable_path/../Frameworks/'
# + VULKAN_DYLIB_NAME
# + '" '
# + executable
# )
os.system("codesign -f -s - " + bundle_path)
2023-10-05 18:27:52 +11:00
os.system("codesign -f -s - " + executable)