Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regex dependency #66

Merged
merged 5 commits into from
Sep 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .gitmodules
Empty file.
19 changes: 18 additions & 1 deletion prolog/biomake/biomake.pl
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,16 @@
report_run_exec/4,
update_hash/3,

shell_var_specified/1,

bindvar/3,
bindvar_rule/4,
expand_vars/2,
expand_vars/3
]).

:- use_module(library(pcre)).

:- use_module(library(biomake/utils)).
:- use_module(library(biomake/functions)).
:- use_module(library(biomake/embed)).
Expand Down Expand Up @@ -476,6 +480,10 @@
get_opt(oneshell,true,Opts),
!,
run_execs_in_script(Rule,SL,Opts).
run_execs_now(Rule,SL,Opts) :-
shell_var_specified(_),
!,
run_execs_in_script(Rule,SL,Opts).
run_execs_now(Rule,SL,Opts) :-
rule_target(Rule,T,Opts),
rule_dependencies(Rule,DL,Opts),
Expand Down Expand Up @@ -542,13 +550,22 @@

silent_run_exec(Exec,T,SL,Opts) :-
get_time(T1),
shell(Exec,Err),
run_shell(Exec,Err),
get_time(T2),
DT is T2-T1,
debug_report(build,' Return: ~w Time: ~w',[Err,DT],SL),
handle_exec_error(Exec,Err,T,SL,Opts),
!.

shell_var_specified(Sh) :-
atom_string(SHELL,"SHELL"),
global_binding(SHELL,Sh).

run_shell(Exec,Err) :-
!,
debug_report(shell,'sh ~w',[Exec]),
shell(Exec,Err).

handle_exec_error(_,0,_,_,_) :- !.
handle_exec_error(Exec,Err,T,SL,Opts) :-
( get_opt(keep_going_on_error,true,Opts)
Expand Down
26 changes: 24 additions & 2 deletions prolog/biomake/queue.pl
Original file line number Diff line number Diff line change
Expand Up @@ -193,21 +193,43 @@
append(ShellExecs,ShellCleanup,ExecsWithCleanup),
write_script_file_contents(T,Headers,ExecsWithCleanup,Opts,Subdirs,ScriptFilename).

write_script_file_contents(T,Headers,Execs,_Opts,Subdirs,ScriptFilename) :-
write_script_file_contents(T,Headers,Execs,Opts,Subdirs,ScriptFilename) :-
working_directory(CWD,CWD),
open_script_file(T,Subdirs,ScriptFilename,IO),
shell_path(Sh),
concat_string_list(Execs,ExecStr," &&\n"),
wrap_shell_execs(T,Execs,Opts,Subdirs,ExecStr),
concat_string_list(Headers,HeaderStr,"\n"),
format(IO,"#!~w~n~w~ncd ~w~n~w~n",[Sh,HeaderStr,CWD,ExecStr]),
close(IO),
format(string(Chmod),"chmod +x ~w",[ScriptFilename]),
shell(Chmod).

wrap_shell_execs(T,Execs,_Opts,Subdirs,ShellFilename) :-
shell_var_specified(Sh),
!,
open_shell_file(T,Subdirs,ShellFilename,IO),
concat_string_list(Execs,ExecStr,"\n"),
format(IO,"#!~w~n~w~n",[Sh,ExecStr]),
close(IO),
format(string(Chmod),"chmod +x ~w",[ShellFilename]),
shell(Chmod).

wrap_shell_execs(_T,Execs,_Opts,_Subdirs,ExecStr) :-
!,
join_with_ands(Execs,ExecStr).

join_with_ands(List,Str) :-
!,
concat_string_list(List,Str," &&\n").

open_script_file(Target,Subdirs,Filename,Stream) :-
append(Subdirs,["script"],SubdirsScript),
open_biomake_private_file(Target,SubdirsScript,Filename,Stream).

open_shell_file(Target,Subdirs,Filename,Stream) :-
append(Subdirs,["shell"],SubdirsShell),
open_biomake_private_file(Target,SubdirsShell,Filename,Stream).

% ----------------------------------------
% No queue engine (runs execs immediately)
% ----------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions prolog/test/test.pl
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@
run_test("-f Makefile.dcg","dcg_test"),
run_test("-f Makefile.dcg","mismatch_dcg_test"),

announce("PCRE REGEX LIBRARY"),
run_test("-f Makefile.regex","testregex_apple"),
run_failure_test("-f Makefile.regex","testregex_cat"),
run_failure_test("-f Makefile.regex","testregex_ALBACORE"), % fails due to default case-sensitivity of regexes

% All done
report_counts,
( failed_test(_,_)
Expand Down
1 change: 1 addition & 0 deletions t/ref/testregex_apple
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fired rule for testregex_apple
2 changes: 2 additions & 0 deletions t/target/Makefile.regex
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
testregex_$(ABC): { re_match('^a',ABC) }
echo Fired rule for $@ >$@