diff options
author | alisdair sullivan <alisdairsullivan@yahoo.ca> | 2016-08-27 13:04:05 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-27 13:04:05 -0700 |
commit | 00b10530584135888e9a40c186b049f76c226028 (patch) | |
tree | eb5f3a925f2bd4752c2bf5e265ad394a6e644722 /src | |
parent | 8ee9cc89969afd79bf8687dcdf978f1a09e01d48 (diff) | |
parent | 4b0a07221de5e338cd71d774deff249f0528fa36 (diff) |
Merge pull request #1314 from ferd/cover_excl_mods
Cover excl mods
Diffstat (limited to 'src')
-rw-r--r-- | src/rebar_prv_cover.erl | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/src/rebar_prv_cover.erl b/src/rebar_prv_cover.erl index 464967b..7c2597b 100644 --- a/src/rebar_prv_cover.erl +++ b/src/rebar_prv_cover.erl @@ -303,23 +303,44 @@ cover_compile(State, Dirs) -> {ok, CoverPid} = start_cover(), %% redirect cover output true = redirect_cover_output(State, CoverPid), + ExclMods = rebar_state:get(State, cover_excl_mods, []), + lists:foreach(fun(Dir) -> - ?DEBUG("cover compiling ~p", [Dir]), - case catch(cover:compile_beam_directory(Dir)) of + case file:list_dir(Dir) of + {ok, Files} -> + ?DEBUG("cover compiling ~p", [Dir]), + [cover_compile_file(filename:join(Dir, File)) + || File <- Files, + filename:extension(File) == ".beam", + not is_ignored(Dir, File, ExclMods)], + ok; {error, eacces} -> ?WARN("Directory ~p not readable, modules will not be included in coverage", [Dir]); {error, enoent} -> ?WARN("Directory ~p not found", [Dir]); - {'EXIT', {Reason, _}} -> - ?WARN("Cover compilation for directory ~p failed: ~p", [Dir, Reason]); - Results -> - %% print any warnings about modules that failed to cover compile - lists:foreach(fun print_cover_warnings/1, lists:flatten(Results)) + {error, Reason} -> + ?WARN("Directory ~p error ~p", [Dir, Reason]) end end, Dirs), rebar_utils:cleanup_code_path(rebar_state:code_paths(State, default)), ok. +is_ignored(Dir, File, ExclMods) -> + Ignored = lists:any(fun(Excl) -> + File =:= atom_to_list(Excl) ++ ".beam" + end, + ExclMods), + Ignored andalso ?DEBUG("cover ignoring ~p ~p", [Dir, File]), + Ignored. + +cover_compile_file(FileName) -> + case catch(cover:compile_beam(FileName)) of + {error, Reason} -> + ?WARN("Cover compilation failed: ~p", [Reason]); + {ok, _} -> + ok + end. + app_dirs(Apps) -> lists:foldl(fun app_ebin_dirs/2, [], Apps). @@ -349,10 +370,6 @@ redirect_cover_output(State, CoverPid) -> [append]), group_leader(F, CoverPid). -print_cover_warnings({ok, _}) -> ok; -print_cover_warnings({error, Error}) -> - ?WARN("Cover compilation failed: ~p", [Error]). - write_coverdata(State, Task) -> DataDir = cover_dir(State), ok = filelib:ensure_dir(filename:join([DataDir, "dummy.log"])), |