-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[GDExtension] Add config option to specify custom library lookup paths. #88049
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/**************************************************************************/ | ||
/* gdextension.compat.inc */ | ||
/**************************************************************************/ | ||
/* This file is part of: */ | ||
/* GODOT ENGINE */ | ||
/* https://godotengine.org */ | ||
/**************************************************************************/ | ||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ | ||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ | ||
/* */ | ||
/* Permission is hereby granted, free of charge, to any person obtaining */ | ||
/* a copy of this software and associated documentation files (the */ | ||
/* "Software"), to deal in the Software without restriction, including */ | ||
/* without limitation the rights to use, copy, modify, merge, publish, */ | ||
/* distribute, sublicense, and/or sell copies of the Software, and to */ | ||
/* permit persons to whom the Software is furnished to do so, subject to */ | ||
/* the following conditions: */ | ||
/* */ | ||
/* The above copyright notice and this permission notice shall be */ | ||
/* included in all copies or substantial portions of the Software. */ | ||
/* */ | ||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ | ||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ | ||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ | ||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ | ||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ | ||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ | ||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ | ||
/**************************************************************************/ | ||
|
||
#ifndef DISABLE_DEPRECATED | ||
|
||
#include "gdextension.h" | ||
|
||
Error GDExtension::_open_library_bind_compat_88049(const String &p_path, const String &p_entry_symbol) { | ||
return open_library(p_path, p_entry_symbol, Vector<String>()); | ||
} | ||
|
||
void GDExtension::_bind_compatibility_methods() { | ||
ClassDB::bind_compatibility_method(D_METHOD("open_library", "path", "entry_symbol"), &GDExtension::_open_library_bind_compat_88049); | ||
} | ||
Comment on lines
+39
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is no longer necessary. After PR #88418, |
||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ | |
#include "core/object/method_bind.h" | ||
#include "core/os/os.h" | ||
#include "core/version.h" | ||
#include "gdextension.compat.inc" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To follow current include conventions, this should be: #include "gdextension.h"
#include "gdextension.compat.inc"
#include "core/config/project_settings.h"
#include "core/extension/gdextension_manager.h"
#include "core/io/dir_access.h"
#include "core/object/class_db.h"
#include "core/object/method_bind.h"
#include "core/os/os.h"
#include "core/version.h" |
||
#include "gdextension_manager.h" | ||
|
||
extern void gdextension_setup_interface(); | ||
|
@@ -679,7 +680,7 @@ GDExtensionInterfaceFunctionPtr GDExtension::get_interface_function(const String | |
return *function; | ||
} | ||
|
||
Error GDExtension::open_library(const String &p_path, const String &p_entry_symbol) { | ||
Error GDExtension::open_library(const String &p_path, const String &p_entry_symbol, const Vector<String> &p_lookup_paths) { | ||
String abs_path = ProjectSettings::get_singleton()->globalize_path(p_path); | ||
#if defined(WINDOWS_ENABLED) && defined(TOOLS_ENABLED) | ||
// If running on the editor on Windows, we copy the library and open the copy. | ||
|
@@ -716,6 +717,22 @@ Error GDExtension::open_library(const String &p_path, const String &p_entry_symb | |
} | ||
#endif | ||
|
||
if (!p_lookup_paths.is_empty() && !FileAccess::exists(abs_path) && !DirAccess::exists(abs_path)) { | ||
// Try using custom lookup paths. | ||
for (const String &dir : p_lookup_paths) { | ||
String lookup_dir = dir; | ||
lookup_dir = lookup_dir.begins_with("pck_dir://") ? lookup_dir.replace_first("pck_dir:/", ProjectSettings::get_singleton()->get_main_pack_path()) : lookup_dir; | ||
lookup_dir = lookup_dir.begins_with("bundle_dir://") ? lookup_dir.replace_first("bundle_dir:/", OS::get_singleton()->get_bundle_resource_dir()) : lookup_dir; | ||
lookup_dir = lookup_dir.begins_with("exe_dir://") ? lookup_dir.replace_first("exe_dir:/", OS::get_singleton()->get_executable_path().get_base_dir()) : lookup_dir; | ||
Comment on lines
+724
to
+726
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to replace this with the custom path mapping from PR #87586 after that is merged, so that these paths aren't exclusive to GDExtension loading. Perhaps a TODO should be added here? Also, are we sure we want to commit to these specific prefix names? Not that I want to spend lots of time bike-shedding the names :-) but we will be committing to them as part of our external API, so they probably should go through a little bit wider discussion. |
||
lookup_dir = lookup_dir.path_join(abs_path.get_file()); | ||
lookup_dir = ProjectSettings::get_singleton()->globalize_path(lookup_dir); | ||
if (FileAccess::exists(lookup_dir) || DirAccess::exists(lookup_dir)) { | ||
abs_path = lookup_dir; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
Error err = OS::get_singleton()->open_dynamic_library(abs_path, library, true, &library_path); | ||
ERR_FAIL_COND_V_MSG(err == ERR_FILE_NOT_FOUND, err, "GDExtension dynamic library not found: " + abs_path); | ||
ERR_FAIL_COND_V_MSG(err != OK, err, "Can't open GDExtension dynamic library: " + abs_path); | ||
|
@@ -801,7 +818,7 @@ void GDExtension::deinitialize_library(InitializationLevel p_level) { | |
} | ||
|
||
void GDExtension::_bind_methods() { | ||
ClassDB::bind_method(D_METHOD("open_library", "path", "entry_symbol"), &GDExtension::open_library); | ||
ClassDB::bind_method(D_METHOD("open_library", "path", "entry_symbol", "lookup_paths"), &GDExtension::open_library, DEFVAL(Vector<String>())); | ||
ClassDB::bind_method(D_METHOD("close_library"), &GDExtension::close_library); | ||
ClassDB::bind_method(D_METHOD("is_library_open"), &GDExtension::is_library_open); | ||
|
||
|
@@ -932,8 +949,9 @@ Error GDExtensionResourceLoader::load_gdextension_resource(const String &p_path, | |
FileAccess::get_modified_time(p_path), | ||
FileAccess::get_modified_time(library_path)); | ||
#endif | ||
Vector<String> lookup_paths = config->get_value("configuration", "lookup_paths", Vector<String>()); | ||
|
||
err = p_extension->open_library(is_static_library ? String() : library_path, entry_symbol); | ||
err = p_extension->open_library(is_static_library ? String() : library_path, entry_symbol, lookup_paths); | ||
if (err != OK) { | ||
#if defined(WINDOWS_ENABLED) && defined(TOOLS_ENABLED) | ||
// If the DLL fails to load, make sure that temporary DLL copies are cleaned up. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,7 @@ | |
<return type="int" enum="Error" /> | ||
<param index="0" name="path" type="String" /> | ||
<param index="1" name="entry_symbol" type="String" /> | ||
<param index="2" name="lookup_paths" type="PackedStringArray" default="PackedStringArray()" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be good to document it. |
||
<description> | ||
Opens the library at the specified [param path]. | ||
[b]Note:[/b] You normally should not call this method directly. This is handled automatically by [method GDExtensionManager.load_extension]. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary