Skip to content

Commit f014b2f

Browse files
committed
Merge branch 'eyraud/399' into 'master'
Support passing directory arguments Closes #399 See merge request eng/das/cov/gnatcoverage!788 Closes eng/das/cov/gnatcoverage#399
2 parents 87de933 + 25f9673 commit f014b2f

File tree

8 files changed

+198
-8
lines changed

8 files changed

+198
-8
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!native DEAD Use GNATCOV_TRACE_FILE feature only available with the binary file dump-channel
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"""
2+
Check that gnatcov accepts directory arguments for the --trace and
3+
--sid switches.
4+
"""
5+
6+
import os
7+
import os.path
8+
9+
from SCOV.minicheck import build_and_run, check_xcov_reports
10+
from SUITE.context import thistest
11+
from SUITE.cutils import Wdir
12+
from SUITE.gprutils import GPRswitches
13+
from SUITE.tutils import gprfor, xcov
14+
15+
Wdir("tmp_")
16+
17+
os.mkdir("traces-dir")
18+
env = dict(os.environ)
19+
env.update({"GNATCOV_TRACE_FILE": "traces-dir/"})
20+
build_and_run(
21+
gprsw=GPRswitches(gprfor(srcdirs=[".."], mains=["test_1", "test_2"])),
22+
covlevel="stmt",
23+
mains=["test_1", "test_2"],
24+
extra_coverage_args=[],
25+
trace_mode="src",
26+
program_env=env,
27+
)
28+
xcov(
29+
[
30+
"coverage",
31+
"--level=stmt",
32+
"--annotate=xcov",
33+
"--sid",
34+
"obj/",
35+
"--trace",
36+
"traces-dir/",
37+
]
38+
)
39+
40+
# Check that the coverage report is as expected
41+
check_xcov_reports(
42+
".",
43+
{
44+
"test_1.adb.xcov": {"+": {3}},
45+
"test_2.adb.xcov": {"+": {3}},
46+
},
47+
)
48+
49+
thistest.result()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
procedure Test_1 is
2+
begin
3+
null;
4+
end Test_1;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
procedure Test_2 is
2+
begin
3+
null;
4+
end Test_2;

tools/gnatcov/command_line.ads

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,10 @@ package Command_Line is
15191519
(Long_Name => "--trace",
15201520
Short_Name => "-T",
15211521
Pattern => "[TRACE|@LISTFILE]",
1522-
Help => "Specify trace files to read.",
1522+
Help =>
1523+
"Specify trace files to read. If the path ends with a directory "
1524+
& " separator, consider it is a directory path containing the list"
1525+
& " of traces to be read.",
15231526
Commands => (Cmd_Coverage
15241527
| Cmd_Dump_Trace
15251528
| Cmd_Dump_Trace_Raw

tools/gnatcov/gnatcov_bits_specific.adb

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,37 @@ procedure GNATcov_Bits_Specific is
533533
Invalidate_Unit_List ("--scos is present");
534534
end if;
535535

536-
Copy_Arg_List (Opt_SID, SID_Inputs);
536+
declare
537+
procedure Process_Dir_Entry (Dir_Entry : Directory_Entry_Type);
538+
539+
procedure Process_Arg (Exp_Arg : String);
540+
541+
-----------------------
542+
-- Process_Dir_Entry --
543+
-----------------------
544+
545+
procedure Process_Dir_Entry (Dir_Entry : Directory_Entry_Type) is
546+
begin
547+
SID_Inputs.Append (+Full_Name (Dir_Entry));
548+
end Process_Dir_Entry;
549+
550+
-----------------
551+
-- Process_Arg --
552+
-----------------
553+
554+
procedure Process_Arg (Exp_Arg : String) is
555+
begin
556+
SID_Inputs.Append (+Exp_Arg);
557+
end Process_Arg;
558+
559+
begin
560+
Switches.Process_File_Or_Dir_Switch
561+
(Args => Args.String_List_Args (Opt_SID),
562+
Orig_Switch => "--sid",
563+
Process_Dir_Entry => Process_Dir_Entry'Access,
564+
Process_Arg => Process_Arg'Access,
565+
Pattern => "*.sid");
566+
end;
537567
if not SID_Inputs.Is_Empty then
538568
Invalidate_Unit_List ("--sid is present");
539569
end if;
@@ -681,11 +711,36 @@ procedure GNATcov_Bits_Specific is
681711
(+Args.String_Args (Opt_Output_Directory).Value);
682712
end if;
683713

684-
for Arg of Args.String_List_Args (Opt_Trace) loop
685-
for Exp_Arg of Expand_Argument (+Arg) loop
686-
Handle_Trace_List_Element (+Exp_Arg);
687-
end loop;
688-
end loop;
714+
declare
715+
procedure Process_Dir_Entry (Dir_Entry : Directory_Entry_Type);
716+
717+
procedure Process_Arg (Exp_Arg : String);
718+
719+
-----------------------
720+
-- Process_Dir_Entry --
721+
-----------------------
722+
723+
procedure Process_Dir_Entry (Dir_Entry : Directory_Entry_Type) is
724+
begin
725+
Trace_Inputs.Append ((+Full_Name (Dir_Entry), Current_Exec));
726+
end Process_Dir_Entry;
727+
728+
-----------------
729+
-- Process_Arg --
730+
-----------------
731+
732+
procedure Process_Arg (Exp_Arg : String) is
733+
begin
734+
Handle_Trace_List_Element (Exp_Arg);
735+
end Process_Arg;
736+
737+
begin
738+
Switches.Process_File_Or_Dir_Switch
739+
(Args => Args.String_List_Args (Opt_Trace),
740+
Orig_Switch => "--trace",
741+
Process_Dir_Entry => Process_Dir_Entry'Access,
742+
Process_Arg => Process_Arg'Access);
743+
end;
689744

690745
if Args.String_Args (Opt_Trace_Source).Present then
691746
Convert.Set_Trace_Source (+Args.String_Args (Opt_Trace_Source).Value);

tools/gnatcov/switches.adb

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
with Ada.Characters.Handling; use Ada.Characters.Handling;
2020
with Ada.Command_Line;
2121
with Ada.Containers; use Ada.Containers;
22-
with Ada.Directories;
2322
with Ada.Strings.Fixed;
2423
with Ada.Text_IO; use Ada.Text_IO;
2524

@@ -158,6 +157,61 @@ package body Switches is
158157
end loop;
159158
end Copy_Arg_List;
160159

160+
--------------------------------
161+
-- Process_File_Or_Dir_Switch --
162+
--------------------------------
163+
164+
procedure Process_File_Or_Dir_Switch
165+
(Args : String_Vectors.Vector;
166+
Orig_Switch : String;
167+
Process_Dir_Entry : access procedure
168+
(Dir : Ada.Directories.Directory_Entry_Type);
169+
Process_Arg : access procedure (Exp_Arg : String);
170+
Pattern : String := "")
171+
is
172+
use Ada.Directories;
173+
use US;
174+
begin
175+
for Arg of Args loop
176+
177+
-- The argument is either a directory or a file / response file when
178+
-- prefixed with a '@'.
179+
180+
-- First, deal with the case when it is a directory.
181+
182+
if US.Element (Arg, Length (Arg)) in '/' | '\' then
183+
declare
184+
Path : constant String := +Arg;
185+
S : Search_Type;
186+
Dir_Entry : Directory_Entry_Type;
187+
begin
188+
if Kind (Path) = Directory then
189+
Start_Search
190+
(Search => S,
191+
Directory => Path,
192+
Pattern => Pattern,
193+
Filter => (Ordinary_File => True, others => False));
194+
195+
while More_Entries (S) loop
196+
Get_Next_Entry (S, Dir_Entry);
197+
Process_Dir_Entry (Dir_Entry);
198+
end loop;
199+
End_Search (S);
200+
else
201+
Outputs.Warn
202+
("Skipping processing of " & Orig_Switch & " argument "
203+
& Path & ". Expecting a directory but got a "
204+
& Ada.Directories.File_Kind'Image (Kind (Path)) & ".");
205+
end if;
206+
end;
207+
else
208+
for Exp_Arg of Expand_Argument (+Arg) loop
209+
Process_Arg (+Exp_Arg);
210+
end loop;
211+
end if;
212+
end loop;
213+
end Process_File_Or_Dir_Switch;
214+
161215
----------------------
162216
-- Load_Dump_Config --
163217
----------------------

tools/gnatcov/switches.ads

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
------------------------------------------------------------------------------
1818

1919
with Ada.Containers.Indefinite_Ordered_Maps;
20+
with Ada.Directories;
2021
with Ada.Exceptions;
2122

2223
with GNAT.Strings; use GNAT.Strings;
@@ -99,6 +100,25 @@ package Switches is
99100
-- expanding arguments that start with '@' according to rules described in
100101
-- Inputs.Expand_Argument.
101102

103+
procedure Process_File_Or_Dir_Switch
104+
(Args : String_Vectors.Vector;
105+
Orig_Switch : String;
106+
Process_Dir_Entry : access procedure
107+
(Dir : Ada.Directories.Directory_Entry_Type);
108+
Process_Arg : access procedure (Exp_Arg : String);
109+
Pattern : String := "");
110+
-- This procedure is dedicated to switches accepting a list of files, e.g.
111+
-- --trace, which are either to be passed as an explicit list of files /
112+
-- response file, or as a directory (thus ending with a directory
113+
-- separator) containing a list of files.
114+
--
115+
-- Args is the list of arguments, Orig_Switch is the name of the switch
116+
-- for proper error messaging. Process_Dir_Entry processes a directory
117+
-- entry belonging to one of the directory arguments. Process_Arg processes
118+
-- a file explicitly passed on the command line / response file (expanded).
119+
-- If not empty, Pattern is the file pattern to look for in directory
120+
-- arguments.
121+
102122
----------------------------
103123
-- Miscellaneous switches --
104124
----------------------------

0 commit comments

Comments
 (0)