waf: ardupilotwaf: make build_shortcut create build context class

Instead of just creating a wrapper. With that, the option targets is visible
only to that command instead of all commands in Options.commands.
This commit is contained in:
Gustavo Jose de Sousa 2016-01-27 12:22:24 +00:00 committed by Lucas De Marchi
parent 51505a82bb
commit a867dcdd07
2 changed files with 25 additions and 12 deletions

View File

@ -3,6 +3,7 @@
from __future__ import print_function
from waflib import Logs, Options, Utils
from waflib.Build import BuildContext
from waflib.Configure import conf
import os.path
@ -250,17 +251,28 @@ def test_summary(bld):
bld.fatal('check: some tests failed')
def build_shortcut(targets=None):
def build_fn(bld):
if targets:
if Options.options.targets:
Options.options.targets += ',' + targets
else:
Options.options.targets = targets
_build_shortcuts = {}
Options.commands = ['build'] + Options.commands
def _process_build_shortcut(bld):
if bld.cmd not in _build_shortcuts:
return
return build_fn
params = _build_shortcuts[bld.cmd]
targets = params['targets']
if targets:
if bld.targets:
bld.targets += ',' + targets
else:
bld.targets = targets
def build_shortcut(name, targets=None):
_build_shortcuts[name] = dict(
targets=targets,
)
class context_class(BuildContext):
cmd = name
def _select_programs_from_group(bld):
groups = bld.options.program_group
@ -297,4 +309,5 @@ def options(opt):
)
def build(bld):
bld.add_pre_fun(_process_build_shortcut)
bld.add_pre_fun(_select_programs_from_group)

View File

@ -191,6 +191,6 @@ class CheckContext(BuildContext):
'''executes tests after build'''
cmd = 'check'
copter = ardupilotwaf.build_shortcut(targets='bin/arducopter')
plane = ardupilotwaf.build_shortcut(targets='bin/arduplane')
rover = ardupilotwaf.build_shortcut(targets='bin/ardurover')
ardupilotwaf.build_shortcut('copter', targets='bin/arducopter')
ardupilotwaf.build_shortcut('plane', targets='bin/arduplane')
ardupilotwaf.build_shortcut('rover', targets='bin/ardurover')