Skip to content

Commit 76afc98

Browse files
committed
Merge pull request #91407 from RedMser/doctool-verify-directory
Ensure `--doctool` is run from root directory
2 parents bb1ca58 + 3047bd4 commit 76afc98

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

main/main.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3182,6 +3182,7 @@ int Main::start() {
31823182

31833183
#ifdef TOOLS_ENABLED
31843184
String doc_tool_path;
3185+
bool doc_tool_implicit_cwd = false;
31853186
BitField<DocTools::GenerateFlags> gen_flags;
31863187
String _export_preset;
31873188
bool export_debug = false;
@@ -3252,6 +3253,7 @@ int Main::start() {
32523253
if (doc_tool_path.begins_with("-")) {
32533254
// Assuming other command line arg, so default to cwd.
32543255
doc_tool_path = ".";
3256+
doc_tool_implicit_cwd = true;
32553257
parsed_pair = false;
32563258
}
32573259
#ifdef MODULE_GDSCRIPT_ENABLED
@@ -3282,6 +3284,7 @@ int Main::start() {
32823284
// Handle case where no path is given to --doctool.
32833285
else if (args[i] == "--doctool") {
32843286
doc_tool_path = ".";
3287+
doc_tool_implicit_cwd = true;
32853288
}
32863289
#endif
32873290
}
@@ -3308,6 +3311,11 @@ int Main::start() {
33083311
{
33093312
Ref<DirAccess> da = DirAccess::open(doc_tool_path);
33103313
ERR_FAIL_COND_V_MSG(da.is_null(), EXIT_FAILURE, "Argument supplied to --doctool must be a valid directory path.");
3314+
// Ensure that doctool is running in the root dir, but only if
3315+
// user did not manually specify a path as argument.
3316+
if (doc_tool_implicit_cwd) {
3317+
ERR_FAIL_COND_V_MSG(!da->dir_exists("doc"), EXIT_FAILURE, "--doctool must be run from the Godot repository's root folder, or specify a path that points there.");
3318+
}
33113319
}
33123320

33133321
#ifndef MODULE_MONO_ENABLED
@@ -3636,7 +3644,7 @@ int Main::start() {
36363644
}
36373645
}
36383646

3639-
if (doc_tool_path == ".") {
3647+
if (doc_tool_implicit_cwd) {
36403648
doc_tool_path = "./docs";
36413649
}
36423650

0 commit comments

Comments
 (0)