summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorPatrick Ohly <patrick.ohly@intel.com>2017-01-31 13:50:33 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-01-31 15:28:41 +0000
commitd99b29838dd72394803a279fc26ee3201dd2c557 (patch)
tree235e052cb463074930fbd99e9fd923a80caec4d3 /scripts
parenta15895dac117007fe922bfe5707493ff1215ac56 (diff)
downloadpoky-d99b29838dd72394803a279fc26ee3201dd2c557.tar.gz
verify-bashisms: support warnings with more than one line of source code
All warnings start with "possible bashism in", followed by one or more (in the case of line continuation) lines of source code. To support more than one line, we now split by matching against the known intro text. Example: $ verify-bashisms guile ... /.../openembedded-core/meta/recipes-devtools/guile/guile_2.0.13.bb possible bashism in guile_cross_config line 94 ($'...' should be "$(printf '...')"): echo '#!'`which ${BUILD_SYS}-guile`$' \\\n--no-auto-compile -e main -s\n!#\n(define %guile-build-info '\'\( \ > ${B}/guile-config.cross (From OE-Core rev: e2dd3621c45e854b4eb054b4d4537487462cdd39) Signed-off-by: Patrick Ohly <patrick.ohly@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/verify-bashisms21
1 files changed, 15 insertions, 6 deletions
diff --git a/scripts/verify-bashisms b/scripts/verify-bashisms
index 7283980ed5..dab64ef501 100755
--- a/scripts/verify-bashisms
+++ b/scripts/verify-bashisms
@@ -23,6 +23,7 @@ def is_whitelisted(s):
23 return False 23 return False
24 24
25SCRIPT_LINENO_RE = re.compile(r' line (\d+) ') 25SCRIPT_LINENO_RE = re.compile(r' line (\d+) ')
26BASHISM_WARNING = re.compile(r'^(possible bashism in.*)$', re.MULTILINE)
26 27
27def process(filename, function, lineno, script): 28def process(filename, function, lineno, script):
28 import tempfile 29 import tempfile
@@ -42,11 +43,18 @@ def process(filename, function, lineno, script):
42 # TODO check exit code is 1 43 # TODO check exit code is 1
43 44
44 # Replace the temporary filename with the function and split it 45 # Replace the temporary filename with the function and split it
45 output = e.output.replace(fn.name, function).splitlines() 46 output = e.output.replace(fn.name, function)
46 if len(output) % 2 != 0: 47 if not output or not output.startswith('possible bashism'):
47 print("Unexpected output from checkbashism: %s" % str(output)) 48 # Probably starts with or contains only warnings. Dump verbatim
48 return 49 # with one space indention. Can't do the splitting and whitelist
49 50 # checking below.
51 return '\n'.join([filename,
52 ' Unexpected output from checkbashisms.pl'] +
53 [' ' + x for x in output.splitlines()])
54
55 # We know that the first line matches and that therefore the first
56 # list entry will be empty - skip it.
57 output = BASHISM_WARNING.split(output)[1:]
50 # Turn the output into a single string like this: 58 # Turn the output into a single string like this:
51 # /.../foobar.bb 59 # /.../foobar.bb
52 # possible bashism in updatercd_postrm line 2 (type): 60 # possible bashism in updatercd_postrm line 2 (type):
@@ -60,7 +68,8 @@ def process(filename, function, lineno, script):
60 if lineno is not None: 68 if lineno is not None:
61 message = SCRIPT_LINENO_RE.sub(lambda m: ' line %d ' % (int(m.group(1)) + int(lineno) - 1), 69 message = SCRIPT_LINENO_RE.sub(lambda m: ' line %d ' % (int(m.group(1)) + int(lineno) - 1),
62 message) 70 message)
63 result.extend([' ' + message, ' ' + source]) 71 result.append(' ' + message.strip())
72 result.extend([' %s' % x for x in source.splitlines()])
64 if result: 73 if result:
65 result.insert(0, filename) 74 result.insert(0, filename)
66 return '\n'.join(result) 75 return '\n'.join(result)