1717
1818with Ada.Streams ;
1919with GNAT.OS_Lib ;
20+ with GNATCOLL.Traces ;
2021with GNATCOLL.VFS ;
2122
2223with LSP.GNATCOLL_Tracers ;
@@ -32,11 +33,16 @@ with Spawn.Processes;
3233with Spawn.Processes.Monitor_Loop ;
3334with Spawn.Process_Listeners ;
3435with Spawn.String_Vectors ;
36+ with VSS.Strings.Formatters.Strings ;
37+ with VSS.Strings.Templates ;
3538
3639package body LSP.Alire is
3740
3841 Trace : constant GNATCOLL_Tracers.Tracer :=
39- GNATCOLL_Tracers.Create (" ALS.ALIRE" );
42+ GNATCOLL_Tracers.Create (" ALS.ALIRE" , GNATCOLL.Traces.On);
43+
44+ Alire_Verbose : constant GNATCOLL_Tracers.Tracer :=
45+ GNATCOLL_Tracers.Create (" ALS.ALIRE.VERBOSE" , GNATCOLL.Traces.From_Config);
4046
4147 Fallback_Msg : constant VSS.Strings.Virtual_String :=
4248 " falling back to other methods to load a project" ;
@@ -61,16 +67,25 @@ package body LSP.Alire is
6167 procedure Error_Occurred (Self : in out Process_Listener; Error : Integer);
6268
6369 procedure Start_Alire
64- (ALR : String;
65- Option_1 : String;
66- Option_2 : String;
67- Root : String;
68- Error : out VSS.Strings.Virtual_String;
69- Lines : out VSS.String_Vectors.Virtual_String_Vector);
70+ (Options : VSS.String_Vectors.Virtual_String_Vector;
71+ Root : String;
72+ Error : out VSS.Strings.Virtual_String;
73+ Lines : out VSS.String_Vectors.Virtual_String_Vector);
7074
7175 Anchored : constant VSS.Regular_Expressions.Match_Options :=
7276 (VSS.Regular_Expressions.Anchored_Match => True);
7377
78+ Crate_Pattern : constant VSS.Regular_Expressions.Regular_Expression :=
79+ VSS.Regular_Expressions.To_Regular_Expression (" ^([^= ]+)=" );
80+
81+ Project_Pattern : constant VSS.Regular_Expressions.Regular_Expression :=
82+ VSS.Regular_Expressions.To_Regular_Expression
83+ (" +Project_File: ([^\n]+)" );
84+
85+ Export_Pattern : constant VSS.Regular_Expressions.Regular_Expression :=
86+ VSS.Regular_Expressions.To_Regular_Expression
87+ (" export ([^=]+)="" ([^\n]+)"" " );
88+
7489 -- ------------------
7590 -- Error_Occurred --
7691 -- ------------------
@@ -82,6 +97,22 @@ package body LSP.Alire is
8297 Self.Error := Error;
8398 end Error_Occurred ;
8499
100+ -- ---------------------------
101+ -- Conservative_Alire_Sync --
102+ -- ---------------------------
103+
104+ procedure Conservative_Alire_Sync
105+ (Root : String; Error : out VSS.Strings.Virtual_String)
106+ is
107+ Lines : VSS.String_Vectors.Virtual_String_Vector;
108+ begin
109+ Start_Alire
110+ (Options => [" --non-interactive" , " build" , " --stop-after=generation" ],
111+ Root => Root,
112+ Error => Error,
113+ Lines => Lines);
114+ end Conservative_Alire_Sync ;
115+
85116 -- -------------
86117 -- Run_Alire --
87118 -- -------------
@@ -91,39 +122,17 @@ package body LSP.Alire is
91122 Error : out VSS.Strings.Virtual_String;
92123 Project : out VSS.Strings.Virtual_String)
93124 is
94- use type GNAT.OS_Lib.String_Access;
95- use type VSS.Strings.Virtual_String;
96-
97- ALR : GNAT.OS_Lib.String_Access :=
98- GNAT.OS_Lib.Locate_Exec_On_Path (" alr" );
99-
100- Crate_Pattern : constant VSS.Regular_Expressions.Regular_Expression :=
101- VSS.Regular_Expressions.To_Regular_Expression (" ^([^= ]+)=" );
102-
103- Project_Pattern : constant VSS.Regular_Expressions.Regular_Expression :=
104- VSS.Regular_Expressions.To_Regular_Expression
105- (" +Project_File: ([^\n]+)" );
106-
107125 Lines : VSS.String_Vectors.Virtual_String_Vector;
108126 begin
109127 Project.Clear;
110128
111- if ALR = null then
112- Error :=
113- " Alire executable ('alr') not found in PATH: " & Fallback_Msg;
114- return ;
115- end if ;
116-
117129 Start_Alire
118- (ALR => ALR.all ,
119- Option_1 => " --non-interactive" ,
120- Option_2 => " show" ,
121- Root => Root,
122- Error => Error,
123- Lines => Lines);
130+ (Options => [" --non-interactive" , " show" ],
131+ Root => Root,
132+ Error => Error,
133+ Lines => Lines);
124134
125135 if not Error.Is_Empty then
126- GNAT.OS_Lib.Free (ALR);
127136 return ;
128137 end if ;
129138
@@ -176,9 +185,7 @@ package body LSP.Alire is
176185 if Project.Is_Empty then
177186 Error.Append
178187 (" No project file could be determined from the output of `alr show`:" );
179- for Line of Lines loop
180- Error.Append (Line);
181- end loop ;
188+ Error.Append (Lines.Join_Lines (VSS.Strings.LF));
182189 end if ;
183190
184191 end Determine_Alire_Project ;
@@ -192,29 +199,17 @@ package body LSP.Alire is
192199 Error : out VSS.Strings.Virtual_String;
193200 Environment : in out GPR2.Environment.Object)
194201 is
195- use type GNAT.OS_Lib.String_Access;
196- use type VSS.Strings.Virtual_String;
197-
198- ALR : GNAT.OS_Lib.String_Access :=
199- GNAT.OS_Lib.Locate_Exec_On_Path (" alr" );
200-
201- Export_Pattern : constant VSS.Regular_Expressions.Regular_Expression :=
202- VSS.Regular_Expressions.To_Regular_Expression
203- (" export ([^=]+)="" ([^\n]+)"" " );
202+ use VSS.Strings.Conversions;
204203
205204 Lines : VSS.String_Vectors.Virtual_String_Vector;
206205 begin
207206
208- if ALR = null then
209- Error := " No 'alr' in the PATH: " & Fallback_Msg;
207+ Start_Alire ([" --non-interactive" , " printenv" ], Root, Error, Lines);
208+
209+ if not Error.Is_Empty then
210210 return ;
211211 end if ;
212212
213- Start_Alire
214- (ALR.all , " --non-interactive" , " printenv" , Root, Error, Lines);
215-
216- GNAT.OS_Lib.Free (ALR);
217-
218213 -- Find variables in `alr printenv` output
219214
220215 for Line of Lines loop
@@ -225,12 +220,8 @@ package body LSP.Alire is
225220 begin
226221 if Match.Has_Match then
227222 Environment.Insert
228- (Key =>
229- VSS.Strings.Conversions.To_UTF_8_String
230- (Match.Captured (1 )),
231- Value =>
232- VSS.Strings.Conversions.To_UTF_8_String
233- (Match.Captured (2 )));
223+ (Key => To_UTF_8_String (Match.Captured (1 )),
224+ Value => To_UTF_8_String (Match.Captured (2 )));
234225 end if ;
235226 end ;
236227 end loop ;
@@ -241,33 +232,64 @@ package body LSP.Alire is
241232 -- ---------------
242233
243234 procedure Start_Alire
244- (ALR : String;
245- Option_1 : String;
246- Option_2 : String;
247- Root : String;
248- Error : out VSS.Strings.Virtual_String;
249- Lines : out VSS.String_Vectors.Virtual_String_Vector)
235+ (Options : VSS.String_Vectors.Virtual_String_Vector;
236+ Root : String;
237+ Error : out VSS.Strings.Virtual_String;
238+ Lines : out VSS.String_Vectors.Virtual_String_Vector)
250239 is
251240 use type Spawn.Process_Exit_Code;
252241 use type Spawn.Process_Exit_Status;
253242 use type Spawn.Process_Status;
254-
255- Item : aliased Process_Listener;
256- Process : Spawn.Processes.Process renames Item.Process;
257- Options : Spawn.String_Vectors.UTF_8_String_Vector;
258- Decoder : VSS.Strings.Converters.Decoders.Virtual_String_Decoder;
259- Text : VSS.Strings.Virtual_String;
243+ use type VSS.Strings.Virtual_String;
244+ use VSS.Strings.Formatters.Strings;
245+ use VSS.Strings.Conversions;
246+
247+ Item : aliased Process_Listener;
248+ Process : Spawn.Processes.Process renames Item.Process;
249+ Full_Options : VSS.String_Vectors.Virtual_String_Vector := Options;
250+ Sp_Options : Spawn.String_Vectors.UTF_8_String_Vector;
251+ Decoder : VSS.Strings.Converters.Decoders.Virtual_String_Decoder;
252+ Text : VSS.Strings.Virtual_String;
260253 begin
261- Options.Append (Option_1);
262- Options.Append (Option_2);
263- Process.Set_Arguments (Options);
254+
255+ declare
256+ use type GNAT.OS_Lib.String_Access;
257+ ALR : GNAT.OS_Lib.String_Access :=
258+ GNAT.OS_Lib.Locate_Exec_On_Path (" alr" );
259+ begin
260+ if ALR = null then
261+ Error :=
262+ " Alire executable ('alr') not found in PATH: " & Fallback_Msg;
263+ return ;
264+ end if ;
265+
266+ Process.Set_Program (ALR.all );
267+ GNAT.OS_Lib.Free (ALR);
268+ end ;
269+
270+ if Alire_Verbose.Is_Active then
271+ Full_Options.Prepend (" -v" );
272+ end if ;
273+
274+ for Op of Full_Options loop
275+ Sp_Options.Append (To_UTF_8_String (Op));
276+ end loop ;
277+
278+ Process.Set_Arguments (Sp_Options);
264279 Process.Set_Working_Directory (Root);
265- Process.Set_Program (ALR);
266280 Process.Set_Listener (Item'Unchecked_Access);
267281
268282 if Trace.Is_Active then
269- Trace.Trace
270- (" (in " & Root & " ) " & ALR & " " & Option_1 & " " & Option_2);
283+ declare
284+ Template : VSS.Strings.Templates.Virtual_String_Template :=
285+ " (in {}) {} {}" ;
286+ begin
287+ Trace.Trace_Text
288+ (Template.Format
289+ (Image (To_Virtual_String (Process.Working_Directory)),
290+ Image (To_Virtual_String (Process.Program)),
291+ Image (Full_Options.Join (" " ))));
292+ end ;
271293 end if ;
272294
273295 Process.Start;
@@ -312,7 +334,7 @@ package body LSP.Alire is
312334
313335 for Arg of Item.Process.Arguments loop
314336 Error.Append (" " );
315- Error.Append (VSS.Strings.Conversions. To_Virtual_String (Arg));
337+ Error.Append (To_Virtual_String (Arg));
316338 end loop ;
317339
318340 Error.Append (" ' failed: " );
@@ -337,8 +359,7 @@ package body LSP.Alire is
337359
338360 if Item.Error /= 0 then
339361 Error.Append
340- (VSS.Strings.Conversions.To_Virtual_String
341- (GNAT.OS_Lib.Errno_Message (Item.Error)));
362+ (To_Virtual_String (GNAT.OS_Lib.Errno_Message (Item.Error)));
342363 end if ;
343364 end if ;
344365
0 commit comments