diff options
Diffstat (limited to 'meta/lib/bblayers/buildconf.py')
-rw-r--r-- | meta/lib/bblayers/buildconf.py | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/meta/lib/bblayers/buildconf.py b/meta/lib/bblayers/buildconf.py new file mode 100644 index 0000000000..722cf0723c --- /dev/null +++ b/meta/lib/bblayers/buildconf.py | |||
@@ -0,0 +1,84 @@ | |||
1 | # | ||
2 | # Copyright OpenEmbedded Contributors | ||
3 | # | ||
4 | # SPDX-License-Identifier: GPL-2.0-only | ||
5 | # | ||
6 | |||
7 | import logging | ||
8 | import os | ||
9 | import sys | ||
10 | |||
11 | from bblayers.common import LayerPlugin | ||
12 | |||
13 | logger = logging.getLogger('bitbake-layers') | ||
14 | |||
15 | sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) | ||
16 | |||
17 | import oe.buildcfg | ||
18 | |||
19 | def plugin_init(plugins): | ||
20 | return BuildConfPlugin() | ||
21 | |||
22 | class BuildConfPlugin(LayerPlugin): | ||
23 | notes_fixme = """FIXME: Please place here the detailed instructions for using this build configuration. | ||
24 | They will be shown to the users when they set up their builds via TEMPLATECONF. | ||
25 | """ | ||
26 | summary_fixme = """FIXME: Please place here the short summary of what this build configuration is for. | ||
27 | It will be shown to the users when they set up their builds via TEMPLATECONF. | ||
28 | """ | ||
29 | |||
30 | def _save_conf(self, templatename, templatepath, oecorepath, relpaths_to_oecore): | ||
31 | confdir = os.path.join(os.environ["BBPATH"], "conf") | ||
32 | destdir = os.path.join(templatepath, "conf", "templates", templatename) | ||
33 | os.makedirs(destdir, exist_ok=True) | ||
34 | |||
35 | with open(os.path.join(confdir, "local.conf")) as src: | ||
36 | with open(os.path.join(destdir, "local.conf.sample"), 'w') as dest: | ||
37 | dest.write(src.read()) | ||
38 | |||
39 | with open(os.path.join(confdir, "bblayers.conf")) as src: | ||
40 | with open(os.path.join(destdir, "bblayers.conf.sample"), 'w') as dest: | ||
41 | bblayers_data = src.read() | ||
42 | |||
43 | for (abspath, relpath) in relpaths_to_oecore: | ||
44 | bblayers_data = bblayers_data.replace(abspath, "##OEROOT##/" + relpath) | ||
45 | dest.write(bblayers_data) | ||
46 | |||
47 | with open(os.path.join(destdir, "conf-summary.txt"), 'w') as dest: | ||
48 | dest.write(self.summary_fixme) | ||
49 | with open(os.path.join(destdir, "conf-notes.txt"), 'w') as dest: | ||
50 | dest.write(self.notes_fixme) | ||
51 | |||
52 | logger.info("""Configuration template placed into {} | ||
53 | Please review the files in there, and particularly provide a configuration summary in {} | ||
54 | and notes in {} | ||
55 | You can try out the configuration with | ||
56 | TEMPLATECONF={} . {}/oe-init-build-env build-try-{}""" | ||
57 | .format(destdir, os.path.join(destdir, "conf-summary.txt"), os.path.join(destdir, "conf-notes.txt"), destdir, oecorepath, templatename)) | ||
58 | |||
59 | def do_save_build_conf(self, args): | ||
60 | """ Save the currently active build configuration (conf/local.conf, conf/bblayers.conf) as a template into a layer.\n This template can later be used for setting up builds via TEMPLATECONF. """ | ||
61 | layers = oe.buildcfg.get_layer_revisions(self.tinfoil.config_data) | ||
62 | targetlayer = None | ||
63 | oecore = None | ||
64 | |||
65 | for l in layers: | ||
66 | if os.path.abspath(l[0]) == os.path.abspath(args.layerpath): | ||
67 | targetlayer = l[0] | ||
68 | if l[1] == 'meta': | ||
69 | oecore = os.path.dirname(l[0]) | ||
70 | |||
71 | if not targetlayer: | ||
72 | logger.error("Layer {} not in one of the currently enabled layers:\n{}".format(args.layerpath, "\n".join([l[0] for l in layers]))) | ||
73 | elif not oecore: | ||
74 | logger.error("Openembedded-core not in one of the currently enabled layers:\n{}".format("\n".join([l[0] for l in layers]))) | ||
75 | else: | ||
76 | relpaths_to_oecore = [(l[0], os.path.relpath(l[0], start=oecore)) for l in layers] | ||
77 | self._save_conf(args.templatename, targetlayer, oecore, relpaths_to_oecore) | ||
78 | |||
79 | def register_commands(self, sp): | ||
80 | parser_build_conf = self.add_command(sp, 'save-build-conf', self.do_save_build_conf, parserecipes=False) | ||
81 | parser_build_conf.add_argument('layerpath', | ||
82 | help='The path to the layer where the configuration template should be saved.') | ||
83 | parser_build_conf.add_argument('templatename', | ||
84 | help='The name of the configuration template.') | ||