Skip to content

Commit f896fc2

Browse files
keith-zephyrcarlescufi
authored andcommitted
scripts: gen_handles: Sort the device handles
Replicate the devicetree dependencies into a sorted list. This ensures that the structures added to the .__device_handles_pass2 section are reproducible from build to build. Tested with: west build -b native_posix tests/drivers/build_all/sensor Without this change, two consecutive builds do not compare. Signed-off-by: Keith Short <[email protected]>
1 parent 4348caf commit f896fc2

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

scripts/build/gen_handles.py

+22-13
Original file line numberDiff line numberDiff line change
@@ -72,35 +72,35 @@ def parse_args():
7272

7373
sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/dts"))
7474

75-
def c_handle_comment(dev):
75+
def c_handle_comment(dev, handles):
7676
def dev_path_str(dev):
7777
return dev.edt_node and dev.edt_node.path or dev.sym.name
7878
lines = [
7979
'',
8080
'/* {:d} : {:s}:'.format(dev.handle, (dev_path_str(dev))),
8181
]
82-
if len(dev.devs_depends_on) > 0:
82+
if len(handles["depends"]) > 0:
8383
lines.append(' * Direct Dependencies:')
84-
for dep in dev.devs_depends_on:
84+
for dep in handles["depends"]:
8585
lines.append(' * - {:s}'.format(dev_path_str(dep)))
86-
if len(dev.devs_depends_on_injected) > 0:
86+
if len(handles["injected"]) > 0:
8787
lines.append(' * Injected Dependencies:')
88-
for dep in dev.devs_depends_on_injected:
88+
for dep in handles["injected"]:
8989
lines.append(' * - {:s}'.format(dev_path_str(dep)))
90-
if len(dev.devs_supports) > 0:
90+
if len(handles["supports"]) > 0:
9191
lines.append(' * Supported:')
92-
for sup in dev.devs_supports:
92+
for sup in handles["supports"]:
9393
lines.append(' * - {:s}'.format(dev_path_str(sup)))
9494
lines.append(' */')
9595
return lines
9696

97-
def c_handle_array(dev, extra_support_handles=0):
97+
def c_handle_array(dev, handles, extra_support_handles=0):
9898
handles = [
99-
*[str(d.handle) for d in dev.devs_depends_on],
99+
*[str(d.handle) for d in handles["depends"]],
100100
'DEVICE_HANDLE_SEP',
101-
*[str(d.handle) for d in dev.devs_depends_on_injected],
101+
*[str(d.handle) for d in handles["injected"]],
102102
'DEVICE_HANDLE_SEP',
103-
*[str(d.handle) for d in dev.devs_supports],
103+
*[str(d.handle) for d in handles["supports"]],
104104
*(extra_support_handles * ['DEVICE_HANDLE_NULL']),
105105
'DEVICE_HANDLE_ENDS',
106106
]
@@ -131,9 +131,18 @@ def main():
131131
fp.write('#include <zephyr/device.h>\n')
132132
fp.write('#include <zephyr/toolchain.h>\n')
133133
for dev in parsed_elf.devices:
134+
# The device handle are collected up in a set, which has no
135+
# specified order. Sort each sub-category of device handle types
136+
# separately, so that the generated C array is reproducible across
137+
# builds.
138+
sorted_handles = {
139+
"depends": sorted(dev.devs_depends_on, key=lambda d: d.handle),
140+
"injected": sorted(dev.devs_depends_on_injected, key=lambda d: d.handle),
141+
"supports": sorted(dev.devs_supports, key=lambda d: d.handle),
142+
}
134143
extra_sups = args.num_dynamic_devices if dev.pm and dev.pm.is_power_domain else 0
135-
lines = c_handle_comment(dev)
136-
lines.extend(c_handle_array(dev, extra_sups))
144+
lines = c_handle_comment(dev, sorted_handles)
145+
lines.extend(c_handle_array(dev, sorted_handles, extra_sups))
137146
lines.extend([''])
138147
fp.write('\n'.join(lines))
139148

0 commit comments

Comments
 (0)