Mono: Improve C# core files (glue/cs_files) buildsystem
- Search C# files recursively in 'glue/cs_files'. - Determine a version for the C# core files automatically. The latest modified time will do for now.
This commit is contained in:
parent
1f65ed6a7d
commit
7287300433
|
@ -18,14 +18,20 @@ def make_cs_files_header(src, dst):
|
||||||
header.write('#include "ustring.h"\n')
|
header.write('#include "ustring.h"\n')
|
||||||
inserted_files = ''
|
inserted_files = ''
|
||||||
import os
|
import os
|
||||||
for file in os.listdir(src):
|
latest_mtime = 0
|
||||||
if file.endswith('.cs'):
|
for root, _, files in os.walk(src):
|
||||||
with open(os.path.join(src, file), 'rb') as f:
|
files = [f for f in files if f.endswith('.cs')]
|
||||||
|
for file in files:
|
||||||
|
filepath = os.path.join(root, file)
|
||||||
|
filepath_src_rel = os.path.relpath(filepath, src)
|
||||||
|
mtime = os.path.getmtime(filepath)
|
||||||
|
latest_mtime = mtime if mtime > latest_mtime else latest_mtime
|
||||||
|
with open(filepath, 'rb') as f:
|
||||||
buf = f.read()
|
buf = f.read()
|
||||||
decomp_size = len(buf)
|
decomp_size = len(buf)
|
||||||
import zlib
|
import zlib
|
||||||
buf = zlib.compress(buf)
|
buf = zlib.compress(buf)
|
||||||
name = os.path.splitext(file)[0]
|
name = os.path.splitext(os.path.normpath(filepath_src_rel))[0].strip(os.sep).replace(os.sep, '_').replace('.', '_dotto_')
|
||||||
header.write('\nstatic const int _cs_' + name + '_compressed_size = ' + str(len(buf)) + ';\n')
|
header.write('\nstatic const int _cs_' + name + '_compressed_size = ' + str(len(buf)) + ';\n')
|
||||||
header.write('static const int _cs_' + name + '_uncompressed_size = ' + str(decomp_size) + ';\n')
|
header.write('static const int _cs_' + name + '_uncompressed_size = ' + str(decomp_size) + ';\n')
|
||||||
header.write('static const unsigned char _cs_' + name + '_compressed[] = { ')
|
header.write('static const unsigned char _cs_' + name + '_compressed[] = { ')
|
||||||
|
@ -33,18 +39,13 @@ def make_cs_files_header(src, dst):
|
||||||
if i > 0:
|
if i > 0:
|
||||||
header.write(', ')
|
header.write(', ')
|
||||||
header.write(byte_to_str(buf[buf_idx]))
|
header.write(byte_to_str(buf[buf_idx]))
|
||||||
inserted_files += '\tr_files.insert("' + file + '", ' \
|
inserted_files += '\tr_files.insert("' + filepath_src_rel + '", ' \
|
||||||
'CompressedFile(_cs_' + name + '_compressed_size, ' \
|
'CompressedFile(_cs_' + name + '_compressed_size, ' \
|
||||||
'_cs_' + name + '_uncompressed_size, ' \
|
'_cs_' + name + '_uncompressed_size, ' \
|
||||||
'_cs_' + name + '_compressed));\n'
|
'_cs_' + name + '_compressed));\n'
|
||||||
header.write(' };\n')
|
header.write(' };\n')
|
||||||
version_file = os.path.join(src, 'VERSION.txt')
|
glue_version = int(latest_mtime) # The latest modified time will do for now
|
||||||
with open(version_file, 'r') as content_file:
|
header.write('\n#define CS_GLUE_VERSION UINT32_C(' + str(glue_version) + ')\n')
|
||||||
try:
|
|
||||||
glue_version = int(content_file.read()) # make sure the format is valid
|
|
||||||
header.write('\n#define CS_GLUE_VERSION UINT32_C(' + str(glue_version) + ')\n')
|
|
||||||
except ValueError:
|
|
||||||
raise ValueError('Invalid C# glue version in: ' + version_file)
|
|
||||||
header.write('\nstruct CompressedFile\n' '{\n'
|
header.write('\nstruct CompressedFile\n' '{\n'
|
||||||
'\tint compressed_size;\n' '\tint uncompressed_size;\n' '\tconst unsigned char* data;\n'
|
'\tint compressed_size;\n' '\tint uncompressed_size;\n' '\tconst unsigned char* data;\n'
|
||||||
'\n\tCompressedFile(int p_comp_size, int p_uncomp_size, const unsigned char* p_data)\n'
|
'\n\tCompressedFile(int p_comp_size, int p_uncomp_size, const unsigned char* p_data)\n'
|
||||||
|
|
|
@ -512,6 +512,15 @@ Error BindingsGenerator::generate_cs_core_project(const String &p_output_dir, bo
|
||||||
data.resize(file_data.uncompressed_size);
|
data.resize(file_data.uncompressed_size);
|
||||||
Compression::decompress(data.ptrw(), file_data.uncompressed_size, file_data.data, file_data.compressed_size, Compression::MODE_DEFLATE);
|
Compression::decompress(data.ptrw(), file_data.uncompressed_size, file_data.data, file_data.compressed_size, Compression::MODE_DEFLATE);
|
||||||
|
|
||||||
|
String output_dir = output_file.get_base_dir();
|
||||||
|
|
||||||
|
if (!DirAccess::exists(output_dir)) {
|
||||||
|
DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
||||||
|
ERR_FAIL_COND_V(!da, ERR_CANT_CREATE);
|
||||||
|
Error err = da->make_dir_recursive(ProjectSettings::get_singleton()->globalize_path(output_dir));
|
||||||
|
ERR_FAIL_COND_V(err != OK, ERR_CANT_CREATE);
|
||||||
|
}
|
||||||
|
|
||||||
FileAccessRef file = FileAccess::open(output_file, FileAccess::WRITE);
|
FileAccessRef file = FileAccess::open(output_file, FileAccess::WRITE);
|
||||||
ERR_FAIL_COND_V(!file, ERR_FILE_CANT_WRITE);
|
ERR_FAIL_COND_V(!file, ERR_FILE_CANT_WRITE);
|
||||||
file->store_buffer(data.ptr(), data.size());
|
file->store_buffer(data.ptr(), data.size());
|
||||||
|
|
|
@ -210,6 +210,8 @@ bool GodotSharpBuilds::build_api_sln(const String &p_name, const String &p_api_s
|
||||||
|
|
||||||
if (!FileAccess::exists(api_assembly_file)) {
|
if (!FileAccess::exists(api_assembly_file)) {
|
||||||
MonoBuildInfo api_build_info(api_sln_file, p_config);
|
MonoBuildInfo api_build_info(api_sln_file, p_config);
|
||||||
|
// TODO Replace this global NoWarn with '#pragma warning' directives on generated files,
|
||||||
|
// once we start to actively document manually maintained C# classes
|
||||||
api_build_info.custom_props.push_back("NoWarn=1591"); // Ignore missing documentation warnings
|
api_build_info.custom_props.push_back("NoWarn=1591"); // Ignore missing documentation warnings
|
||||||
|
|
||||||
if (!GodotSharpBuilds::get_singleton()->build(api_build_info)) {
|
if (!GodotSharpBuilds::get_singleton()->build(api_build_info)) {
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
9
|
|
Loading…
Reference in New Issue