-
Notifications
You must be signed in to change notification settings - Fork 521
/
Copy pathrebar_prv_bare_compile.erl
86 lines (73 loc) · 2.94 KB
/
rebar_prv_bare_compile.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
-module(rebar_prv_bare_compile).
-behaviour(provider).
-export([init/1,
do/1,
format_error/1]).
-include_lib("providers/include/providers.hrl").
-include("rebar.hrl").
-define(PROVIDER, compile).
-define(NAMESPACE, bare).
-define(DEPS, [{default, app_discovery}]).
%% ===================================================================
%% Public API
%% ===================================================================
-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
init(State) ->
State1 = rebar_state:add_provider(
State,
providers:create([
{name, ?PROVIDER},
{module, ?MODULE},
{namespace, ?NAMESPACE},
{bare, false},
{deps, ?DEPS},
{example, ""},
{short_desc, ""},
{desc, ""},
{opts, [
{paths, $p, "paths", string,
"Wildcard paths of ebin directories to add to code path, "
"separated by a colon"},
{separator, $s, "separator", string,
"In case of multiple return paths, the separator character "
"to use to join them."},
{outdir, $o, "outdir", string,
"Path where build artifacts are located. Defaults to the "
"current directory."}
]}
])
),
{ok, State1}.
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
OrigPath = code:get_path(),
%% Add code paths from --paths to the beginning of the code path
{RawOpts, _} = rebar_state:command_parsed_args(State),
Paths = proplists:get_value(paths, RawOpts),
Sep = proplists:get_value(separator, RawOpts, " "),
%% Because mix won't check for versions, it instead sets this variable
%% that it knows older rebar3 version will ignore so we play nice and
%% honor it.
DefaultOutDir = os:getenv("REBAR_BARE_COMPILER_OUTPUT_DIR", rebar_dir:get_cwd()),
OutDir = proplists:get_value(outdir, RawOpts, DefaultOutDir),
[ code:add_pathsa(filelib:wildcard(PathWildcard))
|| PathWildcard <- rebar_string:lexemes(Paths, Sep) ],
case rebar_state:project_apps(State) of
[] ->
{error, {?MODULE, {not_an_application_structure, OutDir}}};
[AppInfo] ->
AppInfo1 = rebar_app_info:out_dir(AppInfo, OutDir),
%% run compile in the default namespace
rebar_prv_compile:compile(rebar_state:namespace(State, default), AppInfo1),
rebar_utils:cleanup_code_path(OrigPath),
{ok, State}
end.
-spec format_error(any()) -> iolist().
format_error({not_an_application_structure, Path}) ->
io_lib:format(
"Compilation failed: there is no code in this directory (~ts), " ++
"it is unreadable or for some other reason " ++
"is not a recognizable application structure.",
[Path]);
format_error(Reason) ->
io_lib:format("~p", [Reason]).