From 350fe7531feecf7df5208fa19d25730c6ce0a30d Mon Sep 17 00:00:00 2001 From: "James E. King, III" Date: Wed, 25 Oct 2017 09:57:18 -0400 Subject: THRIFT-4370: build generated code before running static code analysis; fix E722 flake8 issues identified in python code This closes #1399 --- build/docker/scripts/sca.sh | 20 +++++++++++++++++--- lib/py/setup.py | 2 +- test/features/container_limit.py | 2 +- test/features/string_limit.py | 2 +- test/py/TestServer.py | 4 ++-- test/py/TestSocket.py | 6 +++--- 6 files changed, 25 insertions(+), 11 deletions(-) diff --git a/build/docker/scripts/sca.sh b/build/docker/scripts/sca.sh index 2f2fb684e..38803d4ae 100755 --- a/build/docker/scripts/sca.sh +++ b/build/docker/scripts/sca.sh @@ -1,6 +1,18 @@ #!/bin/sh set -ev +# +# Generate thrift files so the static code analysis includes an analysis +# of the files the thrift compiler spits out. If running interactively +# set the NOBUILD environment variable to skip the boot/config/make phase. +# + +if [[ -z "$NOBUILD" ]]; then + ./bootstrap.sh + ./configure --enable-tutorial=no + make -j3 precross +fi + # # C/C++ static code analysis with cppcheck # add --error-exitcode=1 to --enable=all as soon as everything is fixed @@ -21,18 +33,20 @@ cppcheck --force --quiet --inline-suppr --enable=all -j2 lib/cpp/src lib/cpp/tes cppcheck --force --quiet --inline-suppr --enable=all -j2 lib/c_glib/src lib/c_glib/test test/c_glib/src tutorial/c_glib # Silent error checks -cppcheck --force --quiet --inline-suppr --error-exitcode=1 -j2 compiler/cpp/src +# See THRIFT-4371 : flex generated code triggers "possible null pointer dereference" in yy_init_buffer +cppcheck --force --quiet --inline-suppr --suppress="*:thrift/thriftl.cc" --error-exitcode=1 -j2 compiler/cpp/src cppcheck --force --quiet --inline-suppr --error-exitcode=1 -j2 lib/cpp/src lib/cpp/test test/cpp tutorial/cpp cppcheck --force --quiet --inline-suppr --error-exitcode=1 -j2 lib/c_glib/src lib/c_glib/test test/c_glib/src tutorial/c_glib # Python code style flake8 --ignore=E501 lib/py flake8 tutorial/py -flake8 --ignore=E501 test/py +# THRIFT-4371 : generated files are excluded because they haven't been scrubbed yet +flake8 --ignore=E501 --exclude="*/gen-py*/*" test/py flake8 test/py.twisted flake8 test/py.tornado flake8 --ignore=E501 test/test.py -flake8 --ignore=E501 test/crossrunner +flake8 --ignore=E501,E722 test/crossrunner flake8 test/features # TODO etc diff --git a/lib/py/setup.py b/lib/py/setup.py index 3d1411812..4056b9b90 100644 --- a/lib/py/setup.py +++ b/lib/py/setup.py @@ -22,7 +22,7 @@ import sys try: from setuptools import setup, Extension -except: +except Exception: from distutils.core import setup, Extension from distutils.command.build_ext import build_ext diff --git a/test/features/container_limit.py b/test/features/container_limit.py index a16e3641e..88f8487fa 100644 --- a/test/features/container_limit.py +++ b/test/features/container_limit.py @@ -61,7 +61,7 @@ def main(argv): print('[OK]: just limit') try: test_list(proto, list(range(args.limit + 1))) - except: + except Exception: print('[OK]: limit + 1') else: print('[ERROR]: limit + 1') diff --git a/test/features/string_limit.py b/test/features/string_limit.py index 14f57d083..b8991d64f 100644 --- a/test/features/string_limit.py +++ b/test/features/string_limit.py @@ -51,7 +51,7 @@ def main(argv): print('[OK]: just limit') try: test_string(proto, 'a' * (args.limit + 1)) - except: + except Exception: print('[OK]: limit + 1') else: print('[ERROR]: limit + 1') diff --git a/test/py/TestServer.py b/test/py/TestServer.py index a7366a87b..04ad62a95 100755 --- a/test/py/TestServer.py +++ b/test/py/TestServer.py @@ -193,7 +193,7 @@ def main(options): try: pfactory.string_length_limit = options.string_limit pfactory.container_length_limit = options.container_limit - except: + except Exception: # Ignore errors for those protocols that does not support length limit pass @@ -255,7 +255,7 @@ def main(options): logging.info('Requesting server to stop()') try: server.stop() - except: + except Exception: pass signal.signal(signal.SIGALRM, clean_shutdown) signal.alarm(4) diff --git a/test/py/TestSocket.py b/test/py/TestSocket.py index ae3160f31..619eb1002 100755 --- a/test/py/TestSocket.py +++ b/test/py/TestSocket.py @@ -36,7 +36,7 @@ class TimeoutTest(unittest.TestCase): self.listen_sock.bind(('localhost', self.port)) self.listen_sock.listen(5) break - except: + except Exception: if i == 49: raise @@ -50,7 +50,7 @@ class TimeoutTest(unittest.TestCase): socket.setTimeout(10) socket.open() leaky.append(socket) - except: + except Exception: self.assert_(time.time() - starttime < 5.0) def testWriteTimeout(self): @@ -64,7 +64,7 @@ class TimeoutTest(unittest.TestCase): while True: lsock.write("hi" * 100) - except: + except Exception: self.assert_(time.time() - starttime < 5.0) -- cgit v1.2.1