Skip to content

Commit e73f40e

Browse files
committed
Merge pull request #87117 from DmitriySalnikov/rename_pdb
Add renaming of PDB files to avoid blocking them
2 parents 5a38628 + b73e740 commit e73f40e

File tree

18 files changed

+411
-77
lines changed

18 files changed

+411
-77
lines changed

core/extension/gdextension.cpp

Lines changed: 6 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -729,53 +729,18 @@ GDExtensionInterfaceFunctionPtr GDExtension::get_interface_function(const String
729729

730730
Error GDExtension::open_library(const String &p_path, const String &p_entry_symbol) {
731731
String abs_path = ProjectSettings::get_singleton()->globalize_path(p_path);
732-
#if defined(WINDOWS_ENABLED) && defined(TOOLS_ENABLED)
733-
// If running on the editor on Windows, we copy the library and open the copy.
734-
// This is so the original file isn't locked and can be updated by a compiler.
735-
bool library_copied = false;
736-
if (Engine::get_singleton()->is_editor_hint()) {
737-
if (!FileAccess::exists(abs_path)) {
738-
ERR_PRINT("GDExtension library not found: " + abs_path);
739-
return ERR_FILE_NOT_FOUND;
740-
}
741-
742-
// Copy the file to the same directory as the original with a prefix in the name.
743-
// This is so relative path to dependencies are satisfied.
744-
String copy_path = abs_path.get_base_dir().path_join("~" + abs_path.get_file());
732+
String actual_lib_path;
733+
Error err = OS::get_singleton()->open_dynamic_library(abs_path, library, true, &actual_lib_path, Engine::get_singleton()->is_editor_hint());
745734

746-
// If there's a left-over copy (possibly from a crash) then delete it first.
747-
if (FileAccess::exists(copy_path)) {
748-
DirAccess::remove_absolute(copy_path);
749-
}
750-
751-
Error copy_err = DirAccess::copy_absolute(abs_path, copy_path);
752-
if (copy_err) {
753-
ERR_PRINT("Error copying GDExtension library: " + abs_path);
754-
return ERR_CANT_CREATE;
755-
}
756-
FileAccess::set_hidden_attribute(copy_path, true);
757-
library_copied = true;
758-
759-
// Save the copied path so it can be deleted later.
760-
temp_lib_path = copy_path;
761-
762-
// Use the copy to open the library.
763-
abs_path = copy_path;
735+
if (actual_lib_path.get_file() != abs_path.get_file()) {
736+
// If temporary files are generated, let's change the library path to point at the original,
737+
// because that's what we want to check to see if it's changed.
738+
library_path = actual_lib_path.get_base_dir().path_join(p_path.get_file());
764739
}
765-
#endif
766740

767-
Error err = OS::get_singleton()->open_dynamic_library(abs_path, library, true, &library_path);
768741
ERR_FAIL_COND_V_MSG(err == ERR_FILE_NOT_FOUND, err, "GDExtension dynamic library not found: " + abs_path);
769742
ERR_FAIL_COND_V_MSG(err != OK, err, "Can't open GDExtension dynamic library: " + abs_path);
770743

771-
#if defined(WINDOWS_ENABLED) && defined(TOOLS_ENABLED)
772-
// If we copied the file, let's change the library path to point at the original,
773-
// because that's what we want to check to see if it's changed.
774-
if (library_copied) {
775-
library_path = library_path.get_base_dir() + "\\" + p_path.get_file();
776-
}
777-
#endif
778-
779744
void *entry_funcptr = nullptr;
780745

781746
err = OS::get_singleton()->get_dynamic_library_symbol_handle(library, p_entry_symbol, entry_funcptr, false);
@@ -803,13 +768,6 @@ void GDExtension::close_library() {
803768
ERR_FAIL_NULL(library);
804769
OS::get_singleton()->close_dynamic_library(library);
805770

806-
#if defined(TOOLS_ENABLED) && defined(WINDOWS_ENABLED)
807-
// Delete temporary copy of library if it exists.
808-
if (!temp_lib_path.is_empty() && Engine::get_singleton()->is_editor_hint()) {
809-
DirAccess::remove_absolute(temp_lib_path);
810-
}
811-
#endif
812-
813771
library = nullptr;
814772
class_icon_paths.clear();
815773

@@ -1014,13 +972,6 @@ Error GDExtensionResourceLoader::load_gdextension_resource(const String &p_path,
1014972

1015973
err = p_extension->open_library(is_static_library ? String() : library_path, entry_symbol);
1016974
if (err != OK) {
1017-
#if defined(WINDOWS_ENABLED) && defined(TOOLS_ENABLED)
1018-
// If the DLL fails to load, make sure that temporary DLL copies are cleaned up.
1019-
if (Engine::get_singleton()->is_editor_hint()) {
1020-
DirAccess::remove_absolute(p_extension->get_temp_library_path());
1021-
}
1022-
#endif
1023-
1024975
// Unreference the extension so that this loading can be considered a failure.
1025976
p_extension.unref();
1026977

core/extension/gdextension.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ class GDExtension : public Resource {
4747

4848
void *library = nullptr; // pointer if valid,
4949
String library_path;
50-
#if defined(WINDOWS_ENABLED) && defined(TOOLS_ENABLED)
51-
String temp_lib_path;
52-
#endif
5350
bool reloadable = false;
5451

5552
struct Extension {
@@ -130,10 +127,6 @@ class GDExtension : public Resource {
130127
Error open_library(const String &p_path, const String &p_entry_symbol);
131128
void close_library();
132129

133-
#if defined(WINDOWS_ENABLED) && defined(TOOLS_ENABLED)
134-
String get_temp_library_path() const { return temp_lib_path; }
135-
#endif
136-
137130
enum InitializationLevel {
138131
INITIALIZATION_LEVEL_CORE = GDEXTENSION_INITIALIZATION_CORE,
139132
INITIALIZATION_LEVEL_SERVERS = GDEXTENSION_INITIALIZATION_SERVERS,

core/os/os.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class OS {
153153

154154
virtual void alert(const String &p_alert, const String &p_title = "ALERT!");
155155

156-
virtual Error open_dynamic_library(const String &p_path, void *&p_library_handle, bool p_also_set_library_path = false, String *r_resolved_path = nullptr) { return ERR_UNAVAILABLE; }
156+
virtual Error open_dynamic_library(const String &p_path, void *&p_library_handle, bool p_also_set_library_path = false, String *r_resolved_path = nullptr, bool p_generate_temp_files = false) { return ERR_UNAVAILABLE; }
157157
virtual Error close_dynamic_library(void *p_library_handle) { return ERR_UNAVAILABLE; }
158158
virtual Error get_dynamic_library_symbol_handle(void *p_library_handle, const String &p_name, void *&p_symbol_handle, bool p_optional = false) { return ERR_UNAVAILABLE; }
159159

drivers/unix/os_unix.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ String OS_Unix::get_locale() const {
741741
return locale;
742742
}
743743

744-
Error OS_Unix::open_dynamic_library(const String &p_path, void *&p_library_handle, bool p_also_set_library_path, String *r_resolved_path) {
744+
Error OS_Unix::open_dynamic_library(const String &p_path, void *&p_library_handle, bool p_also_set_library_path, String *r_resolved_path, bool p_generate_temp_files) {
745745
String path = p_path;
746746

747747
if (FileAccess::exists(path) && path.is_relative_path()) {

drivers/unix/os_unix.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class OS_Unix : public OS {
5555

5656
virtual Error get_entropy(uint8_t *r_buffer, int p_bytes) override;
5757

58-
virtual Error open_dynamic_library(const String &p_path, void *&p_library_handle, bool p_also_set_library_path = false, String *r_resolved_path = nullptr) override;
58+
virtual Error open_dynamic_library(const String &p_path, void *&p_library_handle, bool p_also_set_library_path = false, String *r_resolved_path = nullptr, bool p_generate_temp_files = false) override;
5959
virtual Error close_dynamic_library(void *p_library_handle) override;
6060
virtual Error get_dynamic_library_symbol_handle(void *p_library_handle, const String &p_name, void *&p_symbol_handle, bool p_optional = false) override;
6161

platform/android/os_android.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ Vector<String> OS_Android::get_granted_permissions() const {
162162
return godot_java->get_granted_permissions();
163163
}
164164

165-
Error OS_Android::open_dynamic_library(const String &p_path, void *&p_library_handle, bool p_also_set_library_path, String *r_resolved_path) {
165+
Error OS_Android::open_dynamic_library(const String &p_path, void *&p_library_handle, bool p_also_set_library_path, String *r_resolved_path, bool p_generate_temp_files) {
166166
String path = p_path;
167167
bool so_file_exists = true;
168168
if (!FileAccess::exists(path)) {

platform/android/os_android.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class OS_Android : public OS_Unix {
113113

114114
virtual void alert(const String &p_alert, const String &p_title) override;
115115

116-
virtual Error open_dynamic_library(const String &p_path, void *&p_library_handle, bool p_also_set_library_path = false, String *r_resolved_path = nullptr) override;
116+
virtual Error open_dynamic_library(const String &p_path, void *&p_library_handle, bool p_also_set_library_path = false, String *r_resolved_path = nullptr, bool p_generate_temp_files = false) override;
117117

118118
virtual String get_name() const override;
119119
virtual String get_distribution_name() const override;

platform/ios/os_ios.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class OS_IOS : public OS_Unix {
103103
virtual Vector<String> get_system_font_path_for_text(const String &p_font_name, const String &p_text, const String &p_locale = String(), const String &p_script = String(), int p_weight = 400, int p_stretch = 100, bool p_italic = false) const override;
104104
virtual String get_system_font_path(const String &p_font_name, int p_weight = 400, int p_stretch = 100, bool p_italic = false) const override;
105105

106-
virtual Error open_dynamic_library(const String &p_path, void *&p_library_handle, bool p_also_set_library_path = false, String *r_resolved_path = nullptr) override;
106+
virtual Error open_dynamic_library(const String &p_path, void *&p_library_handle, bool p_also_set_library_path = false, String *r_resolved_path = nullptr, bool p_generate_temp_files = false) override;
107107
virtual Error close_dynamic_library(void *p_library_handle) override;
108108
virtual Error get_dynamic_library_symbol_handle(void *p_library_handle, const String &p_name, void *&p_symbol_handle, bool p_optional = false) override;
109109

platform/ios/os_ios.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ void register_dynamic_symbol(char *name, void *address) {
219219
return p_path;
220220
}
221221

222-
Error OS_IOS::open_dynamic_library(const String &p_path, void *&p_library_handle, bool p_also_set_library_path, String *r_resolved_path) {
222+
Error OS_IOS::open_dynamic_library(const String &p_path, void *&p_library_handle, bool p_also_set_library_path, String *r_resolved_path, bool p_generate_temp_files) {
223223
if (p_path.length() == 0) {
224224
// Static xcframework.
225225
p_library_handle = RTLD_SELF;

platform/macos/os_macos.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class OS_MacOS : public OS_Unix {
8585

8686
virtual void alert(const String &p_alert, const String &p_title = "ALERT!") override;
8787

88-
virtual Error open_dynamic_library(const String &p_path, void *&p_library_handle, bool p_also_set_library_path = false, String *r_resolved_path = nullptr) override;
88+
virtual Error open_dynamic_library(const String &p_path, void *&p_library_handle, bool p_also_set_library_path = false, String *r_resolved_path = nullptr, bool p_generate_temp_files = false) override;
8989

9090
virtual MainLoop *get_main_loop() const override;
9191

0 commit comments

Comments
 (0)