34
35:- module(packloader,
36 [ scanpacks/3,
37 pack_load_files/4,
38 pack_set_path/1,
39 pack_set_local_path/1,
40 pack_load_local/3,
41 use_module_ne/1
42 ]). 43
44:- use_module(library(lists)). 45:- use_module(library(option)). 46:- use_module(library(prolog_source)). 47:- use_module(read_file). 48:- use_module(conc_forall).
56:- meta_predicate
57 scanpacks(+, 1, 1),
58 use_module_ne(:). 59
60:- thread_local pack_path_local/1. 61
62user:file_search_path(pltool, plroot(Pack)) :- pack_path_local(Pack).
63
64use_module_ne(Lib) :- use_module(Lib, []).
65
66scanpacks(PackL, Action, DepAction) :-
67 conc_forall(member(P, PackL), scanpacks(Action, DepAction, [], P)).
68
69scanpacks(_, _, Loaded, Pack) :-
70 memberchk(Pack, Loaded),
71 !,
72 print_message(error, format("Circular dependency not allowed ~w", [[Pack|Loaded]])).
73scanpacks(Action, DepAction, Loaded, Pack) :-
74 absolute_file_name(Pack/pack, F, [file_type(prolog)]),
75 read_file(F, PackOptions),
76 findall(ReqPack, member(requires(ReqPack), PackOptions), PackL),
77 conc_forall(member(P, PackL), scanpacks(Action, DepAction, [Pack|Loaded], P)),
78 forall(member(P, PackL), call(DepAction, P)),
79 with_mutex(Pack, call(Action, Pack)).
80
81pack_set_path(Pack) :-
82 assertz(user:file_search_path(pltool, plroot(Pack))).
83
84pack_set_local_path(Pack) :-
85 assertz(pack_path_local(Pack)).
86
87:- meta_predicate pack_load_files(+,1,+,+). 88
89pack_load_files(Options, Loader, Pack, Dir) :-
90 option(exclude(ExFiles), Options, []),
91 directory_source_files(Dir, Files, [recursive(true), if(true)]),
92 atom_concat('_aux', Pack, AuxModule),
93 forall(( member(File, Files),
94 95 \+ ( member(ExFile, ExFiles),
96 absolute_file_name(ExFile, File, [file_type(prolog), file_errors(fail)])
97 )
98 ), call(Loader, AuxModule:File)).
99
100:- meta_predicate pack_load_local(+,1,+). 101
102pack_load_local(Options, Loader, Pack) :-
103 pack_set_local_path(Pack),
104 pack_load_files(Options, Loader, Pack, plroot(Pack/prolog))
Package loader
This module facilitates the load of all the modules in a package.
*/