blob: d5bc19a8cbd70d505900b8de3439f7ebb6ce6943 [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. """
Andrew Geissler6aa7eec2023-03-03 12:41:14 -060036 if not os.path.exists(args.destdir):
37 os.makedirs(args.destdir)
Patrick Williams92b42cb2022-09-03 06:53:57 -050038 repos = parent.make_repo_config(args.destdir)
39 json = {"version":"1.0","sources":repos}
40 if not repos:
41 raise Exception("Could not determine layer sources")
42 output = args.output_prefix or "setup-layers"
43 output = os.path.join(os.path.abspath(args.destdir),output)
44 self._write_json(json, output + ".json")
45 logger.info('Created {}.json'.format(output))
46 if not args.json_only:
47 self._write_python(os.path.join(os.path.dirname(__file__),'../../../../scripts/oe-setup-layers'), output)
48 logger.info('Created {}'.format(output))
49
50 def register_arguments(self, parser):
51 parser.add_argument('--json-only', action='store_true',
52 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.')