Skip to content
Browse files

west: Use find_build_dir in run_common

In preparation for upcoming changes to the way the default build folder
is defined, switch to using the common find_build_dir() function in the
This actually changes the behavior for the west build command slightly,
since the current working directory (cwd) will now be checked after the
default build folder ('build'). This brings it in line with what is
used for the runners.

Signed-off-by: Carles Cufi <>
  • Loading branch information...
carlescufi committed Jun 3, 2019
1 parent 48100df commit 49c4b1c303e2762ea3c57d147005f454a78d2f28
Showing with 15 additions and 14 deletions.
  1. +9 −6 scripts/west_commands/
  2. +6 −8 scripts/west_commands/
@@ -21,22 +21,25 @@
'''Name of the default CMake generator.'''

Build directory. If missing and run in a Zephyr build directory, it is
used; otherwise, it's "{}".'''.format(
Build directory. If not given, {}/ is used; otherwise if the current directory
is a Zephyr build directory, it is used.'''.format(DEFAULT_BUILD_DIR)

def find_build_dir(dir):
'''Heuristic for finding a build directory.
If the given argument is truthy, it is returned. Otherwise, if
If the given argument is truthy, it is returned. Otherwise if the
DEFAULT_BUILD_DIR is a build directory, it is returned. Next, if
the current working directory is a build directory, it is
returned. Otherwise, DEFAULT_BUILD_DIR is returned.'''
returned. Finally, DEFAULT_BUILD_DIR is returned.'''
if dir:
build_dir = dir
cwd = os.getcwd()
if is_zephyr_build(cwd):
default = os.path.join(cwd, DEFAULT_BUILD_DIR)
if is_zephyr_build(default):
build_dir = default
elif is_zephyr_build(cwd):
build_dir = cwd
@@ -13,7 +13,7 @@
from west import cmake
from west import log
from west import util
from import DEFAULT_BUILD_DIR, is_zephyr_build
from build_helpers import find_build_dir, is_zephyr_build
from west.commands import CommandContextError

from runners import get_runner_cls, ZephyrBinaryRunner
@@ -128,16 +128,14 @@ def _build_dir(args, die_if_none=True):
if args.build_dir:
return args.build_dir

cwd = getcwd()
default = path.join(cwd, DEFAULT_BUILD_DIR)
if is_zephyr_build(default):
return default
elif is_zephyr_build(cwd):
return cwd
dir = find_build_dir(None)

if is_zephyr_build(dir):
return dir
elif die_if_none:
log.die('--build-dir was not given, and neither {} '
'nor {} are zephyr build directories.'.
format(default, cwd))
format(getcwd(), dir))
return None

0 comments on commit 49c4b1c

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