diff mbox series

[yocto-autobuilder-helper,v2,1/2] run-config: Generate a file with build properties

Message ID 20250909-contrib-mathieu-build_props-v2-1-b607bb47be08@bootlin.com
State New
Headers show
Series run-config: Generate a file with build properties | expand

Commit Message

Mathieu Dubois-Briand Sept. 9, 2025, 2:30 p.m. UTC
Extract some important build configuration values, allowing to add them
to buildbot properties. Output filename is based on the one of
--json-outputfile, so no additional argument is needed: the arguments
list remain the same in all yocto-autobuilder-helper branches, with or
without this commit.

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

Patch

diff --git a/scripts/run-config b/scripts/run-config
index 98b48e55473c..1bde354c5dcf 100755
--- a/scripts/run-config
+++ b/scripts/run-config
@@ -11,10 +11,12 @@  import json
 import os
 import sys
 import subprocess
-import errno
+import pathlib
 
 import utils
 
+exported_properties = ['DISTRO', 'MACHINE', 'SDKMACHINE', 'PACKAGE_CLASSES']
+
 parser = utils.ArgParser(description='Runs configurations in json.conf.')
 
 parser.add_argument('target',
@@ -58,7 +60,8 @@  parser.add_argument('--workername',
                     help="the name of the worker the build is running on")
 parser.add_argument('-j', '--json-outputfile',
                     action='store',
-                    default="",
+                    default=None,
+                    type=pathlib.Path,
                     help="the file to store json information about the build in")
 parser.add_argument('--stepname',
                     action='store',
@@ -94,17 +97,26 @@  if arch == "qemux86" or arch == "qemux86-64":
 else:
     ourconfig["HELPERSTMACHTARGS"] = "-a -t machine -t toolchain-user"
 
-# Find out the number of steps this target has
+# Find out the number of steps this target has and properties
 maxsteps = 0
 stepnum = 0
+properties = {}
 if args.target in ourconfig['overrides']:
+    target = ourconfig['overrides'][args.target]
     maxsteps = 1
-    for v in ourconfig['overrides'][args.target]:
+    for v in target:
         if v.startswith("step"):
             n = int(v[4:])
-            if n <= maxsteps:
-                continue
-            maxsteps = n
+            if n > maxsteps:
+                maxsteps = n
+
+            # Get properties values for this build step, falling back to
+            # defaults if they are not set.
+            for prop in exported_properties:
+                for propdict in (target[v], target, ourconfig['defaults']):
+                    if prop in propdict:
+                        properties.setdefault(prop, set()).add(propdict[prop])
+                        break
 
 hp.printheader("Target task %s has %d steps" % (args.target, maxsteps))
 
@@ -377,8 +389,15 @@  elif args.phase == "finish" and args.stepname == "builddir-cleanup":
         runcmd(["mv", args.builddir, args.builddir + "-renamed"])
 
 if args.json_outputfile:
-    with open(args.json_outputfile, "w") as f:
+    with args.json_outputfile.open("w") as f:
         json.dump(jsonconfig, f, indent=4, sort_keys=True)
 
+    properties_outfile = args.json_outputfile.with_stem(f"{args.json_outputfile.stem}-properties")
+    properties = {k: list(v)[0] if len(v) == 1 else list(v)
+                  for k, v in properties.items()}
+
+    with properties_outfile.open("w") as f:
+        json.dump(properties, f, indent=4, sort_keys=True)
+
 sys.exit(0)