JD2022-TU1/main/extern/UbiServices/custom/tests/preBuildCheck.py

41 lines
No EOL
2 KiB
Python

import os
import sys
import mmap
from fnmatch import fnmatch
dir_path = os.path.dirname(os.path.realpath(__file__)) # ubiservices\tests
root = "\\".join(dir_path.split('\\')[:-1]) # ubiservices
path = root + "\\client-sdk\\public" # ubiservices\client-sdk\public
# This is the list of public defines in CmakeLists.txt, that should not be included in any of the SDK's public files.
# How are we going to maintain this list though?
privateDefines = ["US_LOCK_RESTRICTIONS_ENABLED", "US_DEBUG_STRING_ENABLED", "US_SYSTEM_CHECK_ENABLED", "US_NETWORK_LAYER_ENABLED", "US_USE_LIBCURL", "US_LIBCURL_USES_OPENSSL", "US_USE_OPENSSL"]
pattern = "*.h"
headerFault = 0
faultyHeaderMessage = ""
printHeaderMessage = True
for path, subdirs, files in os.walk(path):
for name in files:
if fnmatch(name, pattern):
with open(os.path.join(path, name), 'rb', 0) as file, mmap.mmap(file.fileno(), 0, access=mmap.ACCESS_READ) as s:
if s.find(b'/private/') != -1:
headerFault = headerFault + 1
faultyHeaderMessage = "Public header including PRIVATE header: " + os.path.join(path, name)
for define in privateDefines:
if s.find(bytearray(('defined(' + define + ')'), 'utf8')) != -1:
headerFault = headerFault + 1
faultyHeaderMessage = "Public header including PRIVATE define " + define + ' in: ' + os.path.join(path, name)
if (headerFault == 1 and printHeaderMessage):
print("- FAULTY HEADERS -----------------------------------------------------------------------------------")
printHeaderMessage = False;
if(faultyHeaderMessage):
print(faultyHeaderMessage)
faultyHeaderMessage = ""
if (headerFault > 0):
print("----------------------------------------------------------------------------------------------------")
sys.exit(1)