From e7100658d46e0a74e6d62880b38480cc4a73ba06 Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 29 Jul 2022 21:45:04 +0200 Subject: [PATCH] Ported: Fix exit code of --help and --version, and test them in CI Corrects prior regression which caused ERROR output and exit code of 1. - Bromeon https://github.com/godotengine/godot/commit/861e15554398c98630b905c8f2273477bdba5f99 --- main/main.cpp | 4 ++-- platform/android/java_pandemonium_lib_jni.cpp | 3 ++- platform/iphone/pandemonium_iphone.mm | 5 ++++- platform/osx/pandemonium_main_osx.mm | 8 ++++++-- platform/windows/pandemonium_windows.cpp | 5 +++++ platform/x11/pandemonium_x11.cpp | 5 +++++ 6 files changed, 24 insertions(+), 6 deletions(-) diff --git a/main/main.cpp b/main/main.cpp index 8ce294630..265e0ada7 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -489,12 +489,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 diff --git a/platform/android/java_pandemonium_lib_jni.cpp b/platform/android/java_pandemonium_lib_jni.cpp index 4729543f1..e9dcf1397 100644 --- a/platform/android/java_pandemonium_lib_jni.cpp +++ b/platform/android/java_pandemonium_lib_jni.cpp @@ -136,7 +136,7 @@ JNIEXPORT void JNICALL Java_net_relintai_pandemonium_pandemonium_PandemoniumLib_ FileAccessAndroid::asset_manager = AAssetManager_fromJava(env, amgr); - DirAccessJAndroid::setup(p_directory_access_handler); + DirAccessJAndroid::setup(p_directory_access_handler); FileAccessFilesystemJAndroid::setup(p_file_access_handler); NetSocketAndroid::setup(p_net_utils); @@ -204,6 +204,7 @@ JNIEXPORT void JNICALL Java_net_relintai_pandemonium_pandemonium_PandemoniumLib_ 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 } diff --git a/platform/iphone/pandemonium_iphone.mm b/platform/iphone/pandemonium_iphone.mm index 28d6f3d95..10efd6a08 100644 --- a/platform/iphone/pandemonium_iphone.mm +++ b/platform/iphone/pandemonium_iphone.mm @@ -103,7 +103,10 @@ int iphone_main(int argc, char **argv, String data_dir, String cache_dir) { printf("os created\n"); 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; } diff --git a/platform/osx/pandemonium_main_osx.mm b/platform/osx/pandemonium_main_osx.mm index 2821da48c..da6179042 100644 --- a/platform/osx/pandemonium_main_osx.mm +++ b/platform/osx/pandemonium_main_osx.mm @@ -64,11 +64,15 @@ 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; + } - if (Main::start()) + if (Main::start()) { os.run(); // it is actually the OS that decides how to run + } Main::cleanup(); diff --git a/platform/windows/pandemonium_windows.cpp b/platform/windows/pandemonium_windows.cpp index eff700749..2c303da7f 100644 --- a/platform/windows/pandemonium_windows.cpp +++ b/platform/windows/pandemonium_windows.cpp @@ -162,6 +162,11 @@ __declspec(dllexport) 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; } diff --git a/platform/x11/pandemonium_x11.cpp b/platform/x11/pandemonium_x11.cpp index ef7047372..e0e24e05e 100644 --- a/platform/x11/pandemonium_x11.cpp +++ b/platform/x11/pandemonium_x11.cpp @@ -48,6 +48,11 @@ 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; }