summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb
diff options
context:
space:
mode:
authorRobert Yang <liezhi.yang@windriver.com>2018-12-04 10:06:03 +0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2018-12-09 11:07:48 +0000
commitd6bc389e816441d1af4cde09252b4f27fb074834 (patch)
tree7726fc6dd7cc8004fb5a1e0d5fa070fbe6ec0da2 /bitbake/lib/bb
parentb3f0b96a25de84423cf14597d0770decdaf38ebb (diff)
downloadpoky-d6bc389e816441d1af4cde09252b4f27fb074834.tar.gz
bitbake: bitbake: pysh: Improve error handling for shell code
The p_error() is used for printing errors when parse shell code, but it can't the EOF error correctly - Add the following lines to quilt.inc do_configure_prepend () { find ${s} -name "*.in" -exec sed -i -e "1s,^#\!.*@perl@ -w$,#\! @perl@\nuse warnings;," {} \; if [ hello ]; then } - Before the patch: $ rm -fr cache/ tmp/cache/; bitbake -p [snip] WARNING: /path/to/quilt/quilt-native_0.65.bb: Error during finalise of /path/to/quilt/quilt-native_0.65.bb [snip] bb.pysh.sherrors.ShellSyntaxError: None followed by: We can see that this isn't easy to debug, let p_error() check wheter it is EOF and print appropriate errors can improve the error message. And don't let codeparser.py except pyshlex.NeedMore (in fact, it never worked since p_error() only raise ShellSyntaxError), but make it print the last 5 lines which might be useful for debuging. - After the patch $ rm -fr cache/ tmp/cache/; bitbake -p [snip] ERROR: /path/to/quilt/quilt_0.65.bb: Error during parse shell code, the last 5 lines are: find /path/to/quilt/0.65-r0/quilt-0.65 -name "*.in" -exec sed -i -e "1s,^#\!.*@PERL@ -w$,#\! @PERL@\nuse warnings;," {} \; if [ hello ]; then autotools_do_configure sed -e 's,^COMPAT_SYMLINKS.*:=.*,COMPAT_SYMLINKS :=,' -i /path/to/quilt/0.65-r0/quilt-0.65/Makefile [snip] File "/path/to/bb/pysh/pyshyacc.py", line 649, in p_error(p=None): w('Unexpected EOF') > raise sherrors.ShellSyntaxError(''.join(msg)) bb.pysh.sherrors.ShellSyntaxError: Unexpected EOF (Bitbake rev: 44790597951638e32eb1672de2e40bd5a603326b) Signed-off-by: Robert Yang <liezhi.yang@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb')
-rw-r--r--bitbake/lib/bb/codeparser.py5
-rw-r--r--bitbake/lib/bb/pysh/pyshyacc.py17
2 files changed, 13 insertions, 9 deletions
diff --git a/bitbake/lib/bb/codeparser.py b/bitbake/lib/bb/codeparser.py
index ddd1b97dcb..3f8ac1d5f6 100644
--- a/bitbake/lib/bb/codeparser.py
+++ b/bitbake/lib/bb/codeparser.py
@@ -368,8 +368,9 @@ class ShellParser():
368 def _parse_shell(self, value): 368 def _parse_shell(self, value):
369 try: 369 try:
370 tokens, _ = pyshyacc.parse(value, eof=True, debug=False) 370 tokens, _ = pyshyacc.parse(value, eof=True, debug=False)
371 except pyshlex.NeedMore: 371 except Exception:
372 raise sherrors.ShellSyntaxError("Unexpected EOF") 372 bb.error('Error during parse shell code, the last 5 lines are:\n%s' % '\n'.join(value.split('\n')[-5:]))
373 raise
373 374
374 self.process_tokens(tokens) 375 self.process_tokens(tokens)
375 376
diff --git a/bitbake/lib/bb/pysh/pyshyacc.py b/bitbake/lib/bb/pysh/pyshyacc.py
index ba4cefdcb8..de565dc9af 100644
--- a/bitbake/lib/bb/pysh/pyshyacc.py
+++ b/bitbake/lib/bb/pysh/pyshyacc.py
@@ -636,13 +636,16 @@ def p_empty(p):
636def p_error(p): 636def p_error(p):
637 msg = [] 637 msg = []
638 w = msg.append 638 w = msg.append
639 w('%r\n' % p) 639 if p:
640 w('followed by:\n') 640 w('%r\n' % p)
641 for i in range(5): 641 w('followed by:\n')
642 n = yacc.token() 642 for i in range(5):
643 if not n: 643 n = yacc.token()
644 break 644 if not n:
645 w(' %r\n' % n) 645 break
646 w(' %r\n' % n)
647 else:
648 w('Unexpected EOF')
646 raise sherrors.ShellSyntaxError(''.join(msg)) 649 raise sherrors.ShellSyntaxError(''.join(msg))
647 650
648# Build the parser 651# Build the parser