Skip to content

Commit fc04ecf

Browse files
committed
Added hooks for firing messages when recipes are executed.
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
1 parent 0cb7833 commit fc04ecf

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

prolog/biomake/biomake.pl

+12-1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@
117117

118118
disable_backtrace :- assertz(no_backtrace).
119119

120+
% ----------------------------------------
121+
% MESSAGE PASSING
122+
% ----------------------------------------
123+
124+
:- multifile intercept_message_hook/1.
125+
fire_message(M) :-
126+
findall(M,intercept_message_hook(M),_).
127+
120128

121129
% ----------------------------------------
122130
% TOP-LEVEL
@@ -175,7 +183,8 @@
175183
dep_bindrule(Rule,Opts,Rule2,Opts2), % test dependencies goal
176184
debug_report(build,'Post-dependency rule: ~w',[Rule2],SL),
177185
( rebuild_required(T,DL,SL,Opts2) % test if target is stale
178-
-> run_execs_and_update(Rule2,SL,Opts2) % (re)build
186+
-> run_execs_and_update(Rule2,SL,Opts2), % (re)build
187+
fire_message(was_derived_from(T,DL,Rule2))
179188
; verbose_report('~w is up to date',[T],SL,Opts)),
180189
!.
181190
build(T,SL,Opts) :-
@@ -458,6 +467,7 @@
458467
rule_dependencies(Rule,DL,Opts),
459468
format(string(Cmd),"touch ~w",[T]),
460469
shell(Cmd),
470+
fire_message(was_generated_by(T,Cmd)),
461471
(running_silent(T,Opts) -> true; report('~w',[Cmd],SL,Opts)),
462472
update_hash(T,DL,Opts).
463473
dispatch_run_execs(Rule,SL,Opts) :-
@@ -545,6 +555,7 @@
545555
shell(Exec,Err),
546556
get_time(T2),
547557
DT is T2-T1,
558+
fire_message(was_generated_by(T,Exec,Err,T1,T2)),
548559
debug_report(build,' Return: ~w Time: ~w',[Err,DT],SL),
549560
handle_exec_error(Exec,Err,T,SL,Opts),
550561
!.

prolog/biomake/cli.pl

+9
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,15 @@
310310
simple_arg('--one-shell',oneshell(true)).
311311
arg_info('--one-shell','','Run recipes in single shell (loosely equivalent to GNU Make\'s .ONESHELL)').
312312

313+
% ----------------------------------------
314+
% PROVENANCE
315+
% ----------------------------------------
316+
317+
parse_arg(['--dbpath',X|L],L,dbpath(X)).
318+
arg_info('--dbpath','PATH','Path db file for recording actions').
319+
simple_arg('--prov',prov(true)) :- ensure_loaded(library(biomake/persistent_db)).
320+
arg_info('--prov','','Provenance mode').
321+
313322
% ----------------------------------------
314323
% MD5 CHECKSUMS
315324
% ----------------------------------------

prolog/biomake/persistent_db.pl

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
:- module(persistent_db,
2+
[
3+
attach_persistent_db/1
4+
]).
5+
:- use_module(library(persistency)).
6+
7+
:- persistent action(info:any, time:float, process_id:integer).
8+
9+
:- dynamic attached/0.
10+
11+
ensure_attached :-
12+
attached,
13+
!.
14+
ensure_attached :-
15+
attach_persistent_db('.biomake-store.pro').
16+
17+
ensure_exists(File) :-
18+
exists_file(File),
19+
!.
20+
ensure_exists(File) :-
21+
tell(File),
22+
told,
23+
!.
24+
25+
26+
attach_persistent_db(File) :-
27+
ensure_exists(File),
28+
assert(attached),
29+
db_attach(File, []).
30+
31+
clear_persistent_db :-
32+
with_mutex(persistent_db,
33+
retractall_action(_)).
34+
35+
36+
:- multifile biomake:intercept_message_hook/1.
37+
biomake:intercept_message_hook(M) :-
38+
ensure_attached,
39+
get_time(T),
40+
current_prolog_flag(pid, PID),
41+
assert_action(M,T,PID).
42+

0 commit comments

Comments
 (0)