ShaderProgramDependencies.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/python3
  2. # Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors.
  3. # All rights reserved.
  4. # Code licensed under the BSD License.
  5. # http://www.anki3d.org/LICENSE
  6. # Generates the dependencies of a shader program file. Output consumed by CMake
  7. import optparse
  8. import re
  9. def parse_commandline():
  10. """ Parse the command line arguments """
  11. parser = optparse.OptionParser(usage="usage: %prog [options]",
  12. description="This script gathers all the include files of a shader program")
  13. parser.add_option("-i", "--input", dest="inp", type="string", help="Inpute .ankiprog file")
  14. (options, args) = parser.parse_args()
  15. if not options.inp:
  16. parser.error("argument is missing")
  17. return options.inp
  18. def parse_file(fname):
  19. file = open(fname, mode="r")
  20. txt = file.read()
  21. my_includes = re.findall(r"\s*#\s*include\ <(.*)>", txt)
  22. agregated_includes = []
  23. for include in my_includes:
  24. # Skip non-shaders
  25. if "AnKi/Shaders" not in include:
  26. continue
  27. agregated_includes.append(include)
  28. # Append recursively
  29. other_includes = parse_file(include)
  30. for other_include in other_includes:
  31. if other_include not in agregated_includes:
  32. agregated_includes.append(other_include)
  33. return agregated_includes
  34. def main():
  35. input_fname = parse_commandline()
  36. includes = parse_file(input_fname)
  37. str = ""
  38. for i in range(len(includes)):
  39. include = includes[i]
  40. include = include.replace("AnKi/Shaders/", "")
  41. if i < len(includes) - 1:
  42. str += include + ";" # CMake wants ; as a separator
  43. else:
  44. str += include
  45. print(str, end="") # No newline at the end
  46. if __name__ == "__main__":
  47. main()