From 10697adb8a4ffd084d7d736441cdd3424cd355b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lex=20Rom=C3=A1n=20N=C3=BA=C3=B1ez?= Date: Fri, 22 Sep 2023 14:37:12 +0200 Subject: [PATCH] Fix --gdscript-docs tool failing when autoloads are used in the project. Fixes #79497 --- main/main.cpp | 79 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 33 deletions(-) diff --git a/main/main.cpp b/main/main.cpp index 970c77a34b1..e5a8e3e13fa 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1318,6 +1318,19 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph audio_driver = NULL_AUDIO_DRIVER; display_driver = NULL_DISPLAY_DRIVER; main_args.push_back(I->get()); +#ifdef MODULE_GDSCRIPT_ENABLED + } else if (I->get() == "--gdscript-docs") { + if (I->next()) { + project_path = I->next()->get(); + // Will be handled in start() + main_args.push_back(I->get()); + main_args.push_back(I->next()->get()); + N = I->next()->next(); + } else { + OS::get_singleton()->print("Missing relative or absolute path to project for --gdscript-docs, aborting.\n"); + goto error; + } +#endif // MODULE_GDSCRIPT_ENABLED #endif // TOOLS_ENABLED } else if (I->get() == "--path") { // set path of project to start or edit @@ -2806,39 +2819,7 @@ bool Main::start() { } #ifdef TOOLS_ENABLED -#ifdef MODULE_GDSCRIPT_ENABLED - if (!doc_tool_path.is_empty() && !gdscript_docs_path.is_empty()) { - DocTools docs; - Error err; - - Vector paths = get_files_with_extension(gdscript_docs_path, "gd"); - ERR_FAIL_COND_V_MSG(paths.size() == 0, false, "Couldn't find any GDScript files under the given directory: " + gdscript_docs_path); - - for (const String &path : paths) { - Ref gdscript = ResourceLoader::load(path); - for (const DocData::ClassDoc &class_doc : gdscript->get_documentation()) { - docs.add_doc(class_doc); - } - } - - if (doc_tool_path == ".") { - doc_tool_path = "./docs"; - } - - Ref da = DirAccess::create_for_path(doc_tool_path); - err = da->make_dir_recursive(doc_tool_path); - ERR_FAIL_COND_V_MSG(err != OK, false, "Error: Can't create GDScript docs directory: " + doc_tool_path + ": " + itos(err)); - - HashMap doc_data_classes; - err = docs.save_classes(doc_tool_path, doc_data_classes, false); - ERR_FAIL_COND_V_MSG(err != OK, false, "Error saving GDScript docs:" + itos(err)); - - OS::get_singleton()->set_exit_code(EXIT_SUCCESS); - return false; - } -#endif // MODULE_GDSCRIPT_ENABLED - - if (!doc_tool_path.is_empty()) { + if (!doc_tool_path.is_empty() && gdscript_docs_path.is_empty()) { // Needed to instance editor-only classes for their default values Engine::get_singleton()->set_editor_hint(true); @@ -3170,6 +3151,38 @@ bool Main::start() { } #ifdef TOOLS_ENABLED +#ifdef MODULE_GDSCRIPT_ENABLED + if (!doc_tool_path.is_empty() && !gdscript_docs_path.is_empty()) { + DocTools docs; + Error err; + + Vector paths = get_files_with_extension(gdscript_docs_path, "gd"); + ERR_FAIL_COND_V_MSG(paths.size() == 0, false, "Couldn't find any GDScript files under the given directory: " + gdscript_docs_path); + + for (const String &path : paths) { + Ref gdscript = ResourceLoader::load(path); + for (const DocData::ClassDoc &class_doc : gdscript->get_documentation()) { + docs.add_doc(class_doc); + } + } + + if (doc_tool_path == ".") { + doc_tool_path = "./docs"; + } + + Ref da = DirAccess::create_for_path(doc_tool_path); + err = da->make_dir_recursive(doc_tool_path); + ERR_FAIL_COND_V_MSG(err != OK, false, "Error: Can't create GDScript docs directory: " + doc_tool_path + ": " + itos(err)); + + HashMap doc_data_classes; + err = docs.save_classes(doc_tool_path, doc_data_classes, false); + ERR_FAIL_COND_V_MSG(err != OK, false, "Error saving GDScript docs:" + itos(err)); + + OS::get_singleton()->set_exit_code(EXIT_SUCCESS); + return false; + } +#endif // MODULE_GDSCRIPT_ENABLED + EditorNode *editor_node = nullptr; if (editor) { OS::get_singleton()->benchmark_begin_measure("editor");