Skip to content

Instantly share code, notes, and snippets.

@keithel
Last active January 9, 2023 21:30
Show Gist options
  • Select an option

  • Save keithel/9c8de602aa22dacf5ddcc3206165b22e to your computer and use it in GitHub Desktop.

Select an option

Save keithel/9c8de602aa22dacf5ddcc3206165b22e to your computer and use it in GitHub Desktop.
Copy missing Qt Qml .so files from Qt artifact to runTime qml dir
#!/usr/bin/env python
import sys
from argparse import ArgumentParser, Namespace
from pathlib import Path
import os
from os.path import dirname, basename
from typing import Tuple
from shutil import copy
def find_qml_sos(qtdir) -> list[str]:
cwd = os.getcwd()
try:
cwd_parts = cwd.split("/")
for i in reversed(range(len(cwd_parts))):
try:
qtdir.relative_to("/".join(cwd_parts[:i]))
break
except ValueError:
pass
os.chdir(qtdir)
qml_shared_libs = []
qml_dir = ""
for root, dirs, files in os.walk("."):
if root.endswith("qml"):
qml_dir = root[2:]
break
qml_sos = []
for root, dirs, files in os.walk(qml_dir):
qml_sos = qml_sos + [ root + "/" + file for file in files if file.endswith(".so")]
finally:
os.chdir(cwd)
return qml_sos
if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument("source_qt_dir", type=lambda p: Path(p).resolve(),
help="Path to source Qt dir")
parser.add_argument("runtime_dir", type=lambda p: Path(p).resolve(),
help="Path to the base of a runTime dir")
p = parser.parse_args()
print(f"Qt dir: {p.source_qt_dir}")
print(f"runTime dir: {p.runtime_dir}")
assert(p.source_qt_dir.exists())
assert(p.runtime_dir.exists())
sos = find_qml_sos(p.source_qt_dir)
for so in sos:
runtime_dir_for_so = p.runtime_dir.joinpath(dirname(so))
try:
assert(runtime_dir_for_so.exists())
except AssertionError as e:
print(f"{runtime_dir_for_so} doesn't exist and should. aborting.", file=sys.stderr)
raise
qtdir_so = p.source_qt_dir.joinpath(so)
dest_so = runtime_dir_for_so.joinpath(basename(so))
if not dest_so.exists():
print(f"Copying {qtdir_so} to {dest_so}")
copy(qtdir_so, dest_so)
else:
print(f"{dest_so} already exists, leaving it as-is.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment