summaryrefslogtreecommitdiff
path: root/src/rebar_erlc_compiler.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/rebar_erlc_compiler.erl')
-rw-r--r--src/rebar_erlc_compiler.erl78
1 files changed, 38 insertions, 40 deletions
diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl
index f3dd5b6..2435884 100644
--- a/src/rebar_erlc_compiler.erl
+++ b/src/rebar_erlc_compiler.erl
@@ -87,7 +87,7 @@ compile(Config, _AppFile) ->
fun compile_mib/3),
doterl_compile(Config, "ebin").
--spec clean(Config::rebar_config:config(), AppFile::file:filename()) -> 'ok'.
+-spec clean(rebar_config:config(), file:filename()) -> 'ok'.
clean(_Config, _AppFile) ->
MibFiles = rebar_utils:find_files("mibs", "^.*\\.mib\$"),
MIBs = [filename:rootname(filename:basename(MIB)) || MIB <- MibFiles],
@@ -217,8 +217,7 @@ is_lib_avail(Config, DictKey, Mod, Hrl, Name) ->
{Config, IsAvail}
end.
--spec doterl_compile(Config::rebar_config:config(),
- OutDir::file:filename()) -> 'ok'.
+-spec doterl_compile(rebar_config:config(), file:filename()) -> 'ok'.
doterl_compile(Config, OutDir) ->
doterl_compile(Config, OutDir, []).
@@ -258,7 +257,7 @@ doterl_compile(Config, OutDir, MoreSources) ->
true = code:add_path(filename:absname("ebin")),
rebar_base_compiler:run(Config, NewFirstErls, OtherErls,
fun(S, C) ->
- internal_erl_compile(S, C, OutDir, ErlOpts)
+ internal_erl_compile(C, S, OutDir, ErlOpts)
end),
true = code:set_path(CurrPath),
ok.
@@ -268,15 +267,15 @@ doterl_compile(Config, OutDir, MoreSources) ->
%% Internal functions
%% ===================================================================
--spec include_path(Source::file:filename(),
- Config::rebar_config:config()) -> [file:filename(), ...].
+-spec include_path(file:filename(),
+ rebar_config:config()) -> [file:filename(), ...].
include_path(Source, Config) ->
ErlOpts = rebar_config:get(Config, erl_opts, []),
["include", filename:dirname(Source)]
++ proplists:get_all_values(i, ErlOpts).
--spec inspect(Source::file:filename(),
- IncludePath::[file:filename(), ...]) -> {string(), [string()]}.
+-spec inspect(file:filename(),
+ [file:filename(), ...]) -> {string(), [string()]}.
inspect(Source, IncludePath) ->
ModuleDefault = filename:basename(Source, ".erl"),
case epp:open(Source, IncludePath) of
@@ -287,8 +286,8 @@ inspect(Source, IncludePath) ->
{ModuleDefault, []}
end.
--spec inspect_epp(Epp::pid(), Source::file:filename(), Module::file:filename(),
- Includes::[string()]) -> {string(), [string()]}.
+-spec inspect_epp(pid(), file:filename(), file:filename(),
+ [string()]) -> {string(), [string()]}.
inspect_epp(Epp, Source, Module, Includes) ->
case epp:parse_erl_form(Epp) of
{ok, {attribute, _, module, ModInfo}} ->
@@ -323,18 +322,16 @@ inspect_epp(Epp, Source, Module, Includes) ->
inspect_epp(Epp, Source, Module, Includes)
end.
--spec needs_compile(Source::file:filename(), Target::file:filename(),
- Hrls::[string()]) -> boolean().
+-spec needs_compile(file:filename(), file:filename(),
+ [string()]) -> boolean().
needs_compile(Source, Target, Hrls) ->
TargetLastMod = filelib:last_modified(Target),
lists:any(fun(I) -> TargetLastMod < filelib:last_modified(I) end,
[Source] ++ Hrls).
--spec internal_erl_compile(Source::file:filename(),
- Config::rebar_config:config(),
- Outdir::file:filename(),
- ErlOpts::list()) -> 'ok' | 'skipped'.
-internal_erl_compile(Source, Config, Outdir, ErlOpts) ->
+-spec internal_erl_compile(rebar_config:config(), file:filename(),
+ file:filename(), list()) -> 'ok' | 'skipped'.
+internal_erl_compile(Config, Source, Outdir, ErlOpts) ->
%% Determine the target name and includes list by inspecting the source file
{Module, Hrls} = inspect(Source, include_path(Source, Config)),
@@ -352,17 +349,18 @@ internal_erl_compile(Source, Config, Outdir, ErlOpts) ->
{ok, _Mod} ->
ok;
{ok, _Mod, Ws} ->
- rebar_base_compiler:ok_tuple(Source, Ws);
+ rebar_base_compiler:ok_tuple(Config, Source, Ws);
{error, Es, Ws} ->
- rebar_base_compiler:error_tuple(Source, Es, Ws, Opts)
+ rebar_base_compiler:error_tuple(Config, Source,
+ Es, Ws, Opts)
end;
false ->
skipped
end.
--spec compile_mib(Source::file:filename(), Target::file:filename(),
- Config::rebar_config:config()) -> 'ok'.
-compile_mib(Source, Target, Config) ->
+-spec compile_mib(rebar_config:config(), file:filename(),
+ file:filename()) -> 'ok'.
+compile_mib(Config, Source, Target) ->
ok = rebar_utils:ensure_dir(Target),
ok = rebar_utils:ensure_dir(filename:join("include", "dummy.hrl")),
Opts = [{outdir, "priv/mibs"}, {i, ["priv/mibs"]}] ++
@@ -378,30 +376,31 @@ compile_mib(Source, Target, Config) ->
?FAIL
end.
--spec compile_xrl(Source::file:filename(), Target::file:filename(),
- Config::rebar_config:config()) -> 'ok'.
+-spec compile_xrl(file:filename(), file:filename(),
+ rebar_config:config()) -> 'ok'.
compile_xrl(Source, Target, Config) ->
Opts = [{scannerfile, Target} | rebar_config:get(Config, xrl_opts, [])],
- compile_xrl_yrl(Source, Target, Opts, leex).
+ compile_xrl_yrl(Config, Source, Target, Opts, leex).
--spec compile_yrl(Source::file:filename(), Target::file:filename(),
- Config::rebar_config:config()) -> 'ok'.
+-spec compile_yrl(file:filename(), file:filename(),
+ rebar_config:config()) -> 'ok'.
compile_yrl(Source, Target, Config) ->
Opts = [{parserfile, Target} | rebar_config:get(Config, yrl_opts, [])],
- compile_xrl_yrl(Source, Target, Opts, yecc).
+ compile_xrl_yrl(Config, Source, Target, Opts, yecc).
--spec compile_xrl_yrl(Source::file:filename(), Target::file:filename(),
- Opts::list(), Mod::atom()) -> 'ok'.
-compile_xrl_yrl(Source, Target, Opts, Mod) ->
+-spec compile_xrl_yrl(rebar_config:config(), file:filename(),
+ file:filename(), list(), module()) -> 'ok'.
+compile_xrl_yrl(Config, Source, Target, Opts, Mod) ->
case needs_compile(Source, Target, []) of
true ->
case Mod:file(Source, Opts ++ [{return, true}]) of
{ok, _} ->
ok;
{ok, _Mod, Ws} ->
- rebar_base_compiler:ok_tuple(Source, Ws);
+ rebar_base_compiler:ok_tuple(Config, Source, Ws);
{error, Es, Ws} ->
- rebar_base_compiler:error_tuple(Source, Es, Ws, Opts)
+ rebar_base_compiler:error_tuple(Config, Source,
+ Es, Ws, Opts)
end;
false ->
skipped
@@ -413,21 +412,20 @@ gather_src([Dir|Rest], Srcs) ->
gather_src(Rest, Srcs ++ rebar_utils:find_files(Dir, ".*\\.erl\$")).
--spec dirs(Dir::file:filename()) -> [file:filename()].
+-spec dirs(file:filename()) -> [file:filename()].
dirs(Dir) ->
[F || F <- filelib:wildcard(filename:join([Dir, "*"])), filelib:is_dir(F)].
--spec delete_dir(Dir::file:filename(),
- Subdirs::[string()]) -> 'ok' | {'error', atom()}.
+-spec delete_dir(file:filename(), [string()]) -> 'ok' | {'error', atom()}.
delete_dir(Dir, []) ->
file:del_dir(Dir);
delete_dir(Dir, Subdirs) ->
lists:foreach(fun(D) -> delete_dir(D, dirs(D)) end, Subdirs),
file:del_dir(Dir).
--spec compile_priority(File::file:filename()) -> 'normal' | 'behaviour' |
- 'callback' |
- 'parse_transform'.
+-spec compile_priority(file:filename()) -> 'normal' | 'behaviour' |
+ 'callback' |
+ 'parse_transform'.
compile_priority(File) ->
case epp_dodger:parse_file(File) of
{error, _} ->
@@ -462,7 +460,7 @@ compile_priority(File) ->
%%
%% Ensure all files in a list are present and abort if one is missing
%%
--spec check_files(FileList::[file:filename()]) -> [file:filename()].
+-spec check_files([file:filename()]) -> [file:filename()].
check_files(FileList) ->
[check_file(F) || F <- FileList].