Skip to content

Commit a46f965

Browse files
committed
setup_rts: Do not require a runtime project when Ada is disabled
Gnatcov required a runtime to be available when loading gnatcov_rts.gpr in order to be able to choose an appropriate RTS profile. This is not possible when Ada is not in the list of available languages. This commit lifts the runtime requirement and adds a fallback strategy for when Ada is unavailable, consisting in selecting a full runtime for the native case, and an embedded runtime for cross targets. Change-Id: I3eacf3eee4341565e9ece2ee9eff3ba34d2ce9b7 TN: V913-008
1 parent 252ef02 commit a46f965

File tree

1 file changed

+36
-8
lines changed

1 file changed

+36
-8
lines changed

tools/gnatcov/setup_rts.adb

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -433,19 +433,26 @@ package body Setup_RTS is
433433
-- Print all messages in verbose mode, and all but the Information ones
434434
-- otherwise. Abort on error, or if we failed to get a runtime project
435435
-- (when we cannot find a toolchain, GPR2 only emits warnings).
436+
--
437+
-- C-only projects do not require a runtime, so do not complain if there
438+
-- is no runtime project in this case.
436439

437440
declare
438441
Logs : constant access GPR2.Log.Object := Prj.Log_Messages;
439442
Has_Error : constant Boolean :=
440-
Logs.Has_Error or else not Prj.Has_Runtime_Project;
443+
Logs.Has_Error
444+
or else (Has_Ada and then not Prj.Has_Runtime_Project);
441445
begin
442446
Logs.Output_Messages (Information => Verbose);
443447
if Has_Error then
444448
Fatal_Error ("Could not load the coverage runtime project file");
445449
end if;
446450
end;
447451

448-
Actual_RTS := To_Unbounded_String (String (Prj.Runtime (Main_Language)));
452+
Actual_RTS :=
453+
(if Prj.Has_Runtime_Project
454+
then To_Unbounded_String (String (Prj.Runtime (Main_Language)))
455+
else Null_Unbounded_String);
449456

450457
-- In verbose mode, show the actual names for the target and the runtime
451458
-- that GPR2 uses. They can be slightly different from the names users
@@ -461,14 +468,35 @@ package body Setup_RTS is
461468
-- "full" is to look for an Ada source file that is typically found in
462469
-- full runtime: "a-comlin.ads" for the Ada.Command_Line unit. If we do
463470
-- not have it, consider that the runtime is embedded.
471+
--
472+
-- When only C is enabled and we do not have a runtime at hand to guess
473+
-- what is available, fall back to the full profile for native
474+
-- applications and the embedded runtime otherwise.
464475

465476
Auto_RTS_Profile := Embedded;
466-
for F of Prj.Runtime_Project.Sources loop
467-
if F.Path_Name.Simple_Name = "a-comlin.ads" then
468-
Auto_RTS_Profile := Full;
469-
exit;
470-
end if;
471-
end loop;
477+
if Has_Ada then
478+
for F of Prj.Runtime_Project.Sources loop
479+
if F.Path_Name.Simple_Name = "a-comlin.ads" then
480+
Auto_RTS_Profile := Full;
481+
exit;
482+
end if;
483+
end loop;
484+
else
485+
declare
486+
use GPR2;
487+
Tool_Name : constant Name_Type := "gcc";
488+
begin
489+
-- Add_Tool_Prefix's documentation states that the tool name is
490+
-- returned unchanged for native compilation, so use this as a
491+
-- proxy to determine if we are setting up the gnatcov RTS for
492+
-- a cross target or not.
493+
494+
Auto_RTS_Profile :=
495+
(if Tool_Name = Prj.Add_Tool_Prefix (Tool_Name)
496+
then Full
497+
else Embedded);
498+
end;
499+
end if;
472500

473501
-- Query the support for libraries in this configuration. When GPRconfig
474502
-- fails to find the toolchain for the requested target/RTS, it only

0 commit comments

Comments
 (0)