our_knp/examples/tools/hooks/oclint.py
int 8f43927575 Initial import: KNP experiments (examples, viz, cats-dogs, reports)
examples/ is based on KasperskyLab/knp at 55470ed6 with local changes
to the mnist-learn altai/blifat models, cuda-backend CMake and model_loader.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 18:17:15 +03:00

63 lines
2.4 KiB
Python

#!/usr/bin/env python
"""Wrapper script for oclint."""
import os
import sys
from typing import List
from tools_lib.static_analyzer_cmd import StaticAnalyzerCmd
class OCLintCmd(StaticAnalyzerCmd):
"""Class for the OCLint command."""
command = "oclint"
lookbehind = "OCLint version "
def __init__(self, args: List[str]):
super().__init__(self.command, self.lookbehind, args)
self.version = self.get_version_str()
self.parse_args(args)
# Earlier versions (0.13.1 and before) have -no-analytics and 1 dash instead of 2 for args.
if self.version >= "20":
# Check for as many errors as possible (see https://github.com/oclint/oclint/issues/538).
self.add_if_missing(["--max-priority-3", "0"])
# Enable different classes of analysis.
self.add_if_missing(["--enable-global-analysis", "--enable-clang-static-analyzer"])
else:
# Check for as many errors as possible (see https://github.com/oclint/oclint/issues/538).
self.add_if_missing(["-max-priority-3", "0"])
# Enable different classes of analysis.
self.add_if_missing(["-enable-global-analysis", "-enable-clang-static-analyzer"])
# Sending analytics can cause oclint to hang, but is not an option in later versions.
self.add_if_missing(["-no-analytics"])
def run(self):
"""Run OCLint and remove generated temporary files. OCLint will put the standard reprot into stderr."""
# Split text into an array of args that can be passed into oclint.
for filename in self.files:
current_files = os.listdir(os.getcwd())
self.run_command([filename] + self.args)
# Errors are sent to stdout instead of stderr.
if b"Errors" in self.stdout:
self.stderr = self.stdout
# If errors have been captured, stdout is unexpected.
self.stdout = b""
self.exit_on_error()
self.cleanup_files(current_files)
@staticmethod
def cleanup_files(existing_files: List[str]):
"""Delete the plist files that oclint generates."""
new_files = os.listdir(os.getcwd())
for filename in new_files:
if filename not in existing_files and filename[-6:] == ".plist":
os.remove(filename)
def main(argv: List[str]):
cmd = OCLintCmd(argv)
cmd.run()
if __name__ == '__main__':
main(sys.argv)