mirror of
https://github.com/zephyrproject-rtos/zephyr
synced 2025-08-04 06:04:30 +00:00
Add generated documentation content for known devicetree bindings using the Binding abstraction which was just added to edtlib. This works similarly to the way Kconfig content is generated, so extract a bit of common helper code for doing that out and rename the relevant files to keep the distinction clear. Make the documentation build system respect a preset DTS_ROOT. In this way, out of tree bindings can be added to the generated content by telling the documentation build system where to find them, identically to how out of tree bindings can be added to a Zephyr application. Similarly, make the output directory configurable. Fixes: #28865 Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
30 lines
781 B
Python
30 lines
781 B
Python
# Copyright (c) 2020 Nordic Semiconductor ASA
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
"""
|
|
Helper functions used by gen_kconfig_rest.py and gen_devicetree_rest.py.
|
|
"""
|
|
|
|
import errno
|
|
|
|
def write_if_updated(path, s):
|
|
"""
|
|
Writes 's' as the contents of <out_dir>/<filename>, but only if it
|
|
differs from the current contents of the file. This avoids unnecessary
|
|
timestamp updates, which trigger documentation rebuilds.
|
|
|
|
Returns True if the file was updated, False otherwise.
|
|
"""
|
|
|
|
try:
|
|
with open(path, "r", encoding="utf-8") as f:
|
|
if s == f.read():
|
|
return False
|
|
except OSError as e:
|
|
if e.errno != errno.ENOENT:
|
|
raise
|
|
|
|
with open(path, "w", encoding="utf-8") as f:
|
|
f.write(s)
|
|
return True
|