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.
This commit is contained in:
Kolan Sh 2018-06-21 17:59:49 +03:00
parent 9b11bca35b
commit ee8c6209db
1 changed files with 39 additions and 21 deletions

View File

@ -96,17 +96,26 @@ namespace GObject {
public bool load_modules (string dir_path, ref Gee.ArrayList<Module>? modules) { public bool load_modules (string dir_path, ref Gee.ArrayList<Module>? modules) {
modules = new Gee.ArrayList<Module> (); modules = new Gee.ArrayList<Module> ();
var paths = new Gee.HashSet<string> ();
try { try {
var libPath = File.new_for_path (dir_path); var libPath = File.new_for_path (dir_path);
var lib_enumerator = libPath.enumerate_children (FileAttribute.STANDARD_NAME, 0, null); for (var i = 0; i < 32; ++i) {
FileInfo file_info = null; var saved_length = modules.size;
while ((file_info = lib_enumerator.next_file (null)) != null) { var lib_enumerator = libPath.enumerate_children (FileAttribute.STANDARD_NAME, 0, null);
if (Regex.match_simple ("^.*\\.(so|dll)$", file_info.get_name ())) { FileInfo file_info = null;
var module = new Module (GLib.Module.build_path (dir_path, file_info.get_name ())); while ((file_info = lib_enumerator.next_file (null)) != null) {
if (module.load ()) if (Regex.match_simple ("^.*\\.(so|dll)$", file_info.get_name ())) {
modules.add (module); 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) { } catch (Error e) {
message (e.message); message (e.message);
@ -130,26 +139,35 @@ namespace GObject {
public bool load_modules_depth2 (string dir_path, ref Gee.ArrayList<Module>? modules) { public bool load_modules_depth2 (string dir_path, ref Gee.ArrayList<Module>? modules) {
modules = new Gee.ArrayList<Module> (); modules = new Gee.ArrayList<Module> ();
var paths = new Gee.HashSet<string> ();
try { try {
var libPath = File.new_for_path (dir_path); var libPath = File.new_for_path (dir_path);
var dir_enumerator = libPath.enumerate_children ("standard::*", for (var i = 0; i < 32; ++i) {
FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null); var saved_length = modules.size;
FileInfo dir_info = null; var dir_enumerator = libPath.enumerate_children ("standard::*",
while ((dir_info = dir_enumerator.next_file (null)) != null ) { FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null);
if (dir_info.get_file_type () == FileType.DIRECTORY) { FileInfo dir_info = null;
File subdir = libPath.resolve_relative_path (dir_info.get_name ()); while ((dir_info = dir_enumerator.next_file (null)) != null ) {
var lib_enumerator = subdir.enumerate_children (FileAttribute.STANDARD_NAME, 0, null); if (dir_info.get_file_type () == FileType.DIRECTORY) {
FileInfo file_info = null; File subdir = libPath.resolve_relative_path (dir_info.get_name ());
while ((file_info = lib_enumerator.next_file (null)) != null) { var lib_enumerator = subdir.enumerate_children (FileAttribute.STANDARD_NAME, 0, null);
if (Regex.match_simple ("^.*\\.(so|dll)$", file_info.get_name ())) { FileInfo file_info = null;
var path = Path.build_path (Path.DIR_SEPARATOR_S, dir_path, dir_info.get_name ()); while ((file_info = lib_enumerator.next_file (null)) != null) {
var module = new Module (GLib.Module.build_path (path, file_info.get_name ())); if (Regex.match_simple ("^.*\\.(so|dll)$", file_info.get_name ())) {
if (module.load ()) var path = Path.build_path (Path.DIR_SEPARATOR_S, dir_path, dir_info.get_name ());
modules.add (module); 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) { } catch (Error e) {
message (e.message); message (e.message);