diff options
author | David Snopek <dsnopek@gmail.com> | 2024-01-25 08:54:58 -0600 |
---|---|---|
committer | David Snopek <dsnopek@gmail.com> | 2024-05-07 11:08:18 -0500 |
commit | a434850069212b2d2dbe70fd82c4e5774b739040 (patch) | |
tree | dc624f2af43e2033fb7304e879f5d8348feac7d8 /tools | |
parent | 54fe2f9891525891a52c47ffbd190d15c38cccab (diff) | |
download | redot-cpp-a434850069212b2d2dbe70fd82c4e5774b739040.tar.gz |
Allow submitting documentation to the Godot editor
Diffstat (limited to 'tools')
-rw-r--r-- | tools/godotcpp.py | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/tools/godotcpp.py b/tools/godotcpp.py index 13a57e9..2e61e2b 100644 --- a/tools/godotcpp.py +++ b/tools/godotcpp.py @@ -325,6 +325,51 @@ def options(opts, env): tool.options(opts) +def make_doc_source(target, source, env): + import zlib + + dst = str(target[0]) + g = open(dst, "w", encoding="utf-8") + buf = "" + docbegin = "" + docend = "" + for src in source: + src_path = str(src) + if not src_path.endswith(".xml"): + continue + with open(src_path, "r", encoding="utf-8") as f: + content = f.read() + buf += content + + buf = (docbegin + buf + docend).encode("utf-8") + decomp_size = len(buf) + + # 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) + + g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n") + g.write("\n") + g.write("#include <godot_cpp/godot.hpp>\n") + g.write("\n") + + g.write('static const char *_doc_data_hash = "' + str(hash(buf)) + '";\n') + g.write("static const int _doc_data_uncompressed_size = " + str(decomp_size) + ";\n") + g.write("static const int _doc_data_compressed_size = " + str(len(buf)) + ";\n") + g.write("static const unsigned char _doc_data_compressed[] = {\n") + for i in range(len(buf)): + g.write("\t" + str(buf[i]) + ",\n") + g.write("};\n") + g.write("\n") + + g.write( + "static godot::internal::DocDataRegistration _doc_data_registration(_doc_data_hash, _doc_data_uncompressed_size, _doc_data_compressed_size, _doc_data_compressed);\n" + ) + g.write("\n") + + g.close() + + def generate(env): # Default num_jobs to local cpu count if not user specified. # SCons has a peculiarity where user-specified options won't be overridden @@ -451,7 +496,8 @@ def generate(env): # Builders env.Append( BUILDERS={ - "GodotCPPBindings": Builder(action=Action(scons_generate_bindings, "$GENCOMSTR"), emitter=scons_emit_files) + "GodotCPPBindings": Builder(action=Action(scons_generate_bindings, "$GENCOMSTR"), emitter=scons_emit_files), + "GodotCPPDocData": Builder(action=make_doc_source), } ) env.AddMethod(_godot_cpp, "GodotCPP") |