44--
55
66with Ada.Characters.Handling ; use Ada.Characters.Handling;
7- with Ada.Characters.Latin_1 ;
87with Ada.Containers ;
98with Ada.Directories ; use Ada.Directories;
109with 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