diff options
author | Juan Linietsky <reduzio@gmail.com> | 2023-04-25 20:53:07 +0200 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2023-05-15 12:05:40 +0200 |
commit | d8078d3f4ce338d39ee591641e44020fb98cca2a (patch) | |
tree | 3e0d9966ad8275e0c562a801dd94c7c30c4cd486 /main | |
parent | 45cd5dcad39274da18440d6ea3c2121bec248eaa (diff) | |
download | redot-engine-d8078d3f4ce338d39ee591641e44020fb98cca2a.tar.gz |
Add a backwards-compatibility system for GDExtension method
This adds a way to ensure that methods that were modified in the Godot API will continue working in older builds of GDExtension even if the new signature is different.
```C++
// New version (changed)
ClassDB::bind_method(D_METHOD("add_sphere","radius","position"),&MyShapes::add_sphere);
// Compatibility version (still available to extensions).
ClassDB::bind_compatibility_method(D_METHOD("add_sphere","radius"),&MyShapes::_compat_add_sphere);
```
**Q**: If I add an extra argument and provide a default value (hence can still be called the same), do I still have to provide the compatibility version?
**A**: Yes, you must still provide a compatibility method. Most language bindings use the raw method pointer to do the call and process the default parameters in the binding language, hence if the actual method signature changes it will no longer work.
**Q**: If I removed a method, can I still bind a compatibility version even though the main method no longer exists?
**A**: Yes, for methods that were removed or renamed, compatibility versions can still be provided.
**Q**: Would it be possible to automate checking that methods were removed by mistake?
**A**: Yes, as part of a future PR, the idea is to add a a command line option to Godot that can be run like : `$ godot --test-api-compatibility older_api_dump.json`, which will also be integrated to the CI runs.
Diffstat (limited to 'main')
-rw-r--r-- | main/main.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/main/main.cpp b/main/main.cpp index 6b89d96147..5ba1eac1f3 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -217,6 +217,8 @@ static bool print_fps = false; #ifdef TOOLS_ENABLED static bool dump_gdextension_interface = false; static bool dump_extension_api = false; +static bool validate_extension_api = false; +static String validate_extension_api_file; #endif bool profile_gpu = false; @@ -458,6 +460,7 @@ void Main::print_help(const char *p_binary) { OS::get_singleton()->print(" --build-solutions Build the scripting solutions (e.g. for C# projects). Implies --editor and requires a valid project to edit.\n"); OS::get_singleton()->print(" --dump-gdextension-interface Generate GDExtension header file 'gdextension_interface.h' in the current folder. This file is the base file required to implement a GDExtension.\n"); OS::get_singleton()->print(" --dump-extension-api Generate JSON dump of the Godot API for GDExtension bindings named 'extension_api.json' in the current folder.\n"); + OS::get_singleton()->print(" --validate-extension-api <path> Validate an extension API file dumped (with the option above) from a previous version of the engine to ensure API compatibility. If incompatibilities or errors are detected, the return code will be non zero.\n"); OS::get_singleton()->print(" --startup-benchmark Benchmark the startup time and print it to console.\n"); OS::get_singleton()->print(" --startup-benchmark-file <path> Benchmark the startup time and save it to a given file in JSON format.\n"); #ifdef TESTS_ENABLED @@ -1133,6 +1136,25 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph // run the project instead of a cmdline tool. // Needs full refactoring to fix properly. main_args.push_back(I->get()); + } else if (I->get() == "--validate-extension-api") { + // Register as an editor instance to use low-end fallback if relevant. + editor = true; + cmdline_tool = true; + validate_extension_api = true; + // Hack. Not needed but otherwise we end up detecting that this should + // run the project instead of a cmdline tool. + // Needs full refactoring to fix properly. + main_args.push_back(I->get()); + + if (I->next()) { + validate_extension_api_file = I->next()->get(); + + N = I->next()->next(); + } else { + OS::get_singleton()->print("Missing file to load argument after --validate-extension-api, aborting."); + goto error; + } + } else if (I->get() == "--export-release" || I->get() == "--export-debug" || I->get() == "--export-pack") { // Export project // Actually handling is done in start(). @@ -2650,6 +2672,12 @@ bool Main::start() { return false; } + if (validate_extension_api) { + bool valid = GDExtensionAPIDump::validate_extension_json_file(validate_extension_api_file) == OK; + OS::get_singleton()->set_exit_code(valid ? EXIT_SUCCESS : EXIT_FAILURE); + return false; + } + #ifndef DISABLE_DEPRECATED if (converting_project) { int ret = ProjectConverter3To4(converter_max_kb_file, converter_max_line_length).convert(); |