Skip to content

Commit e73ce94

Browse files
committed
instrumentation: do not instrument main from project dependencies
This is consistent with gprbuild behavior.
1 parent 94f8dff commit e73ce94

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
procedure Main is
2+
begin
3+
null;
4+
end Main;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
with Main;
2+
3+
procedure Main_Root is
4+
begin
5+
Main;
6+
end Main_Root;
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
Regression testcase: checks that gnatcov correctly deals with mains in
3+
dependency projects. It used to crash when there was a main in one of the
4+
dependencies. The correct behavior should be not instrumenting them as a main.
5+
"""
6+
7+
import os.path
8+
9+
from SCOV.minicheck import build_run_and_coverage
10+
from SUITE.context import thistest
11+
from SUITE.cutils import Wdir
12+
from SUITE.gprutils import GPRswitches
13+
from SUITE.tutils import gprfor
14+
15+
tmp = Wdir('tmp_')
16+
17+
main_prj = gprfor(srcdirs=[os.path.join("..", "src-main-dep")],
18+
prjid="main_dep", mains=["main.adb"], objdir="obj-main")
19+
root_prj = gprfor(srcdirs=[os.path.join("..", "src")], deps=[main_prj],
20+
mains=["main_root.adb"], objdir="obj")
21+
22+
# This also checks that we do not produce multiple traces
23+
build_run_and_coverage(
24+
gprsw=GPRswitches(root_project=root_prj),
25+
covlevel='stmt',
26+
mains=["main_root"],
27+
extra_coverage_args=["-axcov"],
28+
)
29+
30+
thistest.result()

Diff for: tools/gnatcov/project.adb

+2-1
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,8 @@ package body Project is
14311431
-- Start of processing for Enumerate_Mains
14321432

14331433
begin
1434-
Iterate_Projects (Root_Project, Enumerate_Mains'Access, True);
1434+
Iterate_Projects
1435+
(Root_Project, Enumerate_Mains'Access, Recursive => False);
14351436
return Result : Main_Source_File_Array (Mains.First_Index
14361437
.. Mains.Last_Index)
14371438
do

0 commit comments

Comments
 (0)