@@ -38,33 +38,65 @@ private static void CollectDependencies(IDictionary<string, LibraryExport> expor
38
38
39
39
public static HashSet < string > GetTypeBuildExclusionList ( this ProjectContext context , IDictionary < string , LibraryExport > exports )
40
40
{
41
- var acceptedExports = new HashSet < string > ( ) ;
41
+ var rootProject = context . RootProject ;
42
+ var buildExports = new HashSet < string > ( ) ;
43
+ var nonBuildExports = new HashSet < string > ( ) ;
42
44
43
- // Accept the root project, obviously :)
44
- acceptedExports . Add ( context . RootProject . Identity . Name ) ;
45
+ var nonBuildExportsToSearch = new Stack < string > ( ) ;
46
+ var buildExportsToSearch = new Stack < string > ( ) ;
45
47
46
- // Walk all dependencies, tagging exports. But don't walk through Build dependencies.
47
- CollectNonBuildDependencies ( exports , context . RootProject . Dependencies , acceptedExports ) ;
48
+ LibraryExport export ;
49
+ string exportName ;
48
50
49
- // Whatever is left in exports was brought in ONLY by a build dependency
50
- var exclusionList = new HashSet < string > ( exports . Keys ) ;
51
- exclusionList . ExceptWith ( acceptedExports ) ;
52
- return exclusionList ;
53
- }
51
+ // Root project is non-build
52
+ nonBuildExportsToSearch . Push ( rootProject . Identity . Name ) ;
53
+ nonBuildExports . Add ( rootProject . Identity . Name ) ;
54
54
55
- private static void CollectNonBuildDependencies ( IDictionary < string , LibraryExport > exports , IEnumerable < LibraryRange > dependencies , HashSet < string > acceptedExports )
56
- {
57
- foreach ( var dependency in dependencies )
55
+ // Mark down all nonbuild exports and all of their dependencies
56
+ // Mark down build exports to come back to them later
57
+ while ( nonBuildExportsToSearch . Count > 0 )
58
58
{
59
- var export = exports [ dependency . Name ] ;
60
- if ( ! dependency . Type . Equals ( LibraryDependencyType . Build ) )
59
+ exportName = nonBuildExportsToSearch . Pop ( ) ;
60
+ export = exports [ exportName ] ;
61
+
62
+ foreach ( var dependency in export . Library . Dependencies )
61
63
{
62
- acceptedExports . Add ( export . Library . Identity . Name ) ;
63
- CollectNonBuildDependencies ( exports , export . Library . Dependencies , acceptedExports ) ;
64
+ if ( ! dependency . Type . Equals ( LibraryDependencyType . Build ) )
65
+ {
66
+ if ( ! nonBuildExports . Contains ( dependency . Name ) )
67
+ {
68
+ nonBuildExportsToSearch . Push ( dependency . Name ) ;
69
+ nonBuildExports . Add ( dependency . Name ) ;
70
+ }
71
+ }
72
+ else
73
+ {
74
+ buildExportsToSearch . Push ( dependency . Name ) ;
75
+ }
64
76
}
65
77
}
66
- }
67
78
79
+ // Go through exports marked build and their dependencies
80
+ // For Exports not marked as non-build, mark them down as build
81
+ while ( buildExportsToSearch . Count > 0 )
82
+ {
83
+ exportName = buildExportsToSearch . Pop ( ) ;
84
+ export = exports [ exportName ] ;
85
+
86
+ buildExports . Add ( exportName ) ;
87
+
88
+ foreach ( var dependency in export . Library . Dependencies )
89
+ {
90
+ if ( ! nonBuildExports . Contains ( dependency . Name ) )
91
+ {
92
+ buildExportsToSearch . Push ( dependency . Name ) ;
93
+ }
94
+ }
95
+ }
96
+
97
+ return buildExports ;
98
+ }
99
+
68
100
public static IEnumerable < LibraryExport > FilterExports ( this IEnumerable < LibraryExport > exports , HashSet < string > exclusionList )
69
101
{
70
102
return exports . Where ( e => ! exclusionList . Contains ( e . Library . Identity . Name ) ) ;
0 commit comments