Skip to content
Browse files

scripts: avoid unnecessary 'west build --force'

Commit 88fb8ba ("scripts: improve west build's board handling")
lets us specify the board with a build.board config or BOARD
environment variable.

However, under some conditions, e.g. if the use has
build.pristine=auto and build.board=some_board, the following fails a
check_force call:

west build samples/hello_world
west build samples/philosophers

The problem is that the check_force wasn't made aware of the other
places a board can come from. Fix that.

Signed-off-by: Marti Bolivar <>
  • Loading branch information...
mbolivar authored and carlescufi committed May 23, 2019
1 parent f5f1b22 commit 8b9b7e7c8a31f8b072c1b5d6d09913c2e6da57b8
Showing with 14 additions and 10 deletions.
  1. +14 −10 scripts/west_commands/
@@ -112,6 +112,7 @@ def do_add_parser(self, parser_adder):

def do_run(self, args, remainder):
self.args = args # Avoid having to pass them around
self.config_board = config_get('board', None)
log.dbg('args: {} remainder: {}'.format(args, remainder),
# Store legacy -s option locally
@@ -169,16 +170,15 @@ def do_run(self, args, remainder):

def _find_board(self):
board, origin = None, None
config_board = config_get('board', None)
if self.cmake_cache:
board, origin = (self.cmake_cache.get('CACHED_BOARD'),
elif self.args.board:
board, origin = self.args.board, 'command line'
elif 'BOARD' in os.environ:
board, origin = os.environ['BOARD'], 'env'
elif config_board is not None:
board, origin = config_board, 'configfile'
elif self.config_board is not None:
board, origin = self.config_board, 'configfile'
return board, origin

def _parse_remainder(self, remainder):
@@ -301,17 +301,21 @@ def _sanity_check(self):
if apps_mismatched:
self.run_cmake = True # If they insist, we need to re-run cmake.

# If CACHED_BOARD is not defined, we need --board from the
# command line.
# If CACHED_BOARD is not defined, we need some other way to
# find the board.
cached_board = self.cmake_cache.get('CACHED_BOARD')
log.dbg('CACHED_BOARD:', cached_board, level=log.VERBOSE_EXTREME)
# If app_mismatched and pristine are true we will run pristine on the
# build, invalidating the cached board. Whenever we run pristine we
# require the user to provide all the require inputs again.
# If apps_mismatched and self.auto_pristine are true, we will
# run pristine on the build, invalidating the cached
# board. In that case, we need some way of getting the board.
self.check_force((cached_board and
not (apps_mismatched and self.auto_pristine))
or self.args.board,
'Cached board not defined, please provide --board')
or self.args.board or self.config_board or
'Cached board not defined, please provide it '
'(provide --board, set default with '
'"west config build.board <BOARD>", or set '
'BOARD in the environment)')

# Check consistency between cached board and --board.
boards_mismatched = (self.args.board and cached_board and

0 comments on commit 8b9b7e7

Please sign in to comment.
You can’t perform that action at this time.