summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/parse/parse_py/ConfHandler.py
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2022-11-27 17:08:04 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-12-08 11:15:47 +0000
commit42e8b2682f56f450c1258956213198052d6bcb96 (patch)
tree6e1e223a179f5df5651fe3742b0e8afa55339597 /bitbake/lib/bb/parse/parse_py/ConfHandler.py
parentf4ffba353eb7877060c25d264fa10cd60f797f0b (diff)
downloadpoky-42e8b2682f56f450c1258956213198052d6bcb96.tar.gz
bitbake: parse: Add support for addpylib conf file directive and BB_GLOBAL_PYMODULES
For many years OE-Core has injected it's own python modules into the python namespace using an immediate expansion of a variable in base.bbclass. It also added all entries from BBPATH to sys.path. We really need this to become a first class citizen of the langauge, this new addpylib directive allows that. Usage is of the form: addpylib <directory> <namespace> The namespace is imported and if there is an attribute BBIMPORT, that list of names is iterated and imported too. This mirrors what OE-Core has done for a long time with one difference in implmentation, sys.path is only appended to. This means later imported namespaces can't overwrite an earlier one and can't overwrite the main python module space. In practice we've never done that and it isn't something we should encourage or support. The new directive is only applied for .conf files and not other filetypes as it only makes sense in that context. It is also only allowed in the "base configuration" context of cookerdata since adding it at the recipe level wouldn't work properly due to the way it changes the global namespace. At the same time, move the list of modules to place in the global namespace into a BB_GLOBAL_PYMODULES variable. It is intended that only the core layer should touch this and it is meant to be a very small list, usually os and sys. BB_GLOBAL_PYMODULES is expected to be set before the first addpylib directive. Layers adding a lib directory will now need to use this directive as BBPATH is not going to be added automatically by OE-Core in future. The directives are immediate operations so it does make modules available sooner than the current OE-Core approach. The new code appends to sys.path rather than prepends as core did, as overwriting python standard library modules would be a bad idea and naturally encouraging people to collaborate around our own core modules is desireable. (Bitbake rev: afb8478d3853f6edf3669b93588314627d617d6b) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/parse/parse_py/ConfHandler.py')
-rw-r--r--bitbake/lib/bb/parse/parse_py/ConfHandler.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/bitbake/lib/bb/parse/parse_py/ConfHandler.py b/bitbake/lib/bb/parse/parse_py/ConfHandler.py
index 451e68dd66..3076067287 100644
--- a/bitbake/lib/bb/parse/parse_py/ConfHandler.py
+++ b/bitbake/lib/bb/parse/parse_py/ConfHandler.py
@@ -46,6 +46,7 @@ __require_regexp__ = re.compile( r"require\s+(.+)" )
46__export_regexp__ = re.compile( r"export\s+([a-zA-Z0-9\-_+.${}/~]+)$" ) 46__export_regexp__ = re.compile( r"export\s+([a-zA-Z0-9\-_+.${}/~]+)$" )
47__unset_regexp__ = re.compile( r"unset\s+([a-zA-Z0-9\-_+.${}/~]+)$" ) 47__unset_regexp__ = re.compile( r"unset\s+([a-zA-Z0-9\-_+.${}/~]+)$" )
48__unset_flag_regexp__ = re.compile( r"unset\s+([a-zA-Z0-9\-_+.${}/~]+)\[([a-zA-Z0-9\-_+.]+)\]$" ) 48__unset_flag_regexp__ = re.compile( r"unset\s+([a-zA-Z0-9\-_+.${}/~]+)\[([a-zA-Z0-9\-_+.]+)\]$" )
49__addpylib_regexp__ = re.compile(r"addpylib\s+(.+)\s+(.+)" )
49 50
50def init(data): 51def init(data):
51 return 52 return
@@ -107,7 +108,7 @@ def include_single_file(parentfn, fn, lineno, data, error_out):
107# parsing. This turns out to be a hard problem to solve any other way. 108# parsing. This turns out to be a hard problem to solve any other way.
108confFilters = [] 109confFilters = []
109 110
110def handle(fn, data, include): 111def handle(fn, data, include, baseconfig=False):
111 init(data) 112 init(data)
112 113
113 if include == 0: 114 if include == 0:
@@ -144,7 +145,7 @@ def handle(fn, data, include):
144 # skip comments 145 # skip comments
145 if s[0] == '#': 146 if s[0] == '#':
146 continue 147 continue
147 feeder(lineno, s, abs_fn, statements) 148 feeder(lineno, s, abs_fn, statements, baseconfig=baseconfig)
148 149
149 # DONE WITH PARSING... time to evaluate 150 # DONE WITH PARSING... time to evaluate
150 data.setVar('FILE', abs_fn) 151 data.setVar('FILE', abs_fn)
@@ -157,7 +158,9 @@ def handle(fn, data, include):
157 158
158 return data 159 return data
159 160
160def feeder(lineno, s, fn, statements): 161# baseconfig is set for the bblayers/layer.conf cookerdata config parsing
162# The function is also used by BBHandler, conffile would be False
163def feeder(lineno, s, fn, statements, baseconfig=False, conffile=True):
161 m = __config_regexp__.match(s) 164 m = __config_regexp__.match(s)
162 if m: 165 if m:
163 groupd = m.groupdict() 166 groupd = m.groupdict()
@@ -189,6 +192,11 @@ def feeder(lineno, s, fn, statements):
189 ast.handleUnsetFlag(statements, fn, lineno, m) 192 ast.handleUnsetFlag(statements, fn, lineno, m)
190 return 193 return
191 194
195 m = __addpylib_regexp__.match(s)
196 if baseconfig and conffile and m:
197 ast.handlePyLib(statements, fn, lineno, m)
198 return
199
192 raise ParseError("unparsed line: '%s'" % s, fn, lineno); 200 raise ParseError("unparsed line: '%s'" % s, fn, lineno);
193 201
194# Add us to the handlers list 202# Add us to the handlers list