Skip to content

Commit

Permalink
Merge pull request #62618 from Bromeon/bugfix/exit-code
Browse files Browse the repository at this point in the history
Fix exit code of --help and --version, and test them in CI
  • Loading branch information
akien-mga authored Jul 2, 2022
2 parents 04bdd7e + d38d76d commit ec1348a
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/linux_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ jobs:
- name: Unit tests
if: ${{ matrix.tests }}
run: |
${{ matrix.bin }} --version
${{ matrix.bin }} --help
${{ matrix.bin }} --test --headless
# Check class reference
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/macos_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ jobs:
- name: Unit tests
if: ${{ matrix.tests }}
run: |
${{ matrix.bin }} --version
${{ matrix.bin }} --help
${{ matrix.bin }} --test
- name: Prepare artifact
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/windows_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ jobs:
- name: Unit tests
if: ${{ matrix.tests }}
run: |
${{ matrix.bin }} --version
${{ matrix.bin }} --help
${{ matrix.bin }} --test
- name: Prepare artifact
Expand Down
4 changes: 2 additions & 2 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -691,12 +691,12 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
if (I->get() == "-h" || I->get() == "--help" || I->get() == "/?") { // display help

show_help = true;
exit_code = OK;
exit_code = ERR_HELP; // Hack to force an early exit in `main()` with a success code.
goto error;

} else if (I->get() == "--version") {
print_line(get_full_version_string());
exit_code = OK;
exit_code = ERR_HELP; // Hack to force an early exit in `main()` with a success code.
goto error;

} else if (I->get() == "-v" || I->get() == "--verbose") { // verbose output
Expand Down
1 change: 1 addition & 0 deletions platform/android/java_godot_lib_jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_setup(JNIEnv *env, jc
memfree(cmdline);
}

// Note: --help and --version return ERR_HELP, but this should be translated to 0 if exit codes are propagated.
if (err != OK) {
return; // should exit instead and print the error
}
Expand Down
5 changes: 4 additions & 1 deletion platform/iphone/godot_iphone.mm
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ int iphone_main(int argc, char **argv, String data_dir, String cache_dir) {

Error err = Main::setup(fargv[0], argc - 1, &fargv[1], false);
printf("setup %i\n", err);
if (err != OK) {

if (err == ERR_HELP) { // Returned by --help and --version, so success.
return 0;
} else if (err != OK) {
return 255;
}

Expand Down
4 changes: 4 additions & 0 deletions platform/linuxbsd/godot_linuxbsd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ int main(int argc, char *argv[]) {
Error err = Main::setup(argv[0], argc - 1, &argv[1]);
if (err != OK) {
free(cwd);

if (err == ERR_HELP) { // Returned by --help and --version, so success.
return 0;
}
return 255;
}

Expand Down
4 changes: 3 additions & 1 deletion platform/osx/godot_main_osx.mm
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ int main(int argc, char **argv) {
err = Main::setup(argv[0], argc - first_arg, &argv[first_arg]);
}

if (err != OK) {
if (err == ERR_HELP) { // Returned by --help and --version, so success.
return 0;
} else if (err != OK) {
return 255;
}

Expand Down
4 changes: 4 additions & 0 deletions platform/windows/godot_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ int widechar_main(int argc, wchar_t **argv) {
delete[] argv_utf8[i];
}
delete[] argv_utf8;

if (err == ERR_HELP) { // Returned by --help and --version, so success.
return 0;
}
return 255;
}

Expand Down

0 comments on commit ec1348a

Please sign in to comment.