Add options to build a subgraph of repos
This commit is contained in:
parent
f639d9f124
commit
e67bdd411e
|
|
@ -152,8 +152,12 @@
|
|||
</Target>
|
||||
|
||||
<Target Name="_GenerateBuildGraph" DependsOnTargets="_FindDotNetPath">
|
||||
<PropertyGroup>
|
||||
<BuildGrapArgs>$(DotNetPath) run -r "$(_CloneRepositoryRoot) " --graph-specs-root "$(_RestoreGraphSpecsDirectory) " "$(_BuildGraphFile)"</BuildGrapArgs>
|
||||
<BuildGrapArgs Condition="'$(BuildGraphOf)'!=''">$(BuildGrapArgs) --start-at $(BuildGraphOf)</BuildGrapArgs>
|
||||
</PropertyGroup>
|
||||
<Exec
|
||||
Command="$(DotNetPath) run -r "$(_CloneRepositoryRoot) " --graph-specs-root "$(_RestoreGraphSpecsDirectory) " "$(_BuildGraphFile)""
|
||||
Command="$(BuildGrapArgs)"
|
||||
WorkingDirectory="$(RepositoryRoot)tools\BuildGraph\" />
|
||||
</Target>
|
||||
|
||||
|
|
@ -192,10 +196,10 @@
|
|||
<RepositoryCloneDirectory>$(_CloneRepositoryRoot)%(Repository.Identity)</RepositoryCloneDirectory>
|
||||
</PropertyGroup>
|
||||
|
||||
<Error Text="%(Repository.Identity) has not been cloned."
|
||||
<Warning Text="%(Repository.Identity) has not been cloned."
|
||||
Condition="!Exists('$(RepositoryCloneDirectory)')" />
|
||||
|
||||
<GetGitCommitInfo WorkingDirectory="$(RepositoryCloneDirectory)">
|
||||
<GetGitCommitInfo WorkingDirectory="$(RepositoryCloneDirectory)" Condition="Exists('$(RepositoryCloneDirectory)')">
|
||||
<Output TaskParameter="CommitHash" PropertyName="_Hash" />
|
||||
</GetGitCommitInfo>
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ namespace BuildGraph
|
|||
{
|
||||
public static class GraphBuilder
|
||||
{
|
||||
public static IList<GraphNode> Generate(IList<Repository> repositories)
|
||||
public static IList<GraphNode> Generate(IList<Repository> repositories, string root)
|
||||
{
|
||||
// Build global list of primary projects
|
||||
var primaryProjects = repositories.SelectMany(c => c.Projects)
|
||||
|
|
@ -14,9 +14,15 @@ namespace BuildGraph
|
|||
var graphNodes = repositories.Select(r => new GraphNode { Repository = r })
|
||||
.ToDictionary(r => r.Repository);
|
||||
|
||||
GraphNode searchRoot = null;
|
||||
|
||||
foreach (var project in repositories.SelectMany(r => r.AllProjects))
|
||||
{
|
||||
var thisProjectRepositoryNode = graphNodes[project.Repository];
|
||||
if (root != null && string.Equals(root, project.Repository.Name, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
searchRoot = thisProjectRepositoryNode;
|
||||
}
|
||||
|
||||
foreach (var packageDependency in project.PackageReferences)
|
||||
{
|
||||
|
|
@ -31,7 +37,25 @@ namespace BuildGraph
|
|||
}
|
||||
}
|
||||
|
||||
var results = new HashSet<GraphNode>();
|
||||
if (searchRoot != null)
|
||||
{
|
||||
Visit(results, searchRoot);
|
||||
return results.ToList();
|
||||
}
|
||||
|
||||
return graphNodes.Values.ToList();
|
||||
}
|
||||
|
||||
private static void Visit(HashSet<GraphNode> results, GraphNode searchRoot)
|
||||
{
|
||||
if (results.Add(searchRoot))
|
||||
{
|
||||
foreach (var node in searchRoot.Outgoing)
|
||||
{
|
||||
Visit(results, node);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -23,6 +23,10 @@ namespace BuildGraph
|
|||
"Directory containing package specs. (Optional)",
|
||||
CommandOptionType.SingleValue);
|
||||
|
||||
var graphRoot = app.Option("--start-at",
|
||||
"Calculate the build graph starting at the specified repo. (Optional)",
|
||||
CommandOptionType.SingleValue);
|
||||
|
||||
var outputPathArgument = app.Argument("Output path", "Output path");
|
||||
|
||||
app.OnExecute(() =>
|
||||
|
|
@ -45,7 +49,6 @@ namespace BuildGraph
|
|||
|
||||
var outputType = outputTypeOption.Value() ?? "msbuild";
|
||||
|
||||
|
||||
var graphSpecProvider = packageSpecsDirectoryOption.HasValue()
|
||||
? new DependencyGraphSpecProvider(packageSpecsDirectoryOption.Value().Trim())
|
||||
: DependencyGraphSpecProvider.Default;
|
||||
|
|
@ -55,7 +58,7 @@ namespace BuildGraph
|
|||
repositories = Repository.ReadAllRepositories(repositoriesRootOption.Value().Trim(), graphSpecProvider);
|
||||
}
|
||||
|
||||
var graph = GraphBuilder.Generate(repositories);
|
||||
var graph = GraphBuilder.Generate(repositories, graphRoot.Value());
|
||||
GraphFormatter formatter;
|
||||
switch (outputType)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue