Skip to content

Commit 392332c

Browse files
committed
Rework the 'codepeer' target selection process
Ensuring that the codepeer target is only chose when no explicit target has been provided, and no other toolchains are available in the current PATH.
1 parent 08e7887 commit 392332c

File tree

2 files changed

+47
-13
lines changed

2 files changed

+47
-13
lines changed

lkql_checker/src/gnatcheck-compiler.adb

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,14 +1552,40 @@ package body Gnatcheck.Compiler is
15521552
--------------------------------
15531553

15541554
function Should_Use_Codepeer_Target return Boolean is
1555-
Regular_Gnatls : String_Access := Locate_Exec_On_Path ("gnatls");
15561555
begin
1556+
-- If an explicit toolchain has been provided to the tool (through the
1557+
-- CLI, the project file of the config file), we need to never fallback
1558+
-- to the codepeer target.
1559+
if Gnatcheck_Prj.Tree.Is_Defined
1560+
and then Gnatcheck_Prj.Tree.Has_Explicit_Target
1561+
then
1562+
return Ada.Strings.Unbounded."=" (Target, "codepeer") or else
1563+
Ada.Strings.Unbounded."=" (Target, "gnatsas");
1564+
end if;
1565+
15571566
-- If we could find a regular gnatls, it means there is a native
15581567
-- toolchain, that takes precedence over a potential codepeer toolchain.
1559-
if Regular_Gnatls /= null then
1560-
Free (Regular_Gnatls);
1561-
return False;
1562-
end if;
1568+
declare
1569+
Regular_Gnatls : String_Access := Locate_Exec_On_Path ("gnatls");
1570+
begin
1571+
if Regular_Gnatls /= null then
1572+
Free (Regular_Gnatls);
1573+
return False;
1574+
else
1575+
declare
1576+
Regular_Gprbuild : String_Access :=
1577+
Locate_Exec_On_Path ("gprbuild");
1578+
begin
1579+
-- If we could find a regular "gprbuild", it means there is a
1580+
-- cross toolchain available, thus we don't want to fallback on
1581+
-- the codepeer target
1582+
if Regular_Gprbuild /= null then
1583+
Free (Regular_Gprbuild);
1584+
return False;
1585+
end if;
1586+
end;
1587+
end if;
1588+
end;
15631589

15641590
-- If we couldn't, look for a codepeer toolchain.
15651591
declare
@@ -1688,7 +1714,7 @@ package body Gnatcheck.Compiler is
16881714
Args (Num_Args) := new String'("--target=" & To_String (Target));
16891715
elsif Should_Use_Codepeer_Target then
16901716
Num_Args := @ + 1;
1691-
Args (Num_Args) := new String'("--target=codepeer");
1717+
Args (Num_Args) := new String'("--target=gnatsas");
16921718
end if;
16931719
else
16941720
-- Target and runtime will be taken from config project anyway
@@ -1833,9 +1859,12 @@ package body Gnatcheck.Compiler is
18331859
Args (8) := new String'("--restricted-to-languages=ada");
18341860
Num_Args := 8;
18351861

1862+
Num_Args := @ + 1;
18361863
if Should_Use_Codepeer_Target then
1837-
Num_Args := @ + 1;
1838-
Args (Num_Args) := new String'("--target=codepeer");
1864+
Args (Num_Args) := new String'("--target=gnatsas");
1865+
else
1866+
Args (Num_Args) :=
1867+
new String'("--target=" & Ada.Strings.Unbounded.To_String (Target));
18391868
end if;
18401869

18411870
if Arg.Jobs.Get > 1 then

lkql_checker/src/gnatcheck-projects.adb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -536,11 +536,6 @@ package body Gnatcheck.Projects is
536536
use GPR2.Containers;
537537
use Ada.Strings.Unbounded;
538538
begin
539-
-- In case of autoconf, restrict to the Ada language
540-
541-
My_Project.Tree.Restrict_Autoconf_To_Languages
542-
(Language_Id_Set.To_Set (GPR2.Ada_Language));
543-
544539
-- Apply the options
545540

546541
if My_Project.Source_Prj /= null then
@@ -563,12 +558,22 @@ package body Gnatcheck.Projects is
563558

564559
if Target /= Null_Unbounded_String then
565560
Project_Options.Add_Switch (GPR2.Options.Target, To_String (Target));
561+
elsif not Gnatkp_Mode and then Should_Use_Codepeer_Target then
562+
GPR2.KB.Set_Default_Target ("gnatsas");
566563
end if;
567564

568565
if Arg.Follow_Symbolic_Links.Get then
569566
Project_Options.Add_Switch (GPR2.Options.Resolve_Links);
570567
end if;
571568

569+
-- In case of autoconf, restrict to the Ada language
570+
-- We do this just before loading the project because calling this
571+
-- procedure will set the `Tree.Is_Defined` to `True`. For now there is
572+
-- no other ways to know if a project has been loaded or not.
573+
-- (see https://gitlab.adacore-it.com/eng/gpr/gpr-issues/-/issues/627)
574+
My_Project.Tree.Restrict_Autoconf_To_Languages
575+
(Language_Id_Set.To_Set (GPR2.Ada_Language));
576+
572577
if not My_Project.Tree.Load
573578
(Project_Options,
574579
Reporter => Gpr2_Reporter,

0 commit comments

Comments
 (0)