summaryrefslogtreecommitdiffstats
path: root/scripts/verify-bashisms
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/verify-bashisms')
-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)