Skip to content

Commit 5e186ed

Browse files
committed
Merge branch 'topic/gnatcheck/codepeer_fallback' into 'master'
Restrict the codepeer target fallback Closes #462 See merge request eng/libadalang/langkit-query-language!501
2 parents 78cc2aa + 392332c commit 5e186ed

File tree

4 files changed

+47
-30
lines changed

4 files changed

+47
-30
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 & 16 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,
@@ -797,17 +802,6 @@ package body Gnatcheck.Projects is
797802
GPR2.Project.Registry.Pack.Check_Attributes (+"Check");
798803
end Register_Tool_Attributes;
799804

800-
------------------------
801-
-- Set_Default_Target --
802-
------------------------
803-
804-
procedure Set_Default_Target is
805-
begin
806-
if not Gnatkp_Mode and then Should_Use_Codepeer_Target then
807-
GPR2.KB.Set_Default_Target ("codepeer");
808-
end if;
809-
end Set_Default_Target;
810-
811805
-------------------------
812806
-- Set_External_Values --
813807
-------------------------

lkql_checker/src/gnatcheck-projects.ads

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,6 @@ package Gnatcheck.Projects is
324324
-- General project file processing --
325325
-------------------------------------
326326

327-
procedure Set_Default_Target;
328-
-- If codepeer is on PATH, replaces default target with "codepeer",
329-
-- does nothing in gnatkp mode.
330-
331327
procedure Initialize_Environment;
332328
-- Initializes the environment for extracting the information from the
333329
-- project file. This includes setting the parameters specific for the

lkql_checker/src/gnatcheck_main.adb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,6 @@ begin
462462
end if;
463463
end if;
464464

465-
Gnatcheck.Projects.Set_Default_Target;
466-
467465
-- If we have the project file specified as a tool parameter, analyze it.
468466

469467
Gnatcheck.Projects.Process_Project_File (Gnatcheck_Prj);

0 commit comments

Comments
 (0)