summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-09-22 22:05:58 +0200
committerRémi Verschelde <rverschelde@gmail.com>2023-09-22 22:05:58 +0200
commitc12d63556b5c1da03a00dd4c45c40e60bd8d68c2 (patch)
tree9315217a988ebc55b5d2246994a9f74f3f73d83b
parent1c10ff37b34e557afe0da0bdd6f7ae180201a533 (diff)
parent10697adb8a4ffd084d7d736441cdd3424cd355b6 (diff)
downloadredot-engine-c12d63556b5c1da03a00dd4c45c40e60bd8d68c2.tar.gz
Merge pull request #82116 from EIREXE/gdscript-docs-fix
Fix `--gdscript-docs` tool failing when autoloads are used in the project.
-rw-r--r--main/main.cpp79
1 files changed, 46 insertions, 33 deletions
diff --git a/main/main.cpp b/main/main.cpp
index 970c77a34b..e5a8e3e13f 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<String> 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> 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<DirAccess> 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<String, String> 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<String> 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> 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<DirAccess> 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<String, String> 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");