|
4 | 4 |
|
5 | 5 | import argparse |
6 | 6 | import os |
| 7 | +import shutil |
| 8 | +import subprocess |
7 | 9 |
|
8 | 10 | from west import log |
9 | 11 | from west import cmake |
@@ -113,11 +115,11 @@ def do_add_parser(self, parser_adder): |
113 | 115 | 'clean', 'pristine', etc.)''') |
114 | 116 | parser.add_argument('-p', '--pristine', choices=['auto', 'always', |
115 | 117 | 'never'], action=AlwaysIfMissing, nargs='?', |
116 | | - help='''Control whether the pristine target is run |
117 | | - before building if a build system is present in the |
118 | | - build dir. --pristine is the same as |
119 | | - --pristine=always. If set to auto, the pristine |
120 | | - target will be run only if required based on the |
| 118 | + help='''Control whether the build folder is made |
| 119 | + pristine before building if a build system is |
| 120 | + present in the build dir. --pristine is the same as |
| 121 | + --pristine=always. If set to auto, the build folder |
| 122 | + will be made pristine only if required based on the |
121 | 123 | existing build system and the options provided. |
122 | 124 | This allows for reusing a build folder even if it |
123 | 125 | contains build files for a different board or |
@@ -159,8 +161,7 @@ def do_run(self, args, remainder): |
159 | 161 | self.auto_pristine)) |
160 | 162 | if is_zephyr_build(self.build_dir): |
161 | 163 | if pristine == 'always': |
162 | | - log.inf('Making build dir {} pristine'.format(self.build_dir)) |
163 | | - self._run_build('pristine') |
| 164 | + self._run_pristine() |
164 | 165 | self.run_cmake = True |
165 | 166 | else: |
166 | 167 | self._update_cache() |
@@ -338,8 +339,7 @@ def _sanity_check(self): |
338 | 339 | format(self.build_dir, cached_board, self.args.board)) |
339 | 340 |
|
340 | 341 | if self.auto_pristine and (apps_mismatched or boards_mismatched): |
341 | | - log.inf('Making build dir {} pristine'.format(self.build_dir)) |
342 | | - self._run_build('pristine') |
| 342 | + self._run_pristine() |
343 | 343 | self.cmake_cache = None |
344 | 344 | log.dbg('run_cmake:', True, level=log.VERBOSE_EXTREME) |
345 | 345 | self.run_cmake = True |
@@ -373,6 +373,26 @@ def _run_cmake(self, cmake_opts): |
373 | 373 | final_cmake_args.extend(cmake_opts) |
374 | 374 | cmake.run_cmake(final_cmake_args) |
375 | 375 |
|
| 376 | + def _run_pristine(self): |
| 377 | + log.inf('Making build dir {} pristine'.format(self.build_dir)) |
| 378 | + |
| 379 | + zb = os.environ.get('ZEPHYR_BASE') |
| 380 | + if not zb: |
| 381 | + log.die('Internal error: ZEPHYR_BASE not set in the environment, ' |
| 382 | + 'and should have been by the main script') |
| 383 | + |
| 384 | + if not is_zephyr_build(self.build_dir): |
| 385 | + log.die('Refusing to run pristine on a folder that is not a Zephyr ' |
| 386 | + 'build system') |
| 387 | + |
| 388 | + cmake_args = ['-P', '{}/cmake/pristine.cmake'.format(zb)] |
| 389 | + cmake = shutil.which('cmake') |
| 390 | + if cmake is None: |
| 391 | + log.die('CMake is not installed or cannot be found; cannot make ' |
| 392 | + 'the build folder pristine') |
| 393 | + cmd = [cmake] + cmake_args |
| 394 | + subprocess.check_call(cmd, cwd=self.build_dir) |
| 395 | + |
376 | 396 | def _run_build(self, target): |
377 | 397 | extra_args = ['--target', target] if target else [] |
378 | 398 | cmake.run_build(self.build_dir, extra_args=extra_args) |
0 commit comments