Here is some code to create the relationships between modules by using predicate_property/2 that I am expecting should be similar to what a super
property for module would return.
After reply by Jan W. added section for import_module/2.
:- module(module_tools,[
init/0,
list_uses/1,
list_imports/1,
compare/0
]).
:- use_module(library(persistency)).
:- persistent
uses(super:atom,module:atom),
imports(module:atom,import:atom).
:- initialization(db_attach('module.journal', [])).
add_uses(Super,Module) :-
(
uses(Super,Module), !
;
assert_uses(Super,Module)
).
init_uses :-
forall(
predicate_property(Super:_, imported_from(Module)),
add_uses(Super,Module)
).
list_uses(uses(Super,Module)) :-
uses(Super,Module).
add_imports(Module,Import) :-
(
imports(Module,Import), !
;
assert_imports(Module,Import)
).
init_imports :-
forall(
(
current_module(Module),
import_module(Module,Import)
),
add_imports(Module,Import)
).
list_imports(imports(Module,Import)) :-
imports(Module,Import).
init :-
init_uses,
init_imports.
compare :-
missing_imports,
missing_uses.
missing_imports :-
list_uses(uses(A,B)),
(
list_imports(imports(A,B))
->
true
;
format('Missing import: ~w, ~w~n',[A,B])
),
fail.
missing_imports.
missing_uses :-
list_imports(imports(A,B)),
(
list_uses(uses(A,B))
->
true
;
format('Missing uses: ~w, ~w~n',[A,B])
),
fail.
missing_uses.
Example usage.
Welcome to SWI-Prolog (threaded, 64 bits, version 8.3.5-8-ge14460a94)
?- working_directory(_,'C:/Users/Groot/Documents').
true.
?- ['module tools'].
true.
?- init.
true.
?- list_uses(Uses).
Uses = uses(prolog_source, system) ;
Uses = uses(prolog_source, prolog_operator) ;
Uses = uses(prolog_source, '$expand') ;
...
?- list_imports(Imports).
Imports = imports(prolog_source, system) ;
Imports = imports(swi_option, system) ;
Imports = imports(prolog_operator, system) ;
...
?- compare.
...
Missing import: prolog_metainference, lists
Missing import: prolog_metainference, apply
Missing uses: prolog, user
Missing uses: pce_expansion, user
...
If you want to look at the journal file created by library persistency remember that you have to execute halt.
first. Also the code will hold a lock on the file while the code is running.