Modified configuration script parsing routines.
[makerl.git] / src / mkrl_execution.erl
blob2331dfaf2fa61b32c05ffcb2193461d23e683099
1 -module(mkrl_execution).
2 -include("makerl.hrl").
3 -export([execute/3]).
5 -compile(export_all).
7 -spec spawn_tasks([term()], options_type()) -> any().
8 spawn_tasks(Tasks, Opts) ->
9 Ctx = #eval_ctx{ task_registry = mkrl_task_registry:new(),
10 options = Opts },
11 mkrl_script_eval:eval(
12 mkrl_script_expand:expand(Tasks, Opts),
13 Ctx),
14 Ctx.
16 -spec execute(string(), [string()], options_type()) -> [build_result()].
17 execute(File, Targets, CmdLineOptions) ->
18 Ctx = spawn_tasks(mkrl_script_read:read(File), CmdLineOptions),
19 ok = check_unknown_targets(Ctx#eval_ctx.task_registry, Targets),
20 [ mkrl_task:build_target(Ctx#eval_ctx.task_registry, T)
21 || T <- Targets ]. %% Bind? Aggregated results?
23 -spec check_unknown_targets(tid(), [string()]) -> ok.
24 check_unknown_targets(TaskRegistry, Targets) ->
25 NotFound = lists:filter(fun(T) ->
26 case mkrl_task_registry:find_pid_by_target(TaskRegistry, T) of
27 {ok, _} -> false;
28 _ -> true
29 end
30 end,
31 Targets),
32 case NotFound of
33 [] -> ok;
34 L -> throw({error, {targets_unknown, L}})
35 end.