Apply Tidier suggestions

This commit is contained in:
Tuncer Ayaz 2011-01-08 19:09:24 +01:00
parent d922985b36
commit e4036cbe56
12 changed files with 78 additions and 71 deletions

View file

@ -75,10 +75,10 @@ parse(OptSpecList, OptAcc, ArgAcc, _ArgPos, ["--" | Tail]) ->
% Any argument present after the terminator is not considered an option. % Any argument present after the terminator is not considered an option.
{ok, {lists:reverse(append_default_options(OptSpecList, OptAcc)), lists:reverse(ArgAcc, Tail)}}; {ok, {lists:reverse(append_default_options(OptSpecList, OptAcc)), lists:reverse(ArgAcc, Tail)}};
%% Process long options. %% Process long options.
parse(OptSpecList, OptAcc, ArgAcc, ArgPos, [[$-, $- | OptArg] = OptStr | Tail]) -> parse(OptSpecList, OptAcc, ArgAcc, ArgPos, ["--" ++ OptArg = OptStr | Tail]) ->
parse_option_long(OptSpecList, OptAcc, ArgAcc, ArgPos, Tail, OptStr, OptArg); parse_option_long(OptSpecList, OptAcc, ArgAcc, ArgPos, Tail, OptStr, OptArg);
%% Process short options. %% Process short options.
parse(OptSpecList, OptAcc, ArgAcc, ArgPos, [[$- | [_Char | _] = OptArg] = OptStr | Tail]) -> parse(OptSpecList, OptAcc, ArgAcc, ArgPos, ["-" ++ ([_Char | _] = OptArg) = OptStr | Tail]) ->
parse_option_short(OptSpecList, OptAcc, ArgAcc, ArgPos, Tail, OptStr, OptArg); parse_option_short(OptSpecList, OptAcc, ArgAcc, ArgPos, Tail, OptStr, OptArg);
%% Process non-option arguments. %% Process non-option arguments.
parse(OptSpecList, OptAcc, ArgAcc, ArgPos, [Arg | Tail]) -> parse(OptSpecList, OptAcc, ArgAcc, ArgPos, [Arg | Tail]) ->
@ -111,11 +111,11 @@ parse_option_long(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptStr, OptArg) ->
parse_option_assigned_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptStr, Long, Arg); parse_option_assigned_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptStr, Long, Arg);
Long -> Long ->
case lists:keysearch(Long, ?OPT_LONG, OptSpecList) of case lists:keyfind(Long, ?OPT_LONG, OptSpecList) of
{value, {Name, _Short, Long, undefined, _Help}} -> {Name, _Short, Long, undefined, _Help} ->
parse(OptSpecList, [Name | OptAcc], ArgAcc, ArgPos, Args); parse(OptSpecList, [Name | OptAcc], ArgAcc, ArgPos, Args);
{value, {_Name, _Short, Long, _ArgSpec, _Help} = OptSpec} -> {_Name, _Short, Long, _ArgSpec, _Help} = OptSpec ->
% The option argument string is empty, but the option requires % The option argument string is empty, but the option requires
% an argument, so we look into the next string in the list. % an argument, so we look into the next string in the list.
parse_option_next_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptSpec); parse_option_next_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptSpec);
@ -132,8 +132,8 @@ parse_option_long(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptStr, OptArg) ->
[string()], string(), string(), string()) -> [string()], string(), string(), string()) ->
{ok, {[option()], [string()]}}. {ok, {[option()], [string()]}}.
parse_option_assigned_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptStr, Long, Arg) -> parse_option_assigned_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptStr, Long, Arg) ->
case lists:keysearch(Long, ?OPT_LONG, OptSpecList) of case lists:keyfind(Long, ?OPT_LONG, OptSpecList) of
{value, {_Name, _Short, Long, ArgSpec, _Help} = OptSpec} -> {_Name, _Short, Long, ArgSpec, _Help} = OptSpec ->
case ArgSpec of case ArgSpec of
undefined -> undefined ->
throw({error, {invalid_option_arg, OptStr}}); throw({error, {invalid_option_arg, OptStr}});
@ -151,7 +151,7 @@ parse_option_assigned_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptStr, Lon
split_assigned_arg(OptStr) -> split_assigned_arg(OptStr) ->
split_assigned_arg(OptStr, OptStr, []). split_assigned_arg(OptStr, OptStr, []).
split_assigned_arg(_OptStr, [$= | Tail], Acc) -> split_assigned_arg(_OptStr, "=" ++ Tail, Acc) ->
{lists:reverse(Acc), Tail}; {lists:reverse(Acc), Tail};
split_assigned_arg(OptStr, [Char | Tail], Acc) -> split_assigned_arg(OptStr, [Char | Tail], Acc) ->
split_assigned_arg(OptStr, Tail, [Char | Acc]); split_assigned_arg(OptStr, Tail, [Char | Acc]);
@ -170,11 +170,11 @@ split_assigned_arg(OptStr, [], _Acc) ->
-spec parse_option_short([option_spec()], [option()], [string()], integer(), [string()], string(), string()) -> -spec parse_option_short([option_spec()], [option()], [string()], integer(), [string()], string(), string()) ->
{ok, {[option()], [string()]}}. {ok, {[option()], [string()]}}.
parse_option_short(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptStr, [Short | Arg]) -> parse_option_short(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptStr, [Short | Arg]) ->
case lists:keysearch(Short, ?OPT_SHORT, OptSpecList) of case lists:keyfind(Short, ?OPT_SHORT, OptSpecList) of
{value, {Name, Short, _Long, undefined, _Help}} -> {Name, Short, _Long, undefined, _Help} ->
parse_option_short(OptSpecList, [Name | OptAcc], ArgAcc, ArgPos, Args, OptStr, Arg); parse_option_short(OptSpecList, [Name | OptAcc], ArgAcc, ArgPos, Args, OptStr, Arg);
{value, {_Name, Short, _Long, ArgSpec, _Help} = OptSpec} -> {_Name, Short, _Long, ArgSpec, _Help} = OptSpec ->
case Arg of case Arg of
[] -> [] ->
% The option argument string is empty, but the option requires % The option argument string is empty, but the option requires

View file

@ -137,7 +137,7 @@ make_cmd(TestDir, Config) ->
%% that are part of the root Erlang install are filtered out to %% that are part of the root Erlang install are filtered out to
%% avoid duplication %% avoid duplication
R = code:root_dir(), R = code:root_dir(),
NonLibCodeDirs = [P || P <- code:get_path(), lists:prefix(R, P) == false], NonLibCodeDirs = [P || P <- code:get_path(), not lists:prefix(R, P)],
CodeDirs = [io_lib:format("\"~s\"", [Dir]) || CodeDirs = [io_lib:format("\"~s\"", [Dir]) ||
Dir <- [EbinDir|NonLibCodeDirs]], Dir <- [EbinDir|NonLibCodeDirs]],
CodePathString = string:join(CodeDirs, " "), CodePathString = string:join(CodeDirs, " "),

View file

@ -134,8 +134,9 @@ compile(Config, AppFile) ->
DepsDir = get_deps_dir(), DepsDir = get_deps_dir(),
Deps = rebar_config:get_local(Config, deps, []), Deps = rebar_config:get_local(Config, deps, []),
{AvailableDeps, _} = find_deps(find, Deps), {AvailableDeps, _} = find_deps(find, Deps),
_ = [delete_dep(D) || D <- AvailableDeps, _ = [delete_dep(D)
lists:prefix(DepsDir, D#dep.dir) == true], || D <- AvailableDeps,
lists:prefix(DepsDir, D#dep.dir)],
ok. ok.
@ -339,11 +340,13 @@ update_source(Dep) ->
end. end.
update_source(AppDir, {git, _Url, {branch, Branch}}) -> update_source(AppDir, {git, _Url, {branch, Branch}}) ->
rebar_utils:sh("git fetch origin", [{cd, AppDir}]), ShOpts = [{cd, AppDir}],
rebar_utils:sh(?FMT("git checkout -q origin/~s", [Branch]), [{cd, AppDir}]); rebar_utils:sh("git fetch origin", ShOpts),
rebar_utils:sh(?FMT("git checkout -q origin/~s", [Branch]), ShOpts);
update_source(AppDir, {git, _Url, {tag, Tag}}) -> update_source(AppDir, {git, _Url, {tag, Tag}}) ->
rebar_utils:sh("git fetch --tags origin", [{cd, AppDir}]), ShOpts = [{cd, AppDir}],
rebar_utils:sh(?FMT("git checkout -q ~s", [Tag]), [{cd, AppDir}]); rebar_utils:sh("git fetch --tags origin", ShOpts),
rebar_utils:sh(?FMT("git checkout -q ~s", [Tag]), ShOpts);
update_source(AppDir, {git, Url, Refspec}) -> update_source(AppDir, {git, Url, Refspec}) ->
update_source(AppDir, {git, Url, {branch, Refspec}}); update_source(AppDir, {git, Url, {branch, Refspec}});
update_source(AppDir, {svn, _Url, Rev}) -> update_source(AppDir, {svn, _Url, Rev}) ->

View file

@ -193,7 +193,7 @@ existing_plt_path(Config, File) ->
?ABORT("No PLT found~n", []) ?ABORT("No PLT found~n", [])
end end
end; end;
[$~|[$/|Plt]] -> "~/" ++ Plt ->
filename:join(Home,Plt); filename:join(Home,Plt);
Plt -> Plt ->
Plt Plt

View file

@ -164,14 +164,13 @@ referenced_dtls1(Step, Config, Seen) ->
[{return, list}]), [{return, list}]),
AllRefs = AllRefs =
lists:append( lists:append(
lists:map( [begin
fun(F) ->
{ok, Res} = rebar_utils:sh( {ok, Res} = rebar_utils:sh(
lists:flatten(["grep -o [^\\\"]*", lists:flatten(["grep -o [^\\\"]*",
ExtMatch," ",F]), ExtMatch," ",F]),
[{use_stdout, false}]), [{use_stdout, false}]),
string:tokens(Res, "\n") string:tokens(Res, "\n")
end, Step)), end || F <- Step]),
DocRoot = option(doc_root, DtlOpts), DocRoot = option(doc_root, DtlOpts),
WithPaths = [ filename:join([DocRoot, F]) || F <- AllRefs ], WithPaths = [ filename:join([DocRoot, F]) || F <- AllRefs ],
Existing = [F || F <- WithPaths, filelib:is_regular(F)], Existing = [F || F <- WithPaths, filelib:is_regular(F)],

View file

@ -49,8 +49,8 @@ rm_rf(Target) ->
ok; ok;
{win32, _} -> {win32, _} ->
Filelist = filelib:wildcard(Target), Filelist = filelib:wildcard(Target),
Dirs = lists:filter(fun filelib:is_dir/1,Filelist), Dirs = [F || F <- Filelist, filelib:is_dir(F)],
Files = lists:subtract(Filelist,Dirs), Files = Filelist -- Dirs,
ok = delete_each(Files), ok = delete_each(Files),
ok = delete_each_dir_win32(Dirs), ok = delete_each_dir_win32(Dirs),
ok ok
@ -82,9 +82,10 @@ mv(Source, Dest) ->
[filename:nativename(Source), [filename:nativename(Source),
filename:nativename(Dest)]), filename:nativename(Dest)]),
[{use_stdout, false}, return_on_error]), [{use_stdout, false}, return_on_error]),
case length(R) == 0 of case R of
true -> ok; [] ->
false -> ok;
_ ->
{error, lists:flatten( {error, lists:flatten(
io_lib:format("Failed to move ~s to ~s~n", io_lib:format("Failed to move ~s to ~s~n",
[Source, Dest]))} [Source, Dest]))}
@ -138,10 +139,9 @@ cp_r_win32({true,SourceDir},{true,DestDir}) ->
Other -> Other Other -> Other
end, end,
ok = xcopy_win32(SourceDir, filename:join(DestDir, SourceBase)); ok = xcopy_win32(SourceDir, filename:join(DestDir, SourceBase));
cp_r_win32({false,Source},{true,DestDir}) -> cp_r_win32({false, Source} = S,{true, DestDir}) ->
% from file to directory % from file to directory
cp_r_win32({false,Source}, cp_r_win32(S, {false, filename:join(DestDir, filename:basename(Source))});
{false,filename:join(DestDir,filename:basename(Source))});
cp_r_win32({false, Source},{false, Dest}) -> cp_r_win32({false, Source},{false, Dest}) ->
% from file to file % from file to file
{ok,_} = file:copy(Source, Dest), {ok,_} = file:copy(Source, Dest),

View file

@ -121,16 +121,15 @@ referenced_pegs1(Step, Config, Seen) ->
NeoOpts = neotoma_opts(Config), NeoOpts = neotoma_opts(Config),
ExtMatch = re:replace(option(source_ext, NeoOpts), "\.", "\\\\\\\\.", ExtMatch = re:replace(option(source_ext, NeoOpts), "\.", "\\\\\\\\.",
[{return, list}]), [{return, list}]),
AllRefs =
lists:append( AllRefs = lists:append([begin
lists:map( {ok, Res} =
fun(F) -> rebar_utils:sh(
{ok, Res} = rebar_utils:sh(
lists:flatten(["grep -o [^\\\"]*", lists:flatten(["grep -o [^\\\"]*",
ExtMatch, " ", F]), ExtMatch, " ", F]),
[{use_stdout, false}]), [{use_stdout, false}]),
string:tokens(Res, "\n") string:tokens(Res, "\n")
end, Step)), end || F <- Step]),
DocRoot = option(doc_root, NeoOpts), DocRoot = option(doc_root, NeoOpts),
WithPaths = [ filename:join([DocRoot, F]) || F <- AllRefs ], WithPaths = [ filename:join([DocRoot, F]) || F <- AllRefs ],
Existing = [F || F <- WithPaths, filelib:is_regular(F)], Existing = [F || F <- WithPaths, filelib:is_regular(F)],

View file

@ -119,7 +119,10 @@ clean(Config, AppFile) ->
rebar_file_utils:delete_each([source_to_bin(S) || S <- Sources]), rebar_file_utils:delete_each([source_to_bin(S) || S <- Sources]),
%% Delete the .so file %% Delete the .so file
rebar_file_utils:delete_each(lists:map(fun({SoName,_}) -> SoName end, so_specs(Config, AppFile, expand_objects(Sources)))), ExtractSoName = fun({SoName, _}) -> SoName end,
rebar_file_utils:delete_each([ExtractSoName(S)
|| S <- so_specs(Config, AppFile,
expand_objects(Sources))]),
%% Run the cleanup script, if it exists %% Run the cleanup script, if it exists
run_cleanup_hook(Config). run_cleanup_hook(Config).

View file

@ -222,13 +222,15 @@ run_reltool(Server, _Config, ReltoolConfig) ->
end, end,
%% Finally, overlay the files specified by the overlay section %% Finally, overlay the files specified by the overlay section
case lists:keysearch(overlay, 1, ReltoolConfig) of case lists:keyfind(overlay, 1, ReltoolConfig) of
{value, {overlay, Overlay}} when is_list(Overlay) -> {overlay, Overlay} when is_list(Overlay) ->
execute_overlay(Overlay, OverlayVars, rebar_utils:get_cwd(), TargetDir); execute_overlay(Overlay, OverlayVars, rebar_utils:get_cwd(),
{value, _} -> TargetDir);
?ABORT("{overlay, [...]} entry in reltool.config must be a list.\n", []);
false -> false ->
?INFO("No {overlay, [...]} found in reltool.config.\n", []) ?INFO("No {overlay, [...]} found in reltool.config.\n", []);
_ ->
?ABORT("{overlay, [...]} entry in reltool.config "
"must be a list.\n", [])
end; end;
{error, Reason} -> {error, Reason} ->

View file

@ -45,7 +45,8 @@ eunit(Config, _) ->
check_versions(Config) -> check_versions(Config) ->
ErtsRegex = rebar_config:get(Config, require_erts_vsn, ".*"), ErtsRegex = rebar_config:get(Config, require_erts_vsn, ".*"),
case re:run(erlang:system_info(version), ErtsRegex, [{capture, none}]) of ReOpts = [{capture, none}],
case re:run(erlang:system_info(version), ErtsRegex, ReOpts) of
match -> match ->
?DEBUG("Matched required ERTS version: ~s -> ~s\n", ?DEBUG("Matched required ERTS version: ~s -> ~s\n",
[erlang:system_info(version), ErtsRegex]); [erlang:system_info(version), ErtsRegex]);
@ -55,7 +56,7 @@ check_versions(Config) ->
end, end,
OtpRegex = rebar_config:get(Config, require_otp_vsn, ".*"), OtpRegex = rebar_config:get(Config, require_otp_vsn, ".*"),
case re:run(erlang:system_info(otp_release), OtpRegex, [{capture, none}]) of case re:run(erlang:system_info(otp_release), OtpRegex, ReOpts) of
match -> match ->
?DEBUG("Matched required OTP release: ~s -> ~s\n", ?DEBUG("Matched required OTP release: ~s -> ~s\n",
[erlang:system_info(otp_release), OtpRegex]); [erlang:system_info(otp_release), OtpRegex]);

View file

@ -75,8 +75,8 @@ sh(Command0, Options0) ->
?INFO("sh: ~s\n~p\n", [Command0, Options0]), ?INFO("sh: ~s\n~p\n", [Command0, Options0]),
DefaultOptions = [use_stdout, abort_on_error], DefaultOptions = [use_stdout, abort_on_error],
Options = lists:map(fun expand_sh_flag/1, Options = [expand_sh_flag(V)
proplists:compact(Options0 ++ DefaultOptions)), || V <- proplists:compact(Options0 ++ DefaultOptions)],
ErrorHandler = proplists:get_value(error_handler, Options), ErrorHandler = proplists:get_value(error_handler, Options),
OutputHandler = proplists:get_value(output_handler, Options), OutputHandler = proplists:get_value(output_handler, Options),
@ -87,8 +87,8 @@ sh(Command0, Options0) ->
Port = open_port({spawn, Command}, PortSettings), Port = open_port({spawn, Command}, PortSettings),
case sh_loop(Port, OutputHandler, []) of case sh_loop(Port, OutputHandler, []) of
{ok, Output} -> {ok, _Output} = Ok ->
{ok, Output}; Ok;
{error, Rc} -> {error, Rc} ->
ErrorHandler(Command, Rc) ErrorHandler(Command, Rc)
end. end.
@ -179,10 +179,10 @@ expand_sh_flag({use_stdout, false}) ->
fun(Line, Acc) -> fun(Line, Acc) ->
[Acc | Line] [Acc | Line]
end}; end};
expand_sh_flag({cd, Dir}) -> expand_sh_flag({cd, _CdArg} = Cd) ->
{port_settings, {cd, Dir}}; {port_settings, Cd};
expand_sh_flag({env, Env}) -> expand_sh_flag({env, _EnvArg} = Env) ->
{port_settings, {env, Env}}. {port_settings, Env}.
-spec log_and_abort(string(), integer()) -> no_return(). -spec log_and_abort(string(), integer()) -> no_return().
log_and_abort(Command, Rc) -> log_and_abort(Command, Rc) ->

View file

@ -252,5 +252,5 @@ assert_full_coverage(Mod) ->
string:str(X, Mod) =/= 0, string:str(X, Mod) =/= 0,
string:str(X, "100%") =/= 0], string:str(X, "100%") =/= 0],
file:close(F), file:close(F),
?assert(length(Result) == 1) ?assert(length(Result) =:= 1)
end. end.