make_interface_dumper.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. def run(target, source, env):
  2. src = source[0]
  3. dst = target[0]
  4. f = open(src, "r", encoding="utf-8")
  5. g = open(dst, "w", encoding="utf-8")
  6. g.write(
  7. """/* THIS FILE IS GENERATED DO NOT EDIT */
  8. #ifndef GDEXTENSION_INTERFACE_DUMP_H
  9. #define GDEXTENSION_INTERFACE_DUMP_H
  10. #ifdef TOOLS_ENABLED
  11. #include "core/io/file_access.h"
  12. #include "core/string/ustring.h"
  13. class GDExtensionInterfaceDump {
  14. private:
  15. static constexpr char const *gdextension_interface_dump ="""
  16. )
  17. for line in f:
  18. g.write('"' + line.rstrip().replace('"', '\\"') + '\\n"\n')
  19. g.write(";\n")
  20. g.write(
  21. """
  22. public:
  23. static void generate_gdextension_interface_file(const String &p_path) {
  24. Ref<FileAccess> fa = FileAccess::open(p_path, FileAccess::WRITE);
  25. ERR_FAIL_COND_MSG(fa.is_null(), vformat("Cannot open file '%s' for writing.", p_path));
  26. CharString cs(gdextension_interface_dump);
  27. fa->store_buffer((const uint8_t *)cs.ptr(), cs.length());
  28. };
  29. };
  30. #endif // TOOLS_ENABLED
  31. #endif // GDEXTENSION_INTERFACE_DUMP_H
  32. """
  33. )
  34. g.close()
  35. f.close()
  36. if __name__ == "__main__":
  37. from platform_methods import subprocess_main
  38. subprocess_main(globals())