"""Compile/link the hand-eye loopback integration harness against built app objects. Usage: python tests/run_handeye_integration.py --build-dir --qt-bin Only an ephemeral 127.0.0.1 fake service and temporary settings are used. """ import argparse import os from pathlib import Path import re import shlex import subprocess parser = argparse.ArgumentParser() parser.add_argument('--build-dir', required=True, type=Path) parser.add_argument('--qt-bin', required=True, type=Path) parser.add_argument('--screenshot', type=Path) options = parser.parse_args() root = Path(__file__).resolve().parents[1] build = options.build_dir.resolve() makefile = (build / 'Makefile.Debug').read_text(encoding='utf-8') def value(name): return re.search(r'^' + name + r'\s*=\s*(.*)$', makefile, re.M).group(1).strip() def args(text): return [word.strip('"') for word in shlex.split(text, posix=False)] output = root / 'bin/debug/handeye_integration_test.exe' obj = build / 'handeyeintegration_test.o' env = dict(os.environ) env['PATH'] = str(options.qt_bin.resolve()) + os.pathsep + env['PATH'] env['QT_QPA_PLATFORM'] = 'offscreen' env['QT_QPA_FONTDIR'] = 'C:/Windows/Fonts' compiler = value('CXX') flags = value('CXXFLAGS').replace('$(DEFINES)', value('DEFINES')) subprocess.run([compiler, '-c', *args(flags), *args(value('INCPATH')), '-I' + str(options.qt_bin.resolve().parent / 'include/QtTest'), str(root / 'tests/handeyeintegration_test.cpp'), '-o', str(obj)], cwd=build, env=env, check=True) objects = (build / 'object_script.CmvrControlStation_d.Debug').read_text().splitlines() objects = [line for line in objects if not line.replace('\\', '/').endswith('/main.o')] response = build / 'handeyeintegration_objects.rsp' response.write_text('\n'.join(objects), encoding='utf-8') subprocess.run([compiler, '-mthreads', '-o', str(output), str(obj), '@' + str(response), *args(value('LIBS')), str(options.qt_bin.resolve().parent / 'lib/libQt5Testd.a')], cwd=build, env=env, check=True) run_args = [str(output)] if options.screenshot: run_args.extend(['--screenshot', str(options.screenshot.resolve())]) subprocess.run(run_args, cwd=output.parent, env=env, check=True, timeout=50)