Skip to content

Instantly share code, notes, and snippets.

@agateau
Created May 5, 2020 07:56
Show Gist options
  • Save agateau/f217cebd8b645b1c7466d233e1f1fcfb to your computer and use it in GitHub Desktop.
Save agateau/f217cebd8b645b1c7466d233e1f1fcfb to your computer and use it in GitHub Desktop.
Patch a Qt install on macOS to fix https://github.com/miurahr/aqtinstall/issues/100
#!/usr/bin/env python3
"""
Change the installation prefix of a Qt install
"""
import argparse
import os
import sys
from pathlib import Path
PREFIX_VAR = b"qt_prfxpath="
def find_qtcore_files(prefix):
framework_dir = prefix.joinpath("lib", "QtCore.framework")
assert framework_dir.exists(), "Invalid installation prefix"
return framework_dir.joinpath("QtCore").resolve(), \
framework_dir.joinpath("QtCore_debug").resolve()
def patch_qtcore(qtcore_path, prefix):
data = qtcore_path.read_bytes()
old_len = len(data)
idx = data.find(PREFIX_VAR)
assert idx > 0, f"Could not find {PREFIX_VAR} in {qtcore_path}"
value = PREFIX_VAR + bytes(prefix, "ascii")
data = data[:idx] + value + data[idx + len(value):]
assert len(data) == old_len
qtcore_path.rename(str(qtcore_path) + ".old")
qtcore_path.write_bytes(data)
def main():
parser = argparse.ArgumentParser()
parser.description = __doc__
parser.add_argument("prefix", help="Qt Installation prefix")
args = parser.parse_args()
prefix = Path(args.prefix)
qtcore_paths = find_qtcore_files(prefix)
for qtcore_path in qtcore_paths:
print(f"Patching {qtcore_path}")
patch_qtcore(qtcore_path, args.prefix)
return 0
if __name__ == "__main__":
sys.exit(main())
# vi: ts=4 sw=4 et
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment