From 844222870c7fa6bedd84ef47ce8fd39b57dc2e3a Mon Sep 17 00:00:00 2001 From: Gustavo Jose de Sousa Date: Fri, 20 May 2016 15:36:15 -0300 Subject: [PATCH] waf: boards: bind get_board() to configure and build contexts A convenience, since we don't expect the board to change for a given configuration. --- Tools/Replay/wscript | 3 +-- Tools/ardupilotwaf/boards.py | 8 ++++++-- Tools/ardupilotwaf/gtest.py | 2 +- wscript | 4 ++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Tools/Replay/wscript b/Tools/Replay/wscript index 773d2816bc..82ed3bda77 100644 --- a/Tools/Replay/wscript +++ b/Tools/Replay/wscript @@ -4,8 +4,7 @@ import boards def build(bld): - board = boards.get_board(bld.env.BOARD) - if not isinstance(board, boards.linux): + if not isinstance(bld.get_board(), boards.linux): return bld.ap_program( diff --git a/Tools/ardupilotwaf/boards.py b/Tools/ardupilotwaf/boards.py index 59abdacc52..babef0290f 100644 --- a/Tools/ardupilotwaf/boards.py +++ b/Tools/ardupilotwaf/boards.py @@ -5,6 +5,7 @@ from collections import OrderedDict import sys import waflib +from waflib.Configure import conf _board_classes = {} @@ -160,10 +161,13 @@ def get_boards_names(): return sorted(list(_board_classes.keys())) _board = None -def get_board(name): +@conf +def get_board(ctx): global _board if not _board: - _board = _board_classes[name]() + if not ctx.env.BOARD: + ctx.fatal('BOARD environment variable must be set before first call to get_board()') + _board = _board_classes[ctx.env.BOARD]() return _board # NOTE: Keeping all the board definitions together so we can easily diff --git a/Tools/ardupilotwaf/gtest.py b/Tools/ardupilotwaf/gtest.py index 1125e37d0f..2ff016df1e 100644 --- a/Tools/ardupilotwaf/gtest.py +++ b/Tools/ardupilotwaf/gtest.py @@ -11,7 +11,7 @@ from waflib.Configure import conf import boards def configure(cfg): - board = boards.get_board(cfg.env.BOARD) + board = cfg.get_board() if isinstance(board, boards.px4): # toolchain is currently broken for gtest cfg.msg( diff --git a/wscript b/wscript index 44e4bd0646..c51a1d1be8 100644 --- a/wscript +++ b/wscript @@ -92,7 +92,7 @@ def configure(cfg): cfg.define('WAF_BUILD', 1) cfg.msg('Setting board to', cfg.options.board) - boards.get_board(cfg.env.BOARD).configure(cfg) + cfg.get_board().configure(cfg) cfg.load('clang_compilation_database') cfg.load('waf_unit_test') @@ -266,7 +266,7 @@ def build(bld): _build_dynamic_sources(bld) bld.add_group('build') - boards.get_board(bld.env.BOARD).build(bld) + bld.get_board().build(bld) _build_common_taskgens(bld) _build_recursion(bld)