[OE-core] [PATCH] action: new bitbake-layer plugin to create a simple layer

leonardo.sandoval.gonzalez at linux.intel.com leonardo.sandoval.gonzalez at linux.intel.com
Tue Jul 25 22:37:17 UTC 2017


From: Leonardo Sandoval <leonardo.sandoval.gonzalez at linux.intel.com>

Though the script bitbake-layers (from the bitbake project), this plugin
creates a simple layer with a example recipe, the latter with a single task
(do_build). Layer's license and priority is MIT and 6, respectively. Example
recipe and layer's priority can be specified through the command line.

[YOCTO #11567]

Signed-off-by: Leonardo Sandoval <leonardo.sandoval.gonzalez at linux.intel.com>
---
 meta/lib/bblayers/create.py            | 66 ++++++++++++++++++++++++++++++++++
 meta/lib/bblayers/templates/README     | 41 +++++++++++++++++++++
 meta/lib/bblayers/templates/example.bb | 11 ++++++
 meta/lib/bblayers/templates/layer.conf | 10 ++++++
 4 files changed, 128 insertions(+)
 create mode 100644 meta/lib/bblayers/create.py
 create mode 100644 meta/lib/bblayers/templates/README
 create mode 100644 meta/lib/bblayers/templates/example.bb
 create mode 100644 meta/lib/bblayers/templates/layer.conf

diff --git a/meta/lib/bblayers/create.py b/meta/lib/bblayers/create.py
new file mode 100644
index 0000000000..6a41fe0504
--- /dev/null
+++ b/meta/lib/bblayers/create.py
@@ -0,0 +1,66 @@
+import logging
+import os
+import sys
+import shutil
+
+import bb.utils
+
+from bblayers.common import LayerPlugin
+
+logger = logging.getLogger('bitbake-layers')
+
+def plugin_init(plugins):
+    return CreatePlugin()
+
+def read_template(template, template_dir='templates'):
+    lines = str()
+    with open(os.path.join(os.path.dirname(__file__), template_dir, template)) as fd:
+        lines = ''.join(fd.readlines())
+    return lines
+
+class CreatePlugin(LayerPlugin):
+    def do_create_layer(self, args):
+        """Create a basic layer"""
+        layerdir = os.path.abspath(args.layerdir)
+        if os.path.exists(layerdir):
+            sys.stderr.write("Specified layer directory exists\n")
+            return 1
+
+        # create dirs
+        conf = os.path.join(layerdir, 'conf')
+        bb.utils.mkdirhier(conf)
+
+        # Create the README from templates/README
+        readme_template =  read_template('README') % (args.layerdir, args.layerdir, args.layerdir, args.layerdir, args.layerdir, args.layerdir)
+        readme = os.path.join(layerdir, 'README')
+        with open(readme, 'w') as fd:
+            fd.write(readme_template)
+
+        # Copy the MIT license from meta
+        copying = 'COPYING.MIT'
+        dn = os.path.dirname
+        license_src = os.path.join(dn(dn(dn(__file__))), copying)
+        license_dst = os.path.join(layerdir, copying)
+        shutil.copy(license_src, license_dst)
+
+        # Create the layer.conf from templates/layer.conf
+        layerconf_template = read_template('layer.conf') % (args.layerdir, args.layerdir, args.layerdir, args.priority)
+        layerconf = os.path.join(conf, 'layer.conf')
+        with open(layerconf, 'w') as fd:
+            fd.write(layerconf_template)
+
+        # Create the example from templates/example.bb
+        example_template = read_template('example.bb')
+        example = os.path.join(layerdir, 'recipes-' + args.examplerecipe, args.examplerecipe)
+        bb.utils.mkdirhier(example)
+        with open(os.path.join(example, args.examplerecipe + '.bb'), 'w') as fd:
+            fd.write(example_template)
+
+        logger.plain('Add your new layer with \'bitbake-layers add-layer %s\'' % args.layerdir)
+
+    def register_commands(self, sp):
+        parser_create_layer = self.add_command(sp, 'create-layer', self.do_create_layer, parserecipes=False)
+        parser_create_layer.add_argument('layerdir', help='Layer directory to create')
+        parser_create_layer.add_argument('--priority', '-p', default=6, help='Layer directory to create')
+        parser_create_layer.add_argument('--example-recipe-name', '-e', dest='examplerecipe', default='example', help='Filename of the example recipe')
+
diff --git a/meta/lib/bblayers/templates/README b/meta/lib/bblayers/templates/README
new file mode 100644
index 0000000000..5a77f8d347
--- /dev/null
+++ b/meta/lib/bblayers/templates/README
@@ -0,0 +1,41 @@
+This README file contains information on the contents of the %s layer.
+
+Please see the corresponding sections below for details.
+
+Dependencies
+============
+
+  URI: <first dependency>
+  branch: <branch name>
+
+  URI: <second dependency>
+  branch: <branch name>
+
+  .
+  .
+  .
+
+Patches
+=======
+
+Please submit any patches against the %s layer to the xxxx mailing list (xxxx at zzzz.org)
+and cc: the maintainer:
+
+Maintainer: XXX YYYYYY <xxx.yyyyyy at zzzzz.com>
+
+Table of Contents
+=================
+
+  I. Adding the %s layer to your build
+ II. Misc
+
+
+I. Adding the %s layer to your build
+=================================================
+
+Run 'bitbake-layers add-layer %s'
+
+II. Misc
+========
+
+--- replace with specific information about the %s layer ---
diff --git a/meta/lib/bblayers/templates/example.bb b/meta/lib/bblayers/templates/example.bb
new file mode 100644
index 0000000000..c4b873d593
--- /dev/null
+++ b/meta/lib/bblayers/templates/example.bb
@@ -0,0 +1,11 @@
+SUMMARY = "bitbake-layers recipe"
+DESCRIPTION = "Recipe created by bitbake-layers"
+LICENSE = "MIT"
+
+python do_build() {
+    bb.plain("***********************************************");
+    bb.plain("*                                             *");
+    bb.plain("*  Example recipe created by bitbake-layers   *");
+    bb.plain("*                                             *");
+    bb.plain("***********************************************");
+}
diff --git a/meta/lib/bblayers/templates/layer.conf b/meta/lib/bblayers/templates/layer.conf
new file mode 100644
index 0000000000..e0d9ba2fde
--- /dev/null
+++ b/meta/lib/bblayers/templates/layer.conf
@@ -0,0 +1,10 @@
+# We have a conf and classes directory, add to BBPATH
+BBPATH .= ":${LAYERDIR}"
+
+# We have recipes-* directories, add to BBFILES
+BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \\
+            ${LAYERDIR}/recipes-*/*/*.bbappend"
+
+BBFILE_COLLECTIONS += "%s"
+BBFILE_PATTERN_%s = "^${LAYERDIR}/"
+BBFILE_PRIORITY_%s = "%s"
-- 
2.12.3




More information about the Openembedded-core mailing list