@@ -20,6 +20,14 @@ interface IBuildRule
20
20
BuildScript Analyse ( Autobuilder builder , bool auto ) ;
21
21
}
22
22
23
+ /// <summary>
24
+ /// Exception indicating that environment variables are missing or invalid.
25
+ /// </summary>
26
+ class InvalidEnvironmentException : Exception
27
+ {
28
+ public InvalidEnvironmentException ( string m ) : base ( m ) { }
29
+ }
30
+
23
31
/// <summary>
24
32
/// Main application logic, containing all data
25
33
/// gathered from the project and filesystem.
@@ -69,7 +77,7 @@ public class Autobuilder
69
77
/// List of project/solution files to build.
70
78
/// </summary>
71
79
public IList < IProjectOrSolution > ProjectsOrSolutionsToBuild => projectsOrSolutionsToBuildLazy . Value ;
72
- readonly Lazy < IList < IProjectOrSolution > > projectsOrSolutionsToBuildLazy ;
80
+ private readonly Lazy < IList < IProjectOrSolution > > projectsOrSolutionsToBuildLazy ;
73
81
74
82
/// <summary>
75
83
/// Holds if a given path was found.
@@ -129,7 +137,7 @@ public Autobuilder(IBuildActions actions, AutobuildOptions options)
129
137
130
138
projectsOrSolutionsToBuildLazy = new Lazy < IList < IProjectOrSolution > > ( ( ) =>
131
139
{
132
- List < IProjectOrSolution > ret ;
140
+ List < IProjectOrSolution > ? ret ;
133
141
if ( options . Solution . Any ( ) )
134
142
{
135
143
ret = new List < IProjectOrSolution > ( ) ;
@@ -143,7 +151,7 @@ public Autobuilder(IBuildActions actions, AutobuildOptions options)
143
151
return ret ;
144
152
}
145
153
146
- IEnumerable < IProjectOrSolution > FindFiles ( string extension , Func < string , ProjectOrSolution > create )
154
+ IEnumerable < IProjectOrSolution > ? FindFiles ( string extension , Func < string , ProjectOrSolution > create )
147
155
{
148
156
var matchingFiles = GetExtensions ( extension ) .
149
157
Select ( p => ( ProjectOrSolution : create ( p . Item1 ) , DistanceFromRoot : p . Item2 ) ) .
@@ -178,18 +186,39 @@ IEnumerable<IProjectOrSolution> FindFiles(string extension, Func<string, Project
178
186
179
187
CodeQLExtractorCSharpRoot = Actions . GetEnvironmentVariable ( "CODEQL_EXTRACTOR_CSHARP_ROOT" ) ;
180
188
181
- CodeQLJavaHome = Actions . GetEnvironmentVariable ( "CODEQL_JAVA_HOME" ) ;
182
-
183
189
SemmleDist = Actions . GetEnvironmentVariable ( "SEMMLE_DIST" ) ;
184
190
191
+ CodeQLJavaHome = Actions . GetEnvironmentVariable ( "CODEQL_JAVA_HOME" ) ;
192
+
185
193
SemmleJavaHome = Actions . GetEnvironmentVariable ( "SEMMLE_JAVA_HOME" ) ;
186
194
195
+ if ( CodeQLJavaHome is null && SemmleJavaHome is null )
196
+ throw new InvalidEnvironmentException ( "The environment variables CODEQL_JAVA_HOME and SEMMLE_JAVA_HOME have not been set." ) ;
197
+
187
198
SemmlePlatformTools = Actions . GetEnvironmentVariable ( "SEMMLE_PLATFORM_TOOLS" ) ;
188
199
189
- if ( CodeQLExtractorCSharpRoot == null && SemmleDist == null )
190
- Log ( Severity . Error , "The environment variables CODEQL_EXTRACTOR_CSHARP_ROOT and SEMMLE_DIST have not been set." ) ;
200
+ if ( CodeQLExtractorCSharpRoot is null && SemmleDist is null )
201
+ throw new InvalidEnvironmentException ( "The environment variables CODEQL_EXTRACTOR_CSHARP_ROOT and SEMMLE_DIST have not been set." ) ;
202
+
203
+ var trapDir = Actions . GetEnvironmentVariable ( "CODEQL_EXTRACTOR_CSHARP_TRAP_DIR" ) ?? Actions . GetEnvironmentVariable ( "TRAP_FOLDER" ) ;
204
+
205
+ if ( trapDir is null )
206
+ throw new InvalidEnvironmentException ( "The environment variables CODEQL_EXTRACTOR_CSHARP_TRAP_DIR and TRAP_FOLDER have not been set." ) ;
207
+
208
+ TrapDir = trapDir ;
209
+
210
+ var sourceArchiveDir = Actions . GetEnvironmentVariable ( "CODEQL_EXTRACTOR_CSHARP_SOURCE_ARCHIVE_DIR" ) ?? Actions . GetEnvironmentVariable ( "SOURCE_ARCHIVE" ) ;
211
+
212
+ if ( sourceArchiveDir is null )
213
+ throw new InvalidEnvironmentException ( "The environment variables CODEQL_EXTRACTOR_CSHARP_SOURCE_ARCHIVE_DIR and SOURCE_ARCHIVE have not been set." ) ;
214
+
215
+ SourceArchiveDir = sourceArchiveDir ;
191
216
}
192
217
218
+ private string TrapDir { get ; }
219
+
220
+ private string SourceArchiveDir { get ; }
221
+
193
222
readonly ILogger logger = new ConsoleLogger ( Verbosity . Info ) ;
194
223
195
224
/// <summary>
@@ -271,9 +300,9 @@ BuildScript CheckExtractorRun(bool warnOnFailure) =>
271
300
break ;
272
301
case CSharpBuildStrategy . Auto :
273
302
var cleanTrapFolder =
274
- BuildScript . DeleteDirectory ( Actions . GetEnvironmentVariable ( "CODEQL_EXTRACTOR_CSHARP_TRAP_DIR" ) ?? Actions . GetEnvironmentVariable ( "TRAP_FOLDER" ) ) ;
303
+ BuildScript . DeleteDirectory ( TrapDir ) ;
275
304
var cleanSourceArchive =
276
- BuildScript . DeleteDirectory ( Actions . GetEnvironmentVariable ( "CODEQL_EXTRACTOR_CSHARP_SOURCE_ARCHIVE_DIR" ) ?? Actions . GetEnvironmentVariable ( "SOURCE_ARCHIVE" ) ) ;
305
+ BuildScript . DeleteDirectory ( SourceArchiveDir ) ;
277
306
var tryCleanExtractorArgsLogs =
278
307
BuildScript . Create ( actions =>
279
308
{
@@ -376,38 +405,43 @@ BuildScript AutobuildFailure() =>
376
405
/// <summary>
377
406
/// Value of CODEQL_EXTRACTOR_CSHARP_ROOT environment variable.
378
407
/// </summary>
379
- public string CodeQLExtractorCSharpRoot { get ; private set ; }
408
+ private string ? CodeQLExtractorCSharpRoot { get ; }
380
409
381
410
/// <summary>
382
411
/// Value of CODEQL_JAVA_HOME environment variable.
383
412
/// </summary>
384
- public string CodeQLJavaHome { get ; private set ; }
413
+ private string ? CodeQLJavaHome { get ; }
385
414
386
415
/// <summary>
387
416
/// Value of SEMMLE_DIST environment variable.
388
417
/// </summary>
389
- public string SemmleDist { get ; private set ; }
418
+ private string ? SemmleDist { get ; }
419
+
420
+ public string Distribution => CodeQLExtractorCSharpRoot ?? SemmleDist ! ;
421
+
422
+ public string JavaHome => CodeQLJavaHome ?? SemmleJavaHome ! ;
390
423
391
424
/// <summary>
392
425
/// Value of SEMMLE_JAVA_HOME environment variable.
393
426
/// </summary>
394
- public string SemmleJavaHome { get ; private set ; }
427
+ public string ? SemmleJavaHome { get ; private set ; }
395
428
396
429
/// <summary>
397
430
/// Value of SEMMLE_PLATFORM_TOOLS environment variable.
398
431
/// </summary>
399
- public string SemmlePlatformTools { get ; private set ; }
432
+ public string ? SemmlePlatformTools { get ; private set ; }
400
433
401
434
/// <summary>
402
435
/// The absolute path of the odasa executable.
436
+ /// null if we are running in CodeQL.
403
437
/// </summary>
404
- public string Odasa => SemmleDist == null ? null : Actions . PathCombine ( SemmleDist , "tools" , "odasa" ) ;
438
+ public string ? Odasa => SemmleDist is null ? null : Actions . PathCombine ( SemmleDist , "tools" , "odasa" ) ;
405
439
406
440
/// <summary>
407
441
/// Construct a command that executed the given <paramref name="cmd"/> wrapped in
408
442
/// an <code>odasa --index</code>, unless indexing has been disabled, in which case
409
443
/// <paramref name="cmd"/> is run directly.
410
444
/// </summary>
411
- internal CommandBuilder MaybeIndex ( CommandBuilder builder , string cmd ) => Options . Indexing ? builder . IndexCommand ( Odasa , cmd ) : builder . RunCommand ( cmd ) ;
445
+ internal CommandBuilder MaybeIndex ( CommandBuilder builder , string cmd ) => Options . Indexing && ! ( Odasa is null ) ? builder . IndexCommand ( Odasa , cmd ) : builder . RunCommand ( cmd ) ;
412
446
}
413
447
}
0 commit comments