west: support build info file for west build

For pristine builds 'west build' will now create a build_info.yml file
containing the west build command including arguments.

This is done to help users and external tools to recreate builds.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit is contained in:
Torsten Rasmussen 2024-08-08 21:23:28 +02:00 committed by Carles Cufí
commit 24ee391231
2 changed files with 22 additions and 0 deletions

View file

@ -104,3 +104,5 @@ mapping:
type: str
topdir:
type: str
version:
type: str

View file

@ -11,6 +11,8 @@ import yaml
from west import log
from west.configuration import config
from west.util import west_topdir
from west.version import __version__
from zcmake import DEFAULT_CMAKE_GENERATOR, run_cmake, run_build, CMakeCache
from build_helpers import is_zephyr_build, find_build_dir, load_domains, \
FIND_BUILD_DIR_DESCRIPTION
@ -22,6 +24,8 @@ _ARG_SEPARATOR = '--'
SYSBUILD_PROJ_DIR = pathlib.Path(__file__).resolve().parent.parent.parent \
/ pathlib.Path('share/sysbuild')
BUILD_INFO_LOG = 'build_info.yml'
BUILD_USAGE = '''\
west build [-h] [-b BOARD[@REV]]] [-d BUILD_DIR]
[-S SNIPPET] [--shield SHIELD]
@ -244,9 +248,25 @@ class Build(Forceable):
self.run_cmake = True
else:
self.run_cmake = True
self.source_dir = self._find_source_dir()
self._sanity_check()
build_info_path = self.build_dir
build_info_file = os.path.join(build_info_path, BUILD_INFO_LOG)
west_workspace = west_topdir(self.source_dir)
if not os.path.exists(build_info_path):
os.makedirs(build_info_path)
if not os.path.exists(build_info_file):
build_command = {'west': {'command': ' '.join(sys.argv[:]),
'topdir': str(west_workspace),
'version': str(__version__)}}
try:
with open(build_info_file, "w") as f:
yaml.dump(build_command, f, default_flow_style=False)
except Exception as e:
log.wrn(f'Failed to create info file: {build_info_file},', e)
board, origin = self._find_board()
self._run_cmake(board, origin, self.args.cmake_opts)
if args.cmake_only: