summaryrefslogtreecommitdiff
path: root/core/extension
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2022-10-31 11:54:38 +0100
committerRémi Verschelde <rverschelde@gmail.com>2022-10-31 11:54:38 +0100
commit6946bc56ef422ae2de51200297f626c4751b06f5 (patch)
tree6567ea5c4904eab3133404962a33e9c5c6e48551 /core/extension
parent099f127cc33c5daa9a3e36b8cdb407e32249b003 (diff)
parent55010a2d9f91798f08bd2deded9445a4354ee3ee (diff)
Merge pull request #67309 from groud/implement_gdnative_interface_h_dump
Implement a way to dump the gdnative_interface.h file from the executable
Diffstat (limited to 'core/extension')
-rw-r--r--core/extension/SCsub7
-rw-r--r--core/extension/make_interface_dumper.py47
2 files changed, 53 insertions, 1 deletions
diff --git a/core/extension/SCsub b/core/extension/SCsub
index 23727c1b76..a8f68a1533 100644
--- a/core/extension/SCsub
+++ b/core/extension/SCsub
@@ -3,10 +3,15 @@
Import("env")
import make_wrappers
+import make_interface_dumper
from platform_methods import run_in_subprocess
env.CommandNoCache(["ext_wrappers.gen.inc"], "make_wrappers.py", run_in_subprocess(make_wrappers.run))
-
+env.CommandNoCache(
+ "gdnative_interface_dump.gen.h",
+ ["gdnative_interface.h", "make_interface_dumper.py"],
+ run_in_subprocess(make_interface_dumper.run),
+)
env_extension = env.Clone()
diff --git a/core/extension/make_interface_dumper.py b/core/extension/make_interface_dumper.py
new file mode 100644
index 0000000000..cc85c728d5
--- /dev/null
+++ b/core/extension/make_interface_dumper.py
@@ -0,0 +1,47 @@
+def run(target, source, env):
+ src = source[0]
+ dst = target[0]
+ f = open(src, "r", encoding="utf-8")
+ g = open(dst, "w", encoding="utf-8")
+
+ g.write(
+ """/* THIS FILE IS GENERATED DO NOT EDIT */
+#ifndef GDNATIVE_INTERFACE_DUMP_H
+#define GDNATIVE_INTERFACE_DUMP_H
+
+#ifdef TOOLS_ENABLED
+
+#include "core/io/file_access.h"
+#include "core/string/ustring.h"
+
+class GDNativeInterfaceDump {
+ private:
+ static constexpr char const *gdnative_interface_dump ="""
+ )
+ for line in f:
+ g.write('"' + line.rstrip().replace('"', '\\"') + '\\n"\n')
+ g.write(";\n")
+
+ g.write(
+ """
+ public:
+ static void generate_gdnative_interface_file(const String &p_path) {
+ Ref<FileAccess> fa = FileAccess::open(p_path, FileAccess::WRITE);
+ CharString cs(gdnative_interface_dump);
+ fa->store_buffer((const uint8_t *)cs.ptr(), cs.length());
+ };
+};
+
+#endif // TOOLS_ENABLED
+
+#endif // GDNATIVE_INTERFACE_DUMP_H
+"""
+ )
+ g.close()
+ f.close()
+
+
+if __name__ == "__main__":
+ from platform_methods import subprocess_main
+
+ subprocess_main(globals())