From 495f1f103096733fe03ae1ef67d68874bb51aafd Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Wed, 6 Mar 2013 07:39:36 +0100 Subject: Fix cover.xml formatting error --- lib/tools/doc/src/cover.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/tools/doc/src/cover.xml b/lib/tools/doc/src/cover.xml index a2444ec947..9c116aa04b 100644 --- a/lib/tools/doc/src/cover.xml +++ b/lib/tools/doc/src/cover.xml @@ -214,7 +214,9 @@ {no_abstract_code,BeamFile} is returned. If the abstract code is encrypted, and no key is available for decrypting it, the error reason - If only the module name (i.e. not the full name of the .beam]]> file) is given to this function, the + {encrypted_abstract_code,BeamFile} is returned.

+

If only the module name (i.e. not the full name of the + .beam file) is given to this function, the .beam file is found by calling code:which(Module). If no .beam file is found, the error reason non_existing is returned. If the -- cgit v1.2.3 From 0a2237a18e16de514677c7c2a13bee7c6e32bbaf Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Sun, 17 Feb 2013 13:30:03 +0100 Subject: Document change to cover.erl source search The change was introduced in commit 29231033. --- lib/tools/doc/src/cover.xml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/tools/doc/src/cover.xml b/lib/tools/doc/src/cover.xml index 9c116aa04b..477871d6c3 100644 --- a/lib/tools/doc/src/cover.xml +++ b/lib/tools/doc/src/cover.xml @@ -5,7 +5,7 @@

2001 - 2012 + 2013 Ericsson AB, All Rights Reserved @@ -315,9 +315,10 @@ file, i.e. using compile_beam/1 or compile_beam_directory/0,1, it is assumed that the source code can be found in the same directory as the - .beam file, or in ../src relative to that - directory. If no source code is found, - ,{error,no_source_code_found} is returned.

+ .beam file, in ../src relative to that + directory, or at the source path in + Module:module_info(compile). If no source code is found, + {error,no_source_code_found} is returned.

HINT: It is possible to issue multiple analyse_to_file commands at the same time.

-- cgit v1.2.3 From 6c9ff9812608c1c893c50eb567f6e8121fdde35d Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Sun, 17 Feb 2013 19:35:40 +0100 Subject: Extend cover.erl source search Commit 29231033 made cover fall back to compile info if source was not found in pwd or ../src. This isn't sufficient for source that lies in subdirectories of ../src when beams and source have been moved since compilation (eg. install of some OTP applications), so first try finding source relative to the beam directory. For example, given a beam path /installed/path/to/app-1.0/ebin/root.beam and a source path /compiled/path/to/app/src/subdir/root.erl then look for /installed/path/to/app-1.0/ebin/../src/subdir/root.erl before the source path. --- lib/tools/doc/src/cover.xml | 9 +++-- lib/tools/src/cover.erl | 86 ++++++++++++++++++++++++++------------------- 2 files changed, 57 insertions(+), 38 deletions(-) diff --git a/lib/tools/doc/src/cover.xml b/lib/tools/doc/src/cover.xml index 477871d6c3..beefd4ee8d 100644 --- a/lib/tools/doc/src/cover.xml +++ b/lib/tools/doc/src/cover.xml @@ -316,8 +316,13 @@ compile_beam_directory/0,1, it is assumed that the source code can be found in the same directory as the .beam file, in ../src relative to that - directory, or at the source path in - Module:module_info(compile). If no source code is found, + directory, or using the source path in + Module:module_info(compile). When using the latter, + two paths are examined: first the one constructed by + joining ../src and the tail of the compiled path + below a trailing src component, then the compiled + path itself. + If no source code is found, {error,no_source_code_found} is returned.

HINT: It is possible to issue multiple analyse_to_file commands at the same time.

diff --git a/lib/tools/src/cover.erl b/lib/tools/src/cover.erl index 2579711dc7..dfcfc3675f 100644 --- a/lib/tools/src/cover.erl +++ b/lib/tools/src/cover.erl @@ -1951,47 +1951,61 @@ move_clauses([{M,F,A,C,_L}|Clauses]) -> move_clauses(Clauses); move_clauses([]) -> ok. - %% Given a .beam file, find the .erl file. Look first in same directory as -%% the .beam file, then in /../src +%% the .beam file, then in ../src, then in compile info. find_source(Module, File0) -> - case filename:rootname(File0,".beam") of - File0 -> - File0; - File -> - InSameDir = File++".erl", - case filelib:is_file(InSameDir) of - true -> - InSameDir; - false -> - Dir = filename:dirname(File), - Mod = filename:basename(File), - InDotDotSrc = filename:join([Dir,"..","src",Mod++".erl"]), - case filelib:is_file(InDotDotSrc) of - true -> - InDotDotSrc; - false -> - find_source_from_module(Module, File0) - end - end + try + Root = filename:rootname(File0, ".beam"), + Root == File0 andalso throw(File0), %% not .beam + %% Look for .erl in pwd. + File = Root ++ ".erl", + throw_file(File), + %% Not in pwd: look in ../src. + BeamDir = filename:dirname(File), + Base = filename:basename(File), + throw_file(filename:join([BeamDir, "..", "src", Base])), + %% Not in ../src: look for source path in compile info, but + %% first look relative the beam directory. + Info = lists:keyfind(source, 1, Module:module_info(compile)), + false == Info andalso throw({beam, File0}), %% stripped + {source, SrcFile} = Info, + throw_file(splice(BeamDir, SrcFile)), %% below ../src + throw_file(SrcFile), %% or absolute + %% No success means that source is either not under ../src or + %% its relative path differs from that of compile info. (For + %% example, compiled under src/x but installed under src/y.) + %% An option to specify an arbitrary source path explicitly is + %% probably a better solution than either more heuristics or a + %% potentially slow filesystem search. + {beam, File0} + catch + Path -> Path 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. +throw_file(Path) -> + false /= Path andalso filelib:is_file(Path) andalso throw(Path). + +%% Splice the tail of a source path, starting from the last "src" +%% component, onto the parent of a beam directory, or return false if +%% no "src" component is found. +%% +%% Eg. splice("/path/to/app-1.0/ebin", "/compiled/path/to/app/src/x/y.erl") +%% --> "/path/to/app-1.0/ebin/../src/x/y.erl" +%% +%% This handles the case of source in subdirectories of ../src with +%% beams that have moved since compilation. +%% +splice(BeamDir, SrcFile) -> + case lists:splitwith(fun(C) -> C /= "src" end, revsplit(SrcFile)) of + {T, [_|_]} -> %% found src component + filename:join([BeamDir, "..", "src" | lists:reverse(T)]); + {_, []} -> %% or not + false + end. + +revsplit(Path) -> + lists:reverse(filename:split(Path)). do_parallel_analysis(Module, Analysis, Level, Loaded, From, State) -> analyse_info(Module,State#main_state.imported), -- cgit v1.2.3 From 2e16ae1127e2e9d7a81b2fb73620babe85d941a0 Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Tue, 5 Mar 2013 16:53:15 +0100 Subject: Remove obsolete common_test note regarding source paths --- lib/common_test/doc/src/cover_chapter.xml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/common_test/doc/src/cover_chapter.xml b/lib/common_test/doc/src/cover_chapter.xml index 4fa92d5583..736486350b 100644 --- a/lib/common_test/doc/src/cover_chapter.xml +++ b/lib/common_test/doc/src/cover_chapter.xml @@ -4,7 +4,7 @@
- 20062012 + 20062013 Ericsson AB. All Rights Reserved. @@ -74,12 +74,6 @@ executed during the test. In overview mode, only the code coverage overview page gets printed.

-

Note: Currently, for Common Test to be able to print - code coverage HTML files for the modules included in the - analysis, the source code files of these modules must be - located in the same directory as the corresponding .beam - files. This is a limitation that will be removed later.

-

You can choose to export and import code coverage data between tests. If you specify the name of an export file in the cover specification file, Common Test will export collected coverage -- cgit v1.2.3