"""Link a UI regression test against an existing qmake Debug app, no hardware.""" import argparse,os,re,shlex,subprocess from pathlib import Path p=argparse.ArgumentParser() p.add_argument('--build-dir',required=True,type=Path) p.add_argument('--qt-bin',required=True,type=Path) p.add_argument('--source',required=True,type=Path) p.add_argument('--makefile',default='Makefile.Merge.Debug') p.add_argument('--platform',default='offscreen') a=p.parse_args(); root=Path(__file__).resolve().parents[1]; build=a.build_dir.resolve() text=(build/a.makefile).read_text(encoding='utf-8') def value(name): return re.search(r'^'+name+r'\s*=\s*(.*)$',text,re.M).group(1).strip() def args(text): return [word.strip('"') for word in shlex.split(text,posix=False)] env=dict(os.environ); env['PATH']=str(a.qt_bin.resolve())+os.pathsep+str(root/'bin/debug')+os.pathsep+env['PATH'] env['QT_QPA_PLATFORM']=a.platform; env['QT_QPA_FONTDIR']='C:/Windows/Fonts' output=root/'build/incoming-main-merge/runtime'; output.mkdir(parents=True,exist_ok=True) binary=output/(a.source.stem+'.exe'); obj=build/(a.source.stem+'.o') compiler=value('CXX'); flags=value('CXXFLAGS').replace('$(DEFINES)',value('DEFINES')) subprocess.run([compiler,'-c',*args(flags),*args(value('INCPATH')),'-I'+str(a.qt_bin.parent/'include/QtTest'),str(a.source.resolve()),'-o',str(obj)],cwd=build,env=env,check=True) objects=(build/'object_script.CmvrControlStation_d.Debug').read_text().splitlines() objects=[x for x in objects if not x.replace('\\','/').endswith('/main.o')] response=build/(a.source.stem+'.rsp'); response.write_text('\n'.join(objects),encoding='utf-8') subprocess.run([compiler,'-mthreads','-o',str(binary),str(obj),'@'+str(response),*args(value('LIBS')),str(a.qt_bin.parent/'lib/libQt5Testd.a')],cwd=build,env=env,check=True) subprocess.run([str(binary)],cwd=output,env=env,check=True,timeout=40)