C#: Fix cs_files glue mismatch bug

This commit is contained in:
Ignacio Etcheverry 2018-09-12 02:50:16 +02:00
parent e558e1ec09
commit d21c64cc3b
5 changed files with 20 additions and 16 deletions

View file

@ -7,7 +7,7 @@ env_mono = env_modules.Clone()
# TODO move functions to their own modules
def make_cs_files_header(src, dst):
def make_cs_files_header(src, dst, version_dst):
from compat import byte_to_str
with open(dst, 'w') as header:
@ -49,8 +49,6 @@ def make_cs_files_header(src, dst):
'_cs_' + name + '_uncompressed_size, ' \
'_cs_' + name + '_compressed));\n'
header.write(' };\n')
glue_version = int(latest_mtime) # The latest modified time will do for now
header.write('\n#define CS_GLUE_VERSION UINT32_C(' + str(glue_version) + ')\n')
header.write('\nstruct CompressedFile\n' '{\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'
@ -61,6 +59,15 @@ def make_cs_files_header(src, dst):
header.write('\n#endif // TOOLS_ENABLED\n')
header.write('\n#endif // CS_COMPRESSED_H\n')
glue_version = int(latest_mtime) # The latest modified time will do for now
with open(version_dst, 'w') as version_header:
version_header.write('/* THIS FILE IS GENERATED DO NOT EDIT */\n')
version_header.write('#ifndef CS_GLUE_VERSION_H\n')
version_header.write('#define CS_GLUE_VERSION_H\n\n')
version_header.write('#define CS_GLUE_VERSION UINT32_C(' + str(glue_version) + ')\n')
version_header.write('\n#endif // CS_GLUE_VERSION_H\n')
env_mono.add_source_files(env.modules_sources, '*.cpp')
env_mono.add_source_files(env.modules_sources, 'glue/*.cpp')
@ -70,7 +77,7 @@ env_mono.add_source_files(env.modules_sources, 'utils/*.cpp')
if env['tools']:
env_mono.add_source_files(env.modules_sources, 'editor/*.cpp')
# NOTE: It is safe to generate this file here, since this is still executed serially
make_cs_files_header('glue/cs_files', 'glue/cs_compressed.gen.h')
make_cs_files_header('glue/cs_files', 'glue/cs_compressed.gen.h', 'glue/cs_glue_version.gen.h')
vars = Variables()
vars.Add(BoolVariable('mono_glue', 'Build with the mono glue sources', True))

View file

@ -41,6 +41,7 @@
#include "ucaps.h"
#include "../glue/cs_compressed.gen.h"
#include "../glue/cs_glue_version.gen.h"
#include "../godotsharp_defs.h"
#include "../mono_gd/gd_mono_marshal.h"
#include "../utils/path_utils.h"
@ -1277,8 +1278,6 @@ Error BindingsGenerator::generate_glue(const String &p_output_dir) {
output.push_back("uint32_t get_bindings_version() { return ");
output.push_back(String::num_uint64(BINDINGS_GENERATOR_VERSION) + "; }\n");
output.push_back("uint32_t get_cs_glue_version() { return ");
output.push_back(String::num_uint64(CS_GLUE_VERSION) + "; }\n");
output.push_back("\nvoid register_generated_icalls() " OPEN_BLOCK);
output.push_back("\tgodot_register_glue_header_icalls();\n");
@ -1363,10 +1362,6 @@ uint32_t BindingsGenerator::get_version() {
return BINDINGS_GENERATOR_VERSION;
}
uint32_t BindingsGenerator::get_cs_glue_version() {
return CS_GLUE_VERSION;
}
Error BindingsGenerator::_save_file(const String &p_path, const List<String> &p_content) {
FileAccessRef file = FileAccess::open(p_path, FileAccess::WRITE);

View file

@ -552,7 +552,6 @@ public:
Error generate_glue(const String &p_output_dir);
static uint32_t get_version();
static uint32_t get_cs_glue_version();
void initialize();

View file

@ -33,6 +33,7 @@
#include "core/vector.h"
#include "main/main.h"
#include "../glue/cs_glue_version.gen.h"
#include "../godotsharp_dirs.h"
#include "../mono_gd/gd_mono_class.h"
#include "../mono_gd/gd_mono_marshal.h"
@ -268,7 +269,7 @@ String GodotSharpBuilds::_api_folder_name(APIAssembly::Type p_api_type) {
GDMono::get_singleton()->get_api_editor_hash();
return String::num_uint64(api_hash) +
"_" + String::num_uint64(BindingsGenerator::get_version()) +
"_" + String::num_uint64(BindingsGenerator::get_cs_glue_version());
"_" + String::num_uint64(CS_GLUE_VERSION);
}
bool GodotSharpBuilds::make_api_sln(APIAssembly::Type p_api_type) {

View file

@ -42,6 +42,7 @@
#include "project_settings.h"
#include "../csharp_script.h"
#include "../glue/cs_glue_version.gen.h"
#include "../godotsharp_dirs.h"
#include "../utils/path_utils.h"
#include "gd_mono_class.h"
@ -307,7 +308,6 @@ uint64_t get_core_api_hash();
uint64_t get_editor_api_hash();
#endif // TOOLS_ENABLED
uint32_t get_bindings_version();
uint32_t get_cs_glue_version();
void register_generated_icalls();
} // namespace GodotSharpBindings
@ -459,7 +459,7 @@ bool GDMono::_load_core_api_assembly() {
APIAssembly::Version api_assembly_ver = APIAssembly::Version::get_from_loaded_assembly(core_api_assembly, APIAssembly::API_CORE);
core_api_assembly_out_of_sync = GodotSharpBindings::get_core_api_hash() != api_assembly_ver.godot_api_hash ||
GodotSharpBindings::get_bindings_version() != api_assembly_ver.bindings_version ||
GodotSharpBindings::get_cs_glue_version() != api_assembly_ver.cs_glue_version;
CS_GLUE_VERSION != api_assembly_ver.cs_glue_version;
#endif
GDMonoUtils::update_godot_api_cache();
}
@ -485,7 +485,7 @@ bool GDMono::_load_editor_api_assembly() {
APIAssembly::Version api_assembly_ver = APIAssembly::Version::get_from_loaded_assembly(editor_api_assembly, APIAssembly::API_EDITOR);
editor_api_assembly_out_of_sync = GodotSharpBindings::get_editor_api_hash() != api_assembly_ver.godot_api_hash ||
GodotSharpBindings::get_bindings_version() != api_assembly_ver.bindings_version ||
GodotSharpBindings::get_cs_glue_version() != api_assembly_ver.cs_glue_version;
CS_GLUE_VERSION != api_assembly_ver.cs_glue_version;
#endif
}
@ -720,13 +720,15 @@ Error GDMono::reload_scripts_domain() {
// so we invalidate the version in the metadata and unload the script domain.
if (core_api_assembly_out_of_sync) {
ERR_PRINT("The loaded Core API assembly is out of sync");
metadata_set_api_assembly_invalidated(APIAssembly::API_CORE, true);
} else if (!GDMonoUtils::mono_cache.godot_api_cache_updated) {
ERR_PRINT("Core API assembly is in sync, but the cache update failed");
ERR_PRINT("The loaded Core API assembly is in sync, but the cache update failed");
metadata_set_api_assembly_invalidated(APIAssembly::API_CORE, true);
}
if (editor_api_assembly_out_of_sync) {
ERR_PRINT("The loaded Editor API assembly is out of sync");
metadata_set_api_assembly_invalidated(APIAssembly::API_EDITOR, true);
}