From 09f34faaf259aaa3193a418276cda038434a7890 Mon Sep 17 00:00:00 2001 From: Ben Spoor Date: Sat, 6 Mar 2021 10:21:58 +0100 Subject: [PATCH 1/3] Add main entry point --- flawfinder | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/flawfinder b/flawfinder index 49fed46..f8829a1 100755 --- a/flawfinder +++ b/flawfinder @@ -2352,8 +2352,11 @@ def flawfind(): return 1 if error_level_exceeded else 0 -if __name__ == '__main__': +def main(): try: sys.exit(flawfind()) except KeyboardInterrupt: print("*** Flawfinder interrupted") + +if __name__ == '__main__': + main() From 6b4b796c48a6ffa27ad74db5694814e46e94aa33 Mon Sep 17 00:00:00 2001 From: Ben Spoor Date: Sat, 6 Mar 2021 10:23:28 +0100 Subject: [PATCH 2/3] Make proper python module (add .py extension) --- flawfinder => flawfinder.py | 0 makefile | 8 ++++---- test/makefile | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) rename flawfinder => flawfinder.py (100%) mode change 100755 => 100644 diff --git a/flawfinder b/flawfinder.py old mode 100755 new mode 100644 similarity index 100% rename from flawfinder rename to flawfinder.py diff --git a/makefile b/makefile index cc2cece..0f6afba 100644 --- a/makefile +++ b/makefile @@ -67,7 +67,7 @@ INSTALL_DATA=cp -p # compiled code to override later uncompiled Python code. install: -$(MKDIR_P) $(DESTDIR)$(INSTALL_DIR_BIN) - $(INSTALL_PROGRAM) flawfinder $(DESTDIR)$(INSTALL_DIR_BIN)/flawfinder$(PYTHONEXT) + $(INSTALL_PROGRAM) flawfinder.py $(DESTDIR)$(INSTALL_DIR_BIN)/flawfinder$(PYTHONEXT) -$(MKDIR_P) $(DESTDIR)$(INSTALL_DIR_MAN) $(INSTALL_DATA) flawfinder.1 $(DESTDIR)$(INSTALL_DIR_MAN)/flawfinder.1 @@ -129,7 +129,7 @@ upload-pypi: time: echo "Timing the program. First, time taken:" - time ./flawfinder $(SAMPLE_DIR)/*/*.[ch] > /dev/null + time ./flawfinder.py $(SAMPLE_DIR)/*/*.[ch] > /dev/null echo "Lines examined:" wc -l $(SAMPLE_DIR)/*/*.[ch] | tail -2 @@ -145,7 +145,7 @@ test-is-correct: cd $(TESTDIR); $(MAKE) test-is-correct profile: - /usr/lib/python1.5/profile.py ./flawfinder > profile-results $(SAMPLE_DIR)/*/*.[ch] > profile-results + /usr/lib/python1.5/profile.py ./flawfinder.py > profile-results $(SAMPLE_DIR)/*/*.[ch] > profile-results rpm: distribute @@ -184,7 +184,7 @@ cwe: cwe.c $(CC) -o cwe cwe.c -lfl show-cwes: cwe - ./cwe < flawfinder | sort -u -V + ./cwe < flawfinder.py | sort -u -V pylint: pylint flawfinder diff --git a/test/makefile b/test/makefile index 20909b0..5ea8715 100644 --- a/test/makefile +++ b/test/makefile @@ -5,7 +5,7 @@ PYTHON=python PYTHON2=python2 PYTHON3=python3 -FLAWFINDER=../flawfinder +FLAWFINDER=../flawfinder.py SETUPPY=../setup.py test_001: $(FLAWFINDER) test.c test2.c From e0655e4fafd8143c1cabb0868d198ec1ecdb33d7 Mon Sep 17 00:00:00 2001 From: Ben Spoor Date: Sat, 6 Mar 2021 10:25:36 +0100 Subject: [PATCH 3/3] Use entry_points instead of scripts As decribed in https://click.palletsprojects.com/en/7.x/setuptools/ shebangs only work in unix and OSX (and in cygwin on windows). By using the entry_points mechanism Python will handle all cross-platform issues making it useable for everybody. --- setup.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index bf91b58..83d71f6 100644 --- a/setup.py +++ b/setup.py @@ -41,7 +41,11 @@ It is released under the GNU GPL license.""", 'Topic :: Software Development :: Testing' ], python_requires = '>=2.7', - scripts = [ 'flawfinder' ], + entry_points={ + 'console_scripts': [ + 'flawfinder = flawfinder:main', + ], + }, data_files = [ ('share/man/man1', [ 'flawfinder.1.gz' ]) ], - py_modules = [ ], + py_modules = ['flawfinder'], )