west build命令解析

2024-06-10 04:36
文章标签 build 命令 解析 west

本文主要是介绍west build命令解析,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

west build命令是zephyr工程的扩展命令,通过python文件scripts\west_commands\build.py实现编译功能。

本文主要介绍west build命令的执行过程,关于扩展命令如何关联python文件,参考添加west扩展命令-CSDN博客中的详细介绍。

为了分析west build命令的执行过程,在源码中增加了新的日志。

以hello world示例的编译命令west build -b qemu_cortex_m3 samples/hello_world为例进行说明。

1)入口函数do_run()

以下均以注释方式展示print语句的输出结果。

    def do_run(self, args, remainder):print("do_run 1 args:", args) # Namespace(help=None, zephyr_base=None, verbose=0, command='build', board='qemu_cortex_m3', source_dir=None, build_dir=None, force=False, cmake=False, cmake_only=False, domain=None, target=None, test_item=None, build_opt=[], dry_run=False, snippets=[], sysbuild=False, no_sysbuild=False, pristine=None)print("do_run 2 remainder:", remainder) # ['samples/hello_world']self.args = args        # Avoid having to pass them aroundself.config_board = config_get('board', None)print("do_run 3 self.config_board:", self.config_board) # Nonelog.dbg('args: {} remainder: {}'.format(args, remainder),level=log.VERBOSE_EXTREME)# Store legacy -s option locallysource_dir = self.args.source_dirprint("do_run 4 source_dir:", source_dir) # Noneself._parse_remainder(remainder)# Parse testcase.yaml or sample.yaml files for additional options.print("do_run 5 self.args.test_item:", self.args.test_item) # Noneif self.args.test_item:# we get path + testitemitem = os.path.basename(self.args.test_item)if self.args.source_dir:test_path = self.args.source_direlse:test_path = os.path.dirname(self.args.test_item)if test_path and os.path.exists(test_path):self.args.source_dir = test_pathif not self._parse_test_item(item):log.die("No test metadata found")else:log.die("test item path does not exist")if source_dir:if self.args.source_dir:log.die("source directory specified twice:({} and {})".format(source_dir, self.args.source_dir))self.args.source_dir = source_dirlog.dbg('source_dir: {} cmake_opts: {}'.format(self.args.source_dir,self.args.cmake_opts),level=log.VERBOSE_EXTREME)self._sanity_precheck()self._setup_build_dir()print("do_run 6 args.pristine:", args.pristine) # Noneif args.pristine is not None:pristine = args.pristineelse:# Load the pristine={auto, always, never} configuration valuepristine = config_get('pristine', 'never')print("do_run 7 pristine:", pristine) # neverif pristine not in ['auto', 'always', 'never']:log.wrn('treating unknown build.pristine value "{}" as "never"'.format(pristine))pristine = 'never'self.auto_pristine = pristine == 'auto'print("do_run 8 self.auto_pristine:", self.auto_pristine) # Falselog.dbg('pristine: {} auto_pristine: {}'.format(pristine,self.auto_pristine),level=log.VERBOSE_VERY)if is_zephyr_build(self.build_dir):if pristine == 'always':self._run_pristine()self.run_cmake = Trueelse:self._update_cache()if (self.args.cmake or self.args.cmake_opts orself.args.cmake_only or self.args.snippets):self.run_cmake = Trueelse:self.run_cmake = Trueprint("do_run 9 self.run_cmake:", self.run_cmake) # Trueself.source_dir = self._find_source_dir()print("do_run 10 self.source_dir:", self.source_dir) # C:\Users\hou\zephyrproject\zephyr\samples\hello_worldself._sanity_check()board, origin = self._find_board()print("do_run 11 board:", board) # qemu_cortex_m3print("do_run 12 origin:", origin) # command lineself._run_cmake(board, origin, self.args.cmake_opts)print("do_run 13 args.cmake_only:", args.cmake_only) # Falseif args.cmake_only:returnself._sanity_check()self._update_cache()print("do_run 14 self.build_dir:", self.build_dir) # C:\Users\hou\zephyrproject\zephyr\buildself.domains = load_domains(self.build_dir)print("do_run 15 self.domains:", self.domains) # <domains.Domains object at 0x000001C3DCACDC90>print("do_run 16 args.target:", args.target) # Noneprint("do_run 17 args.domain:", args.domain) # Noneself._run_build(args.target, args.domain)

2)_find_board()

    def _find_board(self):board, origin = None, Noneprint("_find_board 1 board:", board) # Noneprint("_find_board 2 origin:", origin) # Noneprint("_find_board 3 self.cmake_cache:", self.cmake_cache) # Noneif self.cmake_cache:board, origin = (self.cmake_cache.get('CACHED_BOARD'),'CMakeCache.txt')# A malformed CMake cache may exist, but not have a board.# This happens if there's a build error from a previous run.if board is not None:return (board, origin)print("_find_board 4 self.args.board:", self.args.board) # qemu_cortex_m3print("_find_board 5 os.environ:", os.environ) # environ({'ALLUSERSPROFILE': 'C:\\ProgramData', 'APPDATA': 'C:\\Users\\hou\\AppData\\Roaming', 'CHOCOLATEYINSTALL': 'C:\\ProgramData\\chocolatey', 'CHOCOLATEYLASTPATHUPDATE': '133592202136655120', 'COMMONPROGRAMFILES': 'C:\\Program Files\\Common Files', 'COMMONPROGRAMFILES(X86)': 'C:\\Program Files (x86)\\Common Files', 'COMMONPROGRAMW6432': 'C:\\Program Files\\Common Files', 'COMPUTERNAME': 'LAPTOP-04NNMOG1', 'COMSPEC': 'C:\\WINDOWS\\system32\\cmd.exe', 'CUDA_PATH': 'C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v8.0', 'CUDA_PATH_V8_0': 'C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v8.0', 'DRIVERDATA': 'C:\\Windows\\System32\\Drivers\\DriverData', 'HOMEDRIVE': 'C:', 'HOMEPATH': '\\Users\\hou', 'JAVA_HOME': 'C:\\Program Files\\Java\\jdk-14.0.1', 'LOCALAPPDATA': 'C:\\Users\\hou\\AppData\\Local', 'LOGONSERVER': '\\\\LAPTOP-04NNMOG1', 'NUMBER_OF_PROCESSORS': '8', 'NVCUDASAMPLES8_0_ROOT': 'C:\\ProgramData\\NVIDIA Corporation\\CUDA Samples\\v8.0', 'NVCUDASAMPLES_ROOT': 'C:\\ProgramData\\NVIDIA Corporation\\CUDA Samples\\v8.0', 'NVTOOLSEXT_PATH': 'C:\\Program Files\\NVIDIA Corporation\\NvToolsExt\\', 'ONEDRIVE': 'C:\\Users\\hou\\OneDrive', 'ONLINESERVICES': 'Online Services', 'OS': 'Windows_NT', 'PATH': 'C:\\Program Files\\qemu;C:\\Python311\\Scripts\\;C:\\Python311\\;C:\\Users\\hou\\AppData\\Local\\Programs\\Python\\Python38\\Scripts\\;C:\\Users\\hou\\AppData\\Local\\Programs\\Python\\Python38\\;C:\\ProgramData\\Anaconda3;C:\\ProgramData\\Anaconda3\\Library\\mingw-w64\\bin;C:\\ProgramData\\Anaconda3\\Library\\usr\\bin;C:\\ProgramData\\Anaconda3\\Library\\bin;C:\\ProgramData\\Anaconda3\\Scripts;C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v8.0\\bin;C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v8.0\\libnvvp;C:\\Program Files (x86)\\Intel\\iCLS Client\\;C:\\Program Files\\Intel\\iCLS Client\\;C:\\windows\\system32;C:\\windows;C:\\windows\\System32\\Wbem;C:\\windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\IPT;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\IPT;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Python27\\Scripts;C:\\Program Files\\Microsoft SQL Server\\110\\Tools\\Binn\\;C:\\Program Files (x86)\\Microsoft SDKs\\TypeScript\\1.0\\;C:\\Program Files\\Microsoft SQL Server\\120\\Tools\\Binn\\;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Program Files\\Java\\jdk-14.0.1\\bin;C:\\Program Files\\TortoiseGit\\bin;C:\\Program Files\\CMake\\bin;C:\\ProgramData\\chocolatey\\bin;C:\\Program Files\\Git\\cmd;C:\\Users\\hou\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\hou\\AppData\\Local\\GitHubDesktop\\bin;C:\\Users\\hou\\AppData\\Local\\Microsoft\\WindowsApps;D:\\tools\\PyCharm Community Edition 2019.3.3\\bin;', 'PATHEXT': '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY;.PYW', 'PLATFORMCODE': 'KV', 'PROCESSOR_ARCHITECTURE': 'AMD64', 'PROCESSOR_IDENTIFIER': 'Intel64 Family 6 Model 158 Stepping 9, GenuineIntel', 'PROCESSOR_LEVEL': '6', 'PROCESSOR_REVISION': '9e09', 'PROGRAMDATA': 'C:\\ProgramData', 'PROGRAMFILES': 'C:\\Program Files', 'PROGRAMFILES(X86)': 'C:\\Program Files (x86)', 'PROGRAMW6432': 'C:\\Program Files', 'PROMPT': '$P$G', 'PSMODULEPATH': 'C:\\Program Files\\WindowsPowerShell\\Modules;C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\Modules', 'PUBLIC': 'C:\\Users\\Public', 'PYCHARM COMMUNITY EDITION': 'D:\\tools\\PyCharm Community Edition 2019.3.3\\bin;', 'REGIONCODE': 'APJ', 'SYSTEMDRIVE': 'C:', 'SYSTEMROOT': 'C:\\WINDOWS', 'TEMP': 'C:\\Users\\hou\\AppData\\Local\\Temp', 'TMP': 'C:\\Users\\hou\\AppData\\Local\\Temp', 'USERDOMAIN': 'LAPTOP-04NNMOG1', 'USERDOMAIN_ROAMINGPROFILE': 'LAPTOP-04NNMOG1', 'USERNAME': 'hou', 'USERPROFILE': 'C:\\Users\\hou', 'VBOX_MSI_INSTALL_PATH': 'C:\\Program Files\\Oracle\\VirtualBox\\', 'VS110COMNTOOLS': 'C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\Common7\\Tools\\', 'VS120COMNTOOLS': 'D:\\deep learning\\Common7\\Tools\\', 'WINDIR': 'C:\\WINDOWS', 'ZEPHYR_BASE': 'C:\\Users\\hou\\zephyrproject\\zephyr'})print("_find_board 6 self.config_board:", self.config_board) # Noneif self.args.board:board, origin = self.args.board, 'command line'elif 'BOARD' in os.environ:board, origin = os.environ['BOARD'], 'env'elif self.config_board is not None:board, origin = self.config_board, 'configfile'print("_find_board 7 board:", board) # qemu_cortex_m3print("_find_board 8 origin:", origin) # command linereturn board, origin

3)_parse_remainder()

    def _parse_remainder(self, remainder):print("_parse_remainder 1 remainder:", remainder) # ['samples/hello_world']self.args.source_dir = Noneself.args.cmake_opts = Nonetry:# Only one source_dir is allowed, as the first positional argprint("_parse_remainder 2 _ARG_SEPARATOR:", _ARG_SEPARATOR) # --if remainder[0] != _ARG_SEPARATOR:self.args.source_dir = remainder[0]print("_parse_remainder 3 self.args.source_dir:", self.args.source_dir) # samples/hello_worldremainder = remainder[1:]print("_parse_remainder 4 remainder:", remainder) # []# Only the first argument separator is consumed, the rest are# passed on to CMakeif remainder[0] == _ARG_SEPARATOR:remainder = remainder[1:]print("_parse_remainder 5 remainder:", remainder)if remainder:self.args.cmake_opts = remainderprint("_parse_remainder 6 self.args.cmake_opts:", self.args.cmake_opts)except IndexError:return

4)_sanity_precheck()

    def _sanity_precheck(self):app = self.args.source_dirprint("_sanity_precheck 1 app:", app) # samples/hello_worldif app:self.check_force(os.path.isdir(app),'source directory {} does not exist'.format(app))self.check_force('CMakeLists.txt' in os.listdir(app),"{} doesn't contain a CMakeLists.txt".format(app))

5)_setup_build_dir()

    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)# The CMake Cache has not been loaded yet, so this is safeboard, _ = self._find_board()print("_setup_build_dir 1 board:", board) # qemu_cortex_m3source_dir = self._find_source_dir()print("_setup_build_dir 2 source_dir:", source_dir) # C:\Users\hou\zephyrproject\zephyr\samples\hello_worldapp = os.path.split(source_dir)[1]print("_setup_build_dir 3 app:", app) # hello_worldbuild_dir = find_build_dir(self.args.build_dir, board=board,source_dir=source_dir, app=app)print("_setup_build_dir 4 build_dir:", build_dir) # C:\Users\hou\zephyrproject\zephyr\buildif not build_dir:log.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'.format(build_dir))else:os.makedirs(build_dir, exist_ok=False)self.created_build_dir = Trueprint("_setup_build_dir 5 self.created_build_dir:", self.created_build_dir) # Trueself.run_cmake = Trueprint("_setup_build_dir 6 self.run_cmake:", self.run_cmake) # Trueself.build_dir = build_dirprint("_setup_build_dir 7 self.build_dir:", self.build_dir) # C:\Users\hou\zephyrproject\zephyr\build

6)_find_source_dir()

    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)print("_find_source_dir 1 self.args.source_dir:", self.args.source_dir) # samples/hello_worldprint("_find_source_dir 2 self.cmake_cache:", self.cmake_cache) # Noneif self.args.source_dir:source_dir = self.args.source_direlif self.cmake_cache:source_dir = self.cmake_cache.get('CMAKE_HOME_DIRECTORY')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,'CMake cache has no CMAKE_HOME_DIRECTORY;','please give a source_dir')else:source_dir = os.getcwd()print("_find_source_dir 3 source_dir:", source_dir) # samples/hello_worldreturn os.path.abspath(source_dir)

7)_sanity_check_source_dir()

    def _sanity_check_source_dir(self):print("_sanity_check_source_dir 1 self.source_dir:", self.source_dir) # C:\Users\hou\zephyrproject\zephyr\samples\hello_worldprint("_sanity_check_source_dir 2 self.build_dir:", self.build_dir) # C:\Users\hou\zephyrproject\zephyr\buildif self.source_dir == self.build_dir:# There's no forcing this.log.die('source and build directory {} cannot be the same; ''use --build-dir {} to specify a build directory'.format(self.source_dir, self.build_dir))srcrel = os.path.relpath(self.source_dir)print("_sanity_check_source_dir 3 srcrel:", srcrel) # samples\hello_worldself.check_force(not is_zephyr_build(self.source_dir),'it looks like {srcrel} is a build directory: ''did you mean --build-dir {srcrel} instead?'.format(srcrel=srcrel))self.check_force('CMakeLists.txt' in os.listdir(self.source_dir),'source directory "{srcrel}" does not contain ''a CMakeLists.txt; is this really what you ''want to build? (Use -s SOURCE_DIR to specify ''the application source directory)'.format(srcrel=srcrel))

8)_sanity_check()

    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._sanity_check_source_dir()print("_sanity_check 1 self.cmake_cache:", self.cmake_cache) # Noneif not self.cmake_cache:return          # That's all we can check without a cache.if "CMAKE_PROJECT_NAME" not in self.cmake_cache:# This happens sometimes when a build system is not# completely generated due to an error during the# CMake configuration phase.self.run_cmake = Trueprint("_sanity_check 2 self.run_cmake:", self.run_cmake)cached_proj = self.cmake_cache.get('APPLICATION_SOURCE_DIR')print("_sanity_check 3 cached_proj:", cached_proj)cached_app = self.cmake_cache.get('APP_DIR')print("_sanity_check 4 cached_app:", cached_app)# if APP_DIR is None but APPLICATION_SOURCE_DIR is set, that indicates# an older build folder, this still requires pristine.if cached_app is None and cached_proj:cached_app = cached_projprint("_sanity_check 5 cached_app:", cached_app)log.dbg('APP_DIR:', cached_app, level=log.VERBOSE_EXTREME)print("_sanity_check 6 self.args.source_dir:", self.args.source_dir)source_abs = (os.path.abspath(self.args.source_dir)if self.args.source_dir else None)print("_sanity_check 7 source_abs:", source_abs)cached_abs = os.path.abspath(cached_app) if cached_app else Noneprint("_sanity_check 8 cached_abs:", cached_abs)print("_sanity_check 9 self.auto_pristine:", self.auto_pristine)log.dbg('pristine:', self.auto_pristine, level=log.VERBOSE_EXTREME)# If the build directory specifies a source app, make sure it's# consistent with --source-dir.apps_mismatched = (source_abs and cached_abs andpathlib.Path(source_abs).resolve() != pathlib.Path(cached_abs).resolve())print("_sanity_check 10 apps_mismatched:", apps_mismatched)self.check_force(not apps_mismatched or self.auto_pristine,'Build directory "{}" is for application "{}", but source ''directory "{}" was specified; please clean it, use --pristine, ''or use --build-dir to set another build directory'.format(self.build_dir, cached_abs, source_abs))if apps_mismatched:self.run_cmake = True  # If they insist, we need to re-run cmake.# If CACHED_BOARD is not defined, we need some other way to# find the board.cached_board = self.cmake_cache.get('CACHED_BOARD')print("_sanity_check 11 cached_board:", cached_board)log.dbg('CACHED_BOARD:', cached_board, level=log.VERBOSE_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.self.check_force((cached_board andnot (apps_mismatched and self.auto_pristine))or self.args.board or self.config_board oros.environ.get('BOARD'),'Cached board not defined, please provide it ''(provide --board, set default with ''"west config build.board <BOARD>", or set ''BOARD in the environment)')# Check consistency between cached board and --board.print("_sanity_check 12 self.args.board:", self.args.board)boards_mismatched = (self.args.board and cached_board andself.args.board != cached_board)print("_sanity_check 13 boards_mismatched:", boards_mismatched)self.check_force(not boards_mismatched or self.auto_pristine,'Build directory {} targets board {}, but board {} was specified. ''(Clean the directory, use --pristine, or use --build-dir to ''specify a different one.)'.format(self.build_dir, cached_board, self.args.board))print("_sanity_check 14 self.auto_pristine:", self.auto_pristine)if self.auto_pristine and (apps_mismatched or boards_mismatched):self._run_pristine()self.cmake_cache = Nonelog.dbg('run_cmake:', True, level=log.VERBOSE_EXTREME)self.run_cmake = True# Tricky corner-case: The user has not specified a build folder but# there was one in the CMake cache. Since this is going to be# invalidated, reset to CWD and re-run the basic tests.if ((boards_mismatched and not apps_mismatched) and(not source_abs and cached_abs)):self.source_dir = self._find_source_dir()self._sanity_check_source_dir()

9)_run_cmake()

def _run_cmake(self, board, origin, cmake_opts):print("_run_cmake 1 board:", board) # qemu_cortex_m3print("_run_cmake 2 origin:", origin) # command lineprint("_run_cmake 3 cmake_opts:", cmake_opts) # Noneif board is None and config_getboolean('board_warn', True):log.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',"'west config build.board_warn false'")print("_run_cmake 4 self.run_cmake:", self.run_cmake) # Trueif not self.run_cmake:return_banner('generating a build system')if board is not None and origin != 'CMakeCache.txt':cmake_opts = ['-DBOARD={}'.format(board)]else:cmake_opts = []print("_run_cmake 5 cmake_opts:", cmake_opts) # ['-DBOARD=qemu_cortex_m3']print("_run_cmake 6 self.args.cmake_opts:", self.args.cmake_opts) # Noneif self.args.cmake_opts:cmake_opts.extend(self.args.cmake_opts)print("_run_cmake 7 self.args.snippets:", self.args.snippets) # []if self.args.snippets:cmake_opts.append(f'-DSNIPPET={";".join(self.args.snippets)}')print("_run_cmake 8 cmake_opts:", cmake_opts) # ['-DBOARD=qemu_cortex_m3']user_args = config_get('cmake-args', None)print("_run_cmake 9 user_args:", user_args) # Noneif user_args:cmake_opts.extend(shlex.split(user_args))print("_run_cmake 10 cmake_opts:", cmake_opts) # ['-DBOARD=qemu_cortex_m3']config_sysbuild = config_getboolean('sysbuild', False)print("_run_cmake 11 config_sysbuild:", config_sysbuild) # Falseprint("_run_cmake 12 self.args.sysbuild:", self.args.sysbuild) # Falseprint("_run_cmake 13 self.args.no_sysbuild:", self.args.no_sysbuild) # Falseif self.args.sysbuild or (config_sysbuild and not self.args.no_sysbuild):cmake_opts.extend(['-S{}'.format(SYSBUILD_PROJ_DIR),'-DAPP_DIR:PATH={}'.format(self.source_dir)])else:# self.args.no_sysbuild == True or config sysbuild Falsecmake_opts.extend(['-S{}'.format(self.source_dir)])print("_run_cmake 14 cmake_opts:", cmake_opts) # ['-DBOARD=qemu_cortex_m3', '-SC:\\Users\\hou\\zephyrproject\\zephyr\\samples\\hello_world']# 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.conffinal_cmake_args = ['-DWEST_PYTHON={}'.format(pathlib.Path(sys.executable).as_posix()),'-B{}'.format(self.build_dir),'-G{}'.format(config_get('generator',DEFAULT_CMAKE_GENERATOR))]print("_run_cmake 15 final_cmake_args:", final_cmake_args) # ['-DWEST_PYTHON=C:/Python311/python.exe', '-BC:\\Users\\hou\\zephyrproject\\zephyr\\build', '-GNinja']if cmake_opts:final_cmake_args.extend(cmake_opts)print("_run_cmake 16 final_cmake_args:", final_cmake_args) # ['-DWEST_PYTHON=C:/Python311/python.exe', '-BC:\\Users\\hou\\zephyrproject\\zephyr\\build', '-GNinja', '-DBOARD=qemu_cortex_m3', '-SC:\\Users\\hou\\zephyrproject\\zephyr\\samples\\hello_world']print("_run_cmake 17 self.args.dry_run:", self.args.dry_run) # Falserun_cmake(final_cmake_args, dry_run=self.args.dry_run)

10)run_cmake() 由_run_cmake()调用,zcmake.py

def run_cmake(args, cwd=None, capture_output=False, dry_run=False):'''Run cmake to (re)generate a build system, a script, etc.:param args: arguments to pass to CMake:param cwd: directory to run CMake in, cwd is default:param capture_output: if True, the output is returned instead of beingdisplayed (None is returned by default, or ifdry_run is also True):param dry_run: don't actually execute the command, just print whatwould have been runIf capture_output is set to True, returns the output of the command insteadof displaying it on stdout/stderr..'''print("run_cmake 1 args:", args) # ['-DWEST_PYTHON=C:/Python311/python.exe', '-BC:\\Users\\hou\\zephyrproject\\zephyr\\build', '-GNinja', '-DBOARD=qemu_cortex_m3', '-SC:\\Users\\hou\\zephyrproject\\zephyr\\samples\\hello_world']print("run_cmake 2 cwd:", cwd) # Noneprint("run_cmake 3 capture_output:", capture_output) # Falseprint("run_cmake 4 dry_run:", dry_run) # Falsecmake = shutil.which('cmake')print("run_cmake 5 cmake:", cmake) # C:\Program Files\CMake\bin\cmake.EXEif cmake is None and not dry_run:log.die('CMake is not installed or cannot be found; cannot build.')_ensure_min_version(cmake, dry_run)cmd = [cmake] + argsprint("run_cmake 6 cmd:", cmd) # ['C:\\Program Files\\CMake\\bin\\cmake.EXE', '-DWEST_PYTHON=C:/Python311/python.exe', '-BC:\\Users\\hou\\zephyrproject\\zephyr\\build', '-GNinja', '-DBOARD=qemu_cortex_m3', '-SC:\\Users\\hou\\zephyrproject\\zephyr\\samples\\hello_world']kwargs = dict()if capture_output:kwargs['stdout'] = subprocess.PIPE# CMake sends the output of message() to stderr unless it's STATUSkwargs['stderr'] = subprocess.STDOUTif cwd:kwargs['cwd'] = cwdprint("run_cmake 7 kwargs:", kwargs) # {}if dry_run:in_cwd = ' (in {})'.format(cwd) if cwd else ''log.inf('Dry run{}:'.format(in_cwd), quote_sh_list(cmd))return Nonelog.dbg('Running CMake:', quote_sh_list(cmd), level=log.VERBOSE_NORMAL)p = subprocess.Popen(cmd, **kwargs)out, _ = p.communicate()print("run_cmake 8 out:", out) # Noneprint("run_cmake 9 p.returncode:", p.returncode) # 0if p.returncode == 0:if out:return out.decode(sys.getdefaultencoding()).splitlines()else:return Noneelse:# A real error occurred, raise an exceptionraise subprocess.CalledProcessError(p.returncode, p.args)

11)_run_build()

    def _run_build(self, target, domain):print("_run_build 1 target:", target) # Noneprint("_run_build 2 domain:", domain) # Noneprint("_run_build 3 self.run_cmake:", self.run_cmake) # Trueif target:_banner('running target {}'.format(target))elif self.run_cmake:_banner('building application')extra_args = ['--target', target] if target else []print("_run_build 4 extra_args:", extra_args) # []print("_run_build 5 self.args.build_opt:", self.args.build_opt) # []if self.args.build_opt:extra_args.append('--')extra_args.extend(self.args.build_opt)print("_run_build 6 extra_args:", extra_args) # []print("_run_build 7 self.args.verbose:", self.args.verbose) # 0if self.args.verbose:self._append_verbose_args(extra_args,not bool(self.args.build_opt))domains = load_domains(self.build_dir)print("_run_build 8 domains:", domains) # <domains.Domains object at 0x000001F080017F90>build_dir_list = []if domain is None:# If no domain is specified, we just build top build dir as that# will build all domains.build_dir_list = [domains.get_top_build_dir()]print("_run_build 9 build_dir_list:", build_dir_list) # ['C:\\Users\\hou\\zephyrproject\\zephyr\\build']else:_banner('building domain(s): {}'.format(' '.join(domain)))domain_list = domains.get_domains(domain)print("_run_build 10 domain_list:", domain_list)for d in domain_list:build_dir_list.append(d.build_dir)print("_run_build 11 build_dir_list:", build_dir_list) # ['C:\\Users\\hou\\zephyrproject\\zephyr\\build']print("_run_build 12 self.args.dry_run:", self.args.dry_run) # Falsefor b in build_dir_list:run_build(b, extra_args=extra_args,dry_run=self.args.dry_run)

12)run_build()

def run_build(build_directory, **kwargs):'''Run cmake in build tool mode.:param build_directory: runs "cmake --build build_directory":param extra_args: optional kwarg. List of additional CMake arguments;these come after "--build <build_directory>"on the command line.Any additional keyword arguments are passed as-is to run_cmake().'''print("run_build 1 build_directory:", build_directory) # C:\Users\hou\zephyrproject\zephyr\buildprint("run_build 2 kwargs:", kwargs) # {'extra_args': [], 'dry_run': False}extra_args = kwargs.pop('extra_args', [])print("run_build 3 extra_args:", extra_args) # []return run_cmake(['--build', build_directory] + extra_args, **kwargs)

13)run_cmake() 由run_build()调用,zcmake.py

def run_cmake(args, cwd=None, capture_output=False, dry_run=False):'''Run cmake to (re)generate a build system, a script, etc.:param args: arguments to pass to CMake:param cwd: directory to run CMake in, cwd is default:param capture_output: if True, the output is returned instead of beingdisplayed (None is returned by default, or ifdry_run is also True):param dry_run: don't actually execute the command, just print whatwould have been runIf capture_output is set to True, returns the output of the command insteadof displaying it on stdout/stderr..'''print("run_cmake 1 args:", args) # ['--build', 'C:\\Users\\hou\\zephyrproject\\zephyr\\build']print("run_cmake 2 cwd:", cwd) # Noneprint("run_cmake 3 capture_output:", capture_output) # Falseprint("run_cmake 4 dry_run:", dry_run) # Falsecmake = shutil.which('cmake')print("run_cmake 5 cmake:", cmake) # C:\Program Files\CMake\bin\cmake.EXEif cmake is None and not dry_run:log.die('CMake is not installed or cannot be found; cannot build.')_ensure_min_version(cmake, dry_run)cmd = [cmake] + argsprint("run_cmake 6 cmd:", cmd) # ['C:\\Program Files\\CMake\\bin\\cmake.EXE', '--build', 'C:\\Users\\hou\\zephyrproject\\zephyr\\build']kwargs = dict()if capture_output:kwargs['stdout'] = subprocess.PIPE# CMake sends the output of message() to stderr unless it's STATUSkwargs['stderr'] = subprocess.STDOUTif cwd:kwargs['cwd'] = cwdprint("run_cmake 7 kwargs:", kwargs) # {}if dry_run:in_cwd = ' (in {})'.format(cwd) if cwd else ''log.inf('Dry run{}:'.format(in_cwd), quote_sh_list(cmd))return Nonelog.dbg('Running CMake:', quote_sh_list(cmd), level=log.VERBOSE_NORMAL)p = subprocess.Popen(cmd, **kwargs)out, _ = p.communicate()print("run_cmake 8 out:", out) # Noneprint("run_cmake 9 p.returncode:", p.returncode) # 0if p.returncode == 0:if out:return out.decode(sys.getdefaultencoding()).splitlines()else:return Noneelse:# A real error occurred, raise an exceptionraise subprocess.CalledProcessError(p.returncode, p.args)

根据以上函数流程,west build -b qemu_cortex_m3 samples/hello_world命令可以拆分为以下两个命令,实现相同的编译功能。

注:测试过程在windows系统中执行,因此打印路径格式为windows格式,运行命令时应转为linux格式。

cmake -DWEST_PYTHON=C:/Python311/python.exe -BC:/Users/hou/zephyrproject/zephyr/build -GNinja -DBOARD=qemu_cortex_m3 -SC:/Users/hou/zephyrproject/zephyr/samples/hello_worldcmake --build C:/Users/hou/zephyrproject/zephyr/build

编译日志如下。

C:\Users\hou\zephyrproject\zephyr>cmake -DWEST_PYTHON=C:/Python311/python.exe -BC:/Users/hou/zephyrproject/zephyr/build -GNinja -DBOARD=qemu_cortex_m3 -SC:/Users/hou/zephyrproject/zephyr/samples/hello_world
Loading Zephyr default modules (Zephyr repository).
-- Application: C:/Users/hou/zephyrproject/zephyr/samples/hello_world
-- CMake version: 3.29.2
-- Found Python3: C:/Python311/python.exe (found suitable version "3.11.9", minimum required is "3.8") found components: Interpreter
-- Cache files will be written to: C:/Users/hou/zephyrproject/zephyr/.cache
-- Zephyr version: 3.6.99 (C:/Users/hou/zephyrproject/zephyr)
-- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
-- Board: qemu_cortex_m3, qualifiers: ti_lm3s6965
-- ZEPHYR_TOOLCHAIN_VARIANT not set, trying to locate Zephyr SDK
-- Found host-tools: zephyr 0.16.5 (C:/Users/hou/zephyr-sdk-0.16.5-1)
-- Found toolchain: zephyr 0.16.5 (C:/Users/hou/zephyr-sdk-0.16.5-1)
-- Found Dtc: C:/ProgramData/chocolatey/bin/dtc.exe (found suitable version "1.5.0", minimum required is "1.4.6")
-- Found BOARD.dts: C:/Users/hou/zephyrproject/zephyr/boards/qemu/cortex_m3/qemu_cortex_m3.dts
-- Generated zephyr.dts: C:/Users/hou/zephyrproject/zephyr/build/zephyr/zephyr.dts
-- Generated devicetree_generated.h: C:/Users/hou/zephyrproject/zephyr/build/zephyr/include/generated/devicetree_generated.h
-- Including generated dts.cmake file: C:/Users/hou/zephyrproject/zephyr/build/zephyr/dts.cmake
Parsing C:/Users/hou/zephyrproject/zephyr/Kconfig
Loaded configuration 'C:/Users/hou/zephyrproject/zephyr/boards/qemu/cortex_m3/qemu_cortex_m3_defconfig'
Merged configuration 'C:/Users/hou/zephyrproject/zephyr/samples/hello_world/prj.conf'
Configuration saved to 'C:/Users/hou/zephyrproject/zephyr/build/zephyr/.config'
Kconfig header saved to 'C:/Users/hou/zephyrproject/zephyr/build/zephyr/include/generated/autoconf.h'
-- Found GnuLd: c:/users/hou/zephyr-sdk-0.16.5-1/arm-zephyr-eabi/arm-zephyr-eabi/bin/ld.bfd.exe (found version "2.38")
-- The C compiler identification is GNU 12.2.0
-- The CXX compiler identification is GNU 12.2.0
-- The ASM compiler identification is GNU
-- Found assembler: C:/Users/hou/zephyr-sdk-0.16.5-1/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc.exe
-- Configuring done (9.4s)
-- Generating done (0.3s)
-- Build files have been written to: C:/Users/hou/zephyrproject/zephyr/buildC:\Users\hou\zephyrproject\zephyr>cmake --build C:/Users/hou/zephyrproject/zephyr/build
[1/106] Generating include/generated/version.h
-- Zephyr version: 3.6.99 (C:/Users/hou/zephyrproject/zephyr), build: v3.6.0-3395-g1ae357850d5c
[106/106] Linking C executable zephyr\zephyr.elf
Memory region         Used Size  Region Size  %age UsedFLASH:        7958 B       256 KB      3.04%RAM:          4 KB        64 KB      6.25%IDT_LIST:          0 GB        32 KB      0.00%
Generating files from C:/Users/hou/zephyrproject/zephyr/build/zephyr/zephyr.elf for board: qemu_cortex_m3

这篇关于west build命令解析的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1047230

相关文章

网页解析 lxml 库--实战

lxml库使用流程 lxml 是 Python 的第三方解析库,完全使用 Python 语言编写,它对 XPath表达式提供了良好的支 持,因此能够了高效地解析 HTML/XML 文档。本节讲解如何通过 lxml 库解析 HTML 文档。 pip install lxml lxm| 库提供了一个 etree 模块,该模块专门用来解析 HTML/XML 文档,下面来介绍一下 lxml 库

【C++】_list常用方法解析及模拟实现

相信自己的力量,只要对自己始终保持信心,尽自己最大努力去完成任何事,就算事情最终结果是失败了,努力了也不留遗憾。💓💓💓 目录   ✨说在前面 🍋知识点一:什么是list? •🌰1.list的定义 •🌰2.list的基本特性 •🌰3.常用接口介绍 🍋知识点二:list常用接口 •🌰1.默认成员函数 🔥构造函数(⭐) 🔥析构函数 •🌰2.list对象

零基础学习Redis(10) -- zset类型命令使用

zset是有序集合,内部除了存储元素外,还会存储一个score,存储在zset中的元素会按照score的大小升序排列,不同元素的score可以重复,score相同的元素会按照元素的字典序排列。 1. zset常用命令 1.1 zadd  zadd key [NX | XX] [GT | LT]   [CH] [INCR] score member [score member ...]

30常用 Maven 命令

Maven 是一个强大的项目管理和构建工具,它广泛用于 Java 项目的依赖管理、构建流程和插件集成。Maven 的命令行工具提供了大量的命令来帮助开发人员管理项目的生命周期、依赖和插件。以下是 常用 Maven 命令的使用场景及其详细解释。 1. mvn clean 使用场景:清理项目的生成目录,通常用于删除项目中自动生成的文件(如 target/ 目录)。共性规律:清理操作

MCU7.keil中build产生的hex文件解读

1.hex文件大致解读 闲来无事,查看了MCU6.用keil新建项目的hex文件 用FlexHex打开 给我的第一印象是:经过软件的解释之后,发现这些数据排列地十分整齐 :02000F0080FE71:03000000020003F8:0C000300787FE4F6D8FD75810702000F3D:00000001FF 把解释后的数据当作十六进制来观察 1.每一行数据

OWASP十大安全漏洞解析

OWASP(开放式Web应用程序安全项目)发布的“十大安全漏洞”列表是Web应用程序安全领域的权威指南,它总结了Web应用程序中最常见、最危险的安全隐患。以下是对OWASP十大安全漏洞的详细解析: 1. 注入漏洞(Injection) 描述:攻击者通过在应用程序的输入数据中插入恶意代码,从而控制应用程序的行为。常见的注入类型包括SQL注入、OS命令注入、LDAP注入等。 影响:可能导致数据泄

从状态管理到性能优化:全面解析 Android Compose

文章目录 引言一、Android Compose基本概念1.1 什么是Android Compose?1.2 Compose的优势1.3 如何在项目中使用Compose 二、Compose中的状态管理2.1 状态管理的重要性2.2 Compose中的状态和数据流2.3 使用State和MutableState处理状态2.4 通过ViewModel进行状态管理 三、Compose中的列表和滚动

Spring 源码解读:自定义实现Bean定义的注册与解析

引言 在Spring框架中,Bean的注册与解析是整个依赖注入流程的核心步骤。通过Bean定义,Spring容器知道如何创建、配置和管理每个Bean实例。本篇文章将通过实现一个简化版的Bean定义注册与解析机制,帮助你理解Spring框架背后的设计逻辑。我们还将对比Spring中的BeanDefinition和BeanDefinitionRegistry,以全面掌握Bean注册和解析的核心原理。

CSP 2023 提高级第一轮 CSP-S 2023初试题 完善程序第二题解析 未完

一、题目阅读 (最大值之和)给定整数序列 a0,⋯,an−1,求该序列所有非空连续子序列的最大值之和。上述参数满足 1≤n≤105 和 1≤ai≤108。 一个序列的非空连续子序列可以用两个下标 ll 和 rr(其中0≤l≤r<n0≤l≤r<n)表示,对应的序列为 al,al+1,⋯,ar​。两个非空连续子序列不同,当且仅当下标不同。 例如,当原序列为 [1,2,1,2] 时,要计算子序列 [

多线程解析报表

假如有这样一个需求,当我们需要解析一个Excel里多个sheet的数据时,可以考虑使用多线程,每个线程解析一个sheet里的数据,等到所有的sheet都解析完之后,程序需要提示解析完成。 Way1 join import java.time.LocalTime;public class Main {public static void main(String[] args) thro