diff mbox series

[yocto-autobuilder-helper,master-next,v4,1/2] getproperties: Also extract build properties

Message ID 20251016-contrib-mathieu-build_props-v4-1-1f2f6700e06b@bootlin.com
State New
Headers show
Series run-config: Export some build properties | expand

Commit Message

Mathieu Dubois-Briand Oct. 16, 2025, 1:20 p.m. UTC
Extract some important build configuration values, allowing to add them
to buildbot properties. This includes MACHINE, DISTRO, SDKMACHINE and
PACKAGE_CLASSES.

Properties will be assign either a single string value or a list of
strings, when different values are used across different steps.

Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
---
 scripts/getproperties.py | 29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/scripts/getproperties.py b/scripts/getproperties.py
index 1148d52be5aa..2119424b2dd4 100755
--- a/scripts/getproperties.py
+++ b/scripts/getproperties.py
@@ -8,8 +8,9 @@  import sys
 
 import utils
 
+# Usage: scripts/getproperties.py <builddir> [builder_name]
 builddir = sys.argv[1]
-
+targetname = sys.argv[2] if len(sys.argv) > 2 else None
 
 with open(builddir + "/../layerinfo.json") as f:
     repos = json.load(f)
@@ -71,5 +72,29 @@  buildid = hashlib.sha1(buildid.encode("utf-8")).hexdigest()
 
 jsonprops['yp_build_revision'] = buildid
 
-print(json.dumps(jsonprops, indent=4, sort_keys=True))
+ourconfig = utils.loadconfig()
+exported_properties = ['DISTRO', 'MACHINE', 'SDKMACHINE', 'PACKAGE_CLASSES']
+if targetname in ourconfig['overrides']:
+    target_props = {}
+    target = ourconfig['overrides'][targetname]
+    maxsteps = 1
+    # For each properties, construct of set of all values this property is
+    # assigned with.
+    # We iterate each steps, and get corresponding values from:
+    # - The step itself.
+    # - If no value was found, the build target template.
+    # - If still not value is found, the defaults value.
+    for v in target:
+        if v.startswith("step"):
+            for prop in exported_properties:
+                for propdict in (target[v], target, ourconfig['defaults']):
+                    if prop in propdict:
+                        target_props.setdefault(prop, set()).add(propdict[prop])
+                        break
+
+    # Transform property sets: as single value if the set only contains one
+    # value, as a list of values otherwise.
+    for k, v in target_props.items():
+        jsonprops[k] = list(v)[0] if len(v) == 1 else list(v)
 
+print(json.dumps(jsonprops, indent=4, sort_keys=True))