cmake_static_check_sparse.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 = "sparse"
  27. CHECKER_ARGS = [
  28. ]
  29. import project_source_info
  30. import subprocess
  31. import sys
  32. import os
  33. USE_QUIET = (os.environ.get("QUIET", None) is not None)
  34. def main():
  35. source_info = project_source_info.build_info(use_cxx=False, ignore_prefix_list=CHECKER_IGNORE_PREFIX)
  36. source_defines = project_source_info.build_defines_as_args()
  37. check_commands = []
  38. for c, inc_dirs, defs in source_info:
  39. cmd = ([CHECKER_BIN] +
  40. CHECKER_ARGS +
  41. [c] +
  42. [("-I%s" % i) for i in inc_dirs] +
  43. [("-D%s" % d) for d in defs] +
  44. source_defines
  45. )
  46. check_commands.append((c, cmd))
  47. def my_process(i, c, cmd):
  48. if not USE_QUIET:
  49. percent = 100.0 * (i / len(check_commands))
  50. percent_str = "[" + ("%.2f]" % percent).rjust(7) + " %:"
  51. sys.stdout.flush()
  52. sys.stdout.write("%s %s\n" % (percent_str, c))
  53. return subprocess.Popen(cmd)
  54. process_functions = []
  55. for i, (c, cmd) in enumerate(check_commands):
  56. process_functions.append((my_process, (i, c, cmd)))
  57. project_source_info.queue_processes(process_functions)
  58. if __name__ == "__main__":
  59. main()