2
2
using System . Collections . Generic ;
3
3
using System . IO ;
4
4
using System . Linq ;
5
- using System . Runtime . InteropServices ;
6
- using Semmle . Util ;
7
5
using Semmle . Extraction . CSharp . Standalone ;
8
6
using System . Threading . Tasks ;
9
- using System . Collections . Concurrent ;
10
7
11
8
namespace Semmle . BuildAnalyser
12
9
{
@@ -47,18 +44,18 @@ interface IBuildAnalysis
47
44
/// </summary>
48
45
class BuildAnalysis : IBuildAnalysis
49
46
{
50
- readonly AssemblyCache assemblyCache ;
51
- readonly NugetPackages nuget ;
52
- readonly IProgressMonitor progressMonitor ;
53
- HashSet < string > usedReferences = new HashSet < string > ( ) ;
54
- readonly HashSet < string > usedSources = new HashSet < string > ( ) ;
55
- readonly HashSet < string > missingSources = new HashSet < string > ( ) ;
56
- readonly Dictionary < string , string > unresolvedReferences = new Dictionary < string , string > ( ) ;
57
- readonly DirectoryInfo sourceDir ;
58
- int failedProjects , succeededProjects ;
59
- readonly string [ ] allSources ;
60
- int conflictedReferences = 0 ;
61
- object mutex = new object ( ) ;
47
+ private readonly AssemblyCache assemblyCache ;
48
+ private readonly NugetPackages nuget ;
49
+ private readonly IProgressMonitor progressMonitor ;
50
+ private HashSet < string > usedReferences = new HashSet < string > ( ) ;
51
+ private readonly HashSet < string > usedSources = new HashSet < string > ( ) ;
52
+ private readonly HashSet < string > missingSources = new HashSet < string > ( ) ;
53
+ private readonly Dictionary < string , string > unresolvedReferences = new Dictionary < string , string > ( ) ;
54
+ private readonly DirectoryInfo sourceDir ;
55
+ private int failedProjects , succeededProjects ;
56
+ private readonly string [ ] allSources ;
57
+ private int conflictedReferences = 0 ;
58
+ private readonly object mutex = new object ( ) ;
62
59
63
60
/// <summary>
64
61
/// Performs a C# build analysis.
@@ -80,7 +77,7 @@ public BuildAnalysis(Options options, IProgressMonitor progress)
80
77
ToArray ( ) ;
81
78
82
79
var dllDirNames = options . DllDirs . Select ( Path . GetFullPath ) . ToList ( ) ;
83
- PackageDirectory = TemporaryDirectory . CreateTempDirectory ( sourceDir . FullName , progressMonitor ) ;
80
+ PackageDirectory = TemporaryDirectory . CreateTempDirectory ( sourceDir . FullName ) ;
84
81
85
82
if ( options . UseNuGet )
86
83
{
@@ -102,6 +99,7 @@ public BuildAnalysis(Options options, IProgressMonitor progress)
102
99
}
103
100
104
101
{
102
+ // These files can sometimes prevent `dotnet restore` from working correctly.
105
103
using var renamer1 = new FileRenamer ( sourceDir . GetFiles ( "global.json" , SearchOption . AllDirectories ) ) ;
106
104
using var renamer2 = new FileRenamer ( sourceDir . GetFiles ( "Directory.Build.props" , SearchOption . AllDirectories ) ) ;
107
105
@@ -118,12 +116,6 @@ public BuildAnalysis(Options options, IProgressMonitor progress)
118
116
usedReferences = new HashSet < string > ( assemblyCache . AllAssemblies . Select ( a => a . Filename ) ) ;
119
117
}
120
118
121
- if ( ! options . AnalyseCsProjFiles )
122
- {
123
- usedReferences = new HashSet < string > ( assemblyCache . AllAssemblies . Select ( a => a . Filename ) ) ;
124
- }
125
-
126
-
127
119
ResolveConflicts ( ) ;
128
120
129
121
if ( options . UseMscorlib )
@@ -150,9 +142,8 @@ public BuildAnalysis(Options options, IProgressMonitor progress)
150
142
UnresolvedReferences . Count ( ) ,
151
143
conflictedReferences ,
152
144
succeededProjects + failedProjects ,
153
- failedProjects ) ;
154
-
155
- Console . WriteLine ( $ "Build analysis completed in { DateTime . Now - startTime } ") ;
145
+ failedProjects ,
146
+ DateTime . Now - startTime ) ;
156
147
}
157
148
158
149
/// <summary>
@@ -285,7 +276,7 @@ void AnalyseProject(FileInfo project)
285
276
286
277
try
287
278
{
288
- var csProj = new CsProjFile ( project ) ;
279
+ IProjectFile csProj = new CsProjFile ( project ) ;
289
280
290
281
foreach ( var @ref in csProj . References )
291
282
{
@@ -329,8 +320,16 @@ public void Cleanup()
329
320
void Restore ( string projectOrSolution )
330
321
{
331
322
int exit = DotNet . RestoreToDirectory ( projectOrSolution , PackageDirectory . DirInfo . FullName ) ;
332
- if ( exit != 0 )
333
- progressMonitor . CommandFailed ( "dotnet" , $ "restore \" { projectOrSolution } \" ", exit ) ;
323
+ switch ( exit )
324
+ {
325
+ case 0 :
326
+ case 1 :
327
+ // No errors
328
+ break ;
329
+ default :
330
+ progressMonitor . CommandFailed ( "dotnet" , $ "restore \" { projectOrSolution } \" ", exit ) ;
331
+ break ;
332
+ }
334
333
}
335
334
336
335
public void RestoreSolutions ( IEnumerable < string > solutions )
0 commit comments