diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-06-10 22:37:54 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-06-27 15:19:29 +0100 |
commit | a8d47b45f3a7be76339fc70ec95f086e544b5c9a (patch) | |
tree | 891eca2a8e84fc51c8bf7750f0b182af441cae86 | |
parent | 45abcdf0d1f656bff8110cc07a457901eca492ab (diff) | |
download | poky-a8d47b45f3a7be76339fc70ec95f086e544b5c9a.tar.gz |
Revert "bitbake-config-build: add a plugin for config fragments"
This reverts commit bf5f18f5a14f238604cefe097fda66684d5a107c.
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | meta-selftest/conf/fragments/selftest/test-another-fragment.inc | 4 | ||||
-rw-r--r-- | meta-selftest/conf/fragments/selftest/test-fragment.inc | 4 | ||||
-rw-r--r-- | meta/lib/bbconfigbuild/configfragments.py | 117 | ||||
-rw-r--r-- | meta/lib/oeqa/selftest/cases/bblayers.py | 21 |
4 files changed, 0 insertions, 146 deletions
diff --git a/meta-selftest/conf/fragments/selftest/test-another-fragment.inc b/meta-selftest/conf/fragments/selftest/test-another-fragment.inc deleted file mode 100644 index 4f6c535de2..0000000000 --- a/meta-selftest/conf/fragments/selftest/test-another-fragment.inc +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | # This is a second configuration fragment intended for testing in oe-selftest context | ||
2 | # | ||
3 | # It defines another variable that can be checked inside the test. | ||
4 | SELFTEST_FRAGMENT_ANOTHER_VARIABLE = "someothervalue" | ||
diff --git a/meta-selftest/conf/fragments/selftest/test-fragment.inc b/meta-selftest/conf/fragments/selftest/test-fragment.inc deleted file mode 100644 index 0ad62db9e1..0000000000 --- a/meta-selftest/conf/fragments/selftest/test-fragment.inc +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | # This is a configuration fragment intended for testing in oe-selftest context | ||
2 | # | ||
3 | # It defines a variable that can be checked inside the test. | ||
4 | SELFTEST_FRAGMENT_VARIABLE = "somevalue" | ||
diff --git a/meta/lib/bbconfigbuild/configfragments.py b/meta/lib/bbconfigbuild/configfragments.py deleted file mode 100644 index d7e4f54dba..0000000000 --- a/meta/lib/bbconfigbuild/configfragments.py +++ /dev/null | |||
@@ -1,117 +0,0 @@ | |||
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 | import bb.utils | ||
12 | |||
13 | from bblayers.common import LayerPlugin | ||
14 | |||
15 | logger = logging.getLogger('bitbake-config-layers') | ||
16 | |||
17 | sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) | ||
18 | |||
19 | def plugin_init(plugins): | ||
20 | return ConfigFragmentsPlugin() | ||
21 | |||
22 | class ConfigFragmentsPlugin(LayerPlugin): | ||
23 | def get_fragment_info(self, path): | ||
24 | summary = "" | ||
25 | description = [] | ||
26 | with open(path) as f: | ||
27 | for l in f.readlines(): | ||
28 | if not l.startswith('#'): | ||
29 | break | ||
30 | if not summary: | ||
31 | summary = l[1:].strip() | ||
32 | else: | ||
33 | description.append(l[1:].strip()) | ||
34 | if not summary or not description: | ||
35 | raise Exception('Please add a one-line summary followed by a description as #-prefixed comments at the beginning of {}'.format(path)) | ||
36 | |||
37 | return summary, description | ||
38 | |||
39 | |||
40 | def discover_fragments(self): | ||
41 | allfragments = {} | ||
42 | for layername in self.bbfile_collections: | ||
43 | layerdir = self.bbfile_collections[layername] | ||
44 | fragments = [] | ||
45 | for topdir, dirs, files in os.walk(os.path.join(layerdir, 'conf/fragments')): | ||
46 | fragmentdir = topdir.split('conf/fragments/')[-1] | ||
47 | for fragmentfile in sorted(files): | ||
48 | fragmentname = "/".join((fragmentdir, fragmentfile.split('.')[0])) | ||
49 | fragmentpath = os.path.join(topdir, fragmentfile) | ||
50 | fragmentsummary, fragmentdesc = self.get_fragment_info(fragmentpath) | ||
51 | fragments.append({'path':fragmentpath, 'name':fragmentname, 'summary':fragmentsummary, 'description':fragmentdesc}) | ||
52 | if fragments: | ||
53 | allfragments[layername] = {'layerdir':layerdir,'fragments':fragments} | ||
54 | return allfragments | ||
55 | |||
56 | |||
57 | def do_list_fragments(self, args): | ||
58 | """ List available configuration fragments """ | ||
59 | for layername, layerdata in self.discover_fragments().items(): | ||
60 | layerdir = layerdata['layerdir'] | ||
61 | fragments = layerdata['fragments'] | ||
62 | |||
63 | print('Available fragments in {} layer located in {}:\n'.format(layername, layerdir)) | ||
64 | for f in fragments: | ||
65 | if not args.verbose: | ||
66 | print('{}\t{}'.format(f['name'], f['summary'])) | ||
67 | else: | ||
68 | print('Name: {}\nPath: {}\nSummary: {}\nDescription:\n{}\n'.format(f['name'], f['path'], f['summary'],''.join(f['description']))) | ||
69 | print('') | ||
70 | |||
71 | def fragment_exists(self, fragmentname): | ||
72 | for layername, layerdata in self.discover_fragments().items(): | ||
73 | for f in layerdata['fragments']: | ||
74 | if f['name'] == fragmentname: | ||
75 | return True | ||
76 | return False | ||
77 | |||
78 | def do_add_fragment(self, args): | ||
79 | """ Add a fragment to the local build configuration """ | ||
80 | if not self.fragment_exists(args.fragmentname): | ||
81 | raise Exception("Fragment {} does not exist; use 'list-fragments' to see the full list.".format(args.fragmentname)) | ||
82 | |||
83 | confpath = os.path.join(os.environ["BBPATH"], "conf/local.conf") | ||
84 | appendline = "require conf/fragments/{}.inc\n".format(args.fragmentname) | ||
85 | |||
86 | with open(confpath) as f: | ||
87 | lines = f.readlines() | ||
88 | for l in lines: | ||
89 | if l == appendline: | ||
90 | print("Fragment {} already included in {}".format(args.fragmentname, confpath)) | ||
91 | return | ||
92 | |||
93 | lines.append(appendline) | ||
94 | with open(confpath, 'w') as f: | ||
95 | f.write(''.join(lines)) | ||
96 | |||
97 | def do_remove_fragment(self, args): | ||
98 | """ Remove a fragment from the local build configuration """ | ||
99 | confpath = os.path.join(os.environ["BBPATH"], "conf/local.conf") | ||
100 | appendline = "require conf/fragments/{}.inc\n".format(args.fragmentname) | ||
101 | |||
102 | with open(confpath) as f: | ||
103 | lines = f.readlines() | ||
104 | lines = [l for l in lines if l != appendline] | ||
105 | |||
106 | with open(confpath, 'w') as f: | ||
107 | f.write(''.join(lines)) | ||
108 | |||
109 | def register_commands(self, sp): | ||
110 | parser_list_fragments = self.add_command(sp, 'list-fragments', self.do_list_fragments, parserecipes=False) | ||
111 | parser_list_fragments.add_argument('--verbose', '-v', action='store_true', help='Print extended descriptions of the fragments') | ||
112 | |||
113 | parser_add_fragment = self.add_command(sp, 'add-fragment', self.do_add_fragment, parserecipes=False) | ||
114 | parser_add_fragment.add_argument('fragmentname', help='The name of the fragment (use list-fragments to see them)') | ||
115 | |||
116 | parser_remove_fragment = self.add_command(sp, 'remove-fragment', self.do_remove_fragment, parserecipes=False) | ||
117 | parser_remove_fragment.add_argument('fragmentname', help='The name of the fragment') | ||
diff --git a/meta/lib/oeqa/selftest/cases/bblayers.py b/meta/lib/oeqa/selftest/cases/bblayers.py index 9e75ef6928..8b2bc319d5 100644 --- a/meta/lib/oeqa/selftest/cases/bblayers.py +++ b/meta/lib/oeqa/selftest/cases/bblayers.py | |||
@@ -253,24 +253,3 @@ class BitbakeLayers(OESelftestTestCase): | |||
253 | meta_selftest_found = True | 253 | meta_selftest_found = True |
254 | self.assertTrue(oe_core_found, "meta/conf/layer.conf not found in {}".format(testcopydir)) | 254 | self.assertTrue(oe_core_found, "meta/conf/layer.conf not found in {}".format(testcopydir)) |
255 | self.assertTrue(meta_selftest_found, "meta-selftest/conf/layer.conf not found in {}".format(testcopydir)) | 255 | self.assertTrue(meta_selftest_found, "meta-selftest/conf/layer.conf not found in {}".format(testcopydir)) |
256 | |||
257 | class BitbakeConfigBuild(OESelftestTestCase): | ||
258 | def test_add_remove_fragments(self): | ||
259 | self.assertEqual(get_bb_var('SELFTEST_FRAGMENT_VARIABLE'), None) | ||
260 | self.assertEqual(get_bb_var('SELFTEST_FRAGMENT_ANOTHER_VARIABLE'), None) | ||
261 | |||
262 | runCmd('bitbake-config-build add-fragment selftest/test-fragment') | ||
263 | self.assertEqual(get_bb_var('SELFTEST_FRAGMENT_VARIABLE'), 'somevalue') | ||
264 | self.assertEqual(get_bb_var('SELFTEST_FRAGMENT_ANOTHER_VARIABLE'), None) | ||
265 | |||
266 | runCmd('bitbake-config-build add-fragment selftest/test-another-fragment') | ||
267 | self.assertEqual(get_bb_var('SELFTEST_FRAGMENT_VARIABLE'), 'somevalue') | ||
268 | self.assertEqual(get_bb_var('SELFTEST_FRAGMENT_ANOTHER_VARIABLE'), 'someothervalue') | ||
269 | |||
270 | runCmd('bitbake-config-build remove-fragment selftest/test-fragment') | ||
271 | self.assertEqual(get_bb_var('SELFTEST_FRAGMENT_VARIABLE'), None) | ||
272 | self.assertEqual(get_bb_var('SELFTEST_FRAGMENT_ANOTHER_VARIABLE'), 'someothervalue') | ||
273 | |||
274 | runCmd('bitbake-config-build remove-fragment selftest/test-another-fragment') | ||
275 | self.assertEqual(get_bb_var('SELFTEST_FRAGMENT_VARIABLE'), None) | ||
276 | self.assertEqual(get_bb_var('SELFTEST_FRAGMENT_ANOTHER_VARIABLE'), None) | ||