donate-cpu.py: Improve header detection by using regex. (#1679)

This detects more includes / headers. For example includes like
"# include <gtk/gtk.h>" with a space before "include" as it is used in
the package http://cppcheck.osuosl.org:8000/gbatnav are now also
detected.
The regex search also searches all includes for one library in one go
instead of one include per loop.
Tested with several packages to make sure libraries that were detected
before are still detected.
This commit is contained in:
Sebastian 2019-02-21 08:14:47 +01:00 committed by GitHub
parent 0ee3f678b5
commit e27a44a0ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 4 deletions

View File

@ -37,7 +37,7 @@ import platform
# Version scheme (MAJOR.MINOR.PATCH) should orientate on "Semantic Versioning" https://semver.org/ # Version scheme (MAJOR.MINOR.PATCH) should orientate on "Semantic Versioning" https://semver.org/
# Every change in this script should result in increasing the version number accordingly (exceptions may be cosmetic # Every change in this script should result in increasing the version number accordingly (exceptions may be cosmetic
# changes) # changes)
CLIENT_VERSION = "1.1.5" CLIENT_VERSION = "1.1.6"
def checkRequirements(): def checkRequirements():
@ -216,9 +216,9 @@ def hasInclude(path, includes):
# Python3 directly reads the data into a string object that has no decode() # Python3 directly reads the data into a string object that has no decode()
pass pass
f.close() f.close()
for inc in includes: re_includes = [re.escape(inc) for inc in includes]
if filedata.find('\n#include ' + inc) >= 0: if re.search('\n#[ \t]*include[ \t]+(' + '|'.join(re_includes) + ')', filedata):
return True return True
except IOError: except IOError:
pass pass
return False return False