diff options
Diffstat (limited to 'bitbake/lib/bb/parse')
-rw-r--r-- | bitbake/lib/bb/parse/__init__.py | 61 | ||||
-rw-r--r-- | bitbake/lib/bb/parse/ast.py | 217 | ||||
-rw-r--r-- | bitbake/lib/bb/parse/parse_py/BBHandler.py | 125 | ||||
-rw-r--r-- | bitbake/lib/bb/parse/parse_py/ConfHandler.py | 58 |
4 files changed, 373 insertions, 88 deletions
diff --git a/bitbake/lib/bb/parse/__init__.py b/bitbake/lib/bb/parse/__init__.py index c01807ba87..d428d8a4b4 100644 --- a/bitbake/lib/bb/parse/__init__.py +++ b/bitbake/lib/bb/parse/__init__.py | |||
@@ -49,20 +49,32 @@ class SkipPackage(SkipRecipe): | |||
49 | __mtime_cache = {} | 49 | __mtime_cache = {} |
50 | def cached_mtime(f): | 50 | def cached_mtime(f): |
51 | if f not in __mtime_cache: | 51 | if f not in __mtime_cache: |
52 | __mtime_cache[f] = os.stat(f)[stat.ST_MTIME] | 52 | res = os.stat(f) |
53 | __mtime_cache[f] = (res.st_mtime_ns, res.st_size, res.st_ino) | ||
53 | return __mtime_cache[f] | 54 | return __mtime_cache[f] |
54 | 55 | ||
55 | def cached_mtime_noerror(f): | 56 | def cached_mtime_noerror(f): |
56 | if f not in __mtime_cache: | 57 | if f not in __mtime_cache: |
57 | try: | 58 | try: |
58 | __mtime_cache[f] = os.stat(f)[stat.ST_MTIME] | 59 | res = os.stat(f) |
60 | __mtime_cache[f] = (res.st_mtime_ns, res.st_size, res.st_ino) | ||
59 | except OSError: | 61 | except OSError: |
60 | return 0 | 62 | return 0 |
61 | return __mtime_cache[f] | 63 | return __mtime_cache[f] |
62 | 64 | ||
65 | def check_mtime(f, mtime): | ||
66 | try: | ||
67 | res = os.stat(f) | ||
68 | current_mtime = (res.st_mtime_ns, res.st_size, res.st_ino) | ||
69 | __mtime_cache[f] = current_mtime | ||
70 | except OSError: | ||
71 | current_mtime = 0 | ||
72 | return current_mtime == mtime | ||
73 | |||
63 | def update_mtime(f): | 74 | def update_mtime(f): |
64 | try: | 75 | try: |
65 | __mtime_cache[f] = os.stat(f)[stat.ST_MTIME] | 76 | res = os.stat(f) |
77 | __mtime_cache[f] = (res.st_mtime_ns, res.st_size, res.st_ino) | ||
66 | except OSError: | 78 | except OSError: |
67 | if f in __mtime_cache: | 79 | if f in __mtime_cache: |
68 | del __mtime_cache[f] | 80 | del __mtime_cache[f] |
@@ -99,12 +111,12 @@ def supports(fn, data): | |||
99 | return 1 | 111 | return 1 |
100 | return 0 | 112 | return 0 |
101 | 113 | ||
102 | def handle(fn, data, include = 0): | 114 | def handle(fn, data, include=0, baseconfig=False): |
103 | """Call the handler that is appropriate for this file""" | 115 | """Call the handler that is appropriate for this file""" |
104 | for h in handlers: | 116 | for h in handlers: |
105 | if h['supports'](fn, data): | 117 | if h['supports'](fn, data): |
106 | with data.inchistory.include(fn): | 118 | with data.inchistory.include(fn): |
107 | return h['handle'](fn, data, include) | 119 | return h['handle'](fn, data, include, baseconfig) |
108 | raise ParseError("not a BitBake file", fn) | 120 | raise ParseError("not a BitBake file", fn) |
109 | 121 | ||
110 | def init(fn, data): | 122 | def init(fn, data): |
@@ -113,6 +125,8 @@ def init(fn, data): | |||
113 | return h['init'](data) | 125 | return h['init'](data) |
114 | 126 | ||
115 | def init_parser(d): | 127 | def init_parser(d): |
128 | if hasattr(bb.parse, "siggen"): | ||
129 | bb.parse.siggen.exit() | ||
116 | bb.parse.siggen = bb.siggen.init(d) | 130 | bb.parse.siggen = bb.siggen.init(d) |
117 | 131 | ||
118 | def resolve_file(fn, d): | 132 | def resolve_file(fn, d): |
@@ -162,4 +176,41 @@ def get_file_depends(d): | |||
162 | dep_files.append(os.path.abspath(fn)) | 176 | dep_files.append(os.path.abspath(fn)) |
163 | return " ".join(dep_files) | 177 | return " ".join(dep_files) |
164 | 178 | ||
179 | def vardeps(*varnames): | ||
180 | """ | ||
181 | Function decorator that can be used to instruct the bitbake dependency | ||
182 | parsing to add a dependency on the specified variables names | ||
183 | |||
184 | Example: | ||
185 | |||
186 | @bb.parse.vardeps("FOO", "BAR") | ||
187 | def my_function(): | ||
188 | ... | ||
189 | |||
190 | """ | ||
191 | def inner(f): | ||
192 | if not hasattr(f, "bb_vardeps"): | ||
193 | f.bb_vardeps = set() | ||
194 | f.bb_vardeps |= set(varnames) | ||
195 | return f | ||
196 | return inner | ||
197 | |||
198 | def vardepsexclude(*varnames): | ||
199 | """ | ||
200 | Function decorator that can be used to instruct the bitbake dependency | ||
201 | parsing to ignore dependencies on the specified variable names in the code | ||
202 | |||
203 | Example: | ||
204 | |||
205 | @bb.parse.vardepsexclude("FOO", "BAR") | ||
206 | def my_function(): | ||
207 | ... | ||
208 | """ | ||
209 | def inner(f): | ||
210 | if not hasattr(f, "bb_vardepsexclude"): | ||
211 | f.bb_vardepsexclude = set() | ||
212 | f.bb_vardepsexclude |= set(varnames) | ||
213 | return f | ||
214 | return inner | ||
215 | |||
165 | from bb.parse.parse_py import __version__, ConfHandler, BBHandler | 216 | from bb.parse.parse_py import __version__, ConfHandler, BBHandler |
diff --git a/bitbake/lib/bb/parse/ast.py b/bitbake/lib/bb/parse/ast.py index 50a88f7da7..49a0788038 100644 --- a/bitbake/lib/bb/parse/ast.py +++ b/bitbake/lib/bb/parse/ast.py | |||
@@ -9,6 +9,7 @@ | |||
9 | # SPDX-License-Identifier: GPL-2.0-only | 9 | # SPDX-License-Identifier: GPL-2.0-only |
10 | # | 10 | # |
11 | 11 | ||
12 | import sys | ||
12 | import bb | 13 | import bb |
13 | from bb import methodpool | 14 | from bb import methodpool |
14 | from bb.parse import logger | 15 | from bb.parse import logger |
@@ -42,6 +43,21 @@ class IncludeNode(AstNode): | |||
42 | else: | 43 | else: |
43 | bb.parse.ConfHandler.include(self.filename, s, self.lineno, data, False) | 44 | bb.parse.ConfHandler.include(self.filename, s, self.lineno, data, False) |
44 | 45 | ||
46 | class IncludeAllNode(AstNode): | ||
47 | def __init__(self, filename, lineno, what_file): | ||
48 | AstNode.__init__(self, filename, lineno) | ||
49 | self.what_file = what_file | ||
50 | |||
51 | def eval(self, data): | ||
52 | """ | ||
53 | Include the file and evaluate the statements | ||
54 | """ | ||
55 | s = data.expand(self.what_file) | ||
56 | logger.debug2("CONF %s:%s: including %s", self.filename, self.lineno, s) | ||
57 | |||
58 | for path in data.getVar("BBPATH").split(":"): | ||
59 | bb.parse.ConfHandler.include(self.filename, os.path.join(path, s), self.lineno, data, False) | ||
60 | |||
45 | class ExportNode(AstNode): | 61 | class ExportNode(AstNode): |
46 | def __init__(self, filename, lineno, var): | 62 | def __init__(self, filename, lineno, var): |
47 | AstNode.__init__(self, filename, lineno) | 63 | AstNode.__init__(self, filename, lineno) |
@@ -130,9 +146,16 @@ class DataNode(AstNode): | |||
130 | else: | 146 | else: |
131 | val = groupd["value"] | 147 | val = groupd["value"] |
132 | 148 | ||
149 | if ":append" in key or ":remove" in key or ":prepend" in key: | ||
150 | if op in ["append", "prepend", "postdot", "predot", "ques"]: | ||
151 | bb.warn(key + " " + groupd[op] + " is not a recommended operator combination, please replace it.") | ||
152 | |||
133 | flag = None | 153 | flag = None |
134 | if 'flag' in groupd and groupd['flag'] is not None: | 154 | if 'flag' in groupd and groupd['flag'] is not None: |
135 | flag = groupd['flag'] | 155 | if groupd["lazyques"]: |
156 | flag = "_defaultval_flag_"+groupd['flag'] | ||
157 | else: | ||
158 | flag = groupd['flag'] | ||
136 | elif groupd["lazyques"]: | 159 | elif groupd["lazyques"]: |
137 | flag = "_defaultval" | 160 | flag = "_defaultval" |
138 | 161 | ||
@@ -145,7 +168,7 @@ class DataNode(AstNode): | |||
145 | data.setVar(key, val, parsing=True, **loginfo) | 168 | data.setVar(key, val, parsing=True, **loginfo) |
146 | 169 | ||
147 | class MethodNode(AstNode): | 170 | class MethodNode(AstNode): |
148 | tr_tbl = str.maketrans('/.+-@%&', '_______') | 171 | tr_tbl = str.maketrans('/.+-@%&~', '________') |
149 | 172 | ||
150 | def __init__(self, filename, lineno, func_name, body, python, fakeroot): | 173 | def __init__(self, filename, lineno, func_name, body, python, fakeroot): |
151 | AstNode.__init__(self, filename, lineno) | 174 | AstNode.__init__(self, filename, lineno) |
@@ -206,10 +229,12 @@ class ExportFuncsNode(AstNode): | |||
206 | 229 | ||
207 | def eval(self, data): | 230 | def eval(self, data): |
208 | 231 | ||
232 | sentinel = " # Export function set\n" | ||
209 | for func in self.n: | 233 | for func in self.n: |
210 | calledfunc = self.classname + "_" + func | 234 | calledfunc = self.classname + "_" + func |
211 | 235 | ||
212 | if data.getVar(func, False) and not data.getVarFlag(func, 'export_func', False): | 236 | basevar = data.getVar(func, False) |
237 | if basevar and sentinel not in basevar: | ||
213 | continue | 238 | continue |
214 | 239 | ||
215 | if data.getVar(func, False): | 240 | if data.getVar(func, False): |
@@ -219,29 +244,30 @@ class ExportFuncsNode(AstNode): | |||
219 | for flag in [ "func", "python" ]: | 244 | for flag in [ "func", "python" ]: |
220 | if data.getVarFlag(calledfunc, flag, False): | 245 | if data.getVarFlag(calledfunc, flag, False): |
221 | data.setVarFlag(func, flag, data.getVarFlag(calledfunc, flag, False)) | 246 | data.setVarFlag(func, flag, data.getVarFlag(calledfunc, flag, False)) |
222 | for flag in [ "dirs" ]: | 247 | for flag in ["dirs", "cleandirs", "fakeroot"]: |
223 | if data.getVarFlag(func, flag, False): | 248 | if data.getVarFlag(func, flag, False): |
224 | data.setVarFlag(calledfunc, flag, data.getVarFlag(func, flag, False)) | 249 | data.setVarFlag(calledfunc, flag, data.getVarFlag(func, flag, False)) |
225 | data.setVarFlag(func, "filename", "autogenerated") | 250 | data.setVarFlag(func, "filename", "autogenerated") |
226 | data.setVarFlag(func, "lineno", 1) | 251 | data.setVarFlag(func, "lineno", 1) |
227 | 252 | ||
228 | if data.getVarFlag(calledfunc, "python", False): | 253 | if data.getVarFlag(calledfunc, "python", False): |
229 | data.setVar(func, " bb.build.exec_func('" + calledfunc + "', d)\n", parsing=True) | 254 | data.setVar(func, sentinel + " bb.build.exec_func('" + calledfunc + "', d)\n", parsing=True) |
230 | else: | 255 | else: |
231 | if "-" in self.classname: | 256 | if "-" in self.classname: |
232 | bb.fatal("The classname %s contains a dash character and is calling an sh function %s using EXPORT_FUNCTIONS. Since a dash is illegal in sh function names, this cannot work, please rename the class or don't use EXPORT_FUNCTIONS." % (self.classname, calledfunc)) | 257 | bb.fatal("The classname %s contains a dash character and is calling an sh function %s using EXPORT_FUNCTIONS. Since a dash is illegal in sh function names, this cannot work, please rename the class or don't use EXPORT_FUNCTIONS." % (self.classname, calledfunc)) |
233 | data.setVar(func, " " + calledfunc + "\n", parsing=True) | 258 | data.setVar(func, sentinel + " " + calledfunc + "\n", parsing=True) |
234 | data.setVarFlag(func, 'export_func', '1') | ||
235 | 259 | ||
236 | class AddTaskNode(AstNode): | 260 | class AddTaskNode(AstNode): |
237 | def __init__(self, filename, lineno, func, before, after): | 261 | def __init__(self, filename, lineno, tasks, before, after): |
238 | AstNode.__init__(self, filename, lineno) | 262 | AstNode.__init__(self, filename, lineno) |
239 | self.func = func | 263 | self.tasks = tasks |
240 | self.before = before | 264 | self.before = before |
241 | self.after = after | 265 | self.after = after |
242 | 266 | ||
243 | def eval(self, data): | 267 | def eval(self, data): |
244 | bb.build.addtask(self.func, self.before, self.after, data) | 268 | tasks = self.tasks.split() |
269 | for task in tasks: | ||
270 | bb.build.addtask(task, self.before, self.after, data) | ||
245 | 271 | ||
246 | class DelTaskNode(AstNode): | 272 | class DelTaskNode(AstNode): |
247 | def __init__(self, filename, lineno, tasks): | 273 | def __init__(self, filename, lineno, tasks): |
@@ -265,6 +291,41 @@ class BBHandlerNode(AstNode): | |||
265 | data.setVarFlag(h, "handler", 1) | 291 | data.setVarFlag(h, "handler", 1) |
266 | data.setVar('__BBHANDLERS', bbhands) | 292 | data.setVar('__BBHANDLERS', bbhands) |
267 | 293 | ||
294 | class PyLibNode(AstNode): | ||
295 | def __init__(self, filename, lineno, libdir, namespace): | ||
296 | AstNode.__init__(self, filename, lineno) | ||
297 | self.libdir = libdir | ||
298 | self.namespace = namespace | ||
299 | |||
300 | def eval(self, data): | ||
301 | global_mods = (data.getVar("BB_GLOBAL_PYMODULES") or "").split() | ||
302 | for m in global_mods: | ||
303 | if m not in bb.utils._context: | ||
304 | bb.utils._context[m] = __import__(m) | ||
305 | |||
306 | libdir = data.expand(self.libdir) | ||
307 | if libdir not in sys.path: | ||
308 | sys.path.append(libdir) | ||
309 | try: | ||
310 | bb.utils._context[self.namespace] = __import__(self.namespace) | ||
311 | toimport = getattr(bb.utils._context[self.namespace], "BBIMPORTS", []) | ||
312 | for i in toimport: | ||
313 | bb.utils._context[self.namespace] = __import__(self.namespace + "." + i) | ||
314 | mod = getattr(bb.utils._context[self.namespace], i) | ||
315 | fn = getattr(mod, "__file__") | ||
316 | funcs = {} | ||
317 | for f in dir(mod): | ||
318 | if f.startswith("_"): | ||
319 | continue | ||
320 | fcall = getattr(mod, f) | ||
321 | if not callable(fcall): | ||
322 | continue | ||
323 | funcs[f] = fcall | ||
324 | bb.codeparser.add_module_functions(fn, funcs, "%s.%s" % (self.namespace, i)) | ||
325 | |||
326 | except AttributeError as e: | ||
327 | bb.error("Error importing OE modules: %s" % str(e)) | ||
328 | |||
268 | class InheritNode(AstNode): | 329 | class InheritNode(AstNode): |
269 | def __init__(self, filename, lineno, classes): | 330 | def __init__(self, filename, lineno, classes): |
270 | AstNode.__init__(self, filename, lineno) | 331 | AstNode.__init__(self, filename, lineno) |
@@ -273,9 +334,68 @@ class InheritNode(AstNode): | |||
273 | def eval(self, data): | 334 | def eval(self, data): |
274 | bb.parse.BBHandler.inherit(self.classes, self.filename, self.lineno, data) | 335 | bb.parse.BBHandler.inherit(self.classes, self.filename, self.lineno, data) |
275 | 336 | ||
337 | class InheritDeferredNode(AstNode): | ||
338 | def __init__(self, filename, lineno, classes): | ||
339 | AstNode.__init__(self, filename, lineno) | ||
340 | self.inherit = (classes, filename, lineno) | ||
341 | |||
342 | def eval(self, data): | ||
343 | bb.parse.BBHandler.inherit_defer(*self.inherit, data) | ||
344 | |||
345 | class AddFragmentsNode(AstNode): | ||
346 | def __init__(self, filename, lineno, fragments_path_prefix, fragments_variable, flagged_variables_list_variable, builtin_fragments_variable): | ||
347 | AstNode.__init__(self, filename, lineno) | ||
348 | self.fragments_path_prefix = fragments_path_prefix | ||
349 | self.fragments_variable = fragments_variable | ||
350 | self.flagged_variables_list_variable = flagged_variables_list_variable | ||
351 | self.builtin_fragments_variable = builtin_fragments_variable | ||
352 | |||
353 | def eval(self, data): | ||
354 | # No need to use mark_dependency since we would only match a fragment | ||
355 | # from a specific layer and there can only be a single layer with a | ||
356 | # given namespace. | ||
357 | def find_fragment(layers, layerid, full_fragment_name): | ||
358 | for layerpath in layers.split(): | ||
359 | candidate_fragment_path = os.path.join(layerpath, full_fragment_name) | ||
360 | if os.path.exists(candidate_fragment_path) and bb.utils.get_file_layer(candidate_fragment_path, data) == layerid: | ||
361 | return candidate_fragment_path | ||
362 | return None | ||
363 | |||
364 | def check_and_set_builtin_fragment(fragment, data, builtin_fragments): | ||
365 | prefix, value = fragment.split('/', 1) | ||
366 | if prefix in builtin_fragments.keys(): | ||
367 | data.setVar(builtin_fragments[prefix], value) | ||
368 | return True | ||
369 | return False | ||
370 | |||
371 | fragments = data.getVar(self.fragments_variable) | ||
372 | layers = data.getVar('BBLAYERS') | ||
373 | flagged_variables = data.getVar(self.flagged_variables_list_variable).split() | ||
374 | builtin_fragments = {f[0]:f[1] for f in [f.split(':') for f in data.getVar(self.builtin_fragments_variable).split()] } | ||
375 | |||
376 | if not fragments: | ||
377 | return | ||
378 | for f in fragments.split(): | ||
379 | if check_and_set_builtin_fragment(f, data, builtin_fragments): | ||
380 | continue | ||
381 | layerid, fragment_name = f.split('/', 1) | ||
382 | full_fragment_name = data.expand("{}/{}.conf".format(self.fragments_path_prefix, fragment_name)) | ||
383 | fragment_path = find_fragment(layers, layerid, full_fragment_name) | ||
384 | if fragment_path: | ||
385 | bb.parse.ConfHandler.include(self.filename, fragment_path, self.lineno, data, "include fragment") | ||
386 | for flagged_var in flagged_variables: | ||
387 | val = data.getVar(flagged_var) | ||
388 | data.setVarFlag(flagged_var, f, val) | ||
389 | data.setVar(flagged_var, None) | ||
390 | else: | ||
391 | bb.error("Could not find fragment {} in enabled layers: {}".format(f, layers)) | ||
392 | |||
276 | def handleInclude(statements, filename, lineno, m, force): | 393 | def handleInclude(statements, filename, lineno, m, force): |
277 | statements.append(IncludeNode(filename, lineno, m.group(1), force)) | 394 | statements.append(IncludeNode(filename, lineno, m.group(1), force)) |
278 | 395 | ||
396 | def handleIncludeAll(statements, filename, lineno, m): | ||
397 | statements.append(IncludeAllNode(filename, lineno, m.group(1))) | ||
398 | |||
279 | def handleExport(statements, filename, lineno, m): | 399 | def handleExport(statements, filename, lineno, m): |
280 | statements.append(ExportNode(filename, lineno, m.group(1))) | 400 | statements.append(ExportNode(filename, lineno, m.group(1))) |
281 | 401 | ||
@@ -297,38 +417,81 @@ def handlePythonMethod(statements, filename, lineno, funcname, modulename, body) | |||
297 | def handleExportFuncs(statements, filename, lineno, m, classname): | 417 | def handleExportFuncs(statements, filename, lineno, m, classname): |
298 | statements.append(ExportFuncsNode(filename, lineno, m.group(1), classname)) | 418 | statements.append(ExportFuncsNode(filename, lineno, m.group(1), classname)) |
299 | 419 | ||
300 | def handleAddTask(statements, filename, lineno, m): | 420 | def handleAddTask(statements, filename, lineno, tasks, before, after): |
301 | func = m.group("func") | 421 | statements.append(AddTaskNode(filename, lineno, tasks, before, after)) |
302 | before = m.group("before") | ||
303 | after = m.group("after") | ||
304 | if func is None: | ||
305 | return | ||
306 | |||
307 | statements.append(AddTaskNode(filename, lineno, func, before, after)) | ||
308 | 422 | ||
309 | def handleDelTask(statements, filename, lineno, m): | 423 | def handleDelTask(statements, filename, lineno, tasks): |
310 | func = m.group(1) | 424 | statements.append(DelTaskNode(filename, lineno, tasks)) |
311 | if func is None: | ||
312 | return | ||
313 | |||
314 | statements.append(DelTaskNode(filename, lineno, func)) | ||
315 | 425 | ||
316 | def handleBBHandlers(statements, filename, lineno, m): | 426 | def handleBBHandlers(statements, filename, lineno, m): |
317 | statements.append(BBHandlerNode(filename, lineno, m.group(1))) | 427 | statements.append(BBHandlerNode(filename, lineno, m.group(1))) |
318 | 428 | ||
429 | def handlePyLib(statements, filename, lineno, m): | ||
430 | statements.append(PyLibNode(filename, lineno, m.group(1), m.group(2))) | ||
431 | |||
319 | def handleInherit(statements, filename, lineno, m): | 432 | def handleInherit(statements, filename, lineno, m): |
320 | classes = m.group(1) | 433 | classes = m.group(1) |
321 | statements.append(InheritNode(filename, lineno, classes)) | 434 | statements.append(InheritNode(filename, lineno, classes)) |
322 | 435 | ||
436 | def handleInheritDeferred(statements, filename, lineno, m): | ||
437 | classes = m.group(1) | ||
438 | statements.append(InheritDeferredNode(filename, lineno, classes)) | ||
439 | |||
440 | def handleAddFragments(statements, filename, lineno, m): | ||
441 | fragments_path_prefix = m.group(1) | ||
442 | fragments_variable = m.group(2) | ||
443 | flagged_variables_list_variable = m.group(3) | ||
444 | builtin_fragments_variable = m.group(4) | ||
445 | statements.append(AddFragmentsNode(filename, lineno, fragments_path_prefix, fragments_variable, flagged_variables_list_variable, builtin_fragments_variable)) | ||
446 | |||
323 | def runAnonFuncs(d): | 447 | def runAnonFuncs(d): |
324 | code = [] | 448 | code = [] |
325 | for funcname in d.getVar("__BBANONFUNCS", False) or []: | 449 | for funcname in d.getVar("__BBANONFUNCS", False) or []: |
326 | code.append("%s(d)" % funcname) | 450 | code.append("%s(d)" % funcname) |
327 | bb.utils.better_exec("\n".join(code), {"d": d}) | 451 | bb.utils.better_exec("\n".join(code), {"d": d}) |
328 | 452 | ||
453 | # Handle recipe level PREFERRED_PROVIDERs | ||
454 | def handleVirtRecipeProviders(tasklist, d): | ||
455 | depends = (d.getVar("DEPENDS") or "").split() | ||
456 | virtprovs = (d.getVar("BB_RECIPE_VIRTUAL_PROVIDERS") or "").split() | ||
457 | newdeps = [] | ||
458 | for dep in depends: | ||
459 | if dep in virtprovs: | ||
460 | newdep = d.getVar("PREFERRED_PROVIDER_" + dep) | ||
461 | if not newdep: | ||
462 | bb.fatal("Error, recipe virtual provider PREFERRED_PROVIDER_%s not set" % dep) | ||
463 | newdeps.append(newdep) | ||
464 | else: | ||
465 | newdeps.append(dep) | ||
466 | d.setVar("DEPENDS", " ".join(newdeps)) | ||
467 | for task in tasklist: | ||
468 | taskdeps = (d.getVarFlag(task, "depends") or "").split() | ||
469 | remapped = [] | ||
470 | for entry in taskdeps: | ||
471 | r, t = entry.split(":") | ||
472 | if r in virtprovs: | ||
473 | r = d.getVar("PREFERRED_PROVIDER_" + r) | ||
474 | remapped.append("%s:%s" % (r, t)) | ||
475 | d.setVarFlag(task, "depends", " ".join(remapped)) | ||
476 | |||
329 | def finalize(fn, d, variant = None): | 477 | def finalize(fn, d, variant = None): |
330 | saved_handlers = bb.event.get_handlers().copy() | 478 | saved_handlers = bb.event.get_handlers().copy() |
331 | try: | 479 | try: |
480 | # Found renamed variables. Exit immediately | ||
481 | if d.getVar("_FAILPARSINGERRORHANDLED", False) == True: | ||
482 | raise bb.BBHandledException() | ||
483 | |||
484 | inherits = [x[0] for x in (d.getVar('__BBDEFINHERITS', False) or [('',)])] | ||
485 | bb.event.fire(bb.event.RecipePreDeferredInherits(fn, inherits), d) | ||
486 | |||
487 | while True: | ||
488 | inherits = d.getVar('__BBDEFINHERITS', False) or [] | ||
489 | if not inherits: | ||
490 | break | ||
491 | inherit, filename, lineno = inherits.pop(0) | ||
492 | d.setVar('__BBDEFINHERITS', inherits) | ||
493 | bb.parse.BBHandler.inherit(inherit, filename, lineno, d, deferred=True) | ||
494 | |||
332 | for var in d.getVar('__BBHANDLERS', False) or []: | 495 | for var in d.getVar('__BBHANDLERS', False) or []: |
333 | # try to add the handler | 496 | # try to add the handler |
334 | handlerfn = d.getVarFlag(var, "filename", False) | 497 | handlerfn = d.getVarFlag(var, "filename", False) |
@@ -347,12 +510,16 @@ def finalize(fn, d, variant = None): | |||
347 | 510 | ||
348 | tasklist = d.getVar('__BBTASKS', False) or [] | 511 | tasklist = d.getVar('__BBTASKS', False) or [] |
349 | bb.event.fire(bb.event.RecipeTaskPreProcess(fn, list(tasklist)), d) | 512 | bb.event.fire(bb.event.RecipeTaskPreProcess(fn, list(tasklist)), d) |
513 | handleVirtRecipeProviders(tasklist, d) | ||
350 | bb.build.add_tasks(tasklist, d) | 514 | bb.build.add_tasks(tasklist, d) |
351 | 515 | ||
352 | bb.parse.siggen.finalise(fn, d, variant) | 516 | bb.parse.siggen.finalise(fn, d, variant) |
353 | 517 | ||
354 | d.setVar('BBINCLUDED', bb.parse.get_file_depends(d)) | 518 | d.setVar('BBINCLUDED', bb.parse.get_file_depends(d)) |
355 | 519 | ||
520 | if d.getVar('__BBAUTOREV_SEEN') and d.getVar('__BBSRCREV_SEEN') and not d.getVar("__BBAUTOREV_ACTED_UPON"): | ||
521 | bb.fatal("AUTOREV/SRCPV set too late for the fetcher to work properly, please set the variables earlier in parsing. Erroring instead of later obtuse build failures.") | ||
522 | |||
356 | bb.event.fire(bb.event.RecipeParsed(fn), d) | 523 | bb.event.fire(bb.event.RecipeParsed(fn), d) |
357 | finally: | 524 | finally: |
358 | bb.event.set_handlers(saved_handlers) | 525 | bb.event.set_handlers(saved_handlers) |
@@ -414,7 +581,7 @@ def multi_finalize(fn, d): | |||
414 | d.setVar("BBEXTENDVARIANT", variantmap[name]) | 581 | d.setVar("BBEXTENDVARIANT", variantmap[name]) |
415 | else: | 582 | else: |
416 | d.setVar("PN", "%s-%s" % (pn, name)) | 583 | d.setVar("PN", "%s-%s" % (pn, name)) |
417 | bb.parse.BBHandler.inherit(extendedmap[name], fn, 0, d) | 584 | bb.parse.BBHandler.inherit_defer(extendedmap[name], fn, 0, d) |
418 | 585 | ||
419 | safe_d.setVar("BBCLASSEXTEND", extended) | 586 | safe_d.setVar("BBCLASSEXTEND", extended) |
420 | _create_variants(datastores, extendedmap.keys(), extendfunc, onlyfinalise) | 587 | _create_variants(datastores, extendedmap.keys(), extendfunc, onlyfinalise) |
diff --git a/bitbake/lib/bb/parse/parse_py/BBHandler.py b/bitbake/lib/bb/parse/parse_py/BBHandler.py index f8988b8631..008fec2308 100644 --- a/bitbake/lib/bb/parse/parse_py/BBHandler.py +++ b/bitbake/lib/bb/parse/parse_py/BBHandler.py | |||
@@ -19,14 +19,12 @@ from . import ConfHandler | |||
19 | from .. import resolve_file, ast, logger, ParseError | 19 | from .. import resolve_file, ast, logger, ParseError |
20 | from .ConfHandler import include, init | 20 | from .ConfHandler import include, init |
21 | 21 | ||
22 | # For compatibility | 22 | __func_start_regexp__ = re.compile(r"(((?P<py>python(?=(\s|\()))|(?P<fr>fakeroot(?=\s)))\s*)*(?P<func>[\w\.\-\+\{\}\$:]+)?\s*\(\s*\)\s*{$" ) |
23 | bb.deprecate_import(__name__, "bb.parse", ["vars_from_file"]) | ||
24 | |||
25 | __func_start_regexp__ = re.compile(r"(((?P<py>python(?=(\s|\()))|(?P<fr>fakeroot(?=\s)))\s*)*(?P<func>[\w\.\-\+\{\}\$]+)?\s*\(\s*\)\s*{$" ) | ||
26 | __inherit_regexp__ = re.compile(r"inherit\s+(.+)" ) | 23 | __inherit_regexp__ = re.compile(r"inherit\s+(.+)" ) |
24 | __inherit_def_regexp__ = re.compile(r"inherit_defer\s+(.+)" ) | ||
27 | __export_func_regexp__ = re.compile(r"EXPORT_FUNCTIONS\s+(.+)" ) | 25 | __export_func_regexp__ = re.compile(r"EXPORT_FUNCTIONS\s+(.+)" ) |
28 | __addtask_regexp__ = re.compile(r"addtask\s+(?P<func>\w+)\s*((before\s*(?P<before>((.*(?=after))|(.*))))|(after\s*(?P<after>((.*(?=before))|(.*)))))*") | 26 | __addtask_regexp__ = re.compile(r"addtask\s+([^#\n]+)(?P<comment>#.*|.*?)") |
29 | __deltask_regexp__ = re.compile(r"deltask\s+(.+)") | 27 | __deltask_regexp__ = re.compile(r"deltask\s+([^#\n]+)(?P<comment>#.*|.*?)") |
30 | __addhandler_regexp__ = re.compile(r"addhandler\s+(.+)" ) | 28 | __addhandler_regexp__ = re.compile(r"addhandler\s+(.+)" ) |
31 | __def_regexp__ = re.compile(r"def\s+(\w+).*:" ) | 29 | __def_regexp__ = re.compile(r"def\s+(\w+).*:" ) |
32 | __python_func_regexp__ = re.compile(r"(\s+.*)|(^$)|(^#)" ) | 30 | __python_func_regexp__ = re.compile(r"(\s+.*)|(^$)|(^#)" ) |
@@ -36,6 +34,7 @@ __infunc__ = [] | |||
36 | __inpython__ = False | 34 | __inpython__ = False |
37 | __body__ = [] | 35 | __body__ = [] |
38 | __classname__ = "" | 36 | __classname__ = "" |
37 | __residue__ = [] | ||
39 | 38 | ||
40 | cached_statements = {} | 39 | cached_statements = {} |
41 | 40 | ||
@@ -43,31 +42,56 @@ def supports(fn, d): | |||
43 | """Return True if fn has a supported extension""" | 42 | """Return True if fn has a supported extension""" |
44 | return os.path.splitext(fn)[-1] in [".bb", ".bbclass", ".inc"] | 43 | return os.path.splitext(fn)[-1] in [".bb", ".bbclass", ".inc"] |
45 | 44 | ||
46 | def inherit(files, fn, lineno, d): | 45 | def inherit_defer(expression, fn, lineno, d): |
46 | inherit = (expression, fn, lineno) | ||
47 | inherits = d.getVar('__BBDEFINHERITS', False) or [] | ||
48 | inherits.append(inherit) | ||
49 | d.setVar('__BBDEFINHERITS', inherits) | ||
50 | |||
51 | def inherit(files, fn, lineno, d, deferred=False): | ||
47 | __inherit_cache = d.getVar('__inherit_cache', False) or [] | 52 | __inherit_cache = d.getVar('__inherit_cache', False) or [] |
53 | #if "${" in files and not deferred: | ||
54 | # bb.warn("%s:%s has non deferred conditional inherit" % (fn, lineno)) | ||
48 | files = d.expand(files).split() | 55 | files = d.expand(files).split() |
49 | for file in files: | 56 | for file in files: |
50 | if not os.path.isabs(file) and not file.endswith(".bbclass"): | 57 | defer = (d.getVar("BB_DEFER_BBCLASSES") or "").split() |
51 | file = os.path.join('classes', '%s.bbclass' % file) | 58 | if not deferred and file in defer: |
52 | 59 | inherit_defer(file, fn, lineno, d) | |
53 | if not os.path.isabs(file): | 60 | continue |
54 | bbpath = d.getVar("BBPATH") | 61 | classtype = d.getVar("__bbclasstype", False) |
55 | abs_fn, attempts = bb.utils.which(bbpath, file, history=True) | 62 | origfile = file |
56 | for af in attempts: | 63 | for t in ["classes-" + classtype, "classes"]: |
57 | if af != abs_fn: | 64 | file = origfile |
58 | bb.parse.mark_dependency(d, af) | 65 | if not os.path.isabs(file) and not file.endswith(".bbclass"): |
59 | if abs_fn: | 66 | file = os.path.join(t, '%s.bbclass' % file) |
60 | file = abs_fn | 67 | |
68 | if not os.path.isabs(file): | ||
69 | bbpath = d.getVar("BBPATH") | ||
70 | abs_fn, attempts = bb.utils.which(bbpath, file, history=True) | ||
71 | for af in attempts: | ||
72 | if af != abs_fn: | ||
73 | bb.parse.mark_dependency(d, af) | ||
74 | if abs_fn: | ||
75 | file = abs_fn | ||
76 | |||
77 | if os.path.exists(file): | ||
78 | break | ||
79 | |||
80 | if not os.path.exists(file): | ||
81 | raise ParseError("Could not inherit file %s" % (file), fn, lineno) | ||
61 | 82 | ||
62 | if not file in __inherit_cache: | 83 | if not file in __inherit_cache: |
63 | logger.debug("Inheriting %s (from %s:%d)" % (file, fn, lineno)) | 84 | logger.debug("Inheriting %s (from %s:%d)" % (file, fn, lineno)) |
64 | __inherit_cache.append( file ) | 85 | __inherit_cache.append( file ) |
65 | d.setVar('__inherit_cache', __inherit_cache) | 86 | d.setVar('__inherit_cache', __inherit_cache) |
66 | include(fn, file, lineno, d, "inherit") | 87 | try: |
88 | bb.parse.handle(file, d, True) | ||
89 | except (IOError, OSError) as exc: | ||
90 | raise ParseError("Could not inherit file %s: %s" % (fn, exc.strerror), fn, lineno) | ||
67 | __inherit_cache = d.getVar('__inherit_cache', False) or [] | 91 | __inherit_cache = d.getVar('__inherit_cache', False) or [] |
68 | 92 | ||
69 | def get_statements(filename, absolute_filename, base_name): | 93 | def get_statements(filename, absolute_filename, base_name): |
70 | global cached_statements | 94 | global cached_statements, __residue__, __body__ |
71 | 95 | ||
72 | try: | 96 | try: |
73 | return cached_statements[absolute_filename] | 97 | return cached_statements[absolute_filename] |
@@ -87,12 +111,17 @@ def get_statements(filename, absolute_filename, base_name): | |||
87 | # add a blank line to close out any python definition | 111 | # add a blank line to close out any python definition |
88 | feeder(lineno, "", filename, base_name, statements, eof=True) | 112 | feeder(lineno, "", filename, base_name, statements, eof=True) |
89 | 113 | ||
114 | if __residue__: | ||
115 | raise ParseError("Unparsed lines %s: %s" % (filename, str(__residue__)), filename, lineno) | ||
116 | if __body__: | ||
117 | raise ParseError("Unparsed lines from unclosed function %s: %s" % (filename, str(__body__)), filename, lineno) | ||
118 | |||
90 | if filename.endswith(".bbclass") or filename.endswith(".inc"): | 119 | if filename.endswith(".bbclass") or filename.endswith(".inc"): |
91 | cached_statements[absolute_filename] = statements | 120 | cached_statements[absolute_filename] = statements |
92 | return statements | 121 | return statements |
93 | 122 | ||
94 | def handle(fn, d, include): | 123 | def handle(fn, d, include, baseconfig=False): |
95 | global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __infunc__, __body__, __residue__, __classname__ | 124 | global __infunc__, __body__, __residue__, __classname__ |
96 | __body__ = [] | 125 | __body__ = [] |
97 | __infunc__ = [] | 126 | __infunc__ = [] |
98 | __classname__ = "" | 127 | __classname__ = "" |
@@ -144,7 +173,7 @@ def handle(fn, d, include): | |||
144 | return d | 173 | return d |
145 | 174 | ||
146 | def feeder(lineno, s, fn, root, statements, eof=False): | 175 | def feeder(lineno, s, fn, root, statements, eof=False): |
147 | global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __def_regexp__, __python_func_regexp__, __inpython__, __infunc__, __body__, bb, __residue__, __classname__ | 176 | global __inpython__, __infunc__, __body__, __residue__, __classname__ |
148 | 177 | ||
149 | # Check tabs in python functions: | 178 | # Check tabs in python functions: |
150 | # - def py_funcname(): covered by __inpython__ | 179 | # - def py_funcname(): covered by __inpython__ |
@@ -181,10 +210,10 @@ def feeder(lineno, s, fn, root, statements, eof=False): | |||
181 | 210 | ||
182 | if s and s[0] == '#': | 211 | if s and s[0] == '#': |
183 | if len(__residue__) != 0 and __residue__[0][0] != "#": | 212 | if len(__residue__) != 0 and __residue__[0][0] != "#": |
184 | bb.fatal("There is a comment on line %s of file %s (%s) which is in the middle of a multiline expression.\nBitbake used to ignore these but no longer does so, please fix your metadata as errors are likely as a result of this change." % (lineno, fn, s)) | 213 | bb.fatal("There is a comment on line %s of file %s:\n'''\n%s\n'''\nwhich is in the middle of a multiline expression. This syntax is invalid, please correct it." % (lineno, fn, s)) |
185 | 214 | ||
186 | if len(__residue__) != 0 and __residue__[0][0] == "#" and (not s or s[0] != "#"): | 215 | if len(__residue__) != 0 and __residue__[0][0] == "#" and (not s or s[0] != "#"): |
187 | bb.fatal("There is a confusing multiline, partially commented expression on line %s of file %s (%s).\nPlease clarify whether this is all a comment or should be parsed." % (lineno, fn, s)) | 216 | bb.fatal("There is a confusing multiline partially commented expression on line %s of file %s:\n%s\nPlease clarify whether this is all a comment or should be parsed." % (lineno - len(__residue__), fn, "\n".join(__residue__))) |
188 | 217 | ||
189 | if s and s[-1] == '\\': | 218 | if s and s[-1] == '\\': |
190 | __residue__.append(s[:-1]) | 219 | __residue__.append(s[:-1]) |
@@ -220,29 +249,38 @@ def feeder(lineno, s, fn, root, statements, eof=False): | |||
220 | 249 | ||
221 | m = __addtask_regexp__.match(s) | 250 | m = __addtask_regexp__.match(s) |
222 | if m: | 251 | if m: |
223 | if len(m.group().split()) == 2: | 252 | after = "" |
224 | # Check and warn for "addtask task1 task2" | 253 | before = "" |
225 | m2 = re.match(r"addtask\s+(?P<func>\w+)(?P<ignores>.*)", s) | 254 | |
226 | if m2 and m2.group('ignores'): | 255 | # This code splits on 'before' and 'after' instead of on whitespace so we can defer |
227 | logger.warning('addtask ignored: "%s"' % m2.group('ignores')) | 256 | # evaluation to as late as possible. |
228 | 257 | tasks = m.group(1).split(" before ")[0].split(" after ")[0] | |
229 | # Check and warn for "addtask task1 before task2 before task3", the | 258 | |
230 | # similar to "after" | 259 | for exp in m.group(1).split(" before "): |
231 | taskexpression = s.split() | 260 | exp2 = exp.split(" after ") |
232 | for word in ('before', 'after'): | 261 | if len(exp2) > 1: |
233 | if taskexpression.count(word) > 1: | 262 | after = after + " ".join(exp2[1:]) |
234 | logger.warning("addtask contained multiple '%s' keywords, only one is supported" % word) | ||
235 | 263 | ||
236 | # Check and warn for having task with exprssion as part of task name | 264 | for exp in m.group(1).split(" after "): |
265 | exp2 = exp.split(" before ") | ||
266 | if len(exp2) > 1: | ||
267 | before = before + " ".join(exp2[1:]) | ||
268 | |||
269 | # Check and warn for having task with a keyword as part of task name | ||
270 | taskexpression = s.split() | ||
237 | for te in taskexpression: | 271 | for te in taskexpression: |
238 | if any( ( "%s_" % keyword ) in te for keyword in bb.data_smart.__setvar_keyword__ ): | 272 | if any( ( "%s_" % keyword ) in te for keyword in bb.data_smart.__setvar_keyword__ ): |
239 | raise ParseError("Task name '%s' contains a keyword which is not recommended/supported.\nPlease rename the task not to include the keyword.\n%s" % (te, ("\n".join(map(str, bb.data_smart.__setvar_keyword__)))), fn) | 273 | raise ParseError("Task name '%s' contains a keyword which is not recommended/supported.\nPlease rename the task not to include the keyword.\n%s" % (te, ("\n".join(map(str, bb.data_smart.__setvar_keyword__)))), fn) |
240 | ast.handleAddTask(statements, fn, lineno, m) | 274 | |
275 | if tasks is not None: | ||
276 | ast.handleAddTask(statements, fn, lineno, tasks, before, after) | ||
241 | return | 277 | return |
242 | 278 | ||
243 | m = __deltask_regexp__.match(s) | 279 | m = __deltask_regexp__.match(s) |
244 | if m: | 280 | if m: |
245 | ast.handleDelTask(statements, fn, lineno, m) | 281 | task = m.group(1) |
282 | if task is not None: | ||
283 | ast.handleDelTask(statements, fn, lineno, task) | ||
246 | return | 284 | return |
247 | 285 | ||
248 | m = __addhandler_regexp__.match(s) | 286 | m = __addhandler_regexp__.match(s) |
@@ -255,7 +293,12 @@ def feeder(lineno, s, fn, root, statements, eof=False): | |||
255 | ast.handleInherit(statements, fn, lineno, m) | 293 | ast.handleInherit(statements, fn, lineno, m) |
256 | return | 294 | return |
257 | 295 | ||
258 | return ConfHandler.feeder(lineno, s, fn, statements) | 296 | m = __inherit_def_regexp__.match(s) |
297 | if m: | ||
298 | ast.handleInheritDeferred(statements, fn, lineno, m) | ||
299 | return | ||
300 | |||
301 | return ConfHandler.feeder(lineno, s, fn, statements, conffile=False) | ||
259 | 302 | ||
260 | # Add us to the handlers list | 303 | # Add us to the handlers list |
261 | from .. import handlers | 304 | from .. import handlers |
diff --git a/bitbake/lib/bb/parse/parse_py/ConfHandler.py b/bitbake/lib/bb/parse/parse_py/ConfHandler.py index f171c5c932..9ddbae123d 100644 --- a/bitbake/lib/bb/parse/parse_py/ConfHandler.py +++ b/bitbake/lib/bb/parse/parse_py/ConfHandler.py | |||
@@ -20,10 +20,10 @@ from bb.parse import ParseError, resolve_file, ast, logger, handle | |||
20 | __config_regexp__ = re.compile( r""" | 20 | __config_regexp__ = re.compile( r""" |
21 | ^ | 21 | ^ |
22 | (?P<exp>export\s+)? | 22 | (?P<exp>export\s+)? |
23 | (?P<var>[a-zA-Z0-9\-_+.${}/~]+?) | 23 | (?P<var>[a-zA-Z0-9\-_+.${}/~:]*?) |
24 | (\[(?P<flag>[a-zA-Z0-9\-_+.]+)\])? | 24 | (\[(?P<flag>[a-zA-Z0-9\-_+.][a-zA-Z0-9\-_+.@/]*)\])? |
25 | 25 | ||
26 | \s* ( | 26 | (?P<whitespace>\s*) ( |
27 | (?P<colon>:=) | | 27 | (?P<colon>:=) | |
28 | (?P<lazyques>\?\?=) | | 28 | (?P<lazyques>\?\?=) | |
29 | (?P<ques>\?=) | | 29 | (?P<ques>\?=) | |
@@ -32,7 +32,7 @@ __config_regexp__ = re.compile( r""" | |||
32 | (?P<predot>=\.) | | 32 | (?P<predot>=\.) | |
33 | (?P<postdot>\.=) | | 33 | (?P<postdot>\.=) | |
34 | = | 34 | = |
35 | ) \s* | 35 | ) (?P<whitespace2>\s*) |
36 | 36 | ||
37 | (?!'[^']*'[^']*'$) | 37 | (?!'[^']*'[^']*'$) |
38 | (?!\"[^\"]*\"[^\"]*\"$) | 38 | (?!\"[^\"]*\"[^\"]*\"$) |
@@ -43,15 +43,15 @@ __config_regexp__ = re.compile( r""" | |||
43 | """, re.X) | 43 | """, re.X) |
44 | __include_regexp__ = re.compile( r"include\s+(.+)" ) | 44 | __include_regexp__ = re.compile( r"include\s+(.+)" ) |
45 | __require_regexp__ = re.compile( r"require\s+(.+)" ) | 45 | __require_regexp__ = re.compile( r"require\s+(.+)" ) |
46 | __includeall_regexp__ = re.compile( r"include_all\s+(.+)" ) | ||
46 | __export_regexp__ = re.compile( r"export\s+([a-zA-Z0-9\-_+.${}/~]+)$" ) | 47 | __export_regexp__ = re.compile( r"export\s+([a-zA-Z0-9\-_+.${}/~]+)$" ) |
47 | __unset_regexp__ = re.compile( r"unset\s+([a-zA-Z0-9\-_+.${}/~]+)$" ) | 48 | __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\-_+.]+)\]$" ) | 49 | __unset_flag_regexp__ = re.compile( r"unset\s+([a-zA-Z0-9\-_+.${}/~]+)\[([a-zA-Z0-9\-_+.][a-zA-Z0-9\-_+.@]+)\]$" ) |
50 | __addpylib_regexp__ = re.compile(r"addpylib\s+(.+)\s+(.+)" ) | ||
51 | __addfragments_regexp__ = re.compile(r"addfragments\s+(.+)\s+(.+)\s+(.+)\s+(.+)" ) | ||
49 | 52 | ||
50 | def init(data): | 53 | def init(data): |
51 | topdir = data.getVar('TOPDIR', False) | 54 | return |
52 | if not topdir: | ||
53 | data.setVar('TOPDIR', os.getcwd()) | ||
54 | |||
55 | 55 | ||
56 | def supports(fn, d): | 56 | def supports(fn, d): |
57 | return fn[-5:] == ".conf" | 57 | return fn[-5:] == ".conf" |
@@ -105,12 +105,12 @@ def include_single_file(parentfn, fn, lineno, data, error_out): | |||
105 | # We have an issue where a UI might want to enforce particular settings such as | 105 | # We have an issue where a UI might want to enforce particular settings such as |
106 | # an empty DISTRO variable. If configuration files do something like assigning | 106 | # an empty DISTRO variable. If configuration files do something like assigning |
107 | # a weak default, it turns out to be very difficult to filter out these changes, | 107 | # a weak default, it turns out to be very difficult to filter out these changes, |
108 | # particularly when the weak default might appear half way though parsing a chain | 108 | # particularly when the weak default might appear half way though parsing a chain |
109 | # of configuration files. We therefore let the UIs hook into configuration file | 109 | # of configuration files. We therefore let the UIs hook into configuration file |
110 | # parsing. This turns out to be a hard problem to solve any other way. | 110 | # parsing. This turns out to be a hard problem to solve any other way. |
111 | confFilters = [] | 111 | confFilters = [] |
112 | 112 | ||
113 | def handle(fn, data, include): | 113 | def handle(fn, data, include, baseconfig=False): |
114 | init(data) | 114 | init(data) |
115 | 115 | ||
116 | if include == 0: | 116 | if include == 0: |
@@ -128,21 +128,26 @@ def handle(fn, data, include): | |||
128 | s = f.readline() | 128 | s = f.readline() |
129 | if not s: | 129 | if not s: |
130 | break | 130 | break |
131 | origlineno = lineno | ||
132 | origline = s | ||
131 | w = s.strip() | 133 | w = s.strip() |
132 | # skip empty lines | 134 | # skip empty lines |
133 | if not w: | 135 | if not w: |
134 | continue | 136 | continue |
135 | s = s.rstrip() | 137 | s = s.rstrip() |
136 | while s[-1] == '\\': | 138 | while s[-1] == '\\': |
137 | s2 = f.readline().rstrip() | 139 | line = f.readline() |
140 | origline += line | ||
141 | s2 = line.rstrip() | ||
138 | lineno = lineno + 1 | 142 | lineno = lineno + 1 |
139 | if (not s2 or s2 and s2[0] != "#") and s[0] == "#" : | 143 | if (not s2 or s2 and s2[0] != "#") and s[0] == "#" : |
140 | bb.fatal("There is a confusing multiline, partially commented expression on line %s of file %s (%s).\nPlease clarify whether this is all a comment or should be parsed." % (lineno, fn, s)) | 144 | bb.fatal("There is a confusing multiline, partially commented expression starting on line %s of file %s:\n%s\nPlease clarify whether this is all a comment or should be parsed." % (origlineno, fn, origline)) |
145 | |||
141 | s = s[:-1] + s2 | 146 | s = s[:-1] + s2 |
142 | # skip comments | 147 | # skip comments |
143 | if s[0] == '#': | 148 | if s[0] == '#': |
144 | continue | 149 | continue |
145 | feeder(lineno, s, abs_fn, statements) | 150 | feeder(lineno, s, abs_fn, statements, baseconfig=baseconfig) |
146 | 151 | ||
147 | # DONE WITH PARSING... time to evaluate | 152 | # DONE WITH PARSING... time to evaluate |
148 | data.setVar('FILE', abs_fn) | 153 | data.setVar('FILE', abs_fn) |
@@ -150,17 +155,21 @@ def handle(fn, data, include): | |||
150 | if oldfile: | 155 | if oldfile: |
151 | data.setVar('FILE', oldfile) | 156 | data.setVar('FILE', oldfile) |
152 | 157 | ||
153 | f.close() | ||
154 | |||
155 | for f in confFilters: | 158 | for f in confFilters: |
156 | f(fn, data) | 159 | f(fn, data) |
157 | 160 | ||
158 | return data | 161 | return data |
159 | 162 | ||
160 | def feeder(lineno, s, fn, statements): | 163 | # baseconfig is set for the bblayers/layer.conf cookerdata config parsing |
164 | # The function is also used by BBHandler, conffile would be False | ||
165 | def feeder(lineno, s, fn, statements, baseconfig=False, conffile=True): | ||
161 | m = __config_regexp__.match(s) | 166 | m = __config_regexp__.match(s) |
162 | if m: | 167 | if m: |
163 | groupd = m.groupdict() | 168 | groupd = m.groupdict() |
169 | if groupd['var'] == "": | ||
170 | raise ParseError("Empty variable name in assignment: '%s'" % s, fn, lineno); | ||
171 | if not groupd['whitespace'] or not groupd['whitespace2']: | ||
172 | logger.warning("%s:%s has a lack of whitespace around the assignment: '%s'" % (fn, lineno, s)) | ||
164 | ast.handleData(statements, fn, lineno, groupd) | 173 | ast.handleData(statements, fn, lineno, groupd) |
165 | return | 174 | return |
166 | 175 | ||
@@ -174,6 +183,11 @@ def feeder(lineno, s, fn, statements): | |||
174 | ast.handleInclude(statements, fn, lineno, m, True) | 183 | ast.handleInclude(statements, fn, lineno, m, True) |
175 | return | 184 | return |
176 | 185 | ||
186 | m = __includeall_regexp__.match(s) | ||
187 | if m: | ||
188 | ast.handleIncludeAll(statements, fn, lineno, m) | ||
189 | return | ||
190 | |||
177 | m = __export_regexp__.match(s) | 191 | m = __export_regexp__.match(s) |
178 | if m: | 192 | if m: |
179 | ast.handleExport(statements, fn, lineno, m) | 193 | ast.handleExport(statements, fn, lineno, m) |
@@ -189,6 +203,16 @@ def feeder(lineno, s, fn, statements): | |||
189 | ast.handleUnsetFlag(statements, fn, lineno, m) | 203 | ast.handleUnsetFlag(statements, fn, lineno, m) |
190 | return | 204 | return |
191 | 205 | ||
206 | m = __addpylib_regexp__.match(s) | ||
207 | if baseconfig and conffile and m: | ||
208 | ast.handlePyLib(statements, fn, lineno, m) | ||
209 | return | ||
210 | |||
211 | m = __addfragments_regexp__.match(s) | ||
212 | if m: | ||
213 | ast.handleAddFragments(statements, fn, lineno, m) | ||
214 | return | ||
215 | |||
192 | raise ParseError("unparsed line: '%s'" % s, fn, lineno); | 216 | raise ParseError("unparsed line: '%s'" % s, fn, lineno); |
193 | 217 | ||
194 | # Add us to the handlers list | 218 | # Add us to the handlers list |