From 1d9b6e1aac10a1ab4531a8f8dfa9f06b3945ecab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Tue, 12 Jul 2022 19:39:07 +0200 Subject: [PATCH] donate-cpu: fixed library detection (#4261) --- tools/donate-cpu.py | 7 ++++--- tools/donate_cpu_lib.py | 14 ++++++++------ tools/test-my-pr.py | 9 +++++---- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/tools/donate-cpu.py b/tools/donate-cpu.py index bb308e038..16345c64b 100755 --- a/tools/donate-cpu.py +++ b/tools/donate-cpu.py @@ -195,7 +195,8 @@ while True: if package.find('/qtcreator/') > 0: # macro_pounder_fn.c is a preprocessor torture test that takes time to finish skip_files = ('macro_pounder_fn.c',) - if not unpack_package(work_path, tgz, skip_files=skip_files): + source_path, source_found = unpack_package(work_path, tgz, skip_files=skip_files) + if not source_found: print("No files to process") continue crash = False @@ -208,7 +209,7 @@ while True: head_timing_info = '' old_timing_info = '' cppcheck_head_info = '' - libraries = get_libraries() + libraries = get_libraries(source_path) for ver in cppcheck_versions: tree_path = os.path.join(work_path, 'tree-'+ver) @@ -217,7 +218,7 @@ while True: tree_path = os.path.join(work_path, 'tree-main') cppcheck_head_info = get_cppcheck_info(tree_path) capture_callstack = True - c, errout, info, t, cppcheck_options, timing_info = scan_package(work_path, tree_path, jobs, libraries, capture_callstack) + c, errout, info, t, cppcheck_options, timing_info = scan_package(work_path, tree_path, source_path, jobs, libraries, capture_callstack) if c < 0: if c == -101 and 'error: could not find or open any of the paths given.' in errout: # No sourcefile found (for example only headers present) diff --git a/tools/donate_cpu_lib.py b/tools/donate_cpu_lib.py index 7199bfc73..eb660d807 100644 --- a/tools/donate_cpu_lib.py +++ b/tools/donate_cpu_lib.py @@ -15,7 +15,7 @@ import shlex # 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 # changes) -CLIENT_VERSION = "1.3.25" +CLIENT_VERSION = "1.3.26" # Timeout for analysis with Cppcheck in seconds CPPCHECK_TIMEOUT = 30 * 60 @@ -268,7 +268,7 @@ def unpack_package(work_path, tgz, cpp_only=False, skip_files=None): pass except AttributeError: pass - return found + return temp_path, found def __has_include(path, includes): @@ -325,7 +325,7 @@ def __run_command(cmd, print_cmd=True): return return_code, stdout, stderr, elapsed_time -def scan_package(work_path, cppcheck_path, jobs, libraries, capture_callstack=True): +def scan_package(work_path, cppcheck_path, source_path, jobs, libraries, capture_callstack=True): print('Analyze..') os.chdir(work_path) libs = '' @@ -333,7 +333,7 @@ def scan_package(work_path, cppcheck_path, jobs, libraries, capture_callstack=Tr if os.path.exists(os.path.join(cppcheck_path, 'cfg', library + '.cfg')): libs += '--library=' + library + ' ' - dir_to_scan = 'temp' + dir_to_scan = os.path.basename(source_path) # Reference for GNU C: https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html options = libs + ' --showtime=top5 --check-library --inconclusive --enable=style,information --inline-suppr --template=daca2' @@ -542,7 +542,7 @@ def upload_info(package, info_output, server_address): return False -def get_libraries(): +def get_libraries(folder): libraries = ['posix', 'gnu'] library_includes = {'boost': ['', '', '', '', '', '', ''], @@ -578,9 +578,11 @@ def get_libraries(): 'wxwidgets': [''], } + print('Detecting library usage...') for library, includes in library_includes.items(): - if __has_include('temp', includes): + if __has_include(folder, includes): libraries.append(library) + print('Found libraries: {}'.format(libraries)) return libraries diff --git a/tools/test-my-pr.py b/tools/test-my-pr.py index dca0f062f..62f521b65 100755 --- a/tools/test-my-pr.py +++ b/tools/test-my-pr.py @@ -119,7 +119,8 @@ if __name__ == "__main__": print("No package downloaded") continue - if not lib.unpack_package(work_path, tgz, args.cpp_only): + source_path, source_found = lib.unpack_package(work_path, tgz, args.cpp_only) + if not source_found: print("No files to process") continue @@ -131,8 +132,8 @@ if __name__ == "__main__": main_timeout = False your_timeout = False - libraries = lib.get_libraries() - c, errout, info, time_main, cppcheck_options, timing_info = lib.scan_package(work_path, main_dir, jobs, libraries) + libraries = lib.get_libraries(source_path) + c, errout, info, time_main, cppcheck_options, timing_info = lib.scan_package(work_path, main_dir, source_path, jobs, libraries) if c < 0: if c == -101 and 'error: could not find or open any of the paths given.' in errout: # No sourcefile found (for example only headers present) @@ -145,7 +146,7 @@ if __name__ == "__main__": main_crashed = True results_to_diff.append(errout) - c, errout, info, time_your, cppcheck_options, timing_info = lib.scan_package(work_path, your_repo_dir, jobs, libraries) + c, errout, info, time_your, cppcheck_options, timing_info = lib.scan_package(work_path, your_repo_dir, source_path, jobs, libraries) if c < 0: if c == -101 and 'error: could not find or open any of the paths given.' in errout: # No sourcefile found (for example only headers present)