mirror of
https://github.com/correl/rebar.git
synced 2024-12-18 03:00:17 +00:00
Tidier improvements
This commit is contained in:
parent
1a577fcd43
commit
7dc76d578e
16 changed files with 78 additions and 99 deletions
|
@ -171,13 +171,13 @@ get(Key, Ctx, Mod) ->
|
|||
error ->
|
||||
case erlang:function_exported(Mod, Key, 1) of
|
||||
true ->
|
||||
Val = to_s(apply(Mod, Key, [Ctx])),
|
||||
Val = to_s(Mod:Key(Ctx)),
|
||||
% io:format("From Mod/1 {~p, ~p}~n", [Key, Val]),
|
||||
Val;
|
||||
false ->
|
||||
case erlang:function_exported(Mod, Key, 0) of
|
||||
true ->
|
||||
Val = to_s(apply(Mod, Key, [])),
|
||||
Val = to_s(Mod:Key()),
|
||||
% io:format("From Mod/0 {~p, ~p}~n", [Key, Val]),
|
||||
Val;
|
||||
false ->
|
||||
|
|
|
@ -63,7 +63,7 @@ is_app_dir(Dir) ->
|
|||
is_app_src(Filename) ->
|
||||
%% If removing the extension .app.src yields a shorter name,
|
||||
%% this is an .app.src file.
|
||||
Filename /= filename:rootname(Filename, ".app.src").
|
||||
Filename =/= filename:rootname(Filename, ".app.src").
|
||||
|
||||
app_src_to_app(Filename) ->
|
||||
filename:join("ebin", filename:basename(Filename, ".app.src") ++ ".app").
|
||||
|
@ -101,14 +101,15 @@ app_vsn(AppFile) ->
|
|||
%% ===================================================================
|
||||
|
||||
load_app_file(Filename) ->
|
||||
case erlang:get({app_file, Filename}) of
|
||||
AppFile = {app_file, Filename},
|
||||
case erlang:get(AppFile) of
|
||||
undefined ->
|
||||
case file:consult(Filename) of
|
||||
{ok, [{application, AppName, AppData}]} ->
|
||||
erlang:put({app_file, Filename}, {AppName, AppData}),
|
||||
erlang:put(AppFile, {AppName, AppData}),
|
||||
{ok, AppName, AppData};
|
||||
{error, Reason} ->
|
||||
{error, Reason};
|
||||
{error, _} = Error ->
|
||||
Error;
|
||||
Other ->
|
||||
{error, {unexpected_terms, Other}}
|
||||
end;
|
||||
|
|
|
@ -66,7 +66,7 @@ run(Config, FirstFiles, SourceDir, SourceExt, TargetDir, TargetExt,
|
|||
|
||||
%% Remove first files from found files
|
||||
RestFiles = [Source || Source <- FoundFiles,
|
||||
lists:member(Source, FirstFiles) == false],
|
||||
not lists:member(Source, FirstFiles)],
|
||||
|
||||
%% Check opts for flag indicating that compile should check lastmod
|
||||
CheckLastMod = proplists:get_bool(check_last_mod, Opts),
|
||||
|
|
|
@ -96,12 +96,7 @@ get_global(Key, Default) ->
|
|||
end.
|
||||
|
||||
is_verbose() ->
|
||||
case get_global(verbose, "0") of
|
||||
"1" ->
|
||||
true;
|
||||
_ ->
|
||||
false
|
||||
end.
|
||||
get_global(verbose, "0") =:= "1".
|
||||
|
||||
get_jobs() ->
|
||||
get_global(jobs, 3).
|
||||
|
|
|
@ -86,20 +86,21 @@ run(RawArgs) ->
|
|||
process_commands(CommandAtoms).
|
||||
|
||||
skip_dir(Dir) ->
|
||||
case erlang:get({skip_dir, Dir}) of
|
||||
SkipDir = {skip_dir, Dir},
|
||||
case erlang:get(SkipDir) of
|
||||
undefined ->
|
||||
?DEBUG("Adding skip dir: ~s\n", [Dir]),
|
||||
erlang:put({skip_dir, Dir}, true);
|
||||
erlang:put(SkipDir, true);
|
||||
true ->
|
||||
ok
|
||||
end.
|
||||
|
||||
is_skip_dir(Dir) ->
|
||||
case erlang:get({skip_dir, Dir}) of
|
||||
undefined ->
|
||||
false;
|
||||
true ->
|
||||
true
|
||||
undefined ->
|
||||
false;
|
||||
true ->
|
||||
true
|
||||
end.
|
||||
|
||||
skip_dirs() ->
|
||||
|
@ -465,7 +466,7 @@ restore_code_path(no_change) ->
|
|||
restore_code_path({old, Path}) ->
|
||||
%% Verify that all of the paths still exist -- some dynamically add paths
|
||||
%% can get blown away during clean.
|
||||
true = code:set_path(lists:filter(fun filelib:is_file/1, Path)),
|
||||
true = code:set_path([F || F <- Path, filelib:is_file(F)]),
|
||||
ok.
|
||||
|
||||
|
||||
|
@ -495,8 +496,8 @@ run_modules([Module | Rest], Command, Config, File) ->
|
|||
case Module:Command(Config, File) of
|
||||
ok ->
|
||||
run_modules(Rest, Command, Config, File);
|
||||
{error, Reason} ->
|
||||
{error, Reason}
|
||||
{error, _} = Error ->
|
||||
Error
|
||||
end.
|
||||
|
||||
|
||||
|
|
|
@ -201,11 +201,8 @@ delete_dep(D) ->
|
|||
end.
|
||||
|
||||
require_source_engine(Source) ->
|
||||
case source_engine_avail(Source) of
|
||||
true ->
|
||||
ok
|
||||
end.
|
||||
|
||||
true = source_engine_avail(Source),
|
||||
ok.
|
||||
|
||||
is_app_available(App, VsnRegex) ->
|
||||
case code:lib_dir(App) of
|
||||
|
|
|
@ -142,8 +142,8 @@ dialyze(Config, File) ->
|
|||
%% @spec app_dirs(Apps::[atom()]) -> [string()]
|
||||
-spec app_dirs(Apps::[atom()]) -> [string()].
|
||||
app_dirs(Apps) ->
|
||||
[filename:join(Path, "ebin") ||
|
||||
Path <- lists:map(fun(App) -> code:lib_dir(App) end, Apps), erlang:is_list(Path)].
|
||||
[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'
|
||||
|
|
|
@ -104,11 +104,11 @@ doterl_compile(Config, OutDir, MoreSources) ->
|
|||
ErlOpts = filter_defines(rebar_config:get(Config, erl_opts, []), []),
|
||||
?DEBUG("erl_opts ~p~n",[ErlOpts]),
|
||||
%% Support the src_dirs option allowing multiple directories to
|
||||
%% contain erlang source. This might be used, for example, should eunit tests be
|
||||
%% separated from the core application source.
|
||||
%% contain erlang source. This might be used, for example, should
|
||||
%% eunit tests be separated from the core application source.
|
||||
SrcDirs = src_dirs(proplists:append_values(src_dirs, ErlOpts)),
|
||||
RestErls = [Source || Source <- gather_src(SrcDirs, []) ++ MoreSources,
|
||||
lists:member(Source, FirstErls) == false],
|
||||
not lists:member(Source, FirstErls)],
|
||||
|
||||
% Split RestErls so that parse_transforms and behaviours are instead added
|
||||
% to erl_first_files, parse transforms first.
|
||||
|
@ -131,8 +131,8 @@ doterl_compile(Config, OutDir, MoreSources) ->
|
|||
CurrPath = code:get_path(),
|
||||
true = code:add_path("ebin"),
|
||||
rebar_base_compiler:run(Config, NewFirstErls, OtherErls,
|
||||
fun(S, C) -> internal_erl_compile(S, C, OutDir,
|
||||
ErlOpts)
|
||||
fun(S, C) ->
|
||||
internal_erl_compile(S, C, OutDir, ErlOpts)
|
||||
end),
|
||||
true = code:set_path(CurrPath),
|
||||
ok.
|
||||
|
|
|
@ -149,31 +149,27 @@ module_name(Target) ->
|
|||
|
||||
needs_compile(Source, Target, Config) ->
|
||||
LM = filelib:last_modified(Target),
|
||||
case LM < filelib:last_modified(Source) of
|
||||
true -> true;
|
||||
false ->
|
||||
lists:any(fun(D) -> LM < filelib:last_modified(D) end,
|
||||
referenced_dtls(Source, Config))
|
||||
end.
|
||||
LM < filelib:last_modified(Source) orelse
|
||||
lists:any(fun(D) -> LM < filelib:last_modified(D) end,
|
||||
referenced_dtls(Source, Config)).
|
||||
|
||||
referenced_dtls(Source, Config) ->
|
||||
Set = referenced_dtls1([Source], Config,
|
||||
sets:add_element(Source, sets:new())),
|
||||
Final = sets:to_list(sets:del_element(Source, Set)),
|
||||
Final.
|
||||
sets:to_list(sets:del_element(Source, Set)).
|
||||
|
||||
referenced_dtls1(Step, Config, Seen) ->
|
||||
DtlOpts = erlydtl_opts(Config),
|
||||
ExtMatch = re:replace(option(source_ext, DtlOpts), "\.", "\\\\\\\\.",
|
||||
[{return, list}]),
|
||||
AllRefs = lists:append(
|
||||
[ string:tokens(
|
||||
os:cmd(["grep -o [^\\\"]*",ExtMatch," ",F]),
|
||||
"\n")
|
||||
|| F <- Step]),
|
||||
[string:tokens(
|
||||
os:cmd(["grep -o [^\\\"]*",ExtMatch," ",F]),
|
||||
"\n")
|
||||
|| F <- Step]),
|
||||
DocRoot = option(doc_root, DtlOpts),
|
||||
WithPaths = [ filename:join([DocRoot, F]) || F <- AllRefs ],
|
||||
Existing = lists:filter(fun filelib:is_file/1, WithPaths),
|
||||
Existing = [F || F <- WithPaths, filelib:is_file(F)],
|
||||
New = sets:subtract(sets:from_list(Existing), Seen),
|
||||
case sets:size(New) of
|
||||
0 -> Seen;
|
||||
|
|
|
@ -286,9 +286,8 @@ is_eunitized(Mod) ->
|
|||
has_header(Mod, "include/eunit.hrl").
|
||||
|
||||
has_eunit_test_fun(Mod) ->
|
||||
length([F || {exports, Funs} <- Mod:module_info(),
|
||||
{F, 0} <- Funs,
|
||||
F == test]) =/= 0.
|
||||
[F || {exports, Funs} <- Mod:module_info(),
|
||||
{F, 0} <- Funs, F =:= test] =/= [].
|
||||
|
||||
has_header(Mod, Header) ->
|
||||
Mod1 = case code:which(Mod) of
|
||||
|
@ -300,8 +299,8 @@ has_header(Mod, Header) ->
|
|||
L -> L
|
||||
end,
|
||||
{ok, {_, [{abstract_code, {_, AC}}]}} = beam_lib:chunks(Mod1, [abstract_code]),
|
||||
length([F || {attribute, 1, file, {F, 1}} <- AC,
|
||||
string:str(F, Header) =/= 0]) =/= 0.
|
||||
[F || {attribute, 1, file, {F, 1}} <- AC,
|
||||
string:str(F, Header) =/= 0] =/= [].
|
||||
|
||||
align_notcovered_count(Module, Covered, NotCovered, false) ->
|
||||
{Module, Covered, NotCovered};
|
||||
|
|
|
@ -108,31 +108,27 @@ do_compile(Source, _Target, Config) ->
|
|||
|
||||
needs_compile(Source, Target, Config) ->
|
||||
LM = filelib:last_modified(Target),
|
||||
case LM < filelib:last_modified(Source) of
|
||||
true -> true;
|
||||
false ->
|
||||
lists:any(fun(D) -> LM < filelib:last_modified(D) end,
|
||||
referenced_pegs(Source, Config))
|
||||
end.
|
||||
LM < filelib:last_modified(Source) orelse
|
||||
lists:any(fun(D) -> LM < filelib:last_modified(D) end,
|
||||
referenced_pegs(Source, Config)).
|
||||
|
||||
referenced_pegs(Source, Config) ->
|
||||
Set = referenced_pegs1([Source], Config,
|
||||
sets:add_element(Source, sets:new())),
|
||||
Final = sets:to_list(sets:del_element(Source, Set)),
|
||||
Final.
|
||||
sets:to_list(sets:del_element(Source, Set)).
|
||||
|
||||
referenced_pegs1(Step, Config, Seen) ->
|
||||
NeoOpts = neotoma_opts(Config),
|
||||
ExtMatch = re:replace(option(source_ext, NeoOpts), "\.", "\\\\\\\\.",
|
||||
[{return, list}]),
|
||||
AllRefs = lists:append(
|
||||
[ string:tokens(
|
||||
os:cmd(["grep -o [^\\\"]*",ExtMatch," ",F]),
|
||||
"\n")
|
||||
|| F <- Step]),
|
||||
[string:tokens(
|
||||
os:cmd(["grep -o [^\\\"]*",ExtMatch," ",F]),
|
||||
"\n")
|
||||
|| F <- Step]),
|
||||
DocRoot = option(doc_root, NeoOpts),
|
||||
WithPaths = [ filename:join([DocRoot, F]) || F <- AllRefs ],
|
||||
Existing = lists:filter(fun filelib:is_file/1, WithPaths),
|
||||
Existing = [F || F <- WithPaths, filelib:is_file(F)],
|
||||
New = sets:subtract(sets:from_list(Existing), Seen),
|
||||
case sets:size(New) of
|
||||
0 -> Seen;
|
||||
|
|
|
@ -137,9 +137,8 @@ expand_sources([Spec | Rest], Acc) ->
|
|||
expand_sources(Rest, Acc2).
|
||||
|
||||
expand_objects(Sources) ->
|
||||
lists:map(fun(File) ->
|
||||
filename:join([filename:dirname(File),filename:basename(File) ++ ".o"])
|
||||
end, Sources).
|
||||
[filename:join([filename:dirname(F), filename:basename(F) ++ ".o"])
|
||||
|| F <- Sources].
|
||||
|
||||
run_precompile_hook(Config, Env) ->
|
||||
case rebar_config:get(Config, port_pre_script, undefined) of
|
||||
|
|
|
@ -74,13 +74,7 @@ clean(_Config, _AppFile) ->
|
|||
%% ===================================================================
|
||||
|
||||
protobuffs_is_present() ->
|
||||
case code:which(protobuffs_compile) of
|
||||
non_existing ->
|
||||
false;
|
||||
_ ->
|
||||
true
|
||||
end.
|
||||
|
||||
code:which(protobuffs_compile) =/= non_existing.
|
||||
|
||||
beam_file(Proto) ->
|
||||
filename:basename(Proto, ".proto") ++ "_pb.beam".
|
||||
|
|
|
@ -106,9 +106,9 @@ load_config(ReltoolFile) ->
|
|||
%% can't run reltool.
|
||||
%%
|
||||
sys_tuple(ReltoolConfig) ->
|
||||
case lists:keysearch(sys, 1, ReltoolConfig) of
|
||||
{value, {sys, Data}} ->
|
||||
{sys, Data};
|
||||
case lists:keyfind(sys, 1, ReltoolConfig) of
|
||||
{sys, _} = SysTuple ->
|
||||
SysTuple;
|
||||
false ->
|
||||
?ABORT("Failed to find {sys, [...]} tuple in reltool.config.", [])
|
||||
end.
|
||||
|
@ -120,13 +120,13 @@ sys_tuple(ReltoolConfig) ->
|
|||
target_dir(ReltoolConfig) ->
|
||||
case rebar_config:get_global(target_dir, undefined) of
|
||||
undefined ->
|
||||
case lists:keysearch(target_dir, 1, ReltoolConfig) of
|
||||
{value, {target_dir, TargetDir}} ->
|
||||
case lists:keyfind(target_dir, 1, ReltoolConfig) of
|
||||
{target_dir, TargetDir} ->
|
||||
filename:absname(TargetDir);
|
||||
false ->
|
||||
{sys, SysInfo} = sys_tuple(ReltoolConfig),
|
||||
case lists:keysearch(rel, 1, SysInfo) of
|
||||
{value, {rel, Name, _Vsn, _Apps}} ->
|
||||
case lists:keyfind(rel, 1, SysInfo) of
|
||||
{rel, Name, _Vsn, _Apps} ->
|
||||
filename:absname(Name);
|
||||
false ->
|
||||
filename:absname("target")
|
||||
|
@ -144,8 +144,8 @@ target_dir(ReltoolConfig) ->
|
|||
overlay_vars(ReltoolConfig) ->
|
||||
case rebar_config:get_global(overlay_vars, undefined) of
|
||||
undefined ->
|
||||
case lists:keysearch(overlay_vars, 1, ReltoolConfig) of
|
||||
{value, {overlay_vars, File}} ->
|
||||
case lists:keyfind(overlay_vars, 1, ReltoolConfig) of
|
||||
{overlay_vars, File} ->
|
||||
File;
|
||||
false ->
|
||||
undefined
|
||||
|
@ -156,8 +156,10 @@ overlay_vars(ReltoolConfig) ->
|
|||
|
||||
|
||||
validate_rel_apps(ReltoolServer, {sys, ReltoolConfig}) ->
|
||||
case lists:keysearch(rel, 1, ReltoolConfig) of
|
||||
{value, {rel, _Name, _Vsn, Apps}} ->
|
||||
case lists:keyfind(rel, 1, ReltoolConfig) of
|
||||
false ->
|
||||
ok;
|
||||
{rel, _Name, _Vsn, Apps} ->
|
||||
%% Identify all the apps that do NOT exist, based on what's available
|
||||
%% from the reltool server
|
||||
Missing = lists:sort([App || App <- Apps,
|
||||
|
@ -168,11 +170,9 @@ validate_rel_apps(ReltoolServer, {sys, ReltoolConfig}) ->
|
|||
_ ->
|
||||
?ABORT("Apps in {rel, ...} section not found by reltool: ~p\n", [Missing])
|
||||
end;
|
||||
{value, Rel} ->
|
||||
Rel ->
|
||||
%% Invalid release format!
|
||||
?ABORT("Invalid {rel, ...} section in reltools.config: ~p\n", [Rel]);
|
||||
false ->
|
||||
ok
|
||||
?ABORT("Invalid {rel, ...} section in reltools.config: ~p\n", [Rel])
|
||||
end.
|
||||
|
||||
app_exists(App, Server) when is_atom(App) ->
|
||||
|
@ -330,9 +330,10 @@ execute_overlay([Other | _Rest], _Vars, _BaseDir, _TargetDir) ->
|
|||
%% Render a binary to a string, using mustache and the specified context
|
||||
%%
|
||||
render(Bin, Context) ->
|
||||
ReOpts = [global, {return, list}],
|
||||
%% Be sure to escape any double-quotes before rendering...
|
||||
Str0 = re:replace(Bin, "\\\\", "\\\\\\", [global, {return, list}]),
|
||||
Str1 = re:replace(Str0, "\"", "\\\\\"", [global, {return,list}]),
|
||||
Str0 = re:replace(Bin, "\\\\", "\\\\\\", ReOpts),
|
||||
Str1 = re:replace(Str0, "\"", "\\\\\"", ReOpts),
|
||||
mustache:render(Str1, Context).
|
||||
|
||||
|
||||
|
|
|
@ -84,8 +84,8 @@ create(_Config, _) ->
|
|||
%% Load the template definition as is and get the list of variables the
|
||||
%% template requires.
|
||||
TemplateTerms = consult(load_file(Type, Template)),
|
||||
case lists:keysearch(variables, 1, TemplateTerms) of
|
||||
{value, {variables, Vars}} ->
|
||||
case lists:keyfind(variables, 1, TemplateTerms) of
|
||||
{variables, Vars} ->
|
||||
case parse_vars(Vars, dict:new()) of
|
||||
{error, Entry} ->
|
||||
Context0 = undefined,
|
||||
|
@ -270,8 +270,8 @@ write_file(Output, Data, Force) ->
|
|||
%% Execute each instruction in a template definition file.
|
||||
%%
|
||||
execute_template([], _TemplateType, _TemplateName, _Context, _Force, ExistingFiles) ->
|
||||
case length(ExistingFiles) of
|
||||
0 ->
|
||||
case ExistingFiles of
|
||||
[] ->
|
||||
ok;
|
||||
_ ->
|
||||
Msg = lists:flatten([io_lib:format("\t* ~p~n", [F]) || F <- lists:reverse(ExistingFiles)]),
|
||||
|
|
|
@ -205,6 +205,6 @@ emulate_escript_foldl(Fun, Acc, File) ->
|
|||
{archive, ArchiveBin} ->
|
||||
zip:foldl(Fun, Acc, {File, ArchiveBin})
|
||||
end;
|
||||
{error, Reason} ->
|
||||
{error, Reason}
|
||||
{error, _} = Error ->
|
||||
Error
|
||||
end.
|
||||
|
|
Loading…
Reference in a new issue