Skip to content

Commit 3258699

Browse files
committed
[nrf fromlist] 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. Upstream PR: zephyrproject-rtos/zephyr#79118 Signed-off-by: Torsten Rasmussen <[email protected]>
1 parent 0605d1c commit 3258699

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

scripts/schemas/build-schema.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,5 @@ mapping:
104104
type: str
105105
topdir:
106106
type: str
107+
version:
108+
type: str

scripts/west_commands/build.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
from west import log
1313
from west.configuration import config
14+
from west.util import west_topdir
15+
from west.version import __version__
1416
from zcmake import DEFAULT_CMAKE_GENERATOR, run_cmake, run_build, CMakeCache
1517
from build_helpers import is_zephyr_build, find_build_dir, load_domains, \
1618
FIND_BUILD_DIR_DESCRIPTION
@@ -22,6 +24,8 @@
2224
SYSBUILD_PROJ_DIR = pathlib.Path(__file__).resolve().parent.parent.parent \
2325
/ pathlib.Path('share/sysbuild')
2426

27+
BUILD_INFO_LOG = 'build_info.yml'
28+
2529
BUILD_USAGE = '''\
2630
west build [-h] [-b BOARD[@REV]]] [-d BUILD_DIR]
2731
[-S SNIPPET] [--shield SHIELD]
@@ -227,9 +231,25 @@ def do_run(self, args, remainder):
227231
self.run_cmake = True
228232
else:
229233
self.run_cmake = True
234+
230235
self.source_dir = self._find_source_dir()
231236
self._sanity_check()
232237

238+
build_info_path = self.build_dir
239+
build_info_file = os.path.join(build_info_path, BUILD_INFO_LOG)
240+
west_workspace = west_topdir(self.source_dir)
241+
if not os.path.exists(build_info_path):
242+
os.makedirs(build_info_path)
243+
if not os.path.exists(build_info_file):
244+
build_command = {'west': {'command': ' '.join(sys.argv[:]),
245+
'topdir': str(west_workspace),
246+
'version': str(__version__)}}
247+
try:
248+
with open(build_info_file, "w") as f:
249+
yaml.dump(build_command, f, default_flow_style=False)
250+
except Exception as e:
251+
log.wrn(f'Failed to create info file: {build_info_file},', e)
252+
233253
board, origin = self._find_board()
234254
self._run_cmake(board, origin, self.args.cmake_opts)
235255
if args.cmake_only:

0 commit comments

Comments
 (0)