def _run_swig(self): """ Do everything that needs doing in the subdir 'swig'. - Edit main *.i file """ print "Traversing swig..." fname_mainswig = self._get_mainswigfile() if fname_mainswig is None: print 'Warning: No main swig file found.' return fname_mainswig = os.path.join('swig', fname_mainswig) print "Editing %s..." % fname_mainswig swig_block_magic_str = '\nGR_SWIG_BLOCK_MAGIC(%s,%s);\n%%include "%s"\n' % ( self._info['modname'], self._info['blockname'], self._info['fullblockname'] + '.h') if re.search('#include', open(fname_mainswig, 'r').read()): append_re_line_sequence(fname_mainswig, '^#include.*\n', '#include "%s.h"' % self._info['fullblockname']) else: # I.e., if the swig file is empty oldfile = open(fname_mainswig, 'r').read() regexp = re.compile('^%\{\n', re.MULTILINE) oldfile = regexp.sub('%%{\n#include "%s.h"\n' % self._info['fullblockname'], oldfile, count=1) open(fname_mainswig, 'w').write(oldfile) open(fname_mainswig, 'a').write(swig_block_magic_str)
def _run_swig(self): """ Do everything that needs doing in the subdir 'swig'. - Edit main *.i file """ if self._get_mainswigfile() is None: print 'Warning: No main swig file found.' return print "Editing %s..." % self._file['swig'] mod_block_sep = '/' if self._info['version'] == '36': mod_block_sep = '_' swig_block_magic_str = get_template('swig_block_magic', **self._info) open(self._file['swig'], 'a').write(swig_block_magic_str) include_str = '#include "%s%s%s.h"' % ( {True: 'gnuradio/' + self._info['modname'], False: self._info['modname']}[self._info['is_component']], mod_block_sep, self._info['blockname']) if re.search('#include', open(self._file['swig'], 'r').read()): append_re_line_sequence(self._file['swig'], '^#include.*\n', include_str) else: # I.e., if the swig file is empty oldfile = open(self._file['swig'], 'r').read() regexp = re.compile('^%\{\n', re.MULTILINE) oldfile = regexp.sub('%%{\n%s\n' % include_str, oldfile, count=1) open(self._file['swig'], 'w').write(oldfile) self.scm.mark_files_updated((self._file['swig'],))
def _run_rfnoc(self): """ Do everything that needs doing in the subdir 'rfnoc' to add a GRC block control bindings XML file. - add .xml file - include in CMakeLists.txt - add verilog file - adds verilog name to Makefile.srcs - Calls _run_testbenches() - Runs build (test) """ fname_rfnoc = self._info['blockname'] + '.xml' fname_rfnocv = 'noc_block_' + self._info['blockname'] + '.v' self._write_tpl('rfnoc_xml', 'rfnoc/blocks', fname_rfnoc) self._write_tpl('rfnoc_v', 'rfnoc/fpga-src', fname_rfnocv) patt_v = re.escape('$(addprefix '+os.path.join(os.getcwd(),'rfnoc','fpga-src','')+', \\\n') #TODO can be replaced with a dummy, as the file is supposed to be empty append_re_line_sequence(self._file['rfnoc_mksrc'], patt_v, 'noc_block_' + self._info['blockname'] + '.v \\') ed = CMakeFileEditor(self._file['cmrfnoc'], '\n ') self._run_testbenches() self._build() if self._skip_cmakefiles or ed.check_for_glob('*.xml'): return print("Editing rfnoc/blocks/CMakeLists.txt...") ed.append_value('install', fname_rfnoc, to_ignore_end='DESTINATION[^()]+') ed.write() self.scm.mark_files_updated((self._file['cmrfnoc'],))
def _run_python(self): """ Do everything that needs doing in the subdir 'python' to add a Python block. - add .py file - include in CMakeLists.txt - include in __init__.py """ fname_py = self._info['blockname'] + '.py' self._write_tpl('block_python', 'python', fname_py) append_re_line_sequence(self._file['pyinit'], '(^from.*import.*\n|# import any pure.*\n)', 'from %s import %s' % (self._info['blockname'], self._info['blockname'])) if self.options.skip_cmakefiles: return ed = CMakeFileEditor(self._file['cmpython']) ed.append_value('GR_PYTHON_INSTALL', fname_py, to_ignore_end='DESTINATION[^()]+') ed.write()
def _run_testbenches(self): """ Generates the template for the OOT mod testbench and puts it into a new folder along with an empty CMakelists and a template for the Makefile. """ dirname = 'noc_block_' + self._info['blockname'] + '_tb' new_tbdir = 'rfnoc/testbenches/' + dirname if not os.path.isdir(new_tbdir): os.makedirs(new_tbdir) print(new_tbdir + ' folder created') tbname = 'noc_block_' + self._info['blockname'] + '_tb.sv' self._write_tpl('rfnoc_tb', new_tbdir, tbname) self._write_tpl('tb_makefile', new_tbdir, 'Makefile') self._write_tpl('empty', new_tbdir, 'CMakeLists.txt') append_re_line_sequence('rfnoc/testbenches/CMakeLists.txt', "--------------------", 'add_subdirectory({})'.format(dirname) + '\n')
def _add_qa(): " Add C++ QA files for 3.7 API " fname_qa_h = 'qa_%s.h' % self._info['blockname'] fname_qa_cc = 'qa_%s.cc' % self._info['blockname'] self._write_tpl('qa_cpp', 'lib', fname_qa_cc) self._write_tpl('qa_h', 'lib', fname_qa_h) if not self._skip_cmakefiles: try: append_re_line_sequence( self._file['cmlib'], '\$\{CMAKE_CURRENT_SOURCE_DIR\}/qa_%s.cc.*\n' % self._info['modname'], ' ${CMAKE_CURRENT_SOURCE_DIR}/qa_%s.cc' % self._info['blockname']) append_re_line_sequence(self._file['qalib'], '#include.*\n', '#include "%s"' % fname_qa_h) append_re_line_sequence( self._file['qalib'], '(addTest.*suite.*\n|new CppUnit.*TestSuite.*\n)', ' s->addTest(gr::%s::qa_%s::suite());' % (self._info['modname'], self._info['blockname'])) self.scm.mark_files_updated((self._file['qalib'], )) except IOError: print "Can't add C++ QA files."
def _add_qa(): " Add C++ QA files for 3.7 API " fname_qa_h = 'qa_%s.h' % self._info['blockname'] fname_qa_cc = 'qa_%s.cc' % self._info['blockname'] self._write_tpl('qa_cpp', 'lib', fname_qa_cc) self._write_tpl('qa_h', 'lib', fname_qa_h) if not self.options.skip_cmakefiles: append_re_line_sequence(self._file['cmlib'], '\$\{CMAKE_CURRENT_SOURCE_DIR\}/qa_%s.cc.*\n' % self._info['modname'], ' ${CMAKE_CURRENT_SOURCE_DIR}/qa_%s.cc' % self._info['blockname']) append_re_line_sequence('lib/qa_%s.cc' % self._info['modname'], '#include.*\n', '#include "%s"' % fname_qa_h) append_re_line_sequence('lib/qa_%s.cc' % self._info['modname'], '(addTest.*suite.*\n|new CppUnit.*TestSuite.*\n)', '\ts->addTest(gr::%s::qa_%s::suite());' % (self._info['modname'], self._info['blockname']) )
def _add_qa(): " Add C++ QA files for 3.7 API " fname_qa_h = 'qa_%s.h' % self._info['blockname'] fname_qa_cc = 'qa_%s.cc' % self._info['blockname'] self._write_tpl('qa_cpp', 'lib', fname_qa_cc) self._write_tpl('qa_h', 'lib', fname_qa_h) if not self._skip_cmakefiles: try: append_re_line_sequence(self._file['cmlib'], '\$\{CMAKE_CURRENT_SOURCE_DIR\}/qa_%s.cc.*\n' % self._info['modname'], ' ${CMAKE_CURRENT_SOURCE_DIR}/qa_%s.cc' % self._info['blockname']) append_re_line_sequence(self._file['qalib'], '#include.*\n', '#include "%s"' % fname_qa_h) append_re_line_sequence(self._file['qalib'], '(addTest.*suite.*\n|new CppUnit.*TestSuite.*\n)', ' s->addTest(gr::%s::qa_%s::suite());' % (self._info['modname'], self._info['blockname']) ) self.scm.mark_files_updated((self._file['qalib'],)) except IOError: print "Can't add C++ QA files."