Browse Source

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.
Rémi Verschelde 3 years ago
parent
commit
90162851a7

+ 1 - 0
core/SCsub

@@ -147,6 +147,7 @@ env.core_sources += thirdparty_obj
 
 
 env.add_source_files(env.core_sources, "*.cpp")
 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, "script_encryption_key.gen.cpp")
+env.add_source_files(env.core_sources, "version_hash.gen.cpp")
 
 
 # Certificates
 # Certificates
 env.Depends(
 env.Depends(

+ 2 - 3
core/config/engine.cpp

@@ -35,7 +35,6 @@
 #include "core/donors.gen.h"
 #include "core/donors.gen.h"
 #include "core/license.gen.h"
 #include "core/license.gen.h"
 #include "core/version.h"
 #include "core/version.h"
-#include "core/version_hash.gen.h"
 
 
 void Engine::set_physics_ticks_per_second(int p_ips) {
 void Engine::set_physics_ticks_per_second(int p_ips) {
 	ERR_FAIL_COND_MSG(p_ips <= 0, "Engine iterations per second must be greater than 0.");
 	ERR_FAIL_COND_MSG(p_ips <= 0, "Engine iterations per second must be greater than 0.");
@@ -95,8 +94,8 @@ Dictionary Engine::get_version_info() const {
 	dict["build"] = VERSION_BUILD;
 	dict["build"] = VERSION_BUILD;
 	dict["year"] = VERSION_YEAR;
 	dict["year"] = VERSION_YEAR;
 
 
-	String hash = VERSION_HASH;
-	dict["hash"] = hash.length() == 0 ? String("unknown") : hash;
+	String hash = String(VERSION_HASH);
+	dict["hash"] = hash.is_empty() ? String("unknown") : hash;
 
 
 	String stringver = String(dict["major"]) + "." + String(dict["minor"]);
 	String stringver = String(dict["major"]) + "." + String(dict["minor"]);
 	if ((int)dict["patch"] != 0) {
 	if ((int)dict["patch"] != 0) {

+ 3 - 0
core/version.h

@@ -68,4 +68,7 @@
 // Example: "Godot v3.1.4.stable.official.mono"
 // Example: "Godot v3.1.4.stable.official.mono"
 #define VERSION_FULL_NAME "" VERSION_NAME " v" VERSION_FULL_BUILD
 #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 // VERSION_H
 #endif // VERSION_H

+ 4 - 14
editor/debugger/script_editor_debugger.cpp

@@ -36,7 +36,6 @@
 #include "core/io/marshalls.h"
 #include "core/io/marshalls.h"
 #include "core/string/ustring.h"
 #include "core/string/ustring.h"
 #include "core/version.h"
 #include "core/version.h"
-#include "core/version_hash.gen.h"
 #include "editor/debugger/debug_adapter/debug_adapter_protocol.h"
 #include "editor/debugger/debug_adapter/debug_adapter_protocol.h"
 #include "editor/debugger/editor_network_profiler.h"
 #include "editor/debugger/editor_network_profiler.h"
 #include "editor/debugger/editor_performance_profiler.h"
 #include "editor/debugger/editor_performance_profiler.h"
@@ -1543,19 +1542,10 @@ void ScriptEditorDebugger::_item_menu_id_pressed(int p_option) {
 			const int line_number = file_line_number[1].to_int();
 			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.
 			// 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).is_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;
 		} break;
 		case ACTION_DELETE_BREAKPOINT: {
 		case ACTION_DELETE_BREAKPOINT: {
 			const TreeItem *selected = breakpoints_tree->get_selected();
 			const TreeItem *selected = breakpoints_tree->get_selected();

+ 1 - 2
editor/editor_about.cpp

@@ -29,13 +29,12 @@
 /*************************************************************************/
 /*************************************************************************/
 
 
 #include "editor_about.h"
 #include "editor_about.h"
-#include "editor_node.h"
 
 
 #include "core/authors.gen.h"
 #include "core/authors.gen.h"
 #include "core/donors.gen.h"
 #include "core/donors.gen.h"
 #include "core/license.gen.h"
 #include "core/license.gen.h"
 #include "core/version.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.
 // 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";
 static const String META_TEXT_TO_COPY = "text_to_copy";

+ 0 - 1
editor/editor_node.cpp

@@ -47,7 +47,6 @@
 #include "core/string/print_string.h"
 #include "core/string/print_string.h"
 #include "core/string/translation.h"
 #include "core/string/translation.h"
 #include "core/version.h"
 #include "core/version.h"
-#include "core/version_hash.gen.h"
 #include "main/main.h"
 #include "main/main.h"
 #include "scene/3d/importer_mesh_instance_3d.h"
 #include "scene/3d/importer_mesh_instance_3d.h"
 #include "scene/gui/center_container.h"
 #include "scene/gui/center_container.h"

+ 0 - 1
editor/project_manager.cpp

@@ -40,7 +40,6 @@
 #include "core/os/os.h"
 #include "core/os/os.h"
 #include "core/string/translation.h"
 #include "core/string/translation.h"
 #include "core/version.h"
 #include "core/version.h"
-#include "core/version_hash.gen.h"
 #include "editor/editor_vcs_interface.h"
 #include "editor/editor_vcs_interface.h"
 #include "editor_scale.h"
 #include "editor_scale.h"
 #include "editor_settings.h"
 #include "editor_settings.h"

+ 1 - 2
main/main.cpp

@@ -50,7 +50,6 @@
 #include "core/register_core_types.h"
 #include "core/register_core_types.h"
 #include "core/string/translation.h"
 #include "core/string/translation.h"
 #include "core/version.h"
 #include "core/version.h"
-#include "core/version_hash.gen.h"
 #include "drivers/register_driver_types.h"
 #include "drivers/register_driver_types.h"
 #include "main/app_icon.gen.h"
 #include "main/app_icon.gen.h"
 #include "main/main_timer_sync.h"
 #include "main/main_timer_sync.h"
@@ -200,7 +199,7 @@ static String unescape_cmdline(const String &p_str) {
 
 
 static String get_full_version_string() {
 static String get_full_version_string() {
 	String hash = String(VERSION_HASH);
 	String hash = String(VERSION_HASH);
-	if (hash.length() != 0) {
+	if (!hash.is_empty()) {
 		hash = "." + hash.left(9);
 		hash = "." + hash.left(9);
 	}
 	}
 	return String(VERSION_FULL_BUILD) + hash;
 	return String(VERSION_FULL_BUILD) + hash;

+ 3 - 5
methods.py

@@ -111,10 +111,9 @@ def update_version(module_version_string=""):
     f.close()
     f.close()
 
 
     # NOTE: It is safe to generate this file here, since this is still executed serially
     # 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("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
-    fhash.write("#ifndef VERSION_HASH_GEN_H\n")
-    fhash.write("#define VERSION_HASH_GEN_H\n")
+    fhash.write('#include "core/version.h"\n')
     githash = ""
     githash = ""
     gitfolder = ".git"
     gitfolder = ".git"
 
 
@@ -132,8 +131,7 @@ def update_version(module_version_string=""):
         else:
         else:
             githash = head
             githash = head
 
 
-    fhash.write('#define VERSION_HASH "' + githash + '"\n')
-    fhash.write("#endif // VERSION_HASH_GEN_H\n")
+    fhash.write('const char *const VERSION_HASH = "' + githash + '";\n')
     fhash.close()
     fhash.close()
 
 
 
 

+ 2 - 3
modules/gltf/gltf_document.cpp

@@ -57,7 +57,6 @@
 #include "core/variant/typed_array.h"
 #include "core/variant/typed_array.h"
 #include "core/variant/variant.h"
 #include "core/variant/variant.h"
 #include "core/version.h"
 #include "core/version.h"
-#include "core/version_hash.gen.h"
 #include "drivers/png/png_driver_common.h"
 #include "drivers/png/png_driver_common.h"
 #include "editor/import/resource_importer_scene.h"
 #include "editor/import/resource_importer_scene.h"
 #include "scene/2d/node_2d.h"
 #include "scene/2d/node_2d.h"
@@ -6655,8 +6654,8 @@ Error GLTFDocument::_serialize_version(Ref<GLTFState> state) {
 	Dictionary asset;
 	Dictionary asset;
 	asset["version"] = version;
 	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.is_empty() ? String("unknown") : hash);
 	state->json["asset"] = asset;
 	state->json["asset"] = asset;
 	ERR_FAIL_COND_V(!asset.has("version"), Error::FAILED);
 	ERR_FAIL_COND_V(!asset.has("version"), Error::FAILED);
 	ERR_FAIL_COND_V(!state->json.has("asset"), Error::FAILED);
 	ERR_FAIL_COND_V(!state->json.has("asset"), Error::FAILED);

+ 3 - 4
platform/linuxbsd/crash_handler_linuxbsd.cpp

@@ -33,7 +33,6 @@
 #include "core/config/project_settings.h"
 #include "core/config/project_settings.h"
 #include "core/os/os.h"
 #include "core/os/os.h"
 #include "core/version.h"
 #include "core/version.h"
-#include "core/version_hash.gen.h"
 #include "main/main.h"
 #include "main/main.h"
 
 
 #ifdef DEBUG_ENABLED
 #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.
 	// 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).is_empty()) {
+		fprintf(stderr, "Engine version: %s\n", VERSION_FULL_NAME);
 	} else {
 	} 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. %s\n", msg.utf8().get_data());
 	fprintf(stderr, "Dumping the backtrace. %s\n", msg.utf8().get_data());
 	char **strings = backtrace_symbols(bt_buffer, size);
 	char **strings = backtrace_symbols(bt_buffer, size);

+ 3 - 4
platform/osx/crash_handler_osx.mm

@@ -33,7 +33,6 @@
 #include "core/config/project_settings.h"
 #include "core/config/project_settings.h"
 #include "core/os/os.h"
 #include "core/os/os.h"
 #include "core/version.h"
 #include "core/version.h"
-#include "core/version_hash.gen.h"
 #include "main/main.h"
 #include "main/main.h"
 
 
 #include <string.h>
 #include <string.h>
@@ -94,10 +93,10 @@ static void handle_crash(int sig) {
 		OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_CRASH);
 		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.
 	// 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).is_empty()) {
+		fprintf(stderr, "Engine version: %s\n", VERSION_FULL_NAME);
 	} else {
 	} 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. %s\n", msg.utf8().get_data());
 	fprintf(stderr, "Dumping the backtrace. %s\n", msg.utf8().get_data());
 	char **strings = backtrace_symbols(bt_buffer, size);
 	char **strings = backtrace_symbols(bt_buffer, size);

+ 3 - 4
platform/windows/crash_handler_windows.cpp

@@ -33,7 +33,6 @@
 #include "core/config/project_settings.h"
 #include "core/config/project_settings.h"
 #include "core/os/os.h"
 #include "core/os/os.h"
 #include "core/version.h"
 #include "core/version.h"
-#include "core/version_hash.gen.h"
 #include "main/main.h"
 #include "main/main.h"
 
 
 #ifdef CRASH_HANDLER_EXCEPTION
 #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.
 	// 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).is_empty()) {
+		fprintf(stderr, "Engine version: %s\n", VERSION_FULL_NAME);
 	} else {
 	} 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. %s\n", msg.utf8().get_data());
 	fprintf(stderr, "Dumping the backtrace. %s\n", msg.utf8().get_data());