Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions scripts/west_commands/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def do_run(self, args, remainder):

self.dbg(f'pristine: {pristine} auto_pristine: {self.auto_pristine}',
level=Verbosity.DBG_MORE)
if is_zephyr_build(self.build_dir):
if is_zephyr_build(self, self.build_dir):
if pristine == 'always':
self._run_pristine()
self.run_cmake = True
Expand Down Expand Up @@ -464,7 +464,7 @@ def _setup_build_dir(self):
board, _ = self._find_board()
source_dir = self._find_source_dir()
app = os.path.split(source_dir)[1]
build_dir = find_build_dir(self.args.build_dir, board=board,
build_dir = find_build_dir(self, self.args.build_dir, board=board,
source_dir=source_dir, app=app)
if not build_dir:
self.die('Unable to determine a default build folder. Check '
Expand Down Expand Up @@ -514,7 +514,7 @@ def _sanity_check_source_dir(self):

srcrel = os.path.relpath(self.source_dir)
self.check_force(
not is_zephyr_build(self.source_dir),
not is_zephyr_build(self, self.source_dir),
f'it looks like {srcrel} is a build directory: '
f'did you mean --build-dir {srcrel} instead?')
self.check_force(
Expand Down Expand Up @@ -664,11 +664,11 @@ def _run_cmake(self, board, origin, cmake_opts):
f'-G{config_get("generator", DEFAULT_CMAKE_GENERATOR)}']
if cmake_opts:
final_cmake_args.extend(cmake_opts)
run_cmake(final_cmake_args, dry_run=self.args.dry_run, env=cmake_env)
run_cmake(self, final_cmake_args, dry_run=self.args.dry_run, env=cmake_env)

def _run_pristine(self):
self._banner(f'making build dir {self.build_dir} pristine')
if not is_zephyr_build(self.build_dir):
if not is_zephyr_build(self, self.build_dir):
self.die('Refusing to run pristine on a folder that is not a '
'Zephyr build system')

Expand All @@ -680,7 +680,7 @@ def _run_pristine(self):
cmake_args = [f'-DBINARY_DIR={app_bin_dir}',
f'-DSOURCE_DIR={app_src_dir}',
'-P', cache['ZEPHYR_BASE'] + '/cmake/pristine.cmake']
run_cmake(cmake_args, cwd=self.build_dir, dry_run=self.args.dry_run)
run_cmake(self, cmake_args, cwd=self.build_dir, dry_run=self.args.dry_run)

def _run_build(self, target, domain):
if target:
Expand Down Expand Up @@ -709,7 +709,7 @@ def _run_build(self, target, domain):
build_dir_list.append(d.build_dir)

for b in build_dir_list:
run_build(b, extra_args=extra_args,
run_build(self, b, extra_args=extra_args,
dry_run=self.args.dry_run)

def _append_verbose_args(self, extra_args, add_dashes):
Expand Down
28 changes: 14 additions & 14 deletions scripts/west_commands/build_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from pathlib import Path

import zcmake
from west import log
from west.commands import Verbosity
from west.configuration import config
from west.util import escapes_directory

Expand All @@ -37,7 +37,7 @@
checked after that. If either is a Zephyr build directory, it is used.
'''

def _resolve_build_dir(fmt, guess, cwd, **kwargs):
def _resolve_build_dir(cmd, fmt, guess, cwd, **kwargs):
# Remove any None values, we do not want 'None' as a string
kwargs = {k: v for k, v in kwargs.items() if v is not None}
# Check if source_dir is below cwd first
Expand Down Expand Up @@ -78,11 +78,11 @@ def _resolve_build_dir(fmt, guess, cwd, **kwargs):
if len(dirs) != 1:
return None
curr = dirs[0]
if is_zephyr_build(str(curr)):
if is_zephyr_build(cmd, str(curr)):
return str(curr)
return str(b)

def find_build_dir(dir, guess=False, **kwargs):
def find_build_dir(cmd, dir, guess=False, **kwargs):
'''Heuristic for finding a build directory.
If `dir` is specified, this directory is returned as the build directory.
Otherwise, the default build directory is determined according to the
Expand All @@ -99,20 +99,20 @@ def find_build_dir(dir, guess=False, **kwargs):
cwd = os.getcwd()
dir_fmt = config.get('build', 'dir-fmt', fallback=None)
if dir_fmt:
log.dbg(f'config dir-fmt: {dir_fmt}', level=log.VERBOSE_EXTREME)
dir_fmt = _resolve_build_dir(dir_fmt, guess, cwd, **kwargs)
if not build_dir and is_zephyr_build(dir_fmt):
cmd.dbg(f'config dir-fmt: {dir_fmt}', level=Verbosity.DBG_EXTREME)
dir_fmt = _resolve_build_dir(cmd, dir_fmt, guess, cwd, **kwargs)
if not build_dir and is_zephyr_build(cmd, dir_fmt):
build_dir = dir_fmt
if not build_dir and is_zephyr_build(cwd):
if not build_dir and is_zephyr_build(cmd, cwd):
build_dir = cwd
if not build_dir and dir_fmt:
build_dir = dir_fmt
if not build_dir:
build_dir = DEFAULT_BUILD_DIR
log.dbg(f'build dir: {build_dir}', level=log.VERBOSE_EXTREME)
cmd.dbg(f'build dir: {build_dir}', level=Verbosity.DBG_EXTREME)
return os.path.abspath(build_dir)

def is_zephyr_build(path):
def is_zephyr_build(cmd, path):
'''Return true if and only if `path` appears to be a valid Zephyr
build directory.

Expand All @@ -135,12 +135,12 @@ def is_zephyr_build(path):
cache = {}

if 'ZEPHYR_BASE' in cache or 'ZEPHYR_TOOLCHAIN_VARIANT' in cache:
log.dbg(f'{path} is a zephyr build directory',
level=log.VERBOSE_EXTREME)
cmd.dbg(f'{path} is a zephyr build directory',
level=Verbosity.DBG_EXTREME)
return True

log.dbg(f'{path} is NOT a valid zephyr build directory',
level=log.VERBOSE_EXTREME)
cmd.dbg(f'{path} is NOT a valid zephyr build directory',
level=Verbosity.DBG_EXTREME)
return False


Expand Down
2 changes: 1 addition & 1 deletion scripts/west_commands/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def run_cmake_export(self, path):
# CMake status messages and instead only prints the important
# information.

lines = run_cmake(['-P', str(path / 'zephyr_export.cmake')],
lines = run_cmake(self, ['-P', str(path / 'zephyr_export.cmake')],
capture_output=True)
msg = [line for line in lines if not line.startswith('-- ')]
self.inf('\n'.join(msg))
2 changes: 1 addition & 1 deletion scripts/west_commands/flash.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ def do_add_parser(self, parser_adder):
return add_parser_common(self, parser_adder)

def do_run(self, my_args, runner_args):
build_dir = get_build_dir(my_args)
build_dir = get_build_dir(self, my_args)
domains_file = Path(build_dir) / 'domains.yaml'
do_run_common(self, my_args, runner_args, domain_file=domains_file)
Loading
Loading