mirror of
https://github.com/correl/rebar.git
synced 2024-11-23 19:19:54 +00:00
Clean up specs
This commit is contained in:
parent
68f4743563
commit
6d75bfbeb0
7 changed files with 57 additions and 56 deletions
|
@ -1,6 +1,3 @@
|
|||
-record(config, { dir,
|
||||
opts }).
|
||||
|
||||
-define(FAIL, throw({error, failed})).
|
||||
|
||||
-define(ABORT(Str, Args), rebar_utils:abort(Str, Args)).
|
||||
|
|
|
@ -36,18 +36,19 @@
|
|||
%% Public API
|
||||
%% ===================================================================
|
||||
|
||||
-spec compile(Config::#config{}, AppFile::string()) -> 'ok'.
|
||||
-spec compile(Config::rebar_config:config(), AppFile::file:filename()) -> 'ok'.
|
||||
compile(Config, _AppFile) ->
|
||||
rebar_base_compiler:run(Config, filelib:wildcard("asn1/*.asn1"),
|
||||
"asn1", ".asn1", "src", ".erl",
|
||||
fun compile_asn1/3).
|
||||
|
||||
-spec clean(Config::#config{}, AppFile::string()) -> 'ok'.
|
||||
-spec clean(Config::rebar_config:config(), AppFile::file:filename()) -> 'ok'.
|
||||
clean(_Config, _AppFile) ->
|
||||
rebar_file_utils:delete_each(asn_generated_files("asn1", "src")),
|
||||
ok.
|
||||
|
||||
-spec compile_asn1(string(), string(), #config{}) -> ok.
|
||||
-spec compile_asn1(file:filename(), file:filename(),
|
||||
rebar_config:config()) -> ok.
|
||||
compile_asn1(Source, Target, Config) ->
|
||||
ok = rebar_utils:ensure_dir(Target),
|
||||
Opts = [{outdir, "src"}, noobj] ++ rebar_config:get(Config, asn1_opts, []),
|
||||
|
|
|
@ -35,6 +35,14 @@
|
|||
|
||||
-include("rebar.hrl").
|
||||
|
||||
-record(config, { dir :: file:filename(),
|
||||
opts :: list() }).
|
||||
|
||||
%% Types that can be used from other modules -- alphabetically ordered.
|
||||
-export_type([config/0]).
|
||||
|
||||
%% data types
|
||||
-opaque config() :: #config{}.
|
||||
|
||||
%% ===================================================================
|
||||
%% Public API
|
||||
|
|
|
@ -61,8 +61,7 @@
|
|||
%% ===================================================================
|
||||
|
||||
%% @doc Perform static analysis on the contents of the ebin directory.
|
||||
%% @spec dialyze(Config::#config{}, File::string()) -> ok
|
||||
-spec dialyze(Config::#config{}, File::string()) -> ok.
|
||||
-spec dialyze(Config::rebar_config:config(), File::file:filename()) -> ok.
|
||||
dialyze(Config, File) ->
|
||||
Plt = existing_plt_path(Config, File),
|
||||
case dialyzer:plt_info(Plt) of
|
||||
|
@ -102,8 +101,7 @@ dialyze(Config, File) ->
|
|||
ok.
|
||||
|
||||
%% @doc Build the PLT.
|
||||
%% @spec 'build-plt'(Config::#config{}, File::string()) -> ok
|
||||
-spec 'build-plt'(Config::#config{}, File::string()) -> ok.
|
||||
-spec 'build-plt'(Config::rebar_config:config(), File::file:filename()) -> ok.
|
||||
'build-plt'(Config, File) ->
|
||||
Plt = new_plt_path(Config, File),
|
||||
|
||||
|
@ -122,8 +120,7 @@ dialyze(Config, File) ->
|
|||
ok.
|
||||
|
||||
%% @doc Check whether the PLT is up-to-date (rebuilding it if not).
|
||||
%% @spec 'check-plt'(Config::#config{}, File::string()) -> ok
|
||||
-spec 'check-plt'(Config::#config{}, File::string()) -> ok.
|
||||
-spec 'check-plt'(Config::rebar_config:config(), File::file:filename()) -> ok.
|
||||
'check-plt'(Config, File) ->
|
||||
Plt = existing_plt_path(Config, File),
|
||||
try dialyzer:run([{analysis_type, plt_check}, {init_plt, Plt}]) of
|
||||
|
@ -143,24 +140,22 @@ dialyze(Config, File) ->
|
|||
%% ===================================================================
|
||||
|
||||
%% @doc Obtain the library paths for the supplied applications.
|
||||
%% @spec app_dirs(Apps::[atom()]) -> [string()]
|
||||
-spec app_dirs(Apps::[atom()]) -> [string()].
|
||||
-spec app_dirs(Apps::[atom()]) -> [file:filename()].
|
||||
app_dirs(Apps) ->
|
||||
[filename:join(Path, "ebin")
|
||||
|| Path <- [code:lib_dir(App) || App <- Apps], erlang:is_list(Path)].
|
||||
|
||||
%% @doc Render the warnings on the console.
|
||||
%% @spec output_warnings(Warnings::[warning()]) -> 'ok'
|
||||
-spec output_warnings(Warnings::[warning()]) -> 'ok'.
|
||||
output_warnings(Warnings) ->
|
||||
lists:foreach(fun(Warning) ->
|
||||
?CONSOLE("~s", [dialyzer:format_warning(Warning)])
|
||||
end, Warnings).
|
||||
|
||||
%% @doc If the plt option is present in rebar.config return its value, otherwise
|
||||
%% return $HOME/.dialyzer_plt.
|
||||
%% @spec new_plt_path(Config::#config{}, File::string()) -> string()
|
||||
-spec new_plt_path(Config::#config{}, File::string()) -> string().
|
||||
%% @doc If the plt option is present in rebar.config return its value,
|
||||
%% otherwise return $HOME/.dialyzer_plt.
|
||||
-spec new_plt_path(Config::rebar_config:config(),
|
||||
File::file:filename()) -> file:filename().
|
||||
new_plt_path(Config, File) ->
|
||||
AppName = rebar_app_utils:app_name(File),
|
||||
DialyzerOpts = rebar_config:get(Config, dialyzer_opts, []),
|
||||
|
@ -175,8 +170,8 @@ new_plt_path(Config, File) ->
|
|||
%% @doc If the plt option is present in rebar.config and the file exists
|
||||
%% return its value or if ~/.AppName_dialyzer_plt exists return that.
|
||||
%% Otherwise return ~/.dialyzer_plt if it exists or abort.
|
||||
%% @spec existing_plt_path(Config::#config{}, File::string()) -> string()
|
||||
-spec existing_plt_path(Config::#config{}, File::string()) -> string().
|
||||
-spec existing_plt_path(Config::rebar_config:config(),
|
||||
File::file:filename()) -> file:filename().
|
||||
existing_plt_path(Config, File) ->
|
||||
AppName = rebar_app_utils:app_name(File),
|
||||
DialyzerOpts = rebar_config:get(Config, dialyzer_opts, []),
|
||||
|
@ -205,8 +200,7 @@ existing_plt_path(Config, File) ->
|
|||
|
||||
%% @doc If the warnings option is present in rebar.config return its value,
|
||||
%% otherwise return [].
|
||||
%% @spec warnings(Config::#config{}) -> list()
|
||||
-spec warnings(Config::#config{}) -> list().
|
||||
-spec warnings(Config::rebar_config:config()) -> list().
|
||||
warnings(Config) ->
|
||||
DialyzerOpts = rebar_config:get(Config, dialyzer_opts, []),
|
||||
proplists:get_value(warnings, DialyzerOpts, []).
|
||||
|
|
|
@ -46,8 +46,7 @@
|
|||
%% ===================================================================
|
||||
|
||||
%% @doc Generate Erlang program documentation.
|
||||
%% @spec doc(#config{}, string()) -> ok
|
||||
-spec(doc(Config::#config{}, File::string()) -> ok).
|
||||
-spec doc(Config::rebar_config:config(), File::file:filename()) -> ok.
|
||||
doc(Config, File) ->
|
||||
{ok, AppName, _AppData} = rebar_app_utils:load_app_file(File),
|
||||
EDocOpts = rebar_config:get(Config, edoc_opts, []),
|
||||
|
|
|
@ -67,7 +67,7 @@
|
|||
%% 'old_inets'}]}.
|
||||
%%
|
||||
|
||||
-spec compile(Config::#config{}, AppFile::string()) -> 'ok'.
|
||||
-spec compile(Config::rebar_config:config(), AppFile::file:filename()) -> 'ok'.
|
||||
compile(Config, _AppFile) ->
|
||||
rebar_base_compiler:run(Config,
|
||||
check_files(rebar_config:get_local(
|
||||
|
@ -86,7 +86,7 @@ compile(Config, _AppFile) ->
|
|||
"mibs", ".mib", "priv/mibs", ".bin",
|
||||
fun compile_mib/3).
|
||||
|
||||
-spec clean(Config::#config{}, AppFile::string()) -> 'ok'.
|
||||
-spec clean(Config::rebar_config:config(), AppFile::file:filename()) -> 'ok'.
|
||||
clean(_Config, _AppFile) ->
|
||||
lists:foreach(fun(F) -> ok = rebar_file_utils:rm_rf(F) end,
|
||||
["ebin/*.beam", "priv/mibs/*.bin"]),
|
||||
|
@ -110,7 +110,8 @@ clean(_Config, _AppFile) ->
|
|||
%% .erl Compilation API (externally used by only eunit)
|
||||
%% ===================================================================
|
||||
|
||||
-spec doterl_compile(Config::#config{}, OutDir::string()) -> 'ok'.
|
||||
-spec doterl_compile(Config::rebar_config:config(),
|
||||
OutDir::file:filename()) -> 'ok'.
|
||||
doterl_compile(Config, OutDir) ->
|
||||
doterl_compile(Config, OutDir, []).
|
||||
|
||||
|
@ -165,14 +166,15 @@ doterl_compile(Config, OutDir, MoreSources) ->
|
|||
%% Internal functions
|
||||
%% ===================================================================
|
||||
|
||||
-spec include_path(Source::string(), Config::#config{}) -> [string(), ...].
|
||||
-spec include_path(Source::file:filename(),
|
||||
Config::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::string(),
|
||||
IncludePath::[string(),...]) -> {string(), [string()]}.
|
||||
-spec inspect(Source::file:filename(),
|
||||
IncludePath::[file:filename(), ...]) -> {string(), [string()]}.
|
||||
inspect(Source, IncludePath) ->
|
||||
ModuleDefault = filename:basename(Source, ".erl"),
|
||||
case epp:open(Source, IncludePath) of
|
||||
|
@ -183,7 +185,7 @@ inspect(Source, IncludePath) ->
|
|||
{ModuleDefault, []}
|
||||
end.
|
||||
|
||||
-spec inspect_epp(Epp::pid(), Source::string(), Module::string(),
|
||||
-spec inspect_epp(Epp::pid(), Source::file:filename(), Module::file:filename(),
|
||||
Includes::[string()]) -> {string(), [string()]}.
|
||||
inspect_epp(Epp, Source, Module, Includes) ->
|
||||
case epp:parse_erl_form(Epp) of
|
||||
|
@ -218,15 +220,16 @@ inspect_epp(Epp, Source, Module, Includes) ->
|
|||
inspect_epp(Epp, Source, Module, Includes)
|
||||
end.
|
||||
|
||||
-spec needs_compile(Source::string(), Target::string(),
|
||||
-spec needs_compile(Source::file:filename(), Target::file:filename(),
|
||||
Hrls::[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::string(), Config::#config{},
|
||||
Outdir::string(),
|
||||
-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) ->
|
||||
%% Determine the target name and includes list by inspecting the source file
|
||||
|
@ -237,7 +240,7 @@ internal_erl_compile(Source, Config, Outdir, ErlOpts) ->
|
|||
ok = filelib:ensure_dir(Target),
|
||||
|
||||
%% If the file needs compilation, based on last mod date of includes or
|
||||
%% the target,
|
||||
%% the target
|
||||
case needs_compile(Source, Target, Hrls) of
|
||||
true ->
|
||||
Opts = [{outdir, filename:dirname(Target)}] ++
|
||||
|
@ -263,8 +266,8 @@ internal_erl_compile(Source, Config, Outdir, ErlOpts) ->
|
|||
skipped
|
||||
end.
|
||||
|
||||
-spec compile_mib(Source::string(), Target::string(),
|
||||
Config::#config{}) -> 'ok'.
|
||||
-spec compile_mib(Source::file:filename(), Target::file:filename(),
|
||||
Config::rebar_config:config()) -> 'ok'.
|
||||
compile_mib(Source, Target, Config) ->
|
||||
ok = rebar_utils:ensure_dir(Target),
|
||||
Opts = [{outdir, "priv/mibs"}, {i, ["priv/mibs"]}] ++
|
||||
|
@ -276,22 +279,22 @@ compile_mib(Source, Target, Config) ->
|
|||
?FAIL
|
||||
end.
|
||||
|
||||
-spec compile_xrl(Source::string(), Target::string(),
|
||||
Config::#config{}) -> 'ok'.
|
||||
-spec compile_xrl(Source::file:filename(), Target::file:filename(),
|
||||
Config::rebar_config:config()) -> 'ok'.
|
||||
compile_xrl(Source, Target, Config) ->
|
||||
Opts = [{scannerfile, Target}, {return, true}
|
||||
|rebar_config:get(Config, xrl_opts, [])],
|
||||
compile_xrl_yrl(Source, Target, Opts, leex).
|
||||
|
||||
-spec compile_yrl(Source::string(), Target::string(),
|
||||
Config::#config{}) -> 'ok'.
|
||||
-spec compile_yrl(Source::file:filename(), Target::file:filename(),
|
||||
Config::rebar_config:config()) -> 'ok'.
|
||||
compile_yrl(Source, Target, Config) ->
|
||||
Opts = [{parserfile, Target}, {return, true}
|
||||
|rebar_config:get(Config, yrl_opts, [])],
|
||||
compile_xrl_yrl(Source, Target, Opts, yecc).
|
||||
|
||||
-spec compile_xrl_yrl(Source::string(), Target::string(), Opts::list(),
|
||||
Mod::atom()) -> 'ok'.
|
||||
-spec compile_xrl_yrl(Source::file:filename(), Target::file:filename(),
|
||||
Opts::list(), Mod::atom()) -> 'ok'.
|
||||
compile_xrl_yrl(Source, Target, Opts, Mod) ->
|
||||
case needs_compile(Source, Target, []) of
|
||||
true ->
|
||||
|
@ -317,17 +320,17 @@ gather_src([], Srcs) ->
|
|||
gather_src([Dir|Rest], Srcs) ->
|
||||
gather_src(Rest, Srcs ++ rebar_utils:find_files(Dir, ".*\\.erl\$")).
|
||||
|
||||
-spec src_dirs(SrcDirs::[string()]) -> [string(),...].
|
||||
-spec src_dirs(SrcDirs::[string()]) -> [file:filename(), ...].
|
||||
src_dirs([]) ->
|
||||
["src"];
|
||||
src_dirs(SrcDirs) ->
|
||||
SrcDirs ++ src_dirs([]).
|
||||
|
||||
-spec dirs(Dir::string()) -> [string()].
|
||||
-spec dirs(Dir::file:filename()) -> [file:filename()].
|
||||
dirs(Dir) ->
|
||||
[F || F <- filelib:wildcard(filename:join([Dir, "*"])), filelib:is_dir(F)].
|
||||
|
||||
-spec delete_dir(Dir::string(),
|
||||
-spec delete_dir(Dir::file:filename(),
|
||||
Subdirs::[string()]) -> 'ok' | {'error', atom()}.
|
||||
delete_dir(Dir, []) ->
|
||||
file:del_dir(Dir);
|
||||
|
@ -335,7 +338,7 @@ delete_dir(Dir, Subdirs) ->
|
|||
lists:foreach(fun(D) -> delete_dir(D, dirs(D)) end, Subdirs),
|
||||
file:del_dir(Dir).
|
||||
|
||||
-spec compile_priority(File::string()) -> 'normal' | 'behaviour' |
|
||||
-spec compile_priority(File::file:filename()) -> 'normal' | 'behaviour' |
|
||||
'parse_transform'.
|
||||
compile_priority(File) ->
|
||||
case epp_dodger:parse_file(File) of
|
||||
|
@ -392,7 +395,7 @@ filter_defines([Opt | Rest], Acc) ->
|
|||
%%
|
||||
%% Ensure all files in a list are present and abort if one is missing
|
||||
%%
|
||||
-spec check_files(FileList::[string()]) -> [string()].
|
||||
-spec check_files(FileList::[file:filename()]) -> [file:filename()].
|
||||
check_files(FileList) ->
|
||||
[check_file(F) || F <- FileList].
|
||||
|
||||
|
|
|
@ -39,8 +39,7 @@
|
|||
|
||||
%% @doc Remove files and directories.
|
||||
%% Target is a single filename, directoryname or wildcard expression.
|
||||
%% @spec rm_rf(string()) -> ok
|
||||
-spec rm_rf(Target::string()) -> ok.
|
||||
-spec rm_rf(Target::file:filename()) -> ok.
|
||||
rm_rf(Target) ->
|
||||
case os:type() of
|
||||
{unix, _} ->
|
||||
|
@ -56,7 +55,7 @@ rm_rf(Target) ->
|
|||
ok
|
||||
end.
|
||||
|
||||
-spec cp_r(Sources::list(string()), Dest::string()) -> ok.
|
||||
-spec cp_r(Sources::list(string()), Dest::file:filename()) -> ok.
|
||||
cp_r(Sources, Dest) ->
|
||||
case os:type() of
|
||||
{unix, _} ->
|
||||
|
@ -69,7 +68,7 @@ cp_r(Sources, Dest) ->
|
|||
ok
|
||||
end.
|
||||
|
||||
-spec mv(Source::string(), Dest::string()) -> ok.
|
||||
-spec mv(Source::string(), Dest::file:filename()) -> ok.
|
||||
mv(Source, Dest) ->
|
||||
case os:type() of
|
||||
{unix, _} ->
|
||||
|
|
Loading…
Reference in a new issue