diff options
author | Alexander Kanavin <alex.kanavin@gmail.com> | 2022-08-31 13:13:56 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-09-01 10:07:02 +0100 |
commit | 3f9e3feb2225b681318c81dc9977b2b9656a373c (patch) | |
tree | ddd664836944b0e99ed61caa92a1b39fa94e9ec0 /meta/lib/bblayers | |
parent | 8791c77a4098d62080ecad09d94718eccd7f1a47 (diff) | |
download | poky-3f9e3feb2225b681318c81dc9977b2b9656a373c.tar.gz |
bitbake-layers: add a command to save the active build configuration as a template into a layer
This is the reverse of setting up a build by pointing TEMPLATECONF to a directory
with a template and running '. oe-init-build-env': this takes the config files from build/conf,
replaces site-specific paths in bblayers.conf with ##OECORE##-relative paths, and copies
the config files into a specified layer under a specified template name.
In many or perhaps most cases such static prefabricated configurations (that require no
further editing) are just enough, and I believe they should be offered by the
official configuration management. On the other hand, generating build configurations with a
sufficiently versatile tool is a far more complex problem, and one we should try to tackle
once we see where and how static configs fall short.
Tooling to discover and select these templates when setting up a build will be provided later on.
How to use:
alex@Zen2:/srv/work/alex/poky/build-layersetup$ bitbake-layers save-build-conf ../../meta-alex/ test-1
NOTE: Starting bitbake server...
NOTE: Configuration template placed into /srv/work/alex/meta-alex/conf/templates/test-1
Please review the files in there, and particularly provide a configuration description in /srv/work/alex/meta-alex/conf/templates/test-1/conf-notes.txt
You can try out the configuration with
TEMPLATECONF=/srv/work/alex/meta-alex/conf/templates/test-1 . /srv/work/alex/poky/oe-init-build-env build-try-test-1
alex@Zen2:/srv/work/alex/poky/build-layersetup$
(From OE-Core rev: f319534dc8fc68dfe120d129154a509f0cd6a3b0)
Signed-off-by: Alexander Kanavin <alex@linutronix.de>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/bblayers')
-rw-r--r-- | meta/lib/bblayers/buildconf.py | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/meta/lib/bblayers/buildconf.py b/meta/lib/bblayers/buildconf.py new file mode 100644 index 0000000000..e07fc534e1 --- /dev/null +++ b/meta/lib/bblayers/buildconf.py | |||
@@ -0,0 +1,85 @@ | |||
1 | # | ||
2 | # Copyright OpenEmbedded Contributors | ||
3 | # | ||
4 | # SPDX-License-Identifier: GPL-2.0-only | ||
5 | # | ||
6 | |||
7 | import logging | ||
8 | import os | ||
9 | import stat | ||
10 | import sys | ||
11 | import shutil | ||
12 | import json | ||
13 | |||
14 | import bb.utils | ||
15 | import bb.process | ||
16 | |||
17 | from bblayers.common import LayerPlugin | ||
18 | |||
19 | logger = logging.getLogger('bitbake-layers') | ||
20 | |||
21 | sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) | ||
22 | |||
23 | import oe.buildcfg | ||
24 | |||
25 | def plugin_init(plugins): | ||
26 | return BuildConfPlugin() | ||
27 | |||
28 | class BuildConfPlugin(LayerPlugin): | ||
29 | notes_fixme = """FIXME: Please place here the description of this build configuration. | ||
30 | It will be shown to the users when they set up their builds via TEMPLATECONF. | ||
31 | """ | ||
32 | |||
33 | def _save_conf(self, templatename, templatepath, oecorepath, relpaths_to_oecore): | ||
34 | confdir = os.path.join(os.environ["BBPATH"], "conf") | ||
35 | destdir = os.path.join(templatepath, "conf", "templates", templatename) | ||
36 | os.makedirs(destdir, exist_ok=True) | ||
37 | |||
38 | with open(os.path.join(confdir, "local.conf")) as src: | ||
39 | with open(os.path.join(destdir, "local.conf.sample"), 'w') as dest: | ||
40 | dest.write(src.read()) | ||
41 | |||
42 | with open(os.path.join(confdir, "bblayers.conf")) as src: | ||
43 | with open(os.path.join(destdir, "bblayers.conf.sample"), 'w') as dest: | ||
44 | bblayers_data = src.read() | ||
45 | |||
46 | for (abspath, relpath) in relpaths_to_oecore: | ||
47 | bblayers_data = bblayers_data.replace(abspath, "##OEROOT##/" + relpath) | ||
48 | dest.write(bblayers_data) | ||
49 | |||
50 | with open(os.path.join(destdir, "conf-notes.txt"), 'w') as dest: | ||
51 | dest.write(self.notes_fixme) | ||
52 | |||
53 | logger.info("""Configuration template placed into {} | ||
54 | Please review the files in there, and particularly provide a configuration description 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-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 | repos = {} | ||
62 | layers = oe.buildcfg.get_layer_revisions(self.tinfoil.config_data) | ||
63 | targetlayer = None | ||
64 | oecore = None | ||
65 | |||
66 | for l in layers: | ||
67 | if l[0] == os.path.abspath(args.layerpath): | ||
68 | targetlayer = l[0] | ||
69 | if l[1] == 'meta': | ||
70 | oecore = os.path.dirname(l[0]) | ||
71 | |||
72 | if not targetlayer: | ||
73 | logger.error("Layer {} not in one of the currently enabled layers:\n{}".format(args.layerpath, "\n".join([l[0] for l in layers]))) | ||
74 | elif not oecore: | ||
75 | logger.error("Openembedded-core not in one of the currently enabled layers:\n{}".format("\n".join([l[0] for l in layers]))) | ||
76 | else: | ||
77 | relpaths_to_oecore = [(l[0], os.path.relpath(l[0], start=oecore)) for l in layers] | ||
78 | self._save_conf(args.templatename, targetlayer, oecore, relpaths_to_oecore) | ||
79 | |||
80 | def register_commands(self, sp): | ||
81 | parser_build_conf = self.add_command(sp, 'save-build-conf', self.do_save_build_conf, parserecipes=False) | ||
82 | parser_build_conf.add_argument('layerpath', | ||
83 | help='The path to the layer where the configuration template should be saved.') | ||
84 | parser_build_conf.add_argument('templatename', | ||
85 | help='The name of the configuration template.') | ||