kernel-yocto: configcheck: create cfg folder if it doesn't exist

Message ID f3dd9984-eae8-61f6-f4bd-812cc13417c5@linux.intel.com
State New
Headers show
Series kernel-yocto: configcheck: create cfg folder if it doesn't exist | expand

Commit Message

Bills, Jason M March 14, 2022, 4:21 p.m. UTC
In some situations, the cfg folder doesn't exist when a config
check returns data, which results in a python exception:

File: '/.../meta/classes/kernel-yocto.bbclass', lineno: 590, function: 
do_kernel_configcheck
      0586:    if analysis:
      0587:        outfile = "{}/{}/cfg/invalid.txt".format(s,kmeta)
      0588:        if os.path.isfile(outfile):
      0589:           os.remove(outfile)
  *** 0590:        with open(outfile, 'w+') as f:
      0591:            f.write( analysis )
      0592:
      0593:        if bsp_check_visibility and os.stat(outfile).st_size > 0:
      0594:            with open (outfile, "r") as myfile:
Exception: FileNotFoundError: [Errno 2] No such file or directory:
 
'/.../openbmc-openbmc/build/tmp/work-shared/.../kernel-source/.kernel-meta/cfg/invalid.txt'

This adds a check to create the cfg folder if it doesn't exist to
avoid the python exception.

I have only seen this error with invalid.txt, but it looks like
mismatch.txt and redefinition.txt could hit the same issue, so
adding the fix for those, too.

Signed-off-by: Jason M. Bills <jason.m.bills@linux.intel.com>
---
  meta/classes/kernel-yocto.bbclass | 15 ++++++++++++---
  1 file changed, 12 insertions(+), 3 deletions(-)

          bb.fatal( "config analysis failed: %s" % e.output.decode('utf-8'))
       if analysis:
-        outfile = "{}/{}/cfg/invalid.txt".format(s,kmeta)
+        outpath = "{}/{}/cfg".format(s,kmeta)
+        if not os.path.exists(outpath):
+            os.makedirs(outpath)
+        outfile = "{}/invalid.txt".format(outpath)
          if os.path.isfile(outfile):
             os.remove(outfile)
          with open(outfile, 'w+') as f:
@@ -603,7 +609,10 @@ python do_kernel_configcheck() {
          bb.fatal( "config analysis failed: %s" % e.output.decode('utf-8'))
       if analysis:
-        outfile = "{}/{}/cfg/redefinition.txt".format(s,kmeta)
+        outpath = "{}/{}/cfg".format(s,kmeta)
+        if not os.path.exists(outpath):
+            os.makedirs(outpath)
+        outfile = "{}/redefinition.txt".format(outpath)
          if os.path.isfile(outfile):
             os.remove(outfile)
          with open(outfile, 'w+') as f:

Patch

diff --git a/meta/classes/kernel-yocto.bbclass 
b/meta/classes/kernel-yocto.bbclass
index 1d5a8cdf29..d35f4629cb 100644
--- a/meta/classes/kernel-yocto.bbclass
+++ b/meta/classes/kernel-yocto.bbclass
@@ -562,7 +562,10 @@  python do_kernel_configcheck() {
          bb.fatal( "config analysis failed: %s" % e.output.decode('utf-8'))
       if analysis:
-        outfile = "{}/{}/cfg/mismatch.txt".format( s, kmeta )
+        outpath = "{}/{}/cfg".format( s, kmeta )
+        if not os.path.exists(outpath):
+            os.makedirs(outpath)
+        outfile = "{}/mismatch.txt".format(outpath)
          if os.path.isfile(outfile):
             os.remove(outfile)
          with open(outfile, 'w+') as f:
@@ -584,7 +587,10 @@  python do_kernel_configcheck() {