make_android_mono_config.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. def generate_compressed_config(config_src, output_dir):
  2. import os.path
  3. # Source file
  4. with open(os.path.join(output_dir, "android_mono_config.gen.cpp"), "w") as cpp:
  5. with open(config_src, "rb") as f:
  6. buf = f.read()
  7. decompr_size = len(buf)
  8. import zlib
  9. # Use maximum zlib compression level to further reduce file size
  10. # (at the cost of initial build times).
  11. buf = zlib.compress(buf, zlib.Z_BEST_COMPRESSION)
  12. compr_size = len(buf)
  13. bytes_seq_str = ""
  14. for i, buf_idx in enumerate(range(compr_size)):
  15. if i > 0:
  16. bytes_seq_str += ", "
  17. bytes_seq_str += str(buf[buf_idx])
  18. cpp.write(
  19. """/* THIS FILE IS GENERATED DO NOT EDIT */
  20. #include "android_mono_config.h"
  21. #ifdef ANDROID_ENABLED
  22. #include "core/io/compression.h"
  23. namespace {
  24. // config
  25. static const int config_compressed_size = %d;
  26. static const int config_uncompressed_size = %d;
  27. static const unsigned char config_compressed_data[] = { %s };
  28. } // namespace
  29. String get_godot_android_mono_config() {
  30. Vector<uint8_t> data;
  31. data.resize(config_uncompressed_size);
  32. uint8_t* w = data.ptrw();
  33. Compression::decompress(w, config_uncompressed_size, config_compressed_data,
  34. config_compressed_size, Compression::MODE_DEFLATE);
  35. String s;
  36. if (s.parse_utf8((const char *)w, data.size()) != OK) {
  37. ERR_FAIL_V(String());
  38. }
  39. return s;
  40. }
  41. #endif // ANDROID_ENABLED
  42. """
  43. % (compr_size, decompr_size, bytes_seq_str)
  44. )