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/mavgen.py
Views: 1798
# encoding: utf-81# (c) Siddharth Bharat Purohit, 3DRobotics Inc.23"""4The **mavgen.py** program is a code generator which creates mavlink header files.5"""67from waflib import Logs, Task, Utils, Node8from waflib.TaskGen import feature, before_method, extension9import os, sys10import os.path11from xml.etree import ElementTree as et1213class mavgen(Task.Task):14"""generate mavlink header files"""15color = 'BLUE'16before = 'cxx c'1718def scan(self):19nodes = []20names = []2122entry_point = self.inputs[0]23queue = [entry_point]24head = 02526while head < len(queue):27node = queue[head]28head += 12930tree = et.parse(node.abspath())31root = tree.getroot()32includes = root.findall('include')33for i in includes:34path = i.text.strip()35n = node.parent.find_node(path)36if n:37nodes.append(n)38if n not in queue:39queue.append(n)40continue4142path = os.path.join(43node.parent.path_from(entry_point.parent),44path45)46if path not in names:47names.append(path)4849return nodes, names5051def run(self):52sys.path.insert(0,self.env.get_flat('MAVLINK_DIR'))53from pymavlink.generator import mavgen54class mavgen_options:55language = 'C'56wire_protocol = '2.0'57validate = False58output = self.env.get_flat('OUTPUT_DIR')59xml = self.inputs[0].abspath()60if mavgen.mavgen(mavgen_options(), [xml]):61return 062return 16364def post_run(self):65super(mavgen, self).post_run()66for header in self.generator.output_dir.ant_glob("*.h **/*.h", remove=False):67header.sig = header.cache_sig = self.cache_sig6869def options(opt):70opt.load('python')7172@feature('mavgen')73@before_method('process_source')74def process_mavgen(self):75if not hasattr(self, 'output_dir'):76self.bld.fatal('mavgen: missing option output_dir')7778inputs = self.to_nodes(self.bld.srcnode.find_node(self.source))79outputs = []8081self.source = []8283if not isinstance(self.output_dir, Node.Node):84self.output_dir = self.bld.bldnode.find_or_declare(self.output_dir)8586task = self.create_task('mavgen', inputs, outputs)87task.env['OUTPUT_DIR'] = self.output_dir.abspath()8889task.env.env = dict(os.environ)90task.env.env['PYTHONPATH'] = task.env.MAVLINK_DIR9192def configure(cfg):93"""94setup environment for mavlink header generator95"""96env = cfg.env97env.MAVLINK_DIR = cfg.srcnode.make_node('modules/mavlink/').abspath()9899100