@@ -20,13 +20,14 @@ public static class StubGenerator
20
20
/// </summary>
21
21
/// <param name="referencesPaths">The paths of the assemblies to generate stubs for.</param>
22
22
/// <param name="outputPath">The path in which to store the stubs.</param>
23
- public static void GenerateStubs ( ILogger logger , IEnumerable < string > referencesPaths , string outputPath )
23
+ public static string [ ] GenerateStubs ( ILogger logger , IEnumerable < string > referencesPaths , string outputPath )
24
24
{
25
25
var stopWatch = new System . Diagnostics . Stopwatch ( ) ;
26
26
stopWatch . Start ( ) ;
27
27
28
28
var threads = EnvironmentVariables . GetDefaultNumberOfThreads ( ) ;
29
29
30
+ using var stubPaths = new BlockingCollection < string > ( ) ;
30
31
using var references = new BlockingCollection < ( MetadataReference Reference , string Path ) > ( ) ;
31
32
32
33
Parallel . ForEach ( referencesPaths , new ParallelOptions { MaxDegreeOfParallelism = threads } , path =>
@@ -45,14 +46,16 @@ public static void GenerateStubs(ILogger logger, IEnumerable<string> referencesP
45
46
46
47
Parallel . ForEach ( references , new ParallelOptions { MaxDegreeOfParallelism = threads } , @ref =>
47
48
{
48
- StubReference ( logger , compilation , outputPath , @ref . Reference , @ref . Path ) ;
49
+ StubReference ( logger , compilation , outputPath , @ref . Reference , @ref . Path , stubPaths ) ;
49
50
} ) ;
50
51
51
52
stopWatch . Stop ( ) ;
52
53
logger . Log ( Severity . Info , $ "Stub generation took { stopWatch . Elapsed } .") ;
54
+
55
+ return stubPaths . ToArray ( ) ;
53
56
}
54
57
55
- private static void StubReference ( ILogger logger , CSharpCompilation compilation , string outputPath , MetadataReference reference , string path )
58
+ private static void StubReference ( ILogger logger , CSharpCompilation compilation , string outputPath , MetadataReference reference , string path , BlockingCollection < string > stubPaths )
56
59
{
57
60
if ( compilation . GetAssemblyOrModuleSymbol ( reference ) is not IAssemblySymbol assembly )
58
61
return ;
@@ -62,7 +65,9 @@ private static void StubReference(ILogger logger, CSharpCompilation compilation,
62
65
if ( ! assembly . Modules . Any ( m => relevantSymbol . IsRelevantNamespace ( m . GlobalNamespace ) ) )
63
66
return ;
64
67
65
- using var fileStream = new FileStream ( FileUtils . NestPaths ( logger , outputPath , path . Replace ( ".dll" , ".cs" ) ) , FileMode . Create , FileAccess . Write ) ;
68
+ var stubPath = FileUtils . NestPaths ( logger , outputPath , path . Replace ( ".dll" , ".cs" ) ) ;
69
+ stubPaths . Add ( stubPath ) ;
70
+ using var fileStream = new FileStream ( stubPath , FileMode . Create , FileAccess . Write ) ;
66
71
using var writer = new StreamWriter ( fileStream , new UTF8Encoding ( false ) ) ;
67
72
68
73
var visitor = new StubVisitor ( writer , relevantSymbol ) ;
0 commit comments