aboutsummaryrefslogtreecommitdiffstats
path: root/lib/tools/src/cover.erl
diff options
context:
space:
mode:
authorJosé Valim <[email protected]>2012-11-28 13:45:37 +0100
committerFredrik Gustafsson <[email protected]>2013-01-25 14:57:00 +0100
commit29231033bfa618e5c4e1c50a5cefba32e02f2708 (patch)
treeec03896e88eb0adb3a51fd0391f2ba6ac1f6b19f /lib/tools/src/cover.erl
parent907d498ff798345fc8e8b71fc08a1c5b40112037 (diff)
downloadotp-29231033bfa618e5c4e1c50a5cefba32e02f2708.tar.gz
otp-29231033bfa618e5c4e1c50a5cefba32e02f2708.tar.bz2
otp-29231033bfa618e5c4e1c50a5cefba32e02f2708.zip
cover now relies on the compile info to find file sources
Prior to this commit, cover relied on a simple heuristic that traverses directory from the beam file to find a source file. The heuristic was maintained with this patch but, if it fails, it fallbacks to the source value in the module compile info. In order to illustrate how it works, one of the tests that could not find its source now passes successfully (showing the source lookup is more robust).
Diffstat (limited to 'lib/tools/src/cover.erl')
-rw-r--r--lib/tools/src/cover.erl22
1 files changed, 19 insertions, 3 deletions
diff --git a/lib/tools/src/cover.erl b/lib/tools/src/cover.erl
index 468225dc13..d7c736b710 100644
--- a/lib/tools/src/cover.erl
+++ b/lib/tools/src/cover.erl
@@ -1945,7 +1945,7 @@ move_clauses([]) ->
%% Given a .beam file, find the .erl file. Look first in same directory as
%% the .beam file, then in <beamdir>/../src
-find_source(File0) ->
+find_source(Module, File0) ->
case filename:rootname(File0,".beam") of
File0 ->
File0;
@@ -1962,11 +1962,27 @@ find_source(File0) ->
true ->
InDotDotSrc;
false ->
- {beam,File0}
+ find_source_from_module(Module, File0)
end
end
end.
+%% In case we can't find the file from the given .beam,
+%% we try to get the information directly from the module source
+find_source_from_module(Module, File) ->
+ Compile = Module:module_info(compile),
+ case lists:keyfind(source, 1, Compile) of
+ {source, Path} ->
+ case filelib:is_file(Path) of
+ true ->
+ Path;
+ false ->
+ {beam, File}
+ end;
+ false ->
+ {beam, File}
+ end.
+
do_parallel_analysis(Module, Analysis, Level, Loaded, From, State) ->
analyse_info(Module,State#main_state.imported),
C = case Loaded of
@@ -2070,7 +2086,7 @@ do_parallel_analysis_to_file(Module, OutFile, Opts, Loaded, From, State) ->
{imported, File0, _} ->
File0
end,
- case find_source(File) of
+ case find_source(Module, File) of
{beam,_BeamFile} ->
reply(From, {error,no_source_code_found});
ErlFile ->