Lines Matching refs:self

66     def __call__(self, parser, namespace, values, option_string=None):  argument
67 setattr(namespace, self.dest, values or 'always')
71 def __init__(self): argument
72 super(Build, self).__init__(
79 self.source_dir = None
82 self.build_dir = None
85 self.created_build_dir = False
88 self.run_cmake = False
95 self.cmake_cache = None
98 def _banner(self, msg): argument
99 self.inf('-- west build: ' + msg, colorize=True)
101 def do_add_parser(self, parser_adder): argument
103 self.name,
104 help=self.help,
106 description=self.description,
118 self.add_force_arg(parser)
189 def do_run(self, args, remainder): argument
190 self.args = args # Avoid having to pass them around
191 self.config_board = config_get('board', None)
192 self.dbg('args: {} remainder: {}'.format(args, remainder),
195 source_dir = self.args.source_dir
196 self._parse_remainder(remainder)
198 if self.args.test_item:
200 item = os.path.basename(self.args.test_item)
201 if self.args.source_dir:
202 test_path = self.args.source_dir
204 test_path = os.path.dirname(self.args.test_item)
206 self.args.source_dir = test_path
207 if not self._parse_test_item(item):
208 self.die("No test metadata found")
210 self.die("test item path does not exist")
213 if self.args.source_dir:
214 self.die("source directory specified twice:({} and {})".format(
215 source_dir, self.args.source_dir))
216 self.args.source_dir = source_dir
217 self.dbg('source_dir: {} cmake_opts: {}'.format(self.args.source_dir,
218 self.args.cmake_opts),
220 self._sanity_precheck()
221 self._setup_build_dir()
229 self.wrn(
233 self.auto_pristine = pristine == 'auto'
235 self.dbg('pristine: {} auto_pristine: {}'.format(pristine,
236 self.auto_pristine),
238 if is_zephyr_build(self.build_dir):
240 self._run_pristine()
241 self.run_cmake = True
243 self._update_cache()
244 if (self.args.cmake or self.args.cmake_opts or
245 self.args.cmake_only or self.args.snippets or
246 self.args.shields or self.args.extra_conf_files or
247 self.args.extra_dtc_overlay_files):
248 self.run_cmake = True
250 self.run_cmake = True
252 self.source_dir = self._find_source_dir()
253 self._sanity_check()
255 build_info_path = self.build_dir
257 west_workspace = west_topdir(self.source_dir)
268 self.wrn(f'Failed to create info file: {build_info_file},', e)
270 board, origin = self._find_board()
271 self._run_cmake(board, origin, self.args.cmake_opts)
275 self._sanity_check()
276 self._update_cache()
277 self.domains = load_domains(self.build_dir)
279 self._run_build(args.target, args.domain)
281 def _find_board(self): argument
283 if self.cmake_cache:
284 board, origin = (self.cmake_cache.get('CACHED_BOARD'),
292 if self.args.board:
293 board, origin = self.args.board, 'command line'
296 elif self.config_board is not None:
297 board, origin = self.config_board, 'configfile'
300 def _parse_remainder(self, remainder): argument
301 self.args.source_dir = None
302 self.args.cmake_opts = None
307 self.args.source_dir = remainder[0]
314 self.args.cmake_opts = remainder
318 def _parse_test_item(self, test_item): argument
321 yf = os.path.join(self.args.source_dir, yp)
329 self.die(exc)
333 self.die(f"No tests found in {yf}")
335 self.die(f"Test item {test_item} not found in {yf}")
371 self.wrn('"west build" does not support '
396 if self.args.cmake_opts:
397 self.args.cmake_opts.extend(args)
399 self.args.cmake_opts = args
401 self.args.sysbuild = sysbuild
420 if self.args.cmake_opts:
421 self.args.cmake_opts.extend(args_expanded)
423 self.args.cmake_opts = args_expanded
427 def _sanity_precheck(self): argument
428 app = self.args.source_dir
430 self.check_force(
433 self.check_force(
437 def _update_cache(self): argument
439 self.cmake_cache = CMakeCache.from_build_dir(self.build_dir)
443 def _setup_build_dir(self): argument
446 self.dbg('setting up build directory', level=Verbosity.DBG_EXTREME)
448 board, _ = self._find_board()
449 source_dir = self._find_source_dir()
451 build_dir = find_build_dir(self.args.build_dir, board=board,
454 self.die('Unable to determine a default build folder. Check '
459 self.die('build directory {} exists and is not a directory'.
463 self.created_build_dir = True
464 self.run_cmake = True
466 self.build_dir = build_dir
468 def _find_source_dir(self): argument
472 self.dbg('setting up source directory', level=Verbosity.DBG_EXTREME)
473 if self.args.source_dir:
474 source_dir = self.args.source_dir
475 elif self.cmake_cache:
476 source_dir = self.cmake_cache.get('APP_DIR')
479 source_dir = self.cmake_cache.get('APPLICATION_SOURCE_DIR')
482 source_dir = self.cmake_cache.get('CMAKE_HOME_DIRECTORY')
487 self.die('build directory', self.build_dir,
494 def _sanity_check_source_dir(self): argument
495 if self.source_dir == self.build_dir:
497 self.die('source and build directory {} cannot be the same; '
499 format(self.source_dir, self.build_dir))
501 srcrel = os.path.relpath(self.source_dir)
502 self.check_force(
503 not is_zephyr_build(self.source_dir),
507 self.check_force(
508 'CMakeLists.txt' in os.listdir(self.source_dir),
515 def _sanity_check(self): argument
518 self.dbg('sanity checking the build', level=Verbosity.DBG_EXTREME)
519 self._sanity_check_source_dir()
521 if not self.cmake_cache:
524 if "CMAKE_PROJECT_NAME" not in self.cmake_cache:
528 self.run_cmake = True
530 cached_proj = self.cmake_cache.get('APPLICATION_SOURCE_DIR')
531 cached_app = self.cmake_cache.get('APP_DIR')
537 self.dbg('APP_DIR:', cached_app, level=Verbosity.DBG_EXTREME)
538 source_abs = (os.path.abspath(self.args.source_dir)
539 if self.args.source_dir else None)
542 self.dbg('pristine:', self.auto_pristine, level=Verbosity.DBG_EXTREME)
549 self.check_force(
550 not apps_mismatched or self.auto_pristine,
554 format(self.build_dir, cached_abs, source_abs))
557 self.run_cmake = True # If they insist, we need to re-run cmake.
561 cached_board = self.cmake_cache.get('CACHED_BOARD')
562 self.dbg('CACHED_BOARD:', cached_board, level=Verbosity.DBG_EXTREME)
566 self.check_force((cached_board and
567 not (apps_mismatched and self.auto_pristine))
568 or self.args.board or self.config_board or
576 boards_mismatched = (self.args.board and cached_board and
577 self.args.board != cached_board)
578 self.check_force(
579 not boards_mismatched or self.auto_pristine,
583 format(self.build_dir, cached_board, self.args.board))
585 if self.auto_pristine and (apps_mismatched or boards_mismatched):
586 self._run_pristine()
587 self.cmake_cache = None
588 self.dbg('run_cmake:', True, level=Verbosity.DBG_EXTREME)
589 self.run_cmake = True
596 self.source_dir = self._find_source_dir()
597 self._sanity_check_source_dir()
599 def _run_cmake(self, board, origin, cmake_opts): argument
601 self.wrn('This looks like a fresh build and BOARD is unknown;',
604 self.inf('Note: to silence the above message, run',
607 if not self.run_cmake:
610 self._banner('generating a build system')
616 if self.args.cmake_opts:
617 cmake_opts.extend(self.args.cmake_opts)
618 if self.args.snippets:
620 if self.args.shields:
622 if self.args.extra_conf_files:
624 if self.args.extra_dtc_overlay_files:
635 if self.args.sysbuild or (config_sysbuild and not self.args.no_sysbuild):
637 '-DAPP_DIR:PATH={}'.format(self.source_dir)])
640 cmake_opts.extend(['-S{}'.format(self.source_dir)])
649 '-B{}'.format(self.build_dir),
654 run_cmake(final_cmake_args, dry_run=self.args.dry_run)
656 def _run_pristine(self): argument
657 self._banner('making build dir {} pristine'.format(self.build_dir))
658 if not is_zephyr_build(self.build_dir):
659 self.die('Refusing to run pristine on a folder that is not a '
662 cache = CMakeCache.from_build_dir(self.build_dir)
670 run_cmake(cmake_args, cwd=self.build_dir, dry_run=self.args.dry_run)
672 def _run_build(self, target, domain): argument
674 self._banner('running target {}'.format(target))
675 elif self.run_cmake:
676 self._banner('building application')
678 if self.args.build_opt:
680 extra_args.extend(self.args.build_opt)
681 if self.args.verbose:
682 self._append_verbose_args(extra_args,
683 not bool(self.args.build_opt))
685 domains = load_domains(self.build_dir)
693 self._banner('building domain(s): {}'.format(' '.join(domain)))
700 dry_run=self.args.dry_run)
702 def _append_verbose_args(self, extra_args, add_dashes): argument
706 self._update_cache()
707 if not self.cmake_cache:
709 generator = self.cmake_cache.get('CMAKE_GENERATOR')