blob: f6a484b766a1565c001ddbc9cb2208923ff39c3a [file] [log] [blame]
Patrick Williams92b42cb2022-09-03 06:53:57 -05001#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: GPL-2.0-only
5#
6
7import logging
8import os
9import json
10import stat
11
12logger = logging.getLogger('bitbake-layers')
13
14def plugin_init(plugins):
15 return OeSetupLayersWriter()
16
17class OeSetupLayersWriter():
18
19 def __str__(self):
20 return "oe-setup-layers"
21
22 def _write_python(self, input, output):
23 with open(input) as f:
24 script = f.read()
25 with open(output, 'w') as f:
26 f.write(script)
27 st = os.stat(output)
28 os.chmod(output, st.st_mode | stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH)
29
30 def _write_json(self, repos, output):
31 with open(output, 'w') as f:
32 json.dump(repos, f, sort_keys=True, indent=4)
33
34 def do_write(self, parent, args):
35 """ Writes out a python script and a json config that replicate the directory structure and revisions of the layers in a current build. """
36 repos = parent.make_repo_config(args.destdir)
37 json = {"version":"1.0","sources":repos}
38 if not repos:
39 raise Exception("Could not determine layer sources")
40 output = args.output_prefix or "setup-layers"
41 output = os.path.join(os.path.abspath(args.destdir),output)
42 self._write_json(json, output + ".json")
43 logger.info('Created {}.json'.format(output))
44 if not args.json_only:
45 self._write_python(os.path.join(os.path.dirname(__file__),'../../../../scripts/oe-setup-layers'), output)
46 logger.info('Created {}'.format(output))
47
48 def register_arguments(self, parser):
49 parser.add_argument('--json-only', action='store_true',
50 help='When using the oe-setup-layers writer, write only the layer configuruation in json format. Otherwise, also a copy of scripts/oe-setup-layers (from oe-core or poky) is provided, which is a self contained python script that fetches all the needed layers and sets them to correct revisions using the data from the json.')