2016-01-02 07:22:36 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# encoding: utf-8
|
|
|
|
# (c) Siddharth Bharat Purohit, 3DRobotics Inc.
|
|
|
|
|
|
|
|
"""
|
|
|
|
The **mavgen.py** program is a code generator which creates mavlink header files.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from waflib import Task, Utils, Node
|
|
|
|
from waflib.TaskGen import feature, before_method, extension
|
|
|
|
import os
|
|
|
|
|
|
|
|
class mavgen(Task.Task):
|
2016-01-13 10:39:32 -04:00
|
|
|
"""generate mavlink header files"""
|
|
|
|
color = 'GREEN'
|
2016-01-14 12:32:26 -04:00
|
|
|
run_str = '${PYTHON} ${MAVGEN} --lang=C --wire-protocol=1.0 --output ${OUTPUT_DIR} ${SRC}'
|
2016-01-13 14:50:06 -04:00
|
|
|
before = 'cxx c'
|
2016-01-02 07:22:36 -04:00
|
|
|
|
2016-01-13 14:28:26 -04:00
|
|
|
def post_run(self):
|
|
|
|
super(mavgen, self).post_run()
|
|
|
|
for header in self.generator.output_dir.ant_glob("*.h **/*.h", remove=False):
|
|
|
|
header.sig = header.cache_sig = self.cache_sig
|
|
|
|
|
2016-01-02 07:22:36 -04:00
|
|
|
def options(opt):
|
2016-01-13 10:39:32 -04:00
|
|
|
opt.load('python')
|
2016-01-02 07:22:36 -04:00
|
|
|
|
|
|
|
@feature('mavgen')
|
|
|
|
@before_method('process_source')
|
|
|
|
def process_mavgen(self):
|
2016-01-14 12:32:26 -04:00
|
|
|
if not hasattr(self, 'output_dir'):
|
|
|
|
self.bld.fatal('mavgen: missing option output_dir')
|
|
|
|
|
2016-01-02 07:22:36 -04:00
|
|
|
inputs = self.to_nodes(self.source)
|
|
|
|
outputs = []
|
|
|
|
|
|
|
|
self.source = []
|
2016-01-13 15:05:48 -04:00
|
|
|
|
2016-01-14 12:32:26 -04:00
|
|
|
if not isinstance(self.output_dir, Node.Node):
|
|
|
|
self.output_dir = self.bld.bldnode.find_or_declare(self.output_dir)
|
|
|
|
|
2016-01-13 15:05:48 -04:00
|
|
|
task = self.create_task('mavgen', inputs, outputs)
|
2016-01-14 12:32:26 -04:00
|
|
|
task.env['OUTPUT_DIR'] = self.output_dir.abspath()
|
2016-01-13 15:05:48 -04:00
|
|
|
|
|
|
|
task.env.env = dict(os.environ)
|
|
|
|
task.env.env['PYTHONPATH'] = task.env.MAVLINK_DIR
|
2016-01-02 07:22:36 -04:00
|
|
|
|
|
|
|
def configure(cfg):
|
2016-01-13 10:39:32 -04:00
|
|
|
"""
|
|
|
|
setup environment for mavlink header generator
|
|
|
|
"""
|
|
|
|
cfg.load('python')
|
|
|
|
cfg.check_python_version(minver=(2,7,0))
|
2016-01-02 07:22:36 -04:00
|
|
|
|
2016-01-13 10:39:32 -04:00
|
|
|
env = cfg.env
|
2016-01-02 07:22:36 -04:00
|
|
|
|
2016-01-14 15:55:54 -04:00
|
|
|
cfg.start_msg('Checking for mavgen')
|
|
|
|
if not cfg.srcnode.find_resource('modules/mavlink/pymavlink/tools/mavgen.py'):
|
|
|
|
cfg.fatal('not found, please run: git submodule init && git submodule update')
|
2016-01-13 10:39:32 -04:00
|
|
|
return
|
2016-01-14 15:55:54 -04:00
|
|
|
cfg.end_msg('yes')
|
2016-01-02 07:22:36 -04:00
|
|
|
|
2016-01-13 10:39:32 -04:00
|
|
|
env.MAVLINK_DIR = cfg.srcnode.find_dir('modules/mavlink/').abspath()
|
|
|
|
env.MAVGEN = env.MAVLINK_DIR + '/pymavlink/tools/mavgen.py'
|