summaryrefslogtreecommitdiff
path: root/modules/mono/build_scripts/make_android_mono_config.py
blob: cd9210897dd943ab603819d9b8b90b800fb7c14f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

def generate_compressed_config(config_src, output_dir):
    import os.path
    from compat import byte_to_str

    # Header file
    with open(os.path.join(output_dir, 'android_mono_config.gen.h'), 'w') as header:
        header.write('''/* THIS FILE IS GENERATED DO NOT EDIT */
#ifndef ANDROID_MONO_CONFIG_GEN_H
#define ANDROID_MONO_CONFIG_GEN_H

#ifdef ANDROID_ENABLED

#include "core/ustring.h"

String get_godot_android_mono_config();

#endif // ANDROID_ENABLED

#endif // ANDROID_MONO_CONFIG_GEN_H
''')

    # Source file
    with open(os.path.join(output_dir, 'android_mono_config.gen.cpp'), 'w') as cpp:
        with open(config_src, 'rb') as f:
            buf = f.read()
            decompr_size = len(buf)
            import zlib
            buf = zlib.compress(buf)
            compr_size = len(buf)

            bytes_seq_str = ''
            for i, buf_idx in enumerate(range(compr_size)):
                if i > 0:
                    bytes_seq_str += ', '
                bytes_seq_str += byte_to_str(buf[buf_idx])

            cpp.write('''/* THIS FILE IS GENERATED DO NOT EDIT */
#include "android_mono_config.gen.h"

#ifdef ANDROID_ENABLED

#include "core/io/compression.h"
#include "core/pool_vector.h"

namespace {

// config
static const int config_compressed_size = %d;
static const int config_uncompressed_size = %d;
static const unsigned char config_compressed_data[] = { %s };

} // namespace

String get_godot_android_mono_config() {
	PoolVector<uint8_t> data;
	data.resize(config_uncompressed_size);
	PoolVector<uint8_t>::Write w = data.write();
	Compression::decompress(w.ptr(), config_uncompressed_size, config_compressed_data,
			config_compressed_size, Compression::MODE_DEFLATE);
	String s;
	if (s.parse_utf8((const char *)w.ptr(), data.size())) {
		ERR_FAIL_V(String());
	}
	return s;
}

#endif // ANDROID_ENABLED
''' % (compr_size, decompr_size, bytes_seq_str))