From ee8c6209db7d283683165aeebcbb2d27c604fd67 Mon Sep 17 00:00:00 2001 From: Kolan Sh Date: Thu, 21 Jun 2018 17:59:49 +0300 Subject: [PATCH] Dependency accounting between modules. Typically, common classes are placed in a separate library that is loaded by the system, but if this is not done, then you need to select the correct sequence for loading the modules, which is done in the loop. --- src/loader/PluginLoader.vala | 60 +++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/src/loader/PluginLoader.vala b/src/loader/PluginLoader.vala index 97b187b..35670a5 100644 --- a/src/loader/PluginLoader.vala +++ b/src/loader/PluginLoader.vala @@ -96,17 +96,26 @@ namespace GObject { public bool load_modules (string dir_path, ref Gee.ArrayList? modules) { modules = new Gee.ArrayList (); + var paths = new Gee.HashSet (); try { var libPath = File.new_for_path (dir_path); - var lib_enumerator = libPath.enumerate_children (FileAttribute.STANDARD_NAME, 0, null); - FileInfo file_info = null; - while ((file_info = lib_enumerator.next_file (null)) != null) { - if (Regex.match_simple ("^.*\\.(so|dll)$", file_info.get_name ())) { - var module = new Module (GLib.Module.build_path (dir_path, file_info.get_name ())); - if (module.load ()) - modules.add (module); + for (var i = 0; i < 32; ++i) { + var saved_length = modules.size; + var lib_enumerator = libPath.enumerate_children (FileAttribute.STANDARD_NAME, 0, null); + FileInfo file_info = null; + while ((file_info = lib_enumerator.next_file (null)) != null) { + if (Regex.match_simple ("^.*\\.(so|dll)$", file_info.get_name ())) { + var path = GLib.Module.build_path (dir_path, file_info.get_name ()); + if (paths.contains(path)) continue; + var module = new Module (path); + if (module.load ()) { + modules.add (module); + paths.add(path); + } + } } + if (modules.size == saved_length) break; } } catch (Error e) { message (e.message); @@ -130,26 +139,35 @@ namespace GObject { public bool load_modules_depth2 (string dir_path, ref Gee.ArrayList? modules) { modules = new Gee.ArrayList (); + var paths = new Gee.HashSet (); try { var libPath = File.new_for_path (dir_path); - var dir_enumerator = libPath.enumerate_children ("standard::*", - FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null); - FileInfo dir_info = null; - while ((dir_info = dir_enumerator.next_file (null)) != null ) { - if (dir_info.get_file_type () == FileType.DIRECTORY) { - File subdir = libPath.resolve_relative_path (dir_info.get_name ()); - var lib_enumerator = subdir.enumerate_children (FileAttribute.STANDARD_NAME, 0, null); - FileInfo file_info = null; - while ((file_info = lib_enumerator.next_file (null)) != null) { - if (Regex.match_simple ("^.*\\.(so|dll)$", file_info.get_name ())) { - var path = Path.build_path (Path.DIR_SEPARATOR_S, dir_path, dir_info.get_name ()); - var module = new Module (GLib.Module.build_path (path, file_info.get_name ())); - if (module.load ()) - modules.add (module); + for (var i = 0; i < 32; ++i) { + var saved_length = modules.size; + var dir_enumerator = libPath.enumerate_children ("standard::*", + FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null); + FileInfo dir_info = null; + while ((dir_info = dir_enumerator.next_file (null)) != null ) { + if (dir_info.get_file_type () == FileType.DIRECTORY) { + File subdir = libPath.resolve_relative_path (dir_info.get_name ()); + var lib_enumerator = subdir.enumerate_children (FileAttribute.STANDARD_NAME, 0, null); + FileInfo file_info = null; + while ((file_info = lib_enumerator.next_file (null)) != null) { + if (Regex.match_simple ("^.*\\.(so|dll)$", file_info.get_name ())) { + var path = Path.build_path (Path.DIR_SEPARATOR_S, dir_path, dir_info.get_name ()); + path = GLib.Module.build_path (path, file_info.get_name ()); + if (paths.contains(path)) continue; + var module = new Module (path); + if (module.load ()) { + modules.add (module); + paths.add(path); + } + } } } } + if (modules.size == saved_length) break; } } catch (Error e) { message (e.message);