mirror of
https://github.com/godotengine/godot.git
synced 2024-12-15 10:12:40 +08:00
cd4e46ee65
Configured for a max line length of 120 characters. psf/black is very opinionated and purposely doesn't leave much room for configuration. The output is mostly OK so that should be fine for us, but some things worth noting: - Manually wrapped strings will be reflowed, so by using a line length of 120 for the sake of preserving readability for our long command calls, it also means that some manually wrapped strings are back on the same line and should be manually merged again. - Code generators using string concatenation extensively look awful, since black puts each operand on a single line. We need to refactor these generators to use more pythonic string formatting, for which many options are available (`%`, `format` or f-strings). - CI checks and a pre-commit hook will be added to ensure that future buildsystem changes are well-formatted.
55 lines
1.4 KiB
Python
55 lines
1.4 KiB
Python
def generate_compressed_config(config_src, output_dir):
|
|
import os.path
|
|
|
|
# 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 += str(buf[buf_idx])
|
|
|
|
cpp.write(
|
|
"""/* THIS FILE IS GENERATED DO NOT EDIT */
|
|
#include "android_mono_config.h"
|
|
|
|
#ifdef ANDROID_ENABLED
|
|
|
|
#include "core/io/compression.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() {
|
|
Vector<uint8_t> data;
|
|
data.resize(config_uncompressed_size);
|
|
uint8_t* w = data.ptrw();
|
|
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)
|
|
)
|