def _run_pristine(self): log.inf('Making build dir {} pristine'.format(self.build_dir)) zb = os.environ.get('ZEPHYR_BASE') if not zb: log.die('Internal error: ZEPHYR_BASE not set in the environment, ' 'and should have been by the main script') if not is_zephyr_build(self.build_dir): log.die( 'Refusing to run pristine on a folder that is not a Zephyr ' 'build system') cmake_args = ['-P', '{}/cmake/pristine.cmake'.format(zb)] run_cmake(cmake_args, cwd=self.build_dir)
def _run_cmake(self, cmake_opts): if not self.run_cmake: log.dbg('not running cmake; build system is present') return # Invoke CMake from the current working directory using the # -S and -B options (officially introduced in CMake 3.13.0). # This is important because users expect invocations like this # to Just Work: # # west build -- -DOVERLAY_CONFIG=relative-path.conf final_cmake_args = [ '-B{}'.format(self.build_dir), '-S{}'.format(self.source_dir), '-G{}'.format(DEFAULT_CMAKE_GENERATOR) ] if self.args.board: final_cmake_args.append('-DBOARD={}'.format(self.args.board)) if cmake_opts: final_cmake_args.extend(cmake_opts) run_cmake(final_cmake_args)
def _run_cmake(self, cmake_opts): if not self.run_cmake: log.dbg('not running cmake; build system is present') return # It's unfortunate to have to use the undocumented -B and -H # options to set the source and binary directories. # # However, it's the only known way to set that directory and # run CMake from the current working directory. This is # important because users expect invocations like this to Just # Work: # # west build -- -DOVERLAY_CONFIG=relative-path.conf final_cmake_args = [ '-B{}'.format(self.build_dir), '-H{}'.format(self.source_dir), '-G{}'.format(DEFAULT_CMAKE_GENERATOR) ] if self.args.board: final_cmake_args.append('-DBOARD={}'.format(self.args.board)) if cmake_opts: final_cmake_args.extend(cmake_opts) cmake.run_cmake(final_cmake_args)
def test_tools_validation(): """ Test the validation step for the python tools. This is done by setting PYTHON_HOME to "" and then checking to ensure that the build fails, and the validation message is printed. """ old_home = os.environ.get("PYTHONHOME", "") old_path = os.environ.get("PATH", "") old_ppath = os.environ.get("PYTHONPATH", "") owd = os.getcwd() tmpd = tempfile.mkdtemp() try: os.chdir(tmpd) python_dir = distutils.spawn.find_executable("python").replace( "/python", "") with pytest.raises(AssertionError): for byekey in ["PYTHONHOME", "PYTHONPATH", "VIRTUALENV"]: try: del os.environ[byekey] except KeyError: pass os.environ["PATH"] = os.environ.get("PATH", "").replace( python_dir + ":", "").replace(":" + python_dir, "") ret, stdout, stderr = cmake.run_cmake(os.path.join( os.path.dirname(__file__), "..", "..", "..", "Ref"), capout=True) print(stdout.decode("utf-8"), file=sys.stdout) print(stderr.decode("utf-8"), file=sys.stderr) all_out = "".join([stdout.decode("utf-8"), stderr.decode("utf-8")]) assert ret, "Assert that the CMake run has failed" ex_texts = [ " [VALIDATION] Validation failed for:\n python3;", "cmake/support/validation/pipsetup.py" ] for ex_text in ex_texts: assert ex_text in all_out, "Failed to find tool check error" finally: os.chdir(owd) shutil.rmtree(tmpd) os.environ["PATH"] = old_path os.environ["PYTHONHOME"] = old_home os.environ["PYTHONPATH"] = old_ppath
def do_run(self, args, unknown_args): zb = os.environ.get('ZEPHYR_BASE') if not zb: log.die('Internal error: ZEPHYR_BASE not set in the environment, ' 'and should have been by the main script') cmake_args = [ '-DBOARD_ROOT_SPACE_SEPARATED={}'.format(zb), '-P', '{}/cmake/boards.cmake'.format(zb) ] lines = run_cmake(cmake_args, capture_output=True) arch_re = re.compile(r'\s*([\w-]+)\:') board_re = re.compile(r'\s*([\w-]+)\s*') arch = None boards = collections.OrderedDict() for line in lines: match = arch_re.match(line) if match: arch = match.group(1) boards[arch] = [] continue match = board_re.match(line) if match: if not arch: log.die( 'Invalid board output from CMake: {}'.format(lines)) board = match.group(1) boards[arch].append(board) for arch in boards: for board in boards[arch]: try: result = args.format.format(name=board, arch=arch) print(result) except KeyError as e: # The raised KeyError seems to just put the first # invalid argument in the args tuple, regardless of # how many unrecognizable keys there were. log.die('unknown key "{}" in format string "{}"'.format( e.args[0], args.format))