Skip to content

Commit 9d99f91

Browse files
committed
Merge branch 'topic/gnatcheck/codepeer_target' into 'master'
Fix target list parsing on Windows See merge request eng/libadalang/langkit-query-language!528
2 parents 006c1ec + 42cb143 commit 9d99f91

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

lkql_checker/src/gnatcheck-compiler.adb

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
--
55

66
with Ada.Characters.Handling; use Ada.Characters.Handling;
7-
with Ada.Characters.Latin_1;
87
with Ada.Containers;
98
with Ada.Directories; use Ada.Directories;
109
with Ada.Strings; use Ada.Strings;
@@ -92,14 +91,14 @@ package body Gnatcheck.Compiler is
9291
-- use the ``Available_Targets`` global to avoid useless calls.
9392

9493
function Get_Available_Targets return String_Sets.Set is
95-
Res : String_Sets.Set;
96-
GPRConfig_Exec : String_Access := Locate_Exec_On_Path ("gprconfig");
97-
Args : Argument_List (1 .. 2);
98-
Return_Code : Integer := -1;
99-
Output_File : File_Descriptor;
100-
Output_File_Name : String_Access;
101-
Output_File_Content : String_Access;
102-
Split_Content : String_Vector;
94+
Res : String_Sets.Set;
95+
GPRConfig_Exec : String_Access :=
96+
Locate_Exec_On_Path ("gprconfig");
97+
Args : Argument_List (1 .. 2);
98+
Return_Code : Integer := -1;
99+
Output_File_Descriptor : File_Descriptor;
100+
Output_File_Name : String_Access;
101+
Output_File : File_Type;
103102
begin
104103
-- If no regular "gprconfig" has been found, look for the gnatsas one
105104
if GPRConfig_Exec = null then
@@ -119,7 +118,7 @@ package body Gnatcheck.Compiler is
119118
end if;
120119

121120
-- Create the temporary file to get the "gprbuild" output
122-
Create_Temp_Output_File (Output_File, Output_File_Name);
121+
Create_Temp_Output_File (Output_File_Descriptor, Output_File_Name);
123122

124123
-- Prepare the argument list
125124
Args (1) := new String'("--show-targets");
@@ -129,29 +128,29 @@ package body Gnatcheck.Compiler is
129128
Spawn
130129
(Program_Name => GPRConfig_Exec.all,
131130
Args => Args,
132-
Output_File_Descriptor => Output_File,
131+
Output_File_Descriptor => Output_File_Descriptor,
133132
Return_Code => Return_Code,
134133
Err_To_Out => False);
135134

136-
-- Parse the output to fill the result
137-
Output_File_Content := Read_File (Output_File_Name.all);
138-
Split_Content :=
139-
Split
140-
(Output_File_Content.all,
141-
Ada.Characters.Latin_1.LF,
142-
Trim_Elems => True);
143-
for I in Split_Content.First_Index + 1 .. Split_Content.Last_Index loop
144-
if Split_Content (I) /= "" then
145-
Res.Include (Split_Content (I));
146-
end if;
147-
end loop;
135+
-- Parse the output to fill the result if the return code is successful
136+
if Return_Code = 0 then
137+
Open (Output_File, In_File, Output_File_Name.all);
138+
139+
-- Skip the first header line of the result since it doesn't contain
140+
-- relevant information.
141+
Set_Line (Output_File, 2);
142+
143+
while not End_Of_File (Output_File) loop
144+
Res.Include (Get_Line (Output_File));
145+
end loop;
146+
Close (Output_File);
147+
end if;
148148

149149
-- Release allocated resources and delete the temporary file
150-
Close (Output_File);
150+
Close (Output_File_Descriptor);
151151
Delete_File (Output_File_Name.all);
152152
Free (GPRConfig_Exec);
153153
Free (Output_File_Name);
154-
Free (Output_File_Content);
155154
for I in Args'Range loop
156155
Free (Args (I));
157156
end loop;

0 commit comments

Comments
 (0)