cmake_static_check_cppcheck.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. # Contributor(s): Campbell Barton
  19. #
  20. # ***** END GPL LICENSE BLOCK *****
  21. # <pep8 compliant>
  22. import project_source_info
  23. import subprocess
  24. import sys
  25. import os
  26. USE_QUIET = (os.environ.get("QUIET", None) is not None)
  27. CHECKER_IGNORE_PREFIX = [
  28. "extern",
  29. "intern/moto",
  30. ]
  31. CHECKER_BIN = "cppcheck"
  32. CHECKER_ARGS = [
  33. # not sure why this is needed, but it is.
  34. "-I" + os.path.join(project_source_info.SOURCE_DIR, "extern", "glew", "include"),
  35. "--suppress=*:%s/extern/glew/include/GL/glew.h:241" % project_source_info.SOURCE_DIR,
  36. "--max-configs=1", # speeds up execution
  37. # "--check-config", # when includes are missing
  38. "--enable=all", # if you want sixty hundred pedantic suggestions
  39. ]
  40. if USE_QUIET:
  41. CHECKER_ARGS.append("--quiet")
  42. def main():
  43. source_info = project_source_info.build_info(ignore_prefix_list=CHECKER_IGNORE_PREFIX)
  44. source_defines = project_source_info.build_defines_as_args()
  45. check_commands = []
  46. for c, inc_dirs, defs in source_info:
  47. cmd = ([CHECKER_BIN] +
  48. CHECKER_ARGS +
  49. [c] +
  50. [("-I%s" % i) for i in inc_dirs] +
  51. [("-D%s" % d) for d in defs] +
  52. source_defines
  53. )
  54. check_commands.append((c, cmd))
  55. process_functions = []
  56. def my_process(i, c, cmd):
  57. if not USE_QUIET:
  58. percent = 100.0 * (i / len(check_commands))
  59. percent_str = "[" + ("%.2f]" % percent).rjust(7) + " %:"
  60. sys.stdout.flush()
  61. sys.stdout.write("%s " % percent_str)
  62. return subprocess.Popen(cmd)
  63. for i, (c, cmd) in enumerate(check_commands):
  64. process_functions.append((my_process, (i, c, cmd)))
  65. project_source_info.queue_processes(process_functions)
  66. print("Finished!")
  67. if __name__ == "__main__":
  68. main()