Skip to content

Commit

Permalink
Added hooks for firing messages when recipes are executed.
Browse files Browse the repository at this point in the history
Default interceptor is a persistent store that logs actions
as unit clauses.

This could be extended to provide a complete workflow record,
as specified in #15
  • Loading branch information
cmungall committed Jan 23, 2018
1 parent 0cb7833 commit fc04ecf
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
13 changes: 12 additions & 1 deletion prolog/biomake/biomake.pl
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@

disable_backtrace :- assertz(no_backtrace).

% ----------------------------------------
% MESSAGE PASSING
% ----------------------------------------

:- multifile intercept_message_hook/1.
fire_message(M) :-
findall(M,intercept_message_hook(M),_).


% ----------------------------------------
% TOP-LEVEL
Expand Down Expand Up @@ -175,7 +183,8 @@
dep_bindrule(Rule,Opts,Rule2,Opts2), % test dependencies goal
debug_report(build,'Post-dependency rule: ~w',[Rule2],SL),
( rebuild_required(T,DL,SL,Opts2) % test if target is stale
-> run_execs_and_update(Rule2,SL,Opts2) % (re)build
-> run_execs_and_update(Rule2,SL,Opts2), % (re)build
fire_message(was_derived_from(T,DL,Rule2))
; verbose_report('~w is up to date',[T],SL,Opts)),
!.
build(T,SL,Opts) :-
Expand Down Expand Up @@ -458,6 +467,7 @@
rule_dependencies(Rule,DL,Opts),
format(string(Cmd),"touch ~w",[T]),
shell(Cmd),
fire_message(was_generated_by(T,Cmd)),
(running_silent(T,Opts) -> true; report('~w',[Cmd],SL,Opts)),
update_hash(T,DL,Opts).
dispatch_run_execs(Rule,SL,Opts) :-
Expand Down Expand Up @@ -545,6 +555,7 @@
shell(Exec,Err),
get_time(T2),
DT is T2-T1,
fire_message(was_generated_by(T,Exec,Err,T1,T2)),
debug_report(build,' Return: ~w Time: ~w',[Err,DT],SL),
handle_exec_error(Exec,Err,T,SL,Opts),
!.
Expand Down
9 changes: 9 additions & 0 deletions prolog/biomake/cli.pl
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,15 @@
simple_arg('--one-shell',oneshell(true)).
arg_info('--one-shell','','Run recipes in single shell (loosely equivalent to GNU Make\'s .ONESHELL)').

% ----------------------------------------
% PROVENANCE
% ----------------------------------------

parse_arg(['--dbpath',X|L],L,dbpath(X)).
arg_info('--dbpath','PATH','Path db file for recording actions').
simple_arg('--prov',prov(true)) :- ensure_loaded(library(biomake/persistent_db)).
arg_info('--prov','','Provenance mode').

% ----------------------------------------
% MD5 CHECKSUMS
% ----------------------------------------
Expand Down
42 changes: 42 additions & 0 deletions prolog/biomake/persistent_db.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
:- module(persistent_db,
[
attach_persistent_db/1
]).
:- use_module(library(persistency)).

:- persistent action(info:any, time:float, process_id:integer).

:- dynamic attached/0.

ensure_attached :-
attached,
!.
ensure_attached :-
attach_persistent_db('.biomake-store.pro').

ensure_exists(File) :-
exists_file(File),
!.
ensure_exists(File) :-
tell(File),
told,
!.


attach_persistent_db(File) :-
ensure_exists(File),
assert(attached),
db_attach(File, []).

clear_persistent_db :-
with_mutex(persistent_db,
retractall_action(_)).


:- multifile biomake:intercept_message_hook/1.
biomake:intercept_message_hook(M) :-
ensure_attached,
get_time(T),
current_prolog_flag(pid, PID),
assert_action(M,T,PID).

0 comments on commit fc04ecf

Please sign in to comment.