Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Tools/ardupilotwaf/dronecangen.py
Views: 1798
# encoding: utf-812"""3generate DSDLC headers for uavcan4"""56from waflib import Logs, Task, Utils, Node7from waflib.TaskGen import feature, before_method, extension8import os9import os.path10from xml.etree import ElementTree as et11import subprocess1213class dronecangen(Task.Task):14"""generate uavcan header files"""15color = 'BLUE'16before = 'cxx c'1718def run(self):19python = self.env.get_flat('PYTHON')20out = self.env.get_flat('OUTPUT_DIR')21src = self.env.get_flat('SRC')22dsdlc = self.env.get_flat("DC_DSDL_COMPILER_DIR")2324cmd = ['{}'.format(python),25'{}/dronecan_dsdlc.py'.format(dsdlc),26'-O{}'.format(out)] + [x.abspath() for x in self.inputs]27ret = self.exec_command(cmd)28if ret != 0:29# ignore if there was a signal to the interpreter rather30# than a real error in the script. Some environments use a31# signed and some an unsigned return for this32if ret > 128 or ret < 0:33Logs.warn('dronecangen crashed with code: {}'.format(ret))34ret = 035else:36Logs.warn('dronecangen: cmd=%s ' % str(cmd))37# re-run command with stdout visible to see errors38subprocess.call(cmd)39Logs.error('dronecangen returned {} error code'.format(ret))40return ret4142def post_run(self):43super(dronecangen, self).post_run()44for header in self.generator.output_dir.ant_glob("*.h **/*.h", remove=False):45header.sig = header.cache_sig = self.cache_sig4647def options(opt):48opt.load('python')4950@feature('dronecangen')51@before_method('process_rule')52def process_dronecangen(self):53if not hasattr(self, 'output_dir'):54self.bld.fatal('dronecangen: missing option output_dir')5556inputs = self.to_nodes(self.source)57# depend on each message file in the source so rebuilds will occur properly58deps = []59for inp in inputs:60deps.extend(inp.ant_glob("**/*.uavcan"))61# also depend on the generator source itself62dsdlc_dir = self.env.get_flat("DC_DSDL_COMPILER_DIR")63dsdlc = self.bld.root.find_node(dsdlc_dir) # expected to be absolute64if dsdlc is None:65self.bld.fatal("dronecangen: waf couldn't find dsdlc at abspath {}".format(dsdlc_dir))66deps.extend(dsdlc.ant_glob("**/*.py **/*.em"))67outputs = []6869self.source = []7071if not isinstance(self.output_dir, Node.Node):72self.output_dir = self.bld.bldnode.find_or_declare(self.output_dir)7374task = self.create_task('dronecangen', inputs, outputs)75task.dep_nodes = deps76task.env['OUTPUT_DIR'] = self.output_dir.abspath()7778task.env.env = dict(os.environ)7980def configure(cfg):81"""82setup environment for uavcan header generator83"""84env = cfg.env85env.DC_DSDL_COMPILER_DIR = cfg.srcnode.make_node('modules/DroneCAN/dronecan_dsdlc/').abspath()86cfg.msg('DC_DSDL compiler in', env.DC_DSDL_COMPILER_DIR)878889