summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kanavin <alex.kanavin@gmail.com>2022-08-31 13:13:56 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-09-01 10:07:02 +0100
commit3f9e3feb2225b681318c81dc9977b2b9656a373c (patch)
treeddd664836944b0e99ed61caa92a1b39fa94e9ec0
parent8791c77a4098d62080ecad09d94718eccd7f1a47 (diff)
downloadpoky-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>
-rw-r--r--meta/lib/bblayers/buildconf.py85
-rw-r--r--meta/lib/oeqa/selftest/cases/bblayers.py5
2 files changed, 90 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
7import logging
8import os
9import stat
10import sys
11import shutil
12import json
13
14import bb.utils
15import bb.process
16
17from bblayers.common import LayerPlugin
18
19logger = logging.getLogger('bitbake-layers')
20
21sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
22
23import oe.buildcfg
24
25def plugin_init(plugins):
26 return BuildConfPlugin()
27
28class BuildConfPlugin(LayerPlugin):
29 notes_fixme = """FIXME: Please place here the description of this build configuration.
30It 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 {}
54Please review the files in there, and particularly provide a configuration description in {}
55You can try out the configuration with
56TEMPLATECONF={} . {}/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.')
diff --git a/meta/lib/oeqa/selftest/cases/bblayers.py b/meta/lib/oeqa/selftest/cases/bblayers.py
index 494fa892a3..549abe7d10 100644
--- a/meta/lib/oeqa/selftest/cases/bblayers.py
+++ b/meta/lib/oeqa/selftest/cases/bblayers.py
@@ -113,6 +113,11 @@ class BitbakeLayers(OESelftestTestCase):
113 113
114 self.assertEqual(bb_vars['BBFILE_PRIORITY_%s' % layername], str(priority), 'BBFILE_PRIORITY_%s != %d' % (layername, priority)) 114 self.assertEqual(bb_vars['BBFILE_PRIORITY_%s' % layername], str(priority), 'BBFILE_PRIORITY_%s != %d' % (layername, priority))
115 115
116 result = runCmd('bitbake-layers save-build-conf {} {}'.format(layerpath, "buildconf-1"))
117 for f in ('local.conf.sample', 'bblayers.conf.sample', 'conf-notes.txt'):
118 fullpath = os.path.join(layerpath, "conf", "templates", "buildconf-1", f)
119 self.assertTrue(os.path.exists(fullpath), "Template configuration file {} not found".format(fullpath))
120
116 def get_recipe_basename(self, recipe): 121 def get_recipe_basename(self, recipe):
117 recipe_file = "" 122 recipe_file = ""
118 result = runCmd("bitbake-layers show-recipes -f %s" % recipe) 123 result = runCmd("bitbake-layers show-recipes -f %s" % recipe)