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 runners. 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 <carles.cufi@nordicsemi.no>
This commit is contained in:
parent
48100df875
commit
49c4b1c303
|
@ -21,22 +21,25 @@ DEFAULT_CMAKE_GENERATOR = 'Ninja'
|
|||
'''Name of the default CMake generator.'''
|
||||
|
||||
BUILD_DIR_DESCRIPTION = '''\
|
||||
Build directory. If missing and run in a Zephyr build directory, it is
|
||||
used; otherwise, it's "{}".'''.format(
|
||||
DEFAULT_BUILD_DIR)
|
||||
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
|
||||
else:
|
||||
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
|
||||
else:
|
||||
build_dir = DEFAULT_BUILD_DIR
|
||||
|
|
|
@ -13,7 +13,7 @@ import textwrap
|
|||
from west import cmake
|
||||
from west import log
|
||||
from west import util
|
||||
from west.build 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))
|
||||
else:
|
||||
return None
|
||||
|
||||
|
|
Loading…
Reference in New Issue