/
agner_rebar_plugin.erl
60 lines (49 loc) · 1.81 KB
/
agner_rebar_plugin.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
-module(agner_rebar_plugin).
-export(['check-deps'/2,
'update-deps'/2,
'get-deps'/2,
pre_compile/2]).
'check-deps'(Config, AppFile) ->
pre_compile(Config, AppFile).
'update-deps'(Config, AppFile) ->
'get-deps'(Config, AppFile).
'get-deps'(Config, AppFile) ->
ensure_agner_started(),
set_indices(Config),
{Pid, Ref} = erlang:spawn_monitor(fun () ->
agner_main:handle_command(fetch,[{app, AppFile},{version, "@master"},{addpath, false},
{install, false},{build, false}, nodeps_flag()])
end),
receive
{'DOWN', Ref, process, Pid, normal} ->
ok
end.
pre_compile(Config, AppFile) ->
ensure_agner_started(),
set_indices(Config),
{Pid, Ref} = erlang:spawn_monitor(fun () ->
agner_main:handle_command(build,[{app, AppFile},{version, "@master"},{quiet, false},
{nofetch, true},
{addpath, false},
{install, false},nodeps_flag()])
end),
receive
{'DOWN', Ref, process, Pid, normal} ->
ok
end.
set_indices(Config) ->
application:set_env(agner, indices, rebar_config:get_local(Config, agner_indices, [{github,"agner"}])).
ensure_agner_started() ->
case proplists:get_value(agner, application:loaded_applications()) of
undefined ->
agner:start();
_ ->
ok %% already started
end.
nodeps_flag() ->
case rebar_config:get_global(skip_deps, false) of
"true" ->
{nodeps, true};
_ ->
{nodeps, false}
end.