Improve traversing performance
This commit is contained in:
parent
3472aee5c9
commit
03e698f0c2
3 changed files with 44 additions and 26 deletions
|
@ -54,6 +54,7 @@ namespace Microsoft.DotNet.Tools.Build
|
|||
BuildCommandApp args)
|
||||
{
|
||||
|
||||
List<Task<ProjectContext>> tasks = new List<Task<ProjectContext>>();
|
||||
// Set defaults based on the environment
|
||||
var settings = ProjectReaderSettings.ReadFromEnvironment();
|
||||
|
||||
|
@ -90,13 +91,14 @@ namespace Microsoft.DotNet.Tools.Build
|
|||
|
||||
foreach (var framework in selectedFrameworks)
|
||||
{
|
||||
yield return new ProjectContextBuilder()
|
||||
tasks.Add(Task.Run(() => new ProjectContextBuilder()
|
||||
.WithProjectDirectory(Path.GetDirectoryName(file))
|
||||
.WithTargetFramework(framework)
|
||||
.WithReaderSettings(settings)
|
||||
.Build();
|
||||
.Build()));
|
||||
}
|
||||
}
|
||||
return Task.WhenAll(tasks).GetAwaiter().GetResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,18 +59,19 @@ namespace Microsoft.DotNet.Tools.Build
|
|||
{
|
||||
foreach (var dependency in projectNode.Dependencies)
|
||||
{
|
||||
var context = dependency.ProjectContext;
|
||||
if (!context.ProjectFile.Files.SourceFiles.Any())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var result = Build(dependency);
|
||||
if (result == CompilationResult.Failure)
|
||||
{
|
||||
return CompilationResult.Failure;
|
||||
}
|
||||
}
|
||||
|
||||
var context = projectNode.ProjectContext;
|
||||
if (!context.ProjectFile.Files.SourceFiles.Any())
|
||||
{
|
||||
return CompilationResult.IncrementalSkip;
|
||||
}
|
||||
|
||||
if (NeedsRebuilding(projectNode))
|
||||
{
|
||||
return RunCompile(projectNode);
|
||||
|
|
|
@ -41,15 +41,17 @@ namespace Microsoft.DotNet.Tools.Build
|
|||
{
|
||||
foreach (var dependency in project.Dependencies)
|
||||
{
|
||||
var libraryDescription = lookup[dependency.Name];
|
||||
|
||||
if (libraryDescription.Identity.Type.Equals(LibraryType.Project))
|
||||
LibraryDescription libraryDescription;
|
||||
if (lookup.TryGetValue(dependency.Name, out libraryDescription))
|
||||
{
|
||||
deps.Add(TraverseProject((ProjectDescription)libraryDescription, lookup));
|
||||
}
|
||||
else
|
||||
{
|
||||
deps.AddRange(TraverseNonProject(libraryDescription, lookup));
|
||||
if (libraryDescription.Identity.Type.Equals(LibraryType.Project))
|
||||
{
|
||||
deps.Add(TraverseProject((ProjectDescription)libraryDescription, lookup));
|
||||
}
|
||||
else
|
||||
{
|
||||
deps.AddRange(TraverseNonProject(libraryDescription, lookup));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -59,21 +61,34 @@ namespace Microsoft.DotNet.Tools.Build
|
|||
|
||||
private IEnumerable<ProjectGraphNode> TraverseNonProject(LibraryDescription root, IDictionary<string, LibraryDescription> lookup)
|
||||
{
|
||||
foreach (var dependency in root.Dependencies)
|
||||
Stack<LibraryDescription> libraries = new Stack<LibraryDescription>();
|
||||
libraries.Push(root);
|
||||
while (libraries.Count > 0)
|
||||
{
|
||||
var libraryDescription = lookup[dependency.Name];
|
||||
|
||||
if (libraryDescription.Identity.Type.Equals(LibraryType.Project))
|
||||
var current = libraries.Pop();
|
||||
bool foundProject = false;
|
||||
foreach (var dependency in current.Dependencies)
|
||||
{
|
||||
yield return TraverseProject((ProjectDescription)libraryDescription, lookup);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach(var node in TraverseNonProject(libraryDescription, lookup))
|
||||
LibraryDescription libraryDescription;
|
||||
if (lookup.TryGetValue(dependency.Name, out libraryDescription))
|
||||
{
|
||||
yield return node;
|
||||
if (libraryDescription.Identity.Type.Equals(LibraryType.Project))
|
||||
{
|
||||
foundProject = true;
|
||||
yield return TraverseProject((ProjectDescription) libraryDescription, lookup);
|
||||
}
|
||||
else
|
||||
{
|
||||
libraries.Push(libraryDescription);
|
||||
}
|
||||
}
|
||||
}
|
||||
// if package didn't have any project dependencies inside remove it from lookup
|
||||
// and do not traverse anymore
|
||||
if (!foundProject)
|
||||
{
|
||||
lookup.Remove(current.Identity.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue