Skip to content

Commit

Permalink
scripts: west_commands: build: Remove deprecated west.log
Browse files Browse the repository at this point in the history
The global state west.log is deprecated, replace with WestCommand
logging.

Signed-off-by: Pieter De Gendt <[email protected]>
  • Loading branch information
pdgendt committed Oct 1, 2024
1 parent a6ed05e commit fa08a30
Showing 1 changed file with 37 additions and 37 deletions.
74 changes: 37 additions & 37 deletions scripts/west_commands/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import sys
import yaml

from west import log
from west.commands import Verbosity
from west.configuration import config
from zcmake import DEFAULT_CMAKE_GENERATOR, run_cmake, run_build, CMakeCache
from build_helpers import is_zephyr_build, find_build_dir, load_domains, \
Expand Down Expand Up @@ -51,9 +51,6 @@
--pristine=always. Setting --pristine=auto uses heuristics to
guess if a pristine build may be necessary."""

def _banner(msg):
log.inf('-- west build: ' + msg, colorize=True)

def config_get(option, fallback):
return config.get('build', option, fallback=fallback)

Expand Down Expand Up @@ -94,6 +91,9 @@ def __init__(self):
self.cmake_cache = None
'''Final parsed CMake cache for the build, or None on error.'''

def _banner(self, msg):
self.inf('-- west build: ' + msg, colorize=True)

def do_add_parser(self, parser_adder):
parser = parser_adder.add_parser(
self.name,
Expand Down Expand Up @@ -185,8 +185,8 @@ 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),
level=log.VERBOSE_EXTREME)
self.dbg('args: {} remainder: {}'.format(args, remainder),
level=Verbosity.DBG_EXTREME)
# Store legacy -s option locally
source_dir = self.args.source_dir
self._parse_remainder(remainder)
Expand All @@ -201,18 +201,18 @@ def do_run(self, args, remainder):
if test_path and os.path.exists(test_path):
self.args.source_dir = test_path
if not self._parse_test_item(item):
log.die("No test metadata found")
self.die("No test metadata found")
else:
log.die("test item path does not exist")
self.die("test item path does not exist")

if source_dir:
if self.args.source_dir:
log.die("source directory specified twice:({} and {})".format(
self.die("source directory specified twice:({} and {})".format(
source_dir, self.args.source_dir))
self.args.source_dir = source_dir
log.dbg('source_dir: {} cmake_opts: {}'.format(self.args.source_dir,
self.dbg('source_dir: {} cmake_opts: {}'.format(self.args.source_dir,
self.args.cmake_opts),
level=log.VERBOSE_EXTREME)
level=Verbosity.DBG_EXTREME)
self._sanity_precheck()
self._setup_build_dir()

Expand All @@ -222,15 +222,15 @@ def do_run(self, args, remainder):
# Load the pristine={auto, always, never} configuration value
pristine = config_get('pristine', 'never')
if pristine not in ['auto', 'always', 'never']:
log.wrn(
self.wrn(
'treating unknown build.pristine value "{}" as "never"'.
format(pristine))
pristine = 'never'
self.auto_pristine = pristine == 'auto'

log.dbg('pristine: {} auto_pristine: {}'.format(pristine,
self.dbg('pristine: {} auto_pristine: {}'.format(pristine,
self.auto_pristine),
level=log.VERBOSE_VERY)
level=Verbosity.DBG_MORE)
if is_zephyr_build(self.build_dir):
if pristine == 'always':
self._run_pristine()
Expand Down Expand Up @@ -306,13 +306,13 @@ def _parse_test_item(self, test_item):
try:
y = yaml.safe_load(stream)
except yaml.YAMLError as exc:
log.die(exc)
self.die(exc)
common = y.get('common')
tests = y.get('tests')
if not tests:
log.die(f"No tests found in {yf}")
self.die(f"No tests found in {yf}")
if test_item not in tests:
log.die(f"Test item {test_item} not found in {yf}")
self.die(f"Test item {test_item} not found in {yf}")
item = tests.get(test_item)

sysbuild = False
Expand Down Expand Up @@ -411,20 +411,20 @@ def _update_cache(self):
def _setup_build_dir(self):
# Initialize build_dir and created_build_dir attributes.
# If we created the build directory, we must run CMake.
log.dbg('setting up build directory', level=log.VERBOSE_EXTREME)
self.dbg('setting up build directory', level=Verbosity.DBG_EXTREME)
# The CMake Cache has not been loaded yet, so this is safe
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,
source_dir=source_dir, app=app)
if not build_dir:
log.die('Unable to determine a default build folder. Check '
self.die('Unable to determine a default build folder. Check '
'your build.dir-fmt configuration option')

if os.path.exists(build_dir):
if not os.path.isdir(build_dir):
log.die('build directory {} exists and is not a directory'.
self.die('build directory {} exists and is not a directory'.
format(build_dir))
else:
os.makedirs(build_dir, exist_ok=False)
Expand All @@ -437,7 +437,7 @@ def _find_source_dir(self):
# Initialize source_dir attribute, either from command line argument,
# implicitly from the build directory's CMake cache, or using the
# default (current working directory).
log.dbg('setting up source directory', level=log.VERBOSE_EXTREME)
self.dbg('setting up source directory', level=Verbosity.DBG_EXTREME)
if self.args.source_dir:
source_dir = self.args.source_dir
elif self.cmake_cache:
Expand All @@ -452,7 +452,7 @@ def _find_source_dir(self):
if not source_dir:
# This really ought to be there. The build directory
# must be corrupted somehow. Let's see what we can do.
log.die('build directory', self.build_dir,
self.die('build directory', self.build_dir,
'CMake cache has no CMAKE_HOME_DIRECTORY;',
'please give a source_dir')
else:
Expand All @@ -462,7 +462,7 @@ def _find_source_dir(self):
def _sanity_check_source_dir(self):
if self.source_dir == self.build_dir:
# There's no forcing this.
log.die('source and build directory {} cannot be the same; '
self.die('source and build directory {} cannot be the same; '
'use --build-dir {} to specify a build directory'.
format(self.source_dir, self.build_dir))

Expand All @@ -483,7 +483,7 @@ def _sanity_check_source_dir(self):
def _sanity_check(self):
# Sanity check the build configuration.
# Side effect: may update cmake_cache attribute.
log.dbg('sanity checking the build', level=log.VERBOSE_EXTREME)
self.dbg('sanity checking the build', level=Verbosity.DBG_EXTREME)
self._sanity_check_source_dir()

if not self.cmake_cache:
Expand All @@ -502,12 +502,12 @@ def _sanity_check(self):
if cached_app is None and cached_proj:
cached_app = cached_proj

log.dbg('APP_DIR:', cached_app, level=log.VERBOSE_EXTREME)
self.dbg('APP_DIR:', cached_app, level=Verbosity.DBG_EXTREME)
source_abs = (os.path.abspath(self.args.source_dir)
if self.args.source_dir else None)
cached_abs = os.path.abspath(cached_app) if cached_app else None

log.dbg('pristine:', self.auto_pristine, level=log.VERBOSE_EXTREME)
self.dbg('pristine:', self.auto_pristine, level=Verbosity.DBG_EXTREME)

# If the build directory specifies a source app, make sure it's
# consistent with --source-dir.
Expand All @@ -527,7 +527,7 @@ def _sanity_check(self):
# 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)
self.dbg('CACHED_BOARD:', cached_board, level=Verbosity.DBG_EXTREME)
# 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.
Expand All @@ -553,7 +553,7 @@ def _sanity_check(self):
if self.auto_pristine and (apps_mismatched or boards_mismatched):
self._run_pristine()
self.cmake_cache = None
log.dbg('run_cmake:', True, level=log.VERBOSE_EXTREME)
self.dbg('run_cmake:', True, level=Verbosity.DBG_EXTREME)
self.run_cmake = True

# Tricky corner-case: The user has not specified a build folder but
Expand All @@ -566,16 +566,16 @@ def _sanity_check(self):

def _run_cmake(self, board, origin, cmake_opts):
if board is None and config_getboolean('board_warn', True):
log.wrn('This looks like a fresh build and BOARD is unknown;',
self.wrn('This looks like a fresh build and BOARD is unknown;',
"so it probably won't work. To fix, use",
'--board=<your-board>.')
log.inf('Note: to silence the above message, run',
self.inf('Note: to silence the above message, run',
"'west config build.board_warn false'")

if not self.run_cmake:
return

_banner('generating a build system')
self._banner('generating a build system')

if board is not None and origin != 'CMakeCache.txt':
cmake_opts = ['-DBOARD={}'.format(board)]
Expand Down Expand Up @@ -622,10 +622,10 @@ def _run_cmake(self, board, origin, cmake_opts):
run_cmake(final_cmake_args, dry_run=self.args.dry_run)

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

cache = CMakeCache.from_build_dir(self.build_dir)

Expand All @@ -639,9 +639,9 @@ def _run_pristine(self):

def _run_build(self, target, domain):
if target:
_banner('running target {}'.format(target))
self._banner('running target {}'.format(target))
elif self.run_cmake:
_banner('building application')
self._banner('building application')
extra_args = ['--target', target] if target else []
if self.args.build_opt:
extra_args.append('--')
Expand All @@ -658,7 +658,7 @@ def _run_build(self, target, domain):
# will build all domains.
build_dir_list = [domains.get_top_build_dir()]
else:
_banner('building domain(s): {}'.format(' '.join(domain)))
self._banner('building domain(s): {}'.format(' '.join(domain)))
domain_list = domains.get_domains(domain)
for d in domain_list:
build_dir_list.append(d.build_dir)
Expand Down

0 comments on commit fa08a30

Please sign in to comment.