From 49c4b1c303e2762ea3c57d147005f454a78d2f28 Mon Sep 17 00:00:00 2001 From: Carles Cufi Date: Mon, 3 Jun 2019 12:43:38 +0200 Subject: [PATCH] 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 --- scripts/west_commands/build_helpers.py | 15 +++++++++------ scripts/west_commands/run_common.py | 14 ++++++-------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/scripts/west_commands/build_helpers.py b/scripts/west_commands/build_helpers.py index 7f3b7021de5..3303bc67cbb 100644 --- a/scripts/west_commands/build_helpers.py +++ b/scripts/west_commands/build_helpers.py @@ -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 diff --git a/scripts/west_commands/run_common.py b/scripts/west_commands/run_common.py index 5c4f8579f13..1b36b66cb29 100644 --- a/scripts/west_commands/run_common.py +++ b/scripts/west_commands/run_common.py @@ -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