2023-05-16 20:11:51 +00:00
|
|
|
import zlib
|
|
|
|
|
|
|
|
|
2022-10-12 14:21:34 +00:00
|
|
|
def run(target, source, env):
|
2024-03-11 18:05:37 +00:00
|
|
|
src = str(source[0])
|
|
|
|
dst = str(target[0])
|
2024-03-10 17:09:48 +00:00
|
|
|
with open(src, "rb") as f, open(dst, "w", encoding="utf-8", newline="\n") as g:
|
|
|
|
buf = f.read()
|
|
|
|
decomp_size = len(buf)
|
2022-10-12 14:21:34 +00:00
|
|
|
|
2024-03-10 17:09:48 +00:00
|
|
|
# Use maximum zlib compression level to further reduce file size
|
|
|
|
# (at the cost of initial build times).
|
|
|
|
buf = zlib.compress(buf, zlib.Z_BEST_COMPRESSION)
|
2023-05-16 20:11:51 +00:00
|
|
|
|
2024-03-10 17:09:48 +00:00
|
|
|
g.write(
|
|
|
|
"""/* THIS FILE IS GENERATED DO NOT EDIT */
|
2022-12-07 11:11:28 +00:00
|
|
|
#ifndef GDEXTENSION_INTERFACE_DUMP_H
|
|
|
|
#define GDEXTENSION_INTERFACE_DUMP_H
|
2022-10-12 14:21:34 +00:00
|
|
|
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
|
2023-05-16 20:11:51 +00:00
|
|
|
#include "core/io/compression.h"
|
2022-10-12 14:21:34 +00:00
|
|
|
#include "core/io/file_access.h"
|
|
|
|
#include "core/string/ustring.h"
|
|
|
|
|
2023-05-16 20:11:51 +00:00
|
|
|
"""
|
2024-03-10 17:09:48 +00:00
|
|
|
)
|
2023-05-16 20:11:51 +00:00
|
|
|
|
2024-03-10 17:09:48 +00:00
|
|
|
g.write("static const int _gdextension_interface_data_compressed_size = " + str(len(buf)) + ";\n")
|
|
|
|
g.write("static const int _gdextension_interface_data_uncompressed_size = " + str(decomp_size) + ";\n")
|
|
|
|
g.write("static const unsigned char _gdextension_interface_data_compressed[] = {\n")
|
|
|
|
for i in range(len(buf)):
|
|
|
|
g.write("\t" + str(buf[i]) + ",\n")
|
|
|
|
g.write("};\n")
|
2022-10-12 14:21:34 +00:00
|
|
|
|
2024-03-10 17:09:48 +00:00
|
|
|
g.write(
|
|
|
|
"""
|
2023-05-16 20:11:51 +00:00
|
|
|
class GDExtensionInterfaceDump {
|
2022-10-12 14:21:34 +00:00
|
|
|
public:
|
2022-12-07 11:11:28 +00:00
|
|
|
static void generate_gdextension_interface_file(const String &p_path) {
|
2022-10-12 14:21:34 +00:00
|
|
|
Ref<FileAccess> fa = FileAccess::open(p_path, FileAccess::WRITE);
|
2023-03-08 04:30:37 +00:00
|
|
|
ERR_FAIL_COND_MSG(fa.is_null(), vformat("Cannot open file '%s' for writing.", p_path));
|
2023-05-16 20:11:51 +00:00
|
|
|
Vector<uint8_t> data;
|
|
|
|
data.resize(_gdextension_interface_data_uncompressed_size);
|
|
|
|
int ret = Compression::decompress(data.ptrw(), _gdextension_interface_data_uncompressed_size, _gdextension_interface_data_compressed, _gdextension_interface_data_compressed_size, Compression::MODE_DEFLATE);
|
|
|
|
ERR_FAIL_COND_MSG(ret == -1, "Compressed file is corrupt.");
|
|
|
|
fa->store_buffer(data.ptr(), data.size());
|
2022-10-12 14:21:34 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // TOOLS_ENABLED
|
|
|
|
|
2022-12-07 11:11:28 +00:00
|
|
|
#endif // GDEXTENSION_INTERFACE_DUMP_H
|
2022-10-12 14:21:34 +00:00
|
|
|
"""
|
2024-03-10 17:09:48 +00:00
|
|
|
)
|