99import sys
1010import yaml
1111
12- from west import log
12+ from west . commands import Verbosity
1313from west .configuration import config
1414from west .util import west_topdir
1515from west .version import __version__
5555--pristine=always. Setting --pristine=auto uses heuristics to
5656guess if a pristine build may be necessary."""
5757
58- def _banner (msg ):
59- log .inf ('-- west build: ' + msg , colorize = True )
60-
6158def config_get (option , fallback ):
6259 return config .get ('build' , option , fallback = fallback )
6360
@@ -98,6 +95,9 @@ def __init__(self):
9895 self .cmake_cache = None
9996 '''Final parsed CMake cache for the build, or None on error.'''
10097
98+ def _banner (self , msg ):
99+ self .inf ('-- west build: ' + msg , colorize = True )
100+
101101 def do_add_parser (self , parser_adder ):
102102 parser = parser_adder .add_parser (
103103 self .name ,
@@ -189,8 +189,8 @@ def do_add_parser(self, parser_adder):
189189 def do_run (self , args , remainder ):
190190 self .args = args # Avoid having to pass them around
191191 self .config_board = config_get ('board' , None )
192- log .dbg ('args: {} remainder: {}' .format (args , remainder ),
193- level = log . VERBOSE_EXTREME )
192+ self .dbg ('args: {} remainder: {}' .format (args , remainder ),
193+ level = Verbosity . DBG_EXTREME )
194194 # Store legacy -s option locally
195195 source_dir = self .args .source_dir
196196 self ._parse_remainder (remainder )
@@ -205,18 +205,18 @@ def do_run(self, args, remainder):
205205 if test_path and os .path .exists (test_path ):
206206 self .args .source_dir = test_path
207207 if not self ._parse_test_item (item ):
208- log .die ("No test metadata found" )
208+ self .die ("No test metadata found" )
209209 else :
210- log .die ("test item path does not exist" )
210+ self .die ("test item path does not exist" )
211211
212212 if source_dir :
213213 if self .args .source_dir :
214- log .die ("source directory specified twice:({} and {})" .format (
214+ self .die ("source directory specified twice:({} and {})" .format (
215215 source_dir , self .args .source_dir ))
216216 self .args .source_dir = source_dir
217- log .dbg ('source_dir: {} cmake_opts: {}' .format (self .args .source_dir ,
217+ self .dbg ('source_dir: {} cmake_opts: {}' .format (self .args .source_dir ,
218218 self .args .cmake_opts ),
219- level = log . VERBOSE_EXTREME )
219+ level = Verbosity . DBG_EXTREME )
220220 self ._sanity_precheck ()
221221 self ._setup_build_dir ()
222222
@@ -226,15 +226,15 @@ def do_run(self, args, remainder):
226226 # Load the pristine={auto, always, never} configuration value
227227 pristine = config_get ('pristine' , 'never' )
228228 if pristine not in ['auto' , 'always' , 'never' ]:
229- log .wrn (
229+ self .wrn (
230230 'treating unknown build.pristine value "{}" as "never"' .
231231 format (pristine ))
232232 pristine = 'never'
233233 self .auto_pristine = pristine == 'auto'
234234
235- log .dbg ('pristine: {} auto_pristine: {}' .format (pristine ,
235+ self .dbg ('pristine: {} auto_pristine: {}' .format (pristine ,
236236 self .auto_pristine ),
237- level = log . VERBOSE_VERY )
237+ level = Verbosity . DBG_MORE )
238238 if is_zephyr_build (self .build_dir ):
239239 if pristine == 'always' :
240240 self ._run_pristine ()
@@ -326,13 +326,13 @@ def _parse_test_item(self, test_item):
326326 try :
327327 y = yaml .safe_load (stream )
328328 except yaml .YAMLError as exc :
329- log .die (exc )
329+ self .die (exc )
330330 common = y .get ('common' )
331331 tests = y .get ('tests' )
332332 if not tests :
333- log .die (f"No tests found in { yf } " )
333+ self .die (f"No tests found in { yf } " )
334334 if test_item not in tests :
335- log .die (f"Test item { test_item } not found in { yf } " )
335+ self .die (f"Test item { test_item } not found in { yf } " )
336336 item = tests .get (test_item )
337337
338338 sysbuild = False
@@ -431,20 +431,20 @@ def _update_cache(self):
431431 def _setup_build_dir (self ):
432432 # Initialize build_dir and created_build_dir attributes.
433433 # If we created the build directory, we must run CMake.
434- log .dbg ('setting up build directory' , level = log . VERBOSE_EXTREME )
434+ self .dbg ('setting up build directory' , level = Verbosity . DBG_EXTREME )
435435 # The CMake Cache has not been loaded yet, so this is safe
436436 board , _ = self ._find_board ()
437437 source_dir = self ._find_source_dir ()
438438 app = os .path .split (source_dir )[1 ]
439439 build_dir = find_build_dir (self .args .build_dir , board = board ,
440440 source_dir = source_dir , app = app )
441441 if not build_dir :
442- log .die ('Unable to determine a default build folder. Check '
442+ self .die ('Unable to determine a default build folder. Check '
443443 'your build.dir-fmt configuration option' )
444444
445445 if os .path .exists (build_dir ):
446446 if not os .path .isdir (build_dir ):
447- log .die ('build directory {} exists and is not a directory' .
447+ self .die ('build directory {} exists and is not a directory' .
448448 format (build_dir ))
449449 else :
450450 os .makedirs (build_dir , exist_ok = False )
@@ -457,7 +457,7 @@ def _find_source_dir(self):
457457 # Initialize source_dir attribute, either from command line argument,
458458 # implicitly from the build directory's CMake cache, or using the
459459 # default (current working directory).
460- log .dbg ('setting up source directory' , level = log . VERBOSE_EXTREME )
460+ self .dbg ('setting up source directory' , level = Verbosity . DBG_EXTREME )
461461 if self .args .source_dir :
462462 source_dir = self .args .source_dir
463463 elif self .cmake_cache :
@@ -472,7 +472,7 @@ def _find_source_dir(self):
472472 if not source_dir :
473473 # This really ought to be there. The build directory
474474 # must be corrupted somehow. Let's see what we can do.
475- log .die ('build directory' , self .build_dir ,
475+ self .die ('build directory' , self .build_dir ,
476476 'CMake cache has no CMAKE_HOME_DIRECTORY;' ,
477477 'please give a source_dir' )
478478 else :
@@ -482,7 +482,7 @@ def _find_source_dir(self):
482482 def _sanity_check_source_dir (self ):
483483 if self .source_dir == self .build_dir :
484484 # There's no forcing this.
485- log .die ('source and build directory {} cannot be the same; '
485+ self .die ('source and build directory {} cannot be the same; '
486486 'use --build-dir {} to specify a build directory' .
487487 format (self .source_dir , self .build_dir ))
488488
@@ -503,7 +503,7 @@ def _sanity_check_source_dir(self):
503503 def _sanity_check (self ):
504504 # Sanity check the build configuration.
505505 # Side effect: may update cmake_cache attribute.
506- log .dbg ('sanity checking the build' , level = log . VERBOSE_EXTREME )
506+ self .dbg ('sanity checking the build' , level = Verbosity . DBG_EXTREME )
507507 self ._sanity_check_source_dir ()
508508
509509 if not self .cmake_cache :
@@ -522,12 +522,12 @@ def _sanity_check(self):
522522 if cached_app is None and cached_proj :
523523 cached_app = cached_proj
524524
525- log .dbg ('APP_DIR:' , cached_app , level = log . VERBOSE_EXTREME )
525+ self .dbg ('APP_DIR:' , cached_app , level = Verbosity . DBG_EXTREME )
526526 source_abs = (os .path .abspath (self .args .source_dir )
527527 if self .args .source_dir else None )
528528 cached_abs = os .path .abspath (cached_app ) if cached_app else None
529529
530- log .dbg ('pristine:' , self .auto_pristine , level = log . VERBOSE_EXTREME )
530+ self .dbg ('pristine:' , self .auto_pristine , level = Verbosity . DBG_EXTREME )
531531
532532 # If the build directory specifies a source app, make sure it's
533533 # consistent with --source-dir.
@@ -547,7 +547,7 @@ def _sanity_check(self):
547547 # If CACHED_BOARD is not defined, we need some other way to
548548 # find the board.
549549 cached_board = self .cmake_cache .get ('CACHED_BOARD' )
550- log .dbg ('CACHED_BOARD:' , cached_board , level = log . VERBOSE_EXTREME )
550+ self .dbg ('CACHED_BOARD:' , cached_board , level = Verbosity . DBG_EXTREME )
551551 # If apps_mismatched and self.auto_pristine are true, we will
552552 # run pristine on the build, invalidating the cached
553553 # board. In that case, we need some way of getting the board.
@@ -573,7 +573,7 @@ def _sanity_check(self):
573573 if self .auto_pristine and (apps_mismatched or boards_mismatched ):
574574 self ._run_pristine ()
575575 self .cmake_cache = None
576- log .dbg ('run_cmake:' , True , level = log . VERBOSE_EXTREME )
576+ self .dbg ('run_cmake:' , True , level = Verbosity . DBG_EXTREME )
577577 self .run_cmake = True
578578
579579 # Tricky corner-case: The user has not specified a build folder but
@@ -586,16 +586,16 @@ def _sanity_check(self):
586586
587587 def _run_cmake (self , board , origin , cmake_opts ):
588588 if board is None and config_getboolean ('board_warn' , True ):
589- log .wrn ('This looks like a fresh build and BOARD is unknown;' ,
589+ self .wrn ('This looks like a fresh build and BOARD is unknown;' ,
590590 "so it probably won't work. To fix, use" ,
591591 '--board=<your-board>.' )
592- log .inf ('Note: to silence the above message, run' ,
592+ self .inf ('Note: to silence the above message, run' ,
593593 "'west config build.board_warn false'" )
594594
595595 if not self .run_cmake :
596596 return
597597
598- _banner ('generating a build system' )
598+ self . _banner ('generating a build system' )
599599
600600 if board is not None and origin != 'CMakeCache.txt' :
601601 cmake_opts = ['-DBOARD={}' .format (board )]
@@ -642,10 +642,10 @@ def _run_cmake(self, board, origin, cmake_opts):
642642 run_cmake (final_cmake_args , dry_run = self .args .dry_run )
643643
644644 def _run_pristine (self ):
645- _banner ('making build dir {} pristine' .format (self .build_dir ))
645+ self . _banner ('making build dir {} pristine' .format (self .build_dir ))
646646 if not is_zephyr_build (self .build_dir ):
647- log .die ('Refusing to run pristine on a folder that is not a '
648- 'Zephyr build system' )
647+ self .die ('Refusing to run pristine on a folder that is not a '
648+ 'Zephyr build system' )
649649
650650 cache = CMakeCache .from_build_dir (self .build_dir )
651651
@@ -659,9 +659,9 @@ def _run_pristine(self):
659659
660660 def _run_build (self , target , domain ):
661661 if target :
662- _banner ('running target {}' .format (target ))
662+ self . _banner ('running target {}' .format (target ))
663663 elif self .run_cmake :
664- _banner ('building application' )
664+ self . _banner ('building application' )
665665 extra_args = ['--target' , target ] if target else []
666666 if self .args .build_opt :
667667 extra_args .append ('--' )
@@ -678,7 +678,7 @@ def _run_build(self, target, domain):
678678 # will build all domains.
679679 build_dir_list = [domains .get_top_build_dir ()]
680680 else :
681- _banner ('building domain(s): {}' .format (' ' .join (domain )))
681+ self . _banner ('building domain(s): {}' .format (' ' .join (domain )))
682682 domain_list = domains .get_domains (domain )
683683 for d in domain_list :
684684 build_dir_list .append (d .build_dir )
0 commit comments