summaryrefslogtreecommitdiff
path: root/modules/mono/editor/bindings_generator.cpp
diff options
context:
space:
mode:
authorIgnacio Etcheverry <ignalfonsore@gmail.com>2019-12-28 19:12:32 +0100
committerIgnacio Etcheverry <ignalfonsore@gmail.com>2019-12-28 20:48:55 +0100
commit86274b9fc9e63c0eb6112bf4d87d67dd97fb0b86 (patch)
tree36b9c9909da20b9c7f0310a506542474bf2d1cba /modules/mono/editor/bindings_generator.cpp
parent318c69351624f7794c51b5385d252af397c0404a (diff)
Mono/C#: Re-structure API solution and GodotTools post-build target
Previously we had a placeholder solution called 'Managed' to benefit from tooling while editing the a part of the C# API. Later the bindings generator would create the final 'GodotSharp' solution including these C# files as well as the auto-generated C# API. Now we replaced the 'Managed' solution with the final 'GodotSharp' solution which is no longer auto-generated, and the bindings generator only takes care of the auto-generated C# API. This has the following benefits: - It's less confusing as there will no longer be two versions of the same file (the original and a generated copy of it). Now there's only one. - We no longer need placeholder for auto-generated API classes, like Node or Resource. We used them for benefiting from tooling. Now we can just use the auto-generated API itself. - Simplifies the build system and bindings generator. Removed lot of code that is not needed anymore. Also added a post-build target to the GodotTools project to copy the output to the data dir. This makes it easy to iterate when doing changes to GodotTools, as SCons doesn't have to be executed anymore just to copy these new files.
Diffstat (limited to 'modules/mono/editor/bindings_generator.cpp')
-rw-r--r--modules/mono/editor/bindings_generator.cpp126
1 files changed, 64 insertions, 62 deletions
diff --git a/modules/mono/editor/bindings_generator.cpp b/modules/mono/editor/bindings_generator.cpp
index 2252f7676d..5b135e97e9 100644
--- a/modules/mono/editor/bindings_generator.cpp
+++ b/modules/mono/editor/bindings_generator.cpp
@@ -40,7 +40,6 @@
#include "core/os/os.h"
#include "core/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"
@@ -874,7 +873,7 @@ void BindingsGenerator::_generate_global_constants(StringBuilder &p_output) {
p_output.append("\n#pragma warning restore CS1591\n");
}
-Error BindingsGenerator::generate_cs_core_project(const String &p_proj_dir, Vector<String> &r_compile_items) {
+Error BindingsGenerator::generate_cs_core_project(const String &p_proj_dir) {
ERR_FAIL_COND_V(!initialized, ERR_UNCONFIGURED);
@@ -887,22 +886,24 @@ Error BindingsGenerator::generate_cs_core_project(const String &p_proj_dir, Vect
}
da->change_dir(p_proj_dir);
- da->make_dir("Core");
- da->make_dir("ObjectType");
+ da->make_dir("Generated");
+ da->make_dir("Generated/GodotObjects");
- String core_dir = path::join(p_proj_dir, "Core");
- String obj_type_dir = path::join(p_proj_dir, "ObjectType");
+ String base_gen_dir = path::join(p_proj_dir, "Generated");
+ String godot_objects_gen_dir = path::join(base_gen_dir, "GodotObjects");
+
+ Vector<String> compile_items;
// Generate source file for global scope constants and enums
{
StringBuilder constants_source;
_generate_global_constants(constants_source);
- String output_file = path::join(core_dir, BINDINGS_GLOBAL_SCOPE_CLASS "_constants.cs");
+ String output_file = path::join(base_gen_dir, BINDINGS_GLOBAL_SCOPE_CLASS "_constants.cs");
Error save_err = _save_file(output_file, constants_source);
if (save_err != OK)
return save_err;
- r_compile_items.push_back(output_file);
+ compile_items.push_back(output_file);
}
for (OrderedHashMap<StringName, TypeInterface>::Element E = obj_types.front(); E; E = E.next()) {
@@ -911,7 +912,7 @@ Error BindingsGenerator::generate_cs_core_project(const String &p_proj_dir, Vect
if (itype.api_type == ClassDB::API_EDITOR)
continue;
- String output_file = path::join(obj_type_dir, itype.proxy_name + ".cs");
+ String output_file = path::join(godot_objects_gen_dir, itype.proxy_name + ".cs");
Error err = _generate_cs_type(itype, output_file);
if (err == ERR_SKIP)
@@ -920,39 +921,11 @@ Error BindingsGenerator::generate_cs_core_project(const String &p_proj_dir, Vect
if (err != OK)
return err;
- r_compile_items.push_back(output_file);
+ compile_items.push_back(output_file);
}
// Generate sources from compressed files
- Map<String, GodotCsCompressedFile> compressed_files;
- get_compressed_files(compressed_files);
-
- for (Map<String, GodotCsCompressedFile>::Element *E = compressed_files.front(); E; E = E->next()) {
- const String &file_name = E->key();
- const GodotCsCompressedFile &file_data = E->value();
-
- String output_file = path::join(core_dir, file_name);
-
- Vector<uint8_t> data;
- data.resize(file_data.uncompressed_size);
- 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)) {
- 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);
- ERR_FAIL_COND_V(!file, ERR_FILE_CANT_WRITE);
- file->store_buffer(data.ptr(), data.size());
- file->close();
-
- r_compile_items.push_back(output_file);
- }
-
StringBuilder cs_icalls_content;
cs_icalls_content.append("using System;\n"
@@ -986,18 +959,36 @@ Error BindingsGenerator::generate_cs_core_project(const String &p_proj_dir, Vect
cs_icalls_content.append(INDENT1 CLOSE_BLOCK CLOSE_BLOCK);
- String internal_methods_file = path::join(core_dir, BINDINGS_CLASS_NATIVECALLS ".cs");
+ String internal_methods_file = path::join(base_gen_dir, BINDINGS_CLASS_NATIVECALLS ".cs");
Error err = _save_file(internal_methods_file, cs_icalls_content);
if (err != OK)
return err;
- r_compile_items.push_back(internal_methods_file);
+ compile_items.push_back(internal_methods_file);
+
+ StringBuilder includes_props_content;
+ includes_props_content.append("<Project>\n"
+ " <ItemGroup>\n");
+
+ for (int i = 0; i < compile_items.size(); i++) {
+ String include = path::relative_to(compile_items[i], p_proj_dir).replace("/", "\\");
+ includes_props_content.append(" <Compile Include=\"" + include + "\" />\n");
+ }
+
+ includes_props_content.append(" </ItemGroup>\n"
+ "</Project>\n");
+
+ String includes_props_file = path::join(base_gen_dir, "GeneratedIncludes.props");
+
+ err = _save_file(includes_props_file, includes_props_content);
+ if (err != OK)
+ return err;
return OK;
}
-Error BindingsGenerator::generate_cs_editor_project(const String &p_proj_dir, Vector<String> &r_compile_items) {
+Error BindingsGenerator::generate_cs_editor_project(const String &p_proj_dir) {
ERR_FAIL_COND_V(!initialized, ERR_UNCONFIGURED);
@@ -1010,11 +1001,13 @@ Error BindingsGenerator::generate_cs_editor_project(const String &p_proj_dir, Ve
}
da->change_dir(p_proj_dir);
- da->make_dir("Core");
- da->make_dir("ObjectType");
+ da->make_dir("Generated");
+ da->make_dir("Generated/GodotObjects");
+
+ String base_gen_dir = path::join(p_proj_dir, "Generated");
+ String godot_objects_gen_dir = path::join(base_gen_dir, "GodotObjects");
- String core_dir = path::join(p_proj_dir, "Core");
- String obj_type_dir = path::join(p_proj_dir, "ObjectType");
+ Vector<String> compile_items;
for (OrderedHashMap<StringName, TypeInterface>::Element E = obj_types.front(); E; E = E.next()) {
const TypeInterface &itype = E.get();
@@ -1022,7 +1015,7 @@ Error BindingsGenerator::generate_cs_editor_project(const String &p_proj_dir, Ve
if (itype.api_type != ClassDB::API_EDITOR)
continue;
- String output_file = path::join(obj_type_dir, itype.proxy_name + ".cs");
+ String output_file = path::join(godot_objects_gen_dir, itype.proxy_name + ".cs");
Error err = _generate_cs_type(itype, output_file);
if (err == ERR_SKIP)
@@ -1031,7 +1024,7 @@ Error BindingsGenerator::generate_cs_editor_project(const String &p_proj_dir, Ve
if (err != OK)
return err;
- r_compile_items.push_back(output_file);
+ compile_items.push_back(output_file);
}
StringBuilder cs_icalls_content;
@@ -1068,13 +1061,31 @@ Error BindingsGenerator::generate_cs_editor_project(const String &p_proj_dir, Ve
cs_icalls_content.append(INDENT1 CLOSE_BLOCK CLOSE_BLOCK);
- String internal_methods_file = path::join(core_dir, BINDINGS_CLASS_NATIVECALLS_EDITOR ".cs");
+ String internal_methods_file = path::join(base_gen_dir, BINDINGS_CLASS_NATIVECALLS_EDITOR ".cs");
Error err = _save_file(internal_methods_file, cs_icalls_content);
if (err != OK)
return err;
- r_compile_items.push_back(internal_methods_file);
+ compile_items.push_back(internal_methods_file);
+
+ StringBuilder includes_props_content;
+ includes_props_content.append("<Project>\n"
+ " <ItemGroup>\n");
+
+ for (int i = 0; i < compile_items.size(); i++) {
+ String include = path::relative_to(compile_items[i], p_proj_dir).replace("/", "\\");
+ includes_props_content.append(" <Compile Include=\"" + include + "\" />\n");
+ }
+
+ includes_props_content.append(" </ItemGroup>\n"
+ "</Project>\n");
+
+ String includes_props_file = path::join(base_gen_dir, "GeneratedIncludes.props");
+
+ err = _save_file(includes_props_file, includes_props_content);
+ if (err != OK)
+ return err;
return OK;
}
@@ -1098,9 +1109,8 @@ Error BindingsGenerator::generate_cs_api(const String &p_output_dir) {
// Generate GodotSharp source files
String core_proj_dir = output_dir.plus_file(CORE_API_ASSEMBLY_NAME);
- Vector<String> core_compile_items;
- proj_err = generate_cs_core_project(core_proj_dir, core_compile_items);
+ proj_err = generate_cs_core_project(core_proj_dir);
if (proj_err != OK) {
ERR_PRINT("Generation of the Core API C# project failed.");
return proj_err;
@@ -1109,22 +1119,14 @@ Error BindingsGenerator::generate_cs_api(const String &p_output_dir) {
// Generate GodotSharpEditor source files
String editor_proj_dir = output_dir.plus_file(EDITOR_API_ASSEMBLY_NAME);
- Vector<String> editor_compile_items;
- proj_err = generate_cs_editor_project(editor_proj_dir, editor_compile_items);
+ proj_err = generate_cs_editor_project(editor_proj_dir);
if (proj_err != OK) {
ERR_PRINT("Generation of the Editor API C# project failed.");
return proj_err;
}
- // Generate solution
-
- if (!CSharpProject::generate_api_solution(output_dir,
- core_proj_dir, core_compile_items, editor_proj_dir, editor_compile_items)) {
- return ERR_CANT_CREATE;
- }
-
- _log("The solution for the Godot API was generated successfully\n");
+ _log("The Godot API sources were successfully generated\n");
return OK;
}
@@ -3170,7 +3172,7 @@ void BindingsGenerator::handle_cmdline_args(const List<String> &p_cmdline_args)
if (bindings_generator.generate_glue(glue_dir_path) != OK)
ERR_PRINTS(generate_all_glue_option + ": Failed to generate the C++ glue.");
- if (bindings_generator.generate_cs_api(glue_dir_path.plus_file("Managed/Generated")) != OK)
+ if (bindings_generator.generate_cs_api(glue_dir_path.plus_file(API_SOLUTION_NAME)) != OK)
ERR_PRINTS(generate_all_glue_option + ": Failed to generate the C# API.");
}