From e67bdd411ee6e6271085f522ca646106033bf2be Mon Sep 17 00:00:00 2001 From: Pranav K Date: Sat, 11 Mar 2017 17:38:30 -0800 Subject: [PATCH] Add options to build a subgraph of repos --- build/repo.targets | 10 +++++++--- tools/BuildGraph/GraphBuilder.cs | 26 +++++++++++++++++++++++++- tools/BuildGraph/Program.cs | 7 +++++-- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/build/repo.targets b/build/repo.targets index 08b47f286e..0228877720 100644 --- a/build/repo.targets +++ b/build/repo.targets @@ -152,8 +152,12 @@ + + $(DotNetPath) run -r "$(_CloneRepositoryRoot) " --graph-specs-root "$(_RestoreGraphSpecsDirectory) " "$(_BuildGraphFile)" + $(BuildGrapArgs) --start-at $(BuildGraphOf) + @@ -192,10 +196,10 @@ $(_CloneRepositoryRoot)%(Repository.Identity) - - + diff --git a/tools/BuildGraph/GraphBuilder.cs b/tools/BuildGraph/GraphBuilder.cs index 283a01e278..0cf9fc7f24 100644 --- a/tools/BuildGraph/GraphBuilder.cs +++ b/tools/BuildGraph/GraphBuilder.cs @@ -6,7 +6,7 @@ namespace BuildGraph { public static class GraphBuilder { - public static IList Generate(IList repositories) + public static IList Generate(IList 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(); + if (searchRoot != null) + { + Visit(results, searchRoot); + return results.ToList(); + } + return graphNodes.Values.ToList(); } + + private static void Visit(HashSet results, GraphNode searchRoot) + { + if (results.Add(searchRoot)) + { + foreach (var node in searchRoot.Outgoing) + { + Visit(results, node); + } + } + } } } \ No newline at end of file diff --git a/tools/BuildGraph/Program.cs b/tools/BuildGraph/Program.cs index 81d0a44de5..3271204a7c 100644 --- a/tools/BuildGraph/Program.cs +++ b/tools/BuildGraph/Program.cs @@ -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) {