forked from dotnet/aspnetcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the calculation of the build graph a task so we can pass metadat…
…a around
- Loading branch information
Showing
18 changed files
with
163 additions
and
304 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using RepoTools.BuildGraph; | ||
using Microsoft.Build.Framework; | ||
using Microsoft.Build.Utilities; | ||
|
||
namespace RepoTasks | ||
{ | ||
public class CalculateBuildGraph : Task | ||
{ | ||
[Required] | ||
public ITaskItem[] Repositories { get; set; } | ||
|
||
[Output] | ||
public ITaskItem[] RepositoriesToBuildInOrder { get; set; } | ||
|
||
/// <summary> | ||
/// The repository at which to root the graph at | ||
/// </summary> | ||
public string StartGraphAt { get; set; } | ||
|
||
/// <summary> | ||
/// Directory that contains the package spec files. | ||
/// </summary> | ||
[Required] | ||
public string PackageSpecsDirectory { get; set; } | ||
|
||
public override bool Execute() | ||
{ | ||
var graphSpecProvider = new DependencyGraphSpecProvider(PackageSpecsDirectory.Trim()); | ||
|
||
var repositoryPaths = Repositories.Select(r => r.GetMetadata("RepositoryPath")).ToList(); | ||
var repositories = Repository.ReadAllRepositories(repositoryPaths, graphSpecProvider); | ||
|
||
var graph = GraphBuilder.Generate(repositories, StartGraphAt); | ||
var repositoriesWithOrder = new List<(ITaskItem repository, int order)>(); | ||
foreach (var repositoryTaskItem in Repositories) | ||
{ | ||
var repositoryName = repositoryTaskItem.ItemSpec; | ||
var graphNodeRepository = graph.First(g => g.Repository.Name == repositoryName); | ||
var order = TopologicalSort.GetOrder(graphNodeRepository); | ||
repositoryTaskItem.SetMetadata("Order", order.ToString()); | ||
repositoriesWithOrder.Add((repositoryTaskItem, order)); | ||
} | ||
|
||
Log.LogMessage(MessageImportance.High, "Repository build order:"); | ||
foreach (var buildGroup in repositoriesWithOrder.GroupBy(r => r.order).OrderBy(g => g.Key)) | ||
{ | ||
var buildGroupRepos = buildGroup.Select(b => b.repository.ItemSpec); | ||
Log.LogMessage(MessageImportance.High, $"{buildGroup.Key.ToString().PadLeft(2, ' ')}: {string.Join(", ", buildGroupRepos)}"); | ||
} | ||
|
||
RepositoriesToBuildInOrder = repositoriesWithOrder | ||
.OrderBy(r => r.order) | ||
.Select(r => r.repository) | ||
.ToArray(); | ||
|
||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.IO; | ||
using NuGet.ProjectModel; | ||
|
||
namespace RepoTools.BuildGraph | ||
{ | ||
public class DependencyGraphSpecProvider | ||
{ | ||
readonly string _packageSpecDirectory; | ||
|
||
public DependencyGraphSpecProvider(string packageSpecDirectory) | ||
{ | ||
_packageSpecDirectory = packageSpecDirectory; | ||
} | ||
|
||
public DependencyGraphSpec GetDependencyGraphSpec(string repositoryName, string solutionPath) | ||
{ | ||
var outputFile = Path.Combine(_packageSpecDirectory, repositoryName, Path.GetFileName(solutionPath) + ".json"); | ||
return DependencyGraphSpec.Load(outputFile); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tools/BuildGraph/GraphNode.cs → build/tasks/BuildGraph/GraphNode.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.