make_android_mono_config.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. def generate_compressed_config(config_src, output_dir):
  2. import os.path
  3. from compat import byte_to_str
  4. # Header file
  5. with open(os.path.join(output_dir, 'android_mono_config.gen.h'), 'w') as header:
  6. header.write('''/* THIS FILE IS GENERATED DO NOT EDIT */
  7. #ifndef ANDROID_MONO_CONFIG_GEN_H
  8. #define ANDROID_MONO_CONFIG_GEN_H
  9. #ifdef ANDROID_ENABLED
  10. #include "core/ustring.h"
  11. String get_godot_android_mono_config();
  12. #endif // ANDROID_ENABLED
  13. #endif // ANDROID_MONO_CONFIG_GEN_H
  14. ''')
  15. # Source file
  16. with open(os.path.join(output_dir, 'android_mono_config.gen.cpp'), 'w') as cpp:
  17. with open(config_src, 'rb') as f:
  18. buf = f.read()
  19. decompr_size = len(buf)
  20. import zlib
  21. buf = zlib.compress(buf)
  22. compr_size = len(buf)
  23. bytes_seq_str = ''
  24. for i, buf_idx in enumerate(range(compr_size)):
  25. if i > 0:
  26. bytes_seq_str += ', '
  27. bytes_seq_str += byte_to_str(buf[buf_idx])
  28. cpp.write('''/* THIS FILE IS GENERATED DO NOT EDIT */
  29. #include "android_mono_config.gen.h"
  30. #ifdef ANDROID_ENABLED
  31. #include "core/io/compression.h"
  32. #include "core/pool_vector.h"
  33. namespace {
  34. // config
  35. static const int config_compressed_size = %d;
  36. static const int config_uncompressed_size = %d;
  37. static const unsigned char config_compressed_data[] = { %s };
  38. } // namespace
  39. String get_godot_android_mono_config() {
  40. PoolVector<uint8_t> data;
  41. data.resize(config_uncompressed_size);
  42. PoolVector<uint8_t>::Write w = data.write();
  43. Compression::decompress(w.ptr(), config_uncompressed_size, config_compressed_data,
  44. config_compressed_size, Compression::MODE_DEFLATE);
  45. String s;
  46. if (s.parse_utf8((const char *)w.ptr(), data.size())) {
  47. ERR_FAIL_V(String());
  48. }
  49. return s;
  50. }
  51. #endif // ANDROID_ENABLED
  52. ''' % (compr_size, decompr_size, bytes_seq_str))