diff mbox series

[yocto-autobuilder-helper,1/2] run-config: generalise auto.conf logging and only show when changed

Message ID 20240207121541.1720874-1-ross.burton@arm.com
State New
Headers show
Series [yocto-autobuilder-helper,1/2] run-config: generalise auto.conf logging and only show when changed | expand

Commit Message

Ross Burton Feb. 7, 2024, 12:15 p.m. UTC
From: Ross Burton <ross.burton@arm.com>

Extract the logging of auto.conf to a new log_file_contents() function,
and instead of calling it before _every_ call of bitbake, only show it when
actually writing the auto.conf.

Signed-off-by: Ross Burton <ross.burton@arm.com>
---
 scripts/run-config | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/scripts/run-config b/scripts/run-config
index 308e954..1c3fb45 100755
--- a/scripts/run-config
+++ b/scripts/run-config
@@ -167,6 +167,19 @@  utils.mkdir(errordir)
 
 errorlogs = set()
 
+def log_file_contents(filename, builddir, stepnum, stepname):
+    logfile = logname(builddir, stepnum, stepname)
+    with open(logfile, "a") as outf, open(filename, "r") as f:
+        def log(s):
+            outf.write(s)
+            sys.stdout.write(s)
+
+        log("Contents of %s:\n" % filename)
+        for line in f:
+            log(line)
+        log("\n")
+
+
 def bitbakecmd(builddir, cmd, report, stepnum, stepname, oeenv=True):
     global finalret
     flush()
@@ -191,16 +204,6 @@  def bitbakecmd(builddir, cmd, report, stepnum, stepname, oeenv=True):
     with open(log, "a") as outf:
         writelog("Running '%s' with output to %s\n" % (cmd, log), outf, sys.stdout)
 
-        autoconf = builddir + "/conf/auto.conf"
-        if os.path.exists(autoconf):
-            with open(autoconf, "r") as inf, open(log, "a") as outf:
-                writelog("auto.conf settings:\n", outf, sys.stdout)
-                for line in inf.readlines():
-                    writelog(line, outf, sys.stdout)
-                writelog("\n", outf, sys.stdout)
-
-    flush()
-
     with subprocess.Popen(cmd, shell=True, cwd=builddir + "/..", stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=0) as p, open(log, 'ab') as f:
         for line in p.stdout:
             writelog(line, f, sys.stdout.buffer)
@@ -259,6 +262,7 @@  def handle_stepnum(stepnum):
             addstepentry("write-config", "Write config", shortdesc, desc, None, str(stepnum))
         elif args.stepname == "write-config":
             runcmd([scriptsdir + "/setup-config", args.target, str(stepnum - 1), args.builddir, args.branchname, args.reponame, "-s", args.sstateprefix, "-b", args.buildappsrcrev])
+            log_file_contents(args.builddir + "/conf/auto.conf", args.builddir, stepnum, args.stepname)
 
     # Execute the targets for this configuration
     targets = utils.getconfigvar("BBTARGETS", ourconfig, args.target, stepnum)