diff options
author | Tuncer Ayaz <tuncer.ayaz@gmail.com> | 2011-03-10 15:07:41 +0100 |
---|---|---|
committer | Tuncer Ayaz <tuncer.ayaz@gmail.com> | 2011-03-28 18:39:38 +0200 |
commit | 6d75bfbeb0c981e25c1b30b481118ea52a3b377e (patch) | |
tree | e8a311712291c0290b908f2d2f83ab9ed00a56ec | |
parent | 68f47435636cb72e6088fb68eacf5aad764f13cd (diff) |
Clean up specs
-rw-r--r-- | include/rebar.hrl | 3 | ||||
-rw-r--r-- | src/rebar_asn1_compiler.erl | 7 | ||||
-rw-r--r-- | src/rebar_config.erl | 8 | ||||
-rw-r--r-- | src/rebar_dialyzer.erl | 28 | ||||
-rw-r--r-- | src/rebar_edoc.erl | 3 | ||||
-rw-r--r-- | src/rebar_erlc_compiler.erl | 57 | ||||
-rw-r--r-- | src/rebar_file_utils.erl | 7 |
7 files changed, 57 insertions, 56 deletions
diff --git a/include/rebar.hrl b/include/rebar.hrl index c435a85..0f4e90f 100644 --- a/include/rebar.hrl +++ b/include/rebar.hrl @@ -1,6 +1,3 @@ --record(config, { dir, - opts }). - -define(FAIL, throw({error, failed})). -define(ABORT(Str, Args), rebar_utils:abort(Str, Args)). diff --git a/src/rebar_asn1_compiler.erl b/src/rebar_asn1_compiler.erl index 750ff41..bd16813 100644 --- a/src/rebar_asn1_compiler.erl +++ b/src/rebar_asn1_compiler.erl @@ -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, []), diff --git a/src/rebar_config.erl b/src/rebar_config.erl index a030e2c..751e088 100644 --- a/src/rebar_config.erl +++ b/src/rebar_config.erl @@ -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 diff --git a/src/rebar_dialyzer.erl b/src/rebar_dialyzer.erl index c3e3c36..431299a 100644 --- a/src/rebar_dialyzer.erl +++ b/src/rebar_dialyzer.erl @@ -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, []). diff --git a/src/rebar_edoc.erl b/src/rebar_edoc.erl index 8eda04d..ce5458a 100644 --- a/src/rebar_edoc.erl +++ b/src/rebar_edoc.erl @@ -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, []), diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl index df9e1c0..a9a8360 100644 --- a/src/rebar_erlc_compiler.erl +++ b/src/rebar_erlc_compiler.erl @@ -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"]), @@ -94,7 +94,7 @@ clean(_Config, _AppFile) -> YrlFiles = rebar_utils:find_files("src", "^.*\\.[x|y]rl\$"), rebar_file_utils:delete_each( [ binary_to_list(iolist_to_binary(re:replace(F, "\\.[x|y]rl$", ".erl"))) - || F <- YrlFiles ]), + || F <- YrlFiles ]), %% Erlang compilation is recursive, so it's possible that we have a nested %% directory structure in ebin with .beam files within. As such, we want @@ -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,8 +338,8 @@ 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' | - 'parse_transform'. +-spec compile_priority(File::file:filename()) -> 'normal' | 'behaviour' | + 'parse_transform'. compile_priority(File) -> case epp_dodger:parse_file(File) of {error, _} -> @@ -369,7 +372,7 @@ compile_priority(File) -> %% Filter a list of erl_opts platform_define options such that only %% those which match the provided architecture regex are returned. %% --spec filter_defines(ErlOpts::list(),Acc::list()) -> list(). +-spec filter_defines(ErlOpts::list(), Acc::list()) -> list(). filter_defines([], Acc) -> lists:reverse(Acc); filter_defines([{platform_define, ArchRegex, Key} | Rest], Acc) -> @@ -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]. diff --git a/src/rebar_file_utils.erl b/src/rebar_file_utils.erl index 731f9d9..56877e3 100644 --- a/src/rebar_file_utils.erl +++ b/src/rebar_file_utils.erl @@ -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, _} -> |