gb-emu/scripts/patch.py

83 lines
2 KiB
Python

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"
SHADERC_OUT = join(frameworks_dir, SHADERC_DYLIB_NAME)
VULKAN_DYLIB_NAME = "libvulkan.1.dylib"
VULKAN_OUT = join(frameworks_dir, VULKAN_DYLIB_NAME)
DYLIB_PATH = join(os.environ["VULKAN_SDK"], "lib")
print("Patching " + executable)
shutil.copyfile(
join(DYLIB_PATH, SHADERC_DYLIB_NAME),
SHADERC_OUT,
follow_symlinks=True,
)
shutil.copyfile(
join(DYLIB_PATH, VULKAN_DYLIB_NAME),
VULKAN_OUT,
follow_symlinks=True,
)
os.system(
'install_name_tool -add_rpath "@loader_path/../Frameworks/" "' + executable + '"'
)
# 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)
os.system("codesign -f -s - " + executable)