Skip to content

Commit

Permalink
Added --library-path command line option.
Browse files Browse the repository at this point in the history
  • Loading branch information
samdeane committed Oct 11, 2024
1 parent 9d045e7 commit 88ef5e1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions core/os/os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ void OS::alert(const String &p_alert, const String &p_title) {
fprintf(stderr, "%s: %s\n", p_title.utf8().get_data(), p_alert.utf8().get_data());
}

void OS::set_dynamic_library_search_path(const String &p_path) {
_library_search_path = p_path;
}

void OS::set_low_processor_usage_mode(bool p_enabled) {
low_processor_usage_mode = p_enabled;
}
Expand Down
6 changes: 5 additions & 1 deletion core/os/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class OS {
bool _verbose_stdout = false;
bool _debug_stdout = false;
String _local_clipboard;
String _library_search_path;
// Assume success by default, all failure cases need to set EXIT_FAILURE explicitly.
int _exit_code = EXIT_SUCCESS;
bool _allow_hidpi = false;
Expand Down Expand Up @@ -164,7 +165,10 @@ class OS {
virtual Error open_dynamic_library(const String &p_path, void *&p_library_handle, GDExtensionData *p_data = nullptr) { return ERR_UNAVAILABLE; }
virtual Error close_dynamic_library(void *p_library_handle) { return ERR_UNAVAILABLE; }
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; }


String get_dynamic_library_search_path() { return _library_search_path; }
void set_dynamic_library_search_path(const String &p_path);

virtual void set_low_processor_usage_mode(bool p_enabled);
virtual bool is_in_low_processor_usage_mode() const;
virtual void set_low_processor_usage_mode_sleep_usec(int p_usec);
Expand Down
8 changes: 8 additions & 0 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ void Main::print_help(const char *p_binary) {
print_help_option("--quit-after <int>", "Quit after the given number of iterations. Set to 0 to disable.\n");
print_help_option("-l, --language <locale>", "Use a specific locale (<locale> being a two-letter code).\n");
print_help_option("--path <directory>", "Path to a project (<directory> must contain a \"project.godot\" file).\n");
print_help_option("--library-path <directory>", "Additional path to search for extension libraries.\n");
print_help_option("-u, --upwards", "Scan folders upwards for project.godot file.\n");
print_help_option("--main-pack <file>", "Path to a pack (.pck) file to load.\n");
print_help_option("--render-thread <mode>", "Render thread mode (\"unsafe\", \"safe\", \"separate\").\n");
Expand Down Expand Up @@ -1537,6 +1538,13 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
OS::get_singleton()->print("Missing relative or absolute path, aborting.\n");
goto error;
}
} else if (arg == "--library-path") { // set path to use to look for libraries
if (N) {
String p = N->get();
OS::get_singleton()->set_dynamic_library_search_path(p);
N = N->next();
OS::get_singleton()->print("Library path set to: \"%s\"\n", p.utf8().get_data());
}
} else if (arg == "-u" || arg == "--upwards") { // scan folders upwards
upwards = true;
} else if (arg == "--quit") { // Auto quit at the end of the first main loop iteration
Expand Down
7 changes: 7 additions & 0 deletions platform/macos/os_macos.mm
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,13 @@
// Load .dylib or framework from PackageFrameworks (eg when running from the Xcode Build Folder).
path = get_framework_executable(get_executable_path().get_base_dir().path_join("PackageFrameworks").path_join(p_path.get_file()));
}

if (!FileAccess::exists(path)) {
// Load .dylib or framework from a custom location supplied on the command line.
path = get_framework_executable(OS::get_singleton()->get_dynamic_library_search_path().path_join(p_path.get_file()));
OS::get_singleton()->print("trying %s\n", path.utf8().get_data());
}

#ifdef TOOLS_ENABLED
if (!FileAccess::exists(path)) {
if (has_environment("GODOT_EDITOR_LIBRARY_PATH")) {
Expand Down

0 comments on commit 88ef5e1

Please sign in to comment.