blob: c1923166fdbe7eed0f64d04d74727cdab7b5b602 [file] [log] [blame]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001import logging
2import os
3import sys
4import shutil
5
6import bb.utils
7
8from bblayers.common import LayerPlugin
9
10logger = logging.getLogger('bitbake-layers')
11
12def plugin_init(plugins):
13 return CreatePlugin()
14
15def read_template(template, template_dir='templates'):
16 lines = str()
17 with open(os.path.join(os.path.dirname(__file__), template_dir, template)) as fd:
18 lines = ''.join(fd.readlines())
19 return lines
20
21class CreatePlugin(LayerPlugin):
22 def do_create_layer(self, args):
23 """Create a basic layer"""
24 layerdir = os.path.abspath(args.layerdir)
25 if os.path.exists(layerdir):
26 sys.stderr.write("Specified layer directory exists\n")
27 return 1
28
29 # create dirs
30 conf = os.path.join(layerdir, 'conf')
31 bb.utils.mkdirhier(conf)
32
33 # Create the README from templates/README
34 readme_template = read_template('README') % (args.layerdir, args.layerdir, args.layerdir, args.layerdir, args.layerdir, args.layerdir)
35 readme = os.path.join(layerdir, 'README')
36 with open(readme, 'w') as fd:
37 fd.write(readme_template)
38
39 # Copy the MIT license from meta
40 copying = 'COPYING.MIT'
41 dn = os.path.dirname
42 license_src = os.path.join(dn(dn(dn(__file__))), copying)
43 license_dst = os.path.join(layerdir, copying)
44 shutil.copy(license_src, license_dst)
45
46 # Create the layer.conf from templates/layer.conf
47 layerconf_template = read_template('layer.conf') % (args.layerdir, args.layerdir, args.layerdir, args.priority)
48 layerconf = os.path.join(conf, 'layer.conf')
49 with open(layerconf, 'w') as fd:
50 fd.write(layerconf_template)
51
52 # Create the example from templates/example.bb
53 example_template = read_template('example.bb')
54 example = os.path.join(layerdir, 'recipes-' + args.examplerecipe, args.examplerecipe)
55 bb.utils.mkdirhier(example)
Brad Bishopd5ae7d92018-06-14 09:52:03 -070056 with open(os.path.join(example, args.examplerecipe + '_%s.bb') % args.version, 'w') as fd:
Brad Bishopd7bf8c12018-02-25 22:55:05 -050057 fd.write(example_template)
58
59 logger.plain('Add your new layer with \'bitbake-layers add-layer %s\'' % args.layerdir)
60
61 def register_commands(self, sp):
62 parser_create_layer = self.add_command(sp, 'create-layer', self.do_create_layer, parserecipes=False)
63 parser_create_layer.add_argument('layerdir', help='Layer directory to create')
64 parser_create_layer.add_argument('--priority', '-p', default=6, help='Layer directory to create')
65 parser_create_layer.add_argument('--example-recipe-name', '-e', dest='examplerecipe', default='example', help='Filename of the example recipe')
Brad Bishopd5ae7d92018-06-14 09:52:03 -070066 parser_create_layer.add_argument('--example-recipe-version', '-v', dest='version', default='0.1', help='Version number for the example recipe')
Brad Bishopd7bf8c12018-02-25 22:55:05 -050067