From f50c7f7415789150a2390deba1467c885d8a471b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Tue, 8 Feb 2022 20:50:37 +0100 Subject: [PATCH] Core: Move generated `VERSION_HASH` to a `.cpp` file This lets us have its definition in `core/version.h` and avoid rebuilding a handful of files every time the commit hash changes. (cherry picked from commit 90162851a79f46a0e8887e9a403b9ee4db333eb9) --- core/SCsub | 1 + core/engine.cpp | 5 ++--- core/version.h | 3 +++ editor/editor_about.cpp | 3 +-- editor/editor_node.cpp | 1 - editor/project_manager.cpp | 1 - editor/script_editor_debugger.cpp | 18 ++++-------------- main/main.cpp | 3 +-- methods.py | 6 ++++-- modules/gltf/gltf_document.cpp | 5 ++--- platform/osx/crash_handler_osx.mm | 7 +++---- platform/windows/crash_handler_windows.cpp | 7 +++---- platform/x11/crash_handler_x11.cpp | 7 +++---- 13 files changed, 27 insertions(+), 40 deletions(-) diff --git a/core/SCsub b/core/SCsub index de2ff26f935..394bcf809f9 100644 --- a/core/SCsub +++ b/core/SCsub @@ -152,6 +152,7 @@ env.core_sources += thirdparty_obj env.add_source_files(env.core_sources, "*.cpp") env.add_source_files(env.core_sources, "script_encryption_key.gen.cpp") +env.add_source_files(env.core_sources, "version_hash.gen.cpp") # Certificates env.Depends( diff --git a/core/engine.cpp b/core/engine.cpp index f150752c924..37d8576a10b 100644 --- a/core/engine.cpp +++ b/core/engine.cpp @@ -34,7 +34,6 @@ #include "core/donors.gen.h" #include "core/license.gen.h" #include "core/version.h" -#include "core/version_hash.gen.h" void Engine::set_iterations_per_second(int p_ips) { ERR_FAIL_COND_MSG(p_ips <= 0, "Engine iterations per second must be greater than 0."); @@ -97,8 +96,8 @@ Dictionary Engine::get_version_info() const { dict["build"] = VERSION_BUILD; dict["year"] = VERSION_YEAR; - String hash = VERSION_HASH; - dict["hash"] = hash.length() == 0 ? String("unknown") : hash; + String hash = String(VERSION_HASH); + dict["hash"] = hash.empty() ? String("unknown") : hash; String stringver = String(dict["major"]) + "." + String(dict["minor"]); if ((int)dict["patch"] != 0) { diff --git a/core/version.h b/core/version.h index 1019bbf4527..d5b50b59737 100644 --- a/core/version.h +++ b/core/version.h @@ -68,4 +68,7 @@ // Example: "Godot v3.1.4.stable.official.mono" #define VERSION_FULL_NAME "" VERSION_NAME " v" VERSION_FULL_BUILD +// Git commit hash, generated at build time in `core/version_hash.gen.cpp`. +extern const char *const VERSION_HASH; + #endif // GODOT_VERSION_H diff --git a/editor/editor_about.cpp b/editor/editor_about.cpp index 319d88e7779..087f205944d 100644 --- a/editor/editor_about.cpp +++ b/editor/editor_about.cpp @@ -29,13 +29,12 @@ /*************************************************************************/ #include "editor_about.h" -#include "editor_node.h" #include "core/authors.gen.h" #include "core/donors.gen.h" #include "core/license.gen.h" #include "core/version.h" -#include "core/version_hash.gen.h" +#include "editor_node.h" // The metadata key used to store and retrieve the version text to copy to the clipboard. static const String META_TEXT_TO_COPY = "text_to_copy"; diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index c4dbf3012c4..7d43fc51258 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -47,7 +47,6 @@ #include "core/project_settings.h" #include "core/translation.h" #include "core/version.h" -#include "core/version_hash.gen.h" #include "main/input_default.h" #include "main/main.h" #include "scene/gui/center_container.h" diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp index 19469284646..ad42f8fc4aa 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -40,7 +40,6 @@ #include "core/os/os.h" #include "core/translation.h" #include "core/version.h" -#include "core/version_hash.gen.h" #include "editor_scale.h" #include "editor_settings.h" #include "editor_themes.h" diff --git a/editor/script_editor_debugger.cpp b/editor/script_editor_debugger.cpp index 8c97b2cad41..bafdbd9d5dd 100644 --- a/editor/script_editor_debugger.cpp +++ b/editor/script_editor_debugger.cpp @@ -34,7 +34,6 @@ #include "core/project_settings.h" #include "core/ustring.h" #include "core/version.h" -#include "core/version_hash.gen.h" #include "editor/editor_log.h" #include "editor/plugins/canvas_item_editor_plugin.h" #include "editor/plugins/spatial_editor_plugin.h" @@ -2293,19 +2292,10 @@ void ScriptEditorDebugger::_item_menu_id_pressed(int p_option) { const int line_number = file_line_number[1].to_int(); // Construct a GitHub repository URL and open it in the user's default web browser. - if (String(VERSION_HASH).length() >= 1) { - // Git commit hash information available; use it for greater accuracy, including for development versions. - OS::get_singleton()->shell_open(vformat("https://github.com/godotengine/godot/blob/%s/%s#L%d", - VERSION_HASH, - file, - line_number)); - } else { - // Git commit hash information unavailable; fall back to tagged releases. - OS::get_singleton()->shell_open(vformat("https://github.com/godotengine/godot/blob/%s-stable/%s#L%d", - VERSION_NUMBER, - file, - line_number)); - } + // If the commit hash is available, use it for greater accuracy. Otherwise fall back to tagged release. + String git_ref = String(VERSION_HASH).empty() ? String(VERSION_NUMBER) + "-stable" : String(VERSION_HASH); + OS::get_singleton()->shell_open(vformat("https://github.com/godotengine/godot/blob/%s/%s#L%d", + git_ref, file, line_number)); } break; } } diff --git a/main/main.cpp b/main/main.cpp index 264fc9b647f..64f5c1d41e8 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -48,7 +48,6 @@ #include "core/script_language.h" #include "core/translation.h" #include "core/version.h" -#include "core/version_hash.gen.h" #include "drivers/register_driver_types.h" #include "main/app_icon.gen.h" #include "main/input_default.h" @@ -176,7 +175,7 @@ static String unescape_cmdline(const String &p_str) { static String get_full_version_string() { String hash = String(VERSION_HASH); - if (hash.length() != 0) { + if (!hash.empty()) { hash = "." + hash.left(9); } return String(VERSION_FULL_BUILD) + hash; diff --git a/methods.py b/methods.py index 146e23cbb10..a8255fb6770 100644 --- a/methods.py +++ b/methods.py @@ -93,7 +93,9 @@ def update_version(module_version_string=""): f.close() # NOTE: It is safe to generate this file here, since this is still executed serially - fhash = open("core/version_hash.gen.h", "w") + fhash = open("core/version_hash.gen.cpp", "w") + fhash.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n") + fhash.write('#include "core/version.h"\n') githash = "" gitfolder = ".git" @@ -111,7 +113,7 @@ def update_version(module_version_string=""): else: githash = head - fhash.write('#define VERSION_HASH "' + githash + '"') + fhash.write('const char *const VERSION_HASH = "' + githash + '";\n') fhash.close() diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index 01999c78628..def7d1956ce 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -49,7 +49,6 @@ #include "core/os/file_access.h" #include "core/variant.h" #include "core/version.h" -#include "core/version_hash.gen.h" #include "drivers/png/png_driver_common.h" #include "scene/2d/node_2d.h" #include "scene/3d/bone_attachment.h" @@ -6743,8 +6742,8 @@ Error GLTFDocument::_serialize_version(Ref state) { Dictionary asset; asset["version"] = version; - String hash = VERSION_HASH; - asset["generator"] = String(VERSION_FULL_NAME) + String("@") + (hash.length() == 0 ? String("unknown") : hash); + String hash = String(VERSION_HASH); + asset["generator"] = String(VERSION_FULL_NAME) + String("@") + (hash.empty() ? String("unknown") : hash); state->json["asset"] = asset; ERR_FAIL_COND_V(!asset.has("version"), Error::FAILED); ERR_FAIL_COND_V(!state->json.has("asset"), Error::FAILED); diff --git a/platform/osx/crash_handler_osx.mm b/platform/osx/crash_handler_osx.mm index 447df3a1c57..6a73628f085 100644 --- a/platform/osx/crash_handler_osx.mm +++ b/platform/osx/crash_handler_osx.mm @@ -33,7 +33,6 @@ #include "core/os/os.h" #include "core/project_settings.h" #include "core/version.h" -#include "core/version_hash.gen.h" #include "main/main.h" #include @@ -94,10 +93,10 @@ static void handle_crash(int sig) { OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_CRASH); // Print the engine version just before, so that people are reminded to include the version in backtrace reports. - if (String(VERSION_HASH).length() != 0) { - fprintf(stderr, "Engine version: " VERSION_FULL_NAME " (" VERSION_HASH ")\n"); + if (String(VERSION_HASH).empty()) { + fprintf(stderr, "Engine version: %s\n", VERSION_FULL_NAME); } else { - fprintf(stderr, "Engine version: " VERSION_FULL_NAME "\n"); + fprintf(stderr, "Engine version: %s (%s)\n", VERSION_FULL_NAME, VERSION_HASH); } fprintf(stderr, "Dumping the backtrace. %ls\n", msg.c_str()); char **strings = backtrace_symbols(bt_buffer, size); diff --git a/platform/windows/crash_handler_windows.cpp b/platform/windows/crash_handler_windows.cpp index b0c4e79af5b..937ca46ded3 100644 --- a/platform/windows/crash_handler_windows.cpp +++ b/platform/windows/crash_handler_windows.cpp @@ -33,7 +33,6 @@ #include "core/os/os.h" #include "core/project_settings.h" #include "core/version.h" -#include "core/version_hash.gen.h" #include "main/main.h" #ifdef CRASH_HANDLER_EXCEPTION @@ -179,10 +178,10 @@ DWORD CrashHandlerException(EXCEPTION_POINTERS *ep) { } // Print the engine version just before, so that people are reminded to include the version in backtrace reports. - if (String(VERSION_HASH).length() != 0) { - fprintf(stderr, "Engine version: " VERSION_FULL_NAME " (" VERSION_HASH ")\n"); + if (String(VERSION_HASH).empty()) { + fprintf(stderr, "Engine version: %s\n", VERSION_FULL_NAME); } else { - fprintf(stderr, "Engine version: " VERSION_FULL_NAME "\n"); + fprintf(stderr, "Engine version: %s (%s)\n", VERSION_FULL_NAME, VERSION_HASH); } fprintf(stderr, "Dumping the backtrace. %ls\n", msg.c_str()); diff --git a/platform/x11/crash_handler_x11.cpp b/platform/x11/crash_handler_x11.cpp index 110a6724230..1fb29d45bee 100644 --- a/platform/x11/crash_handler_x11.cpp +++ b/platform/x11/crash_handler_x11.cpp @@ -33,7 +33,6 @@ #include "core/os/os.h" #include "core/project_settings.h" #include "core/version.h" -#include "core/version_hash.gen.h" #include "main/main.h" #ifdef DEBUG_ENABLED @@ -71,10 +70,10 @@ static void handle_crash(int sig) { } // Print the engine version just before, so that people are reminded to include the version in backtrace reports. - if (String(VERSION_HASH).length() != 0) { - fprintf(stderr, "Engine version: " VERSION_FULL_NAME " (" VERSION_HASH ")\n"); + if (String(VERSION_HASH).empty()) { + fprintf(stderr, "Engine version: %s\n", VERSION_FULL_NAME); } else { - fprintf(stderr, "Engine version: " VERSION_FULL_NAME "\n"); + fprintf(stderr, "Engine version: %s (%s)\n", VERSION_FULL_NAME, VERSION_HASH); } fprintf(stderr, "Dumping the backtrace. %ls\n", msg.c_str()); char **strings = backtrace_symbols(bt_buffer, size);