@@ -77,12 +77,11 @@ package body LSP.Ada_Handlers.Alire is
77
77
-- Run_Alire --
78
78
-- -------------
79
79
80
- procedure Run_Alire
80
+ procedure Determine_Alire_Project
81
81
(Root : String;
82
82
Has_Alire : out Boolean;
83
83
Error : out VSS.Strings.Virtual_String;
84
- Project : out VSS.Strings.Virtual_String;
85
- Environment : in out GPR2.Environment.Object)
84
+ Project : out VSS.Strings.Virtual_String)
86
85
is
87
86
use type GNAT.OS_Lib.String_Access;
88
87
@@ -96,10 +95,6 @@ package body LSP.Ada_Handlers.Alire is
96
95
VSS.Regular_Expressions.To_Regular_Expression
97
96
(" +Project_File: ([^\n]+)" );
98
97
99
- Export_Pattern : constant VSS.Regular_Expressions.Regular_Expression :=
100
- VSS.Regular_Expressions.To_Regular_Expression
101
- (" export ([^=]+)="" ([^\n]+)"" " );
102
-
103
98
Lines : VSS.String_Vectors.Virtual_String_Vector;
104
99
begin
105
100
Project.Clear;
@@ -117,66 +112,64 @@ package body LSP.Ada_Handlers.Alire is
117
112
return ;
118
113
end if ;
119
114
120
- -- Find project file in `alr show` output
121
-
122
- declare
123
- First : constant VSS.Strings.Virtual_String := Lines (1 );
124
- -- We should keep copy of regexp subject string while we have a match
125
- Match : constant VSS.Regular_Expressions.Regular_Expression_Match :=
126
- Crate_Pattern.Match (First);
127
- begin
128
- if Match.Has_Match then
129
- Project := Match.Captured (1 );
130
- Project.Append (" .gpr" );
131
- end if ;
132
- end ;
133
-
115
+ -- Find project file in `alr show` output. There are several cases to cover.
116
+ --
117
+ -- If alire.toml contains a "project-files" entry providing a list of
118
+ -- projects, `alr show` prints one line per project of the pattern:
119
+ -- Project_File: ...
120
+ --
121
+ -- Otherwise `alr show` doesn't print a Project_File line and we can expect
122
+ -- there to be a project named identically to the crate name.
123
+ --
124
+ -- So the strategy below is to first use the crate name as a project
125
+ -- name, and then override it if a Project_File line is found (the first
126
+ -- one is taken).
127
+
128
+ -- When `alr show` is called in a directory where /alire/ and /config/
129
+ -- don't exist, the command auto-generates those directories and prints a
130
+ -- few lines of output before the actual crate information. So we can't
131
+ -- assume that the crate name will be on the first line.
134
132
for Line of Lines loop
135
133
declare
136
- Match : constant VSS.Regular_Expressions.Regular_Expression_Match
137
- := Project_Pattern.Match (Line, Anchored);
134
+ -- We should keep copy of regexp subject string while we have a match
135
+ Match : constant VSS.Regular_Expressions.Regular_Expression_Match :=
136
+ Crate_Pattern.Match (Line);
138
137
begin
139
138
if Match.Has_Match then
140
139
Project := Match.Captured (1 );
140
+ Project.Append (" .gpr" );
141
141
exit ;
142
142
end if ;
143
143
end ;
144
144
end loop ;
145
145
146
- if Project.Is_Empty then
147
- Error.Append (" No project file is found by alire" );
148
- end if ;
149
-
150
- -- Find variables in `alr printenv` output
151
-
152
- Start_Alire
153
- (ALR.all , " --non-interactive" , " printenv" , Root, Error, Lines);
154
-
155
- GNAT.OS_Lib.Free (ALR);
156
-
157
- -- Find variables in `alr printenv` output
158
-
146
+ -- Next check if there is a Project_File line, take the first one.
159
147
for Line of Lines loop
160
148
declare
161
149
Match : constant VSS.Regular_Expressions.Regular_Expression_Match
162
- := Export_Pattern .Match (Line, Anchored);
150
+ := Project_Pattern .Match (Line, Anchored);
163
151
begin
164
152
if Match.Has_Match then
165
- Environment.Insert
166
- (Key => VSS.Strings.Conversions.To_UTF_8_String
167
- (Match.Captured (1 )),
168
- Value => VSS.Strings.Conversions.To_UTF_8_String
169
- (Match.Captured (2 )));
153
+ Project := Match.Captured (1 );
154
+ exit ;
170
155
end if ;
171
156
end ;
172
157
end loop ;
173
- end Run_Alire ;
158
+
159
+ if Project.Is_Empty then
160
+ Error.Append (" No project file could be determined from the output of `alr show`:" );
161
+ for Line of Lines loop
162
+ Error.Append (Line);
163
+ end loop ;
164
+ end if ;
165
+
166
+ end Determine_Alire_Project ;
174
167
175
168
-- -------------
176
169
-- Run_Alire --
177
170
-- -------------
178
171
179
- procedure Run_Alire
172
+ procedure Setup_Alire_Env
180
173
(Root : String;
181
174
Has_Alire : out Boolean;
182
175
Error : out VSS.Strings.Virtual_String;
@@ -221,7 +214,7 @@ package body LSP.Ada_Handlers.Alire is
221
214
end if ;
222
215
end ;
223
216
end loop ;
224
- end Run_Alire ;
217
+ end Setup_Alire_Env ;
225
218
226
219
-- ---------------
227
220
-- Start_Alire --
0 commit comments