cmake_static_check_splint.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. CHECKER_IGNORE_PREFIX = [
  23. "extern",
  24. "intern/moto",
  25. ]
  26. CHECKER_BIN = "splint"
  27. CHECKER_ARGS = [
  28. "-weak",
  29. "-posix-lib",
  30. "-linelen", "10000",
  31. "+ignorequals",
  32. "+relaxtypes",
  33. "-retvalother",
  34. "+matchanyintegral",
  35. "+longintegral",
  36. "+ignoresigns",
  37. "-nestcomment",
  38. "-predboolothers",
  39. "-ifempty",
  40. "-unrecogcomments",
  41. # we may want to remove these later
  42. "-type",
  43. "-fixedformalarray",
  44. "-fullinitblock",
  45. "-fcnuse",
  46. "-initallelements",
  47. "-castfcnptr",
  48. # -forcehints,
  49. "-bufferoverflowhigh", # warns a lot about sprintf()
  50. # re-definitions, rna causes most of these
  51. "-redef",
  52. "-syntax",
  53. # dummy, witjout this splint complains with:
  54. # /usr/include/bits/confname.h:31:27: *** Internal Bug at cscannerHelp.c:2428: Unexpanded macro not function or constant: int _PC_MAX_CANON
  55. "-D_PC_MAX_CANON=0",
  56. ]
  57. import project_source_info
  58. import subprocess
  59. import sys
  60. import os
  61. USE_QUIET = (os.environ.get("QUIET", None) is not None)
  62. def main():
  63. source_info = project_source_info.build_info(use_cxx=False, ignore_prefix_list=CHECKER_IGNORE_PREFIX)
  64. check_commands = []
  65. for c, inc_dirs, defs in source_info:
  66. cmd = ([CHECKER_BIN] +
  67. CHECKER_ARGS +
  68. [c] +
  69. [("-I%s" % i) for i in inc_dirs] +
  70. [("-D%s" % d) for d in defs]
  71. )
  72. check_commands.append((c, cmd))
  73. def my_process(i, c, cmd):
  74. if not USE_QUIET:
  75. percent = 100.0 * (i / len(check_commands))
  76. percent_str = "[" + ("%.2f]" % percent).rjust(7) + " %:"
  77. sys.stdout.write("%s %s\n" % (percent_str, c))
  78. sys.stdout.flush()
  79. return subprocess.Popen(cmd)
  80. process_functions = []
  81. for i, (c, cmd) in enumerate(check_commands):
  82. process_functions.append((my_process, (i, c, cmd)))
  83. project_source_info.queue_processes(process_functions)
  84. if __name__ == "__main__":
  85. main()