def exportPhase2(cgOptions, phase1src): genfiles = phase1src # add makefile genfiles['Makefile'] = mkMakefile( cgOptions ) genfiles['workspace.c'] ='''\ #include "acado_common.h" ACADOworkspace acadoWorkspace; ACADOvariables acadoVariables; ''' # write things in user specified directory if 'export_without_build_path' is not None # then return without building if cgOptions['export_without_build_path'] is not None: codegen.writeDifferentFiles(cgOptions['export_without_build_path'], genfiles) return # write things in user specified directory if 'force_export_path' is not None # then compile as normal if cgOptions['force_export_path'] is not None: codegen.writeDifferentFiles(cgOptions['force_export_path'], genfiles) exportpath = cgOptions['force_export_path'] # otherwise write things in memoized directory, then compile as normal else: exportpath = codegen.memoizeFiles(genfiles,prefix=cgOptions['hashPrefix']+'__') # compile! (ret, msgs) = subprocess_tee.call(['make',codegen.makeJobs()], cwd=exportpath) if ret != 0: raise Exception("ocp compilation failed:\n\n"+msgs) # return shared object return exportpath
def exportPhase2(cgOptions, phase1src): # call pkg-config to get qpoases source and includes qpoStuff = {} for name in ["qpOASESsrc", "qpOASESinc"]: qpoStuff[name] = pkgconfig.call(["--variable", name, "acado"]) qpoStuff["qpOASESsrc"] = qpoStuff["qpOASESsrc"].split(" ") # get qpoases source as file dictionary qpoSrcPath = os.path.join(qpoStuff["qpOASESsrc"][0].split("qpoases")[0], "qpoases") phase2src = codegen.directoryToDict(qpoSrcPath) # merge qpoases source with phase 1 output def mergeAll(srcdict, destdict): for name, src in srcdict.items(): if isinstance(src, dict): if name not in destdict: destdict[name] = {} assert isinstance( destdict[name], dict ), "dictionary merge failed, source was directory but destination was a file" destdict[name] = mergeAll(src, destdict[name]) else: destdict[name] = src return destdict genfiles = mergeAll(phase1src, {"qpoases": phase2src}) # add makefile genfiles["Makefile"] = mkMakefile(cgOptions, qpoStuff["qpOASESsrc"]) genfiles[ "workspace.c" ] = """\ #include "acado_common.h" ACADOworkspace acadoWorkspace; ACADOvariables acadoVariables; """ # write things in user specified directory if 'export_without_build_path' is not None # then return without building if cgOptions["export_without_build_path"] is not None: codegen.writeDifferentFiles(cgOptions["export_without_build_path"], genfiles) return # write things in user specified directory if 'force_export_path' is not None # then compile as normal if cgOptions["force_export_path"] is not None: codegen.writeDifferentFiles(cgOptions["force_export_path"], genfiles) exportpath = cgOptions["force_export_path"] # otherwise write things in memoized directory, then compile as normal else: exportpath = codegen.memoizeFiles(genfiles, prefix=cgOptions["hashPrefix"] + "__") # compile! (ret, msgs) = subprocess_tee.call(["make", codegen.makeJobs()], cwd=exportpath) if ret != 0: raise Exception("ocp compilation failed:\n\n" + msgs) # return shared object return exportpath
def runPhase1(ocp, phase1Options, integratorOptions, ocpOptions): # write the ocp exporter cpp file genfiles = { 'export_ocp.cpp': writeAcadoOcpExport.generateAcadoOcp(ocp, integratorOptions, ocpOptions), 'Makefile': makeExportMakefile(phase1Options) } # add a file which just runs the export in the current directory genfiles['run_export.cpp'] = '''\ extern "C" int exportOcp(const char * exportDir); int main(void){ return exportOcp("."); } ''' exportpath = codegen.memoizeFiles(genfiles, prefix=phase1Options['hashPrefix'] + '_phase1__') # compile the ocp exporter (ret, msgs) = subprocess_tee.call(['make', codegen.makeJobs()], cwd=exportpath) if ret != 0: raise Exception("exportOcp phase 1 compilation failed:\n\n" + msgs) # run the ocp exporter def runOcpExporter(path): lib = ctypes.cdll.LoadLibrary(os.path.join(exportpath, 'export_ocp.so')) ret = lib.exportOcp(ctypes.c_char_p(path)) if ret != 0: print open(os.path.join(path, '_stdout.txt')).read() raise Exception("call to export_ocp.so failed") def callExporterInProcess(q): try: q.put(codegen.withTempdir(runOcpExporter)) finally: q.put(None) q = Queue() p = Process(target=callExporterInProcess, args=(q, )) p.start() ret = q.get() p.join() assert (0 == p.exitcode) and (ret is not None), \ "error exporting ocp, see stdout/stderr above" return ret
def exportPhase2(cgOptions, phase1src): # call pkg-config to get qpoases source and includes qpoStuff = {} for name in ['qpOASESsrc', 'qpOASESinc']: qpoStuff[name] = pkgconfig.call(['--variable', name, 'acado']) qpoStuff['qpOASESsrc'] = qpoStuff['qpOASESsrc'].split(' ') # get qpoases source as file dictionary qpoSrcPath = os.path.join(qpoStuff['qpOASESsrc'][0].split('qpoases')[0], 'qpoases') phase2src = codegen.directoryToDict(qpoSrcPath) # merge qpoases source with phase 1 output def mergeAll(srcdict, destdict): for name, src in srcdict.items(): if isinstance(src, dict): if name not in destdict: destdict[name] = {} assert isinstance( destdict[name], dict ), "dictionary merge failed, source was directory but destination was a file" destdict[name] = mergeAll(src, destdict[name]) else: destdict[name] = src return destdict genfiles = mergeAll(phase1src, {'qpoases': phase2src}) # add makefile genfiles['Makefile'] = mkMakefile(cgOptions, qpoStuff['qpOASESsrc']) genfiles['workspace.c'] = '''\ #include "acado_common.h" ACADOworkspace acadoWorkspace; ACADOvariables acadoVariables; ''' # write things in user specified directory if 'export_without_build_path' is not None if cgOptions['export_without_build_path'] is not None: codegen.writeDifferentFiles(cgOptions['export_without_build_path'], genfiles) return # otherwise write things in memoized directory, then compile exportpath = codegen.memoizeFiles(genfiles, prefix=cgOptions['hashPrefix'] + '__') # compile! (ret, msgs) = subprocess_tee.call(['make', codegen.makeJobs()], cwd=exportpath) if ret != 0: raise Exception("ocp compilation failed:\n\n" + msgs) # return shared object return exportpath
def runPhase1(ocp, phase1Options, integratorOptions, ocpOptions): # write the ocp exporter cpp file genfiles = {'export_ocp.cpp': writeAcadoOcpExport.generateAcadoOcp(ocp, integratorOptions, ocpOptions), 'Makefile': makeExportMakefile(phase1Options)} # add a file which just runs the export in the current directory genfiles['run_export.cpp'] = '''\ extern "C" int exportOcp(const char * exportDir); int main(void){ return exportOcp("."); } ''' exportpath = codegen.memoizeFiles(genfiles,prefix=phase1Options['hashPrefix']+'_phase1__') # compile the ocp exporter (ret, msgs) = subprocess_tee.call(['make',codegen.makeJobs()], cwd=exportpath) if ret != 0: raise Exception("exportOcp phase 1 compilation failed:\n\n"+msgs) # run the ocp exporter def runOcpExporter(path): lib = ctypes.cdll.LoadLibrary(os.path.join(exportpath, 'export_ocp.so')) ret = lib.exportOcp(ctypes.c_char_p(path)) if ret != 0: print open(os.path.join(path, '_stdout.txt')).read() raise Exception("call to export_ocp.so failed") def callExporterInProcess(q): try: q.put(codegen.withTempdir(runOcpExporter)) finally: q.put(None) q = Queue() p = Process(target = callExporterInProcess, args=(q, )) p.start() ret = q.get() p.join() assert (0 == p.exitcode) and (ret is not None), \ "error exporting ocp, see stdout/stderr above" return ret
def exportPhase2(cgOptions, phase1src): # call pkg-config to get qpoases source and includes qpoStuff = {} for name in ['qpOASESsrc', 'qpOASESinc']: qpoStuff[name] = pkgconfig.call(['--variable',name,'acado']) qpoStuff['qpOASESsrc'] = qpoStuff['qpOASESsrc'].split(' ') # get qpoases source as file dictionary qpoSrcPath = os.path.join(qpoStuff['qpOASESsrc'][0].split('qpoases')[0], 'qpoases') phase2src = codegen.directoryToDict(qpoSrcPath) # merge qpoases source with phase 1 output def mergeAll(srcdict,destdict): for name,src in srcdict.items(): if isinstance(src,dict): if name not in destdict: destdict[name] = {} assert isinstance(destdict[name], dict), "dictionary merge failed, source was directory but destination was a file" destdict[name] = mergeAll(src,destdict[name]) else: destdict[name] = src return destdict genfiles = mergeAll(phase1src, {'qpoases':phase2src}) # add makefile genfiles['Makefile'] = mkMakefile(cgOptions, qpoStuff['qpOASESsrc']) genfiles['workspace.c'] ='''\ #include "acado_common.h" ACADOworkspace acadoWorkspace; ACADOvariables acadoVariables; ''' # write things in user specified directory if 'export_without_build_path' is not None if cgOptions['export_without_build_path'] is not None: codegen.writeDifferentFiles(cgOptions['export_without_build_path'], genfiles) return # otherwise write things in memoized directory, then compile exportpath = codegen.memoizeFiles(genfiles,prefix=cgOptions['hashPrefix']+'__') # compile! (ret, msgs) = subprocess_tee.call(['make',codegen.makeJobs()], cwd=exportpath) if ret != 0: raise Exception("ocp compilation failed:\n\n"+msgs) # return shared object return exportpath