@@ -14,12 +14,12 @@ namespace Semmle.Extraction.CSharp
1414 public class CompilerVersion
1515 {
1616 private const string csc_rsp = "csc.rsp" ;
17- private readonly string specifiedFramework = null ;
17+ private readonly string ? specifiedFramework = null ;
1818
1919 /// <summary>
2020 /// The value specified by --compiler, or null.
2121 /// </summary>
22- public string SpecifiedCompiler
22+ public string ? SpecifiedCompiler
2323 {
2424 get ;
2525 private set ;
@@ -28,12 +28,20 @@ public string SpecifiedCompiler
2828 /// <summary>
2929 /// Why was the candidate exe rejected as a compiler?
3030 /// </summary>
31- public string SkipReason
31+ public string ? SkipReason
3232 {
3333 get ;
3434 private set ;
3535 }
3636
37+ private static readonly Dictionary < string , string > knownCompilerNames = new Dictionary < string , string >
38+ {
39+ { "csc.exe" , "Microsoft" } ,
40+ { "csc2.exe" , "Microsoft" } ,
41+ { "csc.dll" , "Microsoft" } ,
42+ { "mcs.exe" , "Novell" }
43+ } ;
44+
3745 /// <summary>
3846 /// Probes the compiler (if specified).
3947 /// </summary>
@@ -52,23 +60,21 @@ public CompilerVersion(Options options)
5260 }
5361
5462 // Reads the file details from the .exe
55- var versionInfo = FileVersionInfo . GetVersionInfo ( SpecifiedCompiler ) ;
56-
5763 var compilerDir = Path . GetDirectoryName ( SpecifiedCompiler ) ;
58- var knownCompilerNames = new Dictionary < string , string >
64+ if ( compilerDir is null )
5965 {
60- { "csc.exe" , "Microsoft" } ,
61- { "csc2.exe" , "Microsoft" } ,
62- { "csc.dll" , "Microsoft" } ,
63- { "mcs.exe" , "Novell" }
64- } ;
66+ SkipExtractionBecause ( "the compiler directory could not be retrieved" ) ;
67+ return ;
68+ }
69+
6570 var mscorlibExists = File . Exists ( Path . Combine ( compilerDir , "mscorlib.dll" ) ) ;
6671
6772 if ( specifiedFramework == null && mscorlibExists )
6873 {
6974 specifiedFramework = compilerDir ;
7075 }
7176
77+ var versionInfo = FileVersionInfo . GetVersionInfo ( SpecifiedCompiler ) ;
7278 if ( ! knownCompilerNames . TryGetValue ( versionInfo . OriginalFilename , out var vendor ) )
7379 {
7480 SkipExtractionBecause ( "the compiler name is not recognised" ) ;
@@ -114,7 +120,7 @@ public bool SkipExtraction
114120 /// <summary>
115121 /// Gets additional reference directories - the compiler directory.
116122 /// </summary>
117- public string AdditionalReferenceDirectories => SpecifiedCompiler != null ? Path . GetDirectoryName ( SpecifiedCompiler ) : null ;
123+ public string ? AdditionalReferenceDirectories => SpecifiedCompiler != null ? Path . GetDirectoryName ( SpecifiedCompiler ) : null ;
118124
119125 /// <summary>
120126 /// Adds @csc.rsp to the argument list to mimic csc.exe.
@@ -134,6 +140,6 @@ private static bool SuppressDefaultResponseFile(IEnumerable<string> args)
134140 return args . Any ( arg => new [ ] { "/noconfig" , "-noconfig" } . Contains ( arg . ToLowerInvariant ( ) ) ) ;
135141 }
136142
137- public IEnumerable < string > ArgsWithResponse { get ; }
143+ public IEnumerable < string > ArgsWithResponse { get ; } = Enumerable . Empty < string > ( ) ;
138144 }
139145}
0 commit comments