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