make_android_mono_config.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. buf = zlib.compress(buf)
  10. compr_size = len(buf)
  11. bytes_seq_str = ''
  12. for i, buf_idx in enumerate(range(compr_size)):
  13. if i > 0:
  14. bytes_seq_str += ', '
  15. bytes_seq_str += str(buf[buf_idx])
  16. cpp.write('''/* THIS FILE IS GENERATED DO NOT EDIT */
  17. #include "android_mono_config.h"
  18. #ifdef ANDROID_ENABLED
  19. #include "core/io/compression.h"
  20. namespace {
  21. // config
  22. static const int config_compressed_size = %d;
  23. static const int config_uncompressed_size = %d;
  24. static const unsigned char config_compressed_data[] = { %s };
  25. } // namespace
  26. String get_godot_android_mono_config() {
  27. Vector<uint8_t> data;
  28. data.resize(config_uncompressed_size);
  29. uint8_t* w = data.ptrw();
  30. Compression::decompress(w.ptr(), config_uncompressed_size, config_compressed_data,
  31. config_compressed_size, Compression::MODE_DEFLATE);
  32. String s;
  33. if (s.parse_utf8((const char *)w.ptr(), data.size())) {
  34. ERR_FAIL_V(String());
  35. }
  36. return s;
  37. }
  38. #endif // ANDROID_ENABLED
  39. ''' % (compr_size, decompr_size, bytes_seq_str))