diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-05-14 17:56:51 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-05-15 17:45:00 +0100 |
commit | fd731142e9e6d31c6735228c67ae0e87b6d4d239 (patch) | |
tree | ed83c2190f091b95752949f9702d8f0e4b4ea97c /bitbake/lib | |
parent | c5316d4d57878eb05cabf1e724242610b86ca2cb (diff) | |
download | poky-fd731142e9e6d31c6735228c67ae0e87b6d4d239.tar.gz |
bitbake: BBHandler: Error for incomplete function definitions
Add some sanity checks on the parsing state engine when returning data
so that incomplete functions raise parse errors.
This means a recipe doing:
do_somefunction {
echo 1
VAR = "1"
will now raise a ParseError. To get the right file/line information,
__infunc__ was changed to a list.
[YOCTO #7633]
(Bitbake rev: 6b54a72638f57882d4fd5aab96b2752a09e065af)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib')
-rw-r--r-- | bitbake/lib/bb/parse/parse_py/BBHandler.py | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/bitbake/lib/bb/parse/parse_py/BBHandler.py b/bitbake/lib/bb/parse/parse_py/BBHandler.py index 9633340d1b..56d4672b0f 100644 --- a/bitbake/lib/bb/parse/parse_py/BBHandler.py +++ b/bitbake/lib/bb/parse/parse_py/BBHandler.py | |||
@@ -32,7 +32,7 @@ import bb.build, bb.utils | |||
32 | from bb import data | 32 | from bb import data |
33 | 33 | ||
34 | from . import ConfHandler | 34 | from . import ConfHandler |
35 | from .. import resolve_file, ast, logger | 35 | from .. import resolve_file, ast, logger, ParseError |
36 | from .ConfHandler import include, init | 36 | from .ConfHandler import include, init |
37 | 37 | ||
38 | # For compatibility | 38 | # For compatibility |
@@ -48,7 +48,7 @@ __def_regexp__ = re.compile( r"def\s+(\w+).*:" ) | |||
48 | __python_func_regexp__ = re.compile( r"(\s+.*)|(^$)" ) | 48 | __python_func_regexp__ = re.compile( r"(\s+.*)|(^$)" ) |
49 | 49 | ||
50 | 50 | ||
51 | __infunc__ = "" | 51 | __infunc__ = [] |
52 | __inpython__ = False | 52 | __inpython__ = False |
53 | __body__ = [] | 53 | __body__ = [] |
54 | __classname__ = "" | 54 | __classname__ = "" |
@@ -120,7 +120,7 @@ def get_statements(filename, absolute_filename, base_name): | |||
120 | def handle(fn, d, include): | 120 | def handle(fn, d, include): |
121 | global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __infunc__, __body__, __residue__, __classname__ | 121 | global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __infunc__, __body__, __residue__, __classname__ |
122 | __body__ = [] | 122 | __body__ = [] |
123 | __infunc__ = "" | 123 | __infunc__ = [] |
124 | __classname__ = "" | 124 | __classname__ = "" |
125 | __residue__ = [] | 125 | __residue__ = [] |
126 | 126 | ||
@@ -159,6 +159,11 @@ def handle(fn, d, include): | |||
159 | if include == 0: | 159 | if include == 0: |
160 | return { "" : d } | 160 | return { "" : d } |
161 | 161 | ||
162 | if __infunc__: | ||
163 | raise ParseError("Shell function %s is never closed" % __infunc__[0], __infunc__[1], __infunc__[2]) | ||
164 | if __residue__: | ||
165 | raise ParseError("Leftover unparsed (incomplete?) data %s from %s" % __residue__, fn) | ||
166 | |||
162 | if ext != ".bbclass" and include == 0: | 167 | if ext != ".bbclass" and include == 0: |
163 | return ast.multi_finalize(fn, d) | 168 | return ast.multi_finalize(fn, d) |
164 | 169 | ||
@@ -172,8 +177,8 @@ def feeder(lineno, s, fn, root, statements): | |||
172 | if __infunc__: | 177 | if __infunc__: |
173 | if s == '}': | 178 | if s == '}': |
174 | __body__.append('') | 179 | __body__.append('') |
175 | ast.handleMethod(statements, fn, lineno, __infunc__, __body__) | 180 | ast.handleMethod(statements, fn, lineno, __infunc__[0], __body__) |
176 | __infunc__ = "" | 181 | __infunc__ = [] |
177 | __body__ = [] | 182 | __body__ = [] |
178 | else: | 183 | else: |
179 | __body__.append(s) | 184 | __body__.append(s) |
@@ -217,8 +222,8 @@ def feeder(lineno, s, fn, root, statements): | |||
217 | 222 | ||
218 | m = __func_start_regexp__.match(s) | 223 | m = __func_start_regexp__.match(s) |
219 | if m: | 224 | if m: |
220 | __infunc__ = m.group("func") or "__anonymous" | 225 | __infunc__ = [m.group("func") or "__anonymous", fn, lineno] |
221 | ast.handleMethodFlags(statements, fn, lineno, __infunc__, m) | 226 | ast.handleMethodFlags(statements, fn, lineno, __infunc__[0], m) |
222 | return | 227 | return |
223 | 228 | ||
224 | m = __def_regexp__.match(s) | 229 | m = __def_regexp__.match(s) |