Skip to content

Commit

Permalink
Merge pull request godotengine#82116 from EIREXE/gdscript-docs-fix
Browse files Browse the repository at this point in the history
Fix `--gdscript-docs` tool failing when autoloads are used in the project.
  • Loading branch information
akien-mga committed Sep 22, 2023
2 parents 1c10ff3 + 10697ad commit c12d635
Showing 1 changed file with 46 additions and 33 deletions.
79 changes: 46 additions & 33 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit c12d635

Please sign in to comment.