waf: generate mavlink headers for waf build

This commit is contained in:
Siddharth Bharat Purohit 2016-01-02 03:22:36 -08:00 committed by Andrew Tridgell
parent dd65495668
commit 11b82474de
2 changed files with 71 additions and 4 deletions

View File

@ -0,0 +1,59 @@
#!/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):
"""generate mavlink header files"""
color = 'GREEN'
run_str = '${PYTHON} ${MAVGEN} --lang=C --wire-protocol=1.0 --output ${TGT} ${SRC}'
def options(opt):
opt.load('python')
@feature('mavgen')
@before_method('process_source')
def process_mavgen(self):
inputs = self.to_nodes(self.source)
outputs = []
self.target = Utils.to_list(getattr(self, 'target', []))
for t in self.target:
if not isinstance(t, Node.Node):
t = self.bld.bldnode.find_or_declare(t)
outputs.append(t)
self.source = []
self.create_task('mavgen', inputs, outputs)
def configure(cfg):
"""
setup environment for mavlink header generator
"""
cfg.load('python')
cfg.check_python_version(minver=(2,7,0))
env = cfg.env
cfg.env.env = dict(os.environ)
cfg.start_msg('Checking for message_definitions')
if not cfg.srcnode.find_resource('modules/mavlink/message_definitions/v1.0/ardupilotmega.xml'):
cfg.fatal(env.MAV_MSG_DEFS + ' not found, please run: git submodule init && git submodule update', color='RED')
return
cfg.end_msg('success')
env.MAVLINK_DIR = cfg.srcnode.find_dir('modules/mavlink/').abspath()
env.MAVLINK_HEADERS = cfg.bldnode.make_node('/libraries/GCS_MAVLink/include/mavlink/v1.0/').abspath()
env.MAVGEN = env.MAVLINK_DIR + '/pymavlink/tools/mavgen.py'
cfg.env.env['PYTHONPATH'] = env.MAVLINK_DIR
env.MAV_MSG_DEFS = cfg.srcnode.find_resource('modules/mavlink/message_definitions/v1.0/ardupilotmega.xml').abspath()

16
wscript
View File

@ -41,7 +41,7 @@ def init(ctx):
def options(opt): def options(opt):
boards_names = boards.get_boards_names() boards_names = boards.get_boards_names()
opt.load('compiler_cxx compiler_c waf_unit_test') opt.load('compiler_cxx compiler_c waf_unit_test python')
opt.add_option('--board', opt.add_option('--board',
action='store', action='store',
choices=boards_names, choices=boards_names,
@ -78,6 +78,7 @@ def configure(cfg):
cfg.load('compiler_cxx compiler_c') cfg.load('compiler_cxx compiler_c')
cfg.load('clang_compilation_database') cfg.load('clang_compilation_database')
cfg.load('waf_unit_test') cfg.load('waf_unit_test')
cfg.load('mavgen')
cfg.load('gbenchmark') cfg.load('gbenchmark')
cfg.load('static_linking') cfg.load('static_linking')
@ -95,8 +96,9 @@ def configure(cfg):
) )
cfg.env.prepend_value('INCLUDES', [ cfg.env.prepend_value('INCLUDES', [
cfg.srcnode.abspath() + '/libraries/' cfg.srcnode.abspath() + '/libraries/',
]) cfg.bldnode.abspath() +'/' + cfg.env.BOARD + '/libraries/',
cfg.bldnode.abspath() +'/' + cfg.env.BOARD + '/libraries/GCS_MAVLink'])
# TODO: Investigate if code could be changed to not depend on the # TODO: Investigate if code could be changed to not depend on the
# source absolute path. # source absolute path.
@ -116,6 +118,13 @@ def list_boards(ctx):
print(*boards.get_boards_names()) print(*boards.get_boards_names())
def build(bld): def build(bld):
#generate mavlink headers
bld(features=['mavgen'],
source=['modules/mavlink/message_definitions/v1.0/ardupilotmega.xml'],
target=['libraries/GCS_MAVLink/include/mavlink/v1.0/'])
bld.add_group()
# NOTE: Static library with vehicle set to UNKNOWN, shared by all # NOTE: Static library with vehicle set to UNKNOWN, shared by all
# the tools and examples. This is the first step until the # the tools and examples. This is the first step until the
# dependency on the vehicles is reduced. Later we may consider # dependency on the vehicles is reduced. Later we may consider
@ -126,7 +135,6 @@ def build(bld):
vehicle='UNKNOWN', vehicle='UNKNOWN',
libraries=ardupilotwaf.get_all_libraries(bld), libraries=ardupilotwaf.get_all_libraries(bld),
) )
# TODO: Currently each vehicle also generate its own copy of the # TODO: Currently each vehicle also generate its own copy of the
# libraries. Fix this, or at least reduce the amount of # libraries. Fix this, or at least reduce the amount of
# vehicle-dependent libraries. # vehicle-dependent libraries.