Skip to content
This repository has been archived by the owner on May 12, 2018. It is now read-only.

Some optimisation/refactoring using stdlib's functions #171

Merged
merged 2 commits into from Jun 14, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions THANKS
Expand Up @@ -125,3 +125,4 @@ YeJun Su
Yuki Ito
alisdair sullivan
Alexander Verbitsky
Pierre Fenoll
21 changes: 9 additions & 12 deletions src/rebar_erlc_compiler.erl
Expand Up @@ -119,8 +119,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 ]),
[re:replace(F, "\\.[xy]rl$", ".erl", [{return,list}]) || F <- YrlFiles]),

%% Delete the build graph, if any
rebar_file_utils:rm_rf(erlcinfo_file(Config)),
Expand Down Expand Up @@ -149,11 +148,9 @@ test_compile(Config, Cmd, OutDir) ->
%% in src but in a subdirectory of src. Cover only looks in cwd and ../src
%% for source files. Also copy files from src_dirs.
SrcDirs = rebar_utils:src_dirs(proplists:append_values(src_dirs, ErlOpts1)),
SrcErls = lists:foldl(
fun(Dir, Acc) ->
Files = rebar_utils:find_files(Dir, ".*\\.erl\$"),
lists:append(Acc, Files)
end, [], SrcDirs),
SrcErls = lists:flatmap(
fun (Dir) -> rebar_utils:find_files(Dir, ".*\\.erl$") end,
SrcDirs),

%% If it is not the first time rebar eunit or rebar qc is executed,
%% there will be source files already present in OutDir. Since some
Expand All @@ -164,17 +161,17 @@ test_compile(Config, Cmd, OutDir) ->
%% rebar_file_utils:cp_r.

%% Get the full path to a file that was previously copied in OutDir
ToCleanUp = fun(F, Acc) ->
ToCleanUp = fun(F) ->
F2 = filename:basename(F),
F3 = filename:join([OutDir, F2]),
case filelib:is_regular(F3) of
true -> [F3|Acc];
false -> Acc
true -> F3;
false -> []
end
end,

ok = rebar_file_utils:delete_each(lists:foldl(ToCleanUp, [], TestErls)),
ok = rebar_file_utils:delete_each(lists:foldl(ToCleanUp, [], SrcErls)),
ok = rebar_file_utils:delete_each(lists:flatmap(ToCleanUp, TestErls)),
ok = rebar_file_utils:delete_each(lists:flatmap(ToCleanUp, SrcErls)),

ok = rebar_file_utils:cp_r(SrcErls ++ TestErls, OutDir),

Expand Down