diff options
Diffstat (limited to 'meta')
| -rw-r--r-- | meta/lib/bblayers/buildconf.py | 85 | ||||
| -rw-r--r-- | meta/lib/oeqa/selftest/cases/bblayers.py | 5 |
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 | |||
| 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.') | ||
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) |
