Skip to content

Commit 10a7e4f

Browse files
committed
Merge branch 'eyraud/166' into 'master'
Normalize path names passed to the --files switch Closes #166 See merge request eng/das/cov/gnatcoverage!347 Fixes eng/das/cov/gnatcoverage#166
2 parents c9956ec + 84460fb commit 10a7e4f

File tree

7 files changed

+98
-26
lines changed

7 files changed

+98
-26
lines changed

doc/gnatcov/integrated_instr.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ directory:
147147

148148
.. code-block:: sh
149149
150-
cmake .. -CMAKE_CXX_COMPILER=<my_project>/build/g++
150+
cmake .. -DCMAKE_CXX_COMPILER=<my_project>/build/g++
151151
152152
The default generator for CMake is "Unix Makefiles", so we can then run the
153153
build process with ``make``, and our executable which will produce a source trace
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
project(HelloWorld)
2+
cmake_minimum_required(VERSION 3.0)
3+
4+
add_executable(hello_world main.c)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <stdio.h>
2+
3+
int
4+
main()
5+
{
6+
printf("Hello world!\n");
7+
return 0;
8+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""
2+
Regression test: gnatcov used to leave paths passed to the --files switch
3+
un-normalized, which resulted in some units of interest being ignored at
4+
instrumentation time.
5+
"""
6+
7+
import os
8+
import os.path
9+
10+
from SUITE.control import env
11+
from SUITE.cutils import Wdir
12+
from SCOV.minicheck import check_xcov_reports
13+
from SUITE.tutils import cmdrun, srctracename_for, thistest, xcov
14+
15+
Wdir("tmp_")
16+
17+
cwd = os.getcwd()
18+
19+
# Setup the instrumentation process
20+
xcov(
21+
[
22+
"setup-integration",
23+
f"--files={os.path.join(cwd, '..', 'main.c')}",
24+
"--compilers=gcc",
25+
]
26+
)
27+
28+
# Shadow the compiler driver with the generated wrapper
29+
env.add_search_path(env_var="PATH", path=cwd)
30+
31+
# Then, run the build process unchanged
32+
compiler_wrapper = os.path.join(cwd, 'gcc')
33+
cmdrun(["cmake", "..", f"-DCMAKE_C_COMPILER={compiler_wrapper}"], for_pgm=False)
34+
cmdrun(["make"], for_pgm=False)
35+
36+
# Run the executable
37+
cmdrun(["hello_world"], for_pgm=False)
38+
39+
# Check coverage expectations
40+
xcov(
41+
[
42+
"coverage",
43+
"--level=stmt",
44+
"--sid=main.c.sid",
45+
"-axcov",
46+
srctracename_for("main"),
47+
]
48+
)
49+
check_xcov_reports("*.xcov", {"main.c.xcov": {"+": {6, 7}}})
50+
51+
thistest.result()

tools/gnatcov/gnatcov_bits_specific.adb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ with GNAT.OS_Lib;
2929
with GNAT.Regexp;
3030
with GNAT.Strings; use GNAT.Strings;
3131

32+
with GNATCOLL.VFS;
33+
3234
with System.Multiprocessors;
3335

3436
with Snames;
@@ -112,7 +114,7 @@ procedure GNATcov_Bits_Specific is
112114
Compiler_Drivers : Inputs.Inputs_Type;
113115
Source_Rebase_Inputs : Inputs.Inputs_Type;
114116
Source_Search_Inputs : Inputs.Inputs_Type;
115-
Subprograms_Inputs : Inputs.Inputs_Type;
117+
Subprograms_Inputs : Inputs.Inputs_Type;
116118
Text_Start : Pc_Type := 0;
117119
Output : String_Access := null;
118120
Tag : String_Access := null;
@@ -566,7 +568,16 @@ procedure GNATcov_Bits_Specific is
566568
Copy_Arg_List (Opt_Ignore_Source_Files, Ignored_Source_Files);
567569
Copy_Arg_List (Opt_Files, Files_Of_Interest);
568570
Copy_Arg_List (Opt_Compiler_Wrappers, Compiler_Drivers);
569-
Switches.Files_Of_Interest := To_String_Set (Files_Of_Interest);
571+
572+
for File of Files_Of_Interest loop
573+
declare
574+
use GNATCOLL.VFS;
575+
F : constant Virtual_File := Create (+File.Name.all);
576+
begin
577+
F.Normalize_Path;
578+
Switches.Files_Of_Interest.Include (+(+Full_Name (F)));
579+
end;
580+
end loop;
570581

571582
-- Compute the languages for which we want coverage analysis, or enable
572583
-- just the default ones.

tools/gnatcov/inputs.ads

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,17 @@ package Inputs is
3939
-- May raise Name_Error or Status_Error if the corresponding text file
4040
-- cannot be opened.
4141

42-
type Inputs_Type is private;
42+
type Inputs_Entry is record
43+
Name, Qualifier : String_Access;
44+
end record;
45+
46+
function Equal (L, R : Inputs_Entry) return Boolean;
47+
48+
package Input_Lists is new Ada.Containers.Doubly_Linked_Lists
49+
(Element_Type => Inputs_Entry,
50+
"=" => Equal);
51+
52+
type Inputs_Type is new Input_Lists.List with null record;
4353
-- Input lists. Can be used to accumulate the arguments given on
4454
-- a command line.
4555

@@ -68,7 +78,8 @@ package Inputs is
6878
-- Go through the input list and call Process on each entry (qualifiers are
6979
-- ignored in the first variant).
7080

71-
function Length (Inputs : Inputs_Type) return Ada.Containers.Count_Type;
81+
function Length (Inputs : Inputs_Type) return Ada.Containers.Count_Type
82+
with Inline;
7283
-- Return the number of elements in Inputs
7384

7485
procedure Log_File_Open (File_Name : String);
@@ -104,20 +115,4 @@ package Inputs is
104115
Case_Insensitive : Boolean := False);
105116
-- Overload to work on Inputs.Inputs_Type values
106117

107-
private
108-
109-
type Inputs_Entry is record
110-
Name, Qualifier : String_Access;
111-
end record;
112-
113-
function Equal (L, R : Inputs_Entry) return Boolean;
114-
115-
package Input_Lists is new Ada.Containers.Doubly_Linked_Lists
116-
(Element_Type => Inputs_Entry,
117-
"=" => Equal);
118-
119-
type Inputs_Type is new Input_Lists.List with null record;
120-
121-
pragma Inline (Length);
122-
123118
end Inputs;

tools/gnatcov/instrument-clean_objdirs.adb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ with Ada.Directories; use Ada.Directories;
2020

2121
with GNATCOLL.Projects; use GNATCOLL.Projects;
2222

23+
with Command_Line; use Command_Line;
2324
with Instrument.Common; use Instrument.Common;
2425
with Project;
2526

@@ -62,9 +63,11 @@ begin
6263
-- through extended projects, as their object directories can interfere
6364
-- with the build of the extending project.
6465

65-
Project.Iterate_Projects
66-
(Root_Project => Project.Project.Root_Project,
67-
Process => Clean_Subdir'Access,
68-
Recursive => True,
69-
Include_Extended => True);
66+
if not Args.Bool_Args (Opt_Save_Temps) then
67+
Project.Iterate_Projects
68+
(Root_Project => Project.Project.Root_Project,
69+
Process => Clean_Subdir'Access,
70+
Recursive => True,
71+
Include_Extended => True);
72+
end if;
7073
end Instrument.Clean_Objdirs;

0 commit comments

Comments
 (0)