cmake_static_check_cppcheck.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/usr/bin/env python3
  2. # ***** BEGIN GPL LICENSE BLOCK *****
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software Foundation,
  16. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. #
  18. # ***** END GPL LICENSE BLOCK *****
  19. # <pep8 compliant>
  20. import project_source_info
  21. import subprocess
  22. import sys
  23. import os
  24. USE_QUIET = (os.environ.get("QUIET", None) is not None)
  25. CHECKER_IGNORE_PREFIX = [
  26. "extern",
  27. "intern/moto",
  28. ]
  29. CHECKER_BIN = "cppcheck"
  30. CHECKER_ARGS = [
  31. # not sure why this is needed, but it is.
  32. "-I" + os.path.join(project_source_info.SOURCE_DIR, "extern", "glew", "include"),
  33. "--suppress=*:%s/extern/glew/include/GL/glew.h:241" % project_source_info.SOURCE_DIR,
  34. "--max-configs=1", # speeds up execution
  35. # "--check-config", # when includes are missing
  36. "--enable=all", # if you want sixty hundred pedantic suggestions
  37. ]
  38. if USE_QUIET:
  39. CHECKER_ARGS.append("--quiet")
  40. def main():
  41. source_info = project_source_info.build_info(ignore_prefix_list=CHECKER_IGNORE_PREFIX)
  42. source_defines = project_source_info.build_defines_as_args()
  43. check_commands = []
  44. for c, inc_dirs, defs in source_info:
  45. cmd = ([CHECKER_BIN] +
  46. CHECKER_ARGS +
  47. [c] +
  48. [("-I%s" % i) for i in inc_dirs] +
  49. [("-D%s" % d) for d in defs] +
  50. source_defines
  51. )
  52. check_commands.append((c, cmd))
  53. process_functions = []
  54. def my_process(i, c, cmd):
  55. if not USE_QUIET:
  56. percent = 100.0 * (i / len(check_commands))
  57. percent_str = "[" + ("%.2f]" % percent).rjust(7) + " %:"
  58. sys.stdout.flush()
  59. sys.stdout.write("%s " % percent_str)
  60. return subprocess.Popen(cmd)
  61. for i, (c, cmd) in enumerate(check_commands):
  62. process_functions.append((my_process, (i, c, cmd)))
  63. project_source_info.queue_processes(process_functions)
  64. print("Finished!")
  65. if __name__ == "__main__":
  66. main()