]> code.ossystems Code Review - openembedded-core.git/commitdiff
recipetool: create: fix creating empty shell functions
authorPaul Eggleton <paul.eggleton@linux.intel.com>
Tue, 22 Sep 2015 16:21:28 +0000 (17:21 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Tue, 22 Sep 2015 17:12:55 +0000 (18:12 +0100)
The shell considers empty functions to be a syntax error, so for
template shell functions that contain only comments (or no lines at all)
then add a : to act as a no-op which avoids the syntax error.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
scripts/lib/recipetool/create.py

index c4754dbcddca778844935f1d58a39cafbfef35f0..99d9cc850e26ac08d9dd7461bbbdd36e9d62dfc2 100644 (file)
@@ -46,10 +46,26 @@ class RecipeHandler():
             results.extend(glob.glob(os.path.join(path, spec)))
         return results
 
-    def genfunction(self, outlines, funcname, content):
-        outlines.append('%s () {' % funcname)
+    def genfunction(self, outlines, funcname, content, python=False, forcespace=False):
+        if python:
+            prefix = 'python '
+        else:
+            prefix = ''
+        outlines.append('%s%s () {' % (prefix, funcname))
+        if python or forcespace:
+            indent = '    '
+        else:
+            indent = '\t'
+        addnoop = not python
         for line in content:
-            outlines.append('\t%s' % line)
+            outlines.append('%s%s' % (indent, line))
+            if addnoop:
+                strippedline = line.lstrip()
+                if strippedline and not strippedline.startswith('#'):
+                    addnoop = False
+        if addnoop:
+            # Without this there'll be a syntax error
+            outlines.append('%s:' % indent)
         outlines.append('}')
         outlines.append('')