diff --git a/NuGet.config b/NuGet.config index e32bddfd..cec9479a 100644 --- a/NuGet.config +++ b/NuGet.config @@ -2,6 +2,11 @@ - + + diff --git a/build/GenerateCode.targets b/build/GenerateCode.targets deleted file mode 100644 index 069e358a..00000000 --- a/build/GenerateCode.targets +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - diff --git a/build/buildorder.props b/build/buildorder.props index e76dcda5..ca08cb52 100644 --- a/build/buildorder.props +++ b/build/buildorder.props @@ -16,22 +16,22 @@ - + - + - + - + diff --git a/build/repo.targets b/build/repo.targets index a379d87a..f842e896 100644 --- a/build/repo.targets +++ b/build/repo.targets @@ -5,10 +5,7 @@ - - - - + $(IntermediateDir)dependencies.g.props @@ -226,12 +223,6 @@ - - <_UndeclaredPackageArtifact Include="%(ArtifactInfo.PackageId)" Condition="'%(ArtifactInfo.ArtifactType)' == 'NuGetPackage'" /> <_UndeclaredPackageArtifact Remove="@(PackageArtifact)" /> @@ -240,16 +231,6 @@ - - - - - diff --git a/build/tasks/AnalyzeBuildGraph.cs b/build/tasks/AnalyzeBuildGraph.cs deleted file mode 100644 index fac4914f..00000000 --- a/build/tasks/AnalyzeBuildGraph.cs +++ /dev/null @@ -1,294 +0,0 @@ -// 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.IO; -using System.Linq; -using System.Text; -using System.Threading; -using Microsoft.Build.Framework; -using Microsoft.Build.Utilities; -using NuGet.Versioning; -using RepoTasks.ProjectModel; -using RepoTasks.Utilities; -using RepoTools.BuildGraph; - -namespace RepoTasks -{ - public class AnalyzeBuildGraph : Task, ICancelableTask - { - private readonly CancellationTokenSource _cts = new CancellationTokenSource(); - - /// - /// Repositories that we are building new versions of. - /// - [Required] - public ITaskItem[] Solutions { get; set; } - - [Required] - public ITaskItem[] Artifacts { get; set; } - - [Required] - public ITaskItem[] Repositories { get; set; } - - [Required] - public ITaskItem[] Dependencies { get; set; } - - [Required] - public string Properties { get; set; } - - /// - /// The order in which to build repositories - /// - [Output] - public ITaskItem[] RepositoryBuildOrder { get; set; } - - public void Cancel() - { - _cts.Cancel(); - } - - public override bool Execute() - { - var packageArtifacts = Artifacts.Select(ArtifactInfo.Parse) - .OfType() - .Where(p => !p.IsSymbolsArtifact); - - var factory = new SolutionInfoFactory(Log, BuildEngine5); - var props = MSBuildListSplitter.GetNamedProperties(Properties); - - Log.LogMessage(MessageImportance.High, $"Beginning cross-repo analysis on {Solutions.Length} solutions. Hang tight..."); - - if (!props.TryGetValue("Configuration", out var defaultConfig)) - { - defaultConfig = "Debug"; - } - - var solutions = factory.Create(Solutions, props, defaultConfig, _cts.Token); - Log.LogMessage($"Found {solutions.Count} and {solutions.Sum(p => p.Projects.Count)} projects"); - - var policies = new Dictionary(); - foreach (var repo in Repositories) - { - policies.Add(repo.ItemSpec, Enum.Parse(repo.GetMetadata("PatchPolicy"))); - } - - foreach (var solution in solutions) - { - var repoName = Path.GetFileName(solution.Directory); - solution.PatchPolicy = policies[repoName]; - } - - if (_cts.IsCancellationRequested) - { - return false; - } - - EnsureConsistentGraph(packageArtifacts, solutions); - RepositoryBuildOrder = GetRepositoryBuildOrder(packageArtifacts, solutions.Where(s => s.ShouldBuild)); - - return !Log.HasLoggedErrors; - } - - private struct VersionMismatch - { - public SolutionInfo Solution; - public ProjectInfo Project; - public string PackageId; - public string ActualVersion; - public NuGetVersion ExpectedVersion; - } - - private void EnsureConsistentGraph(IEnumerable packages, IEnumerable solutions) - { - // ensure versions cascade - var buildPackageMap = packages.ToDictionary(p => p.PackageInfo.Id, p => p, StringComparer.OrdinalIgnoreCase); - var dependencyMap = new Dictionary>(StringComparer.OrdinalIgnoreCase); - foreach (var dep in Dependencies) - { - if (!dependencyMap.TryGetValue(dep.ItemSpec, out var versions)) - { - dependencyMap[dep.ItemSpec] = versions = new List(); - } - - versions.Add(new ExternalDependency - { - PackageId = dep.ItemSpec, - Version = dep.GetMetadata("Version"), - }); - } - - var inconsistentVersions = new List(); - - foreach (var solution in solutions) - foreach (var project in solution.Projects) - foreach (var tfm in project.Frameworks) - foreach (var dependency in tfm.Dependencies) - { - var dependencyVersion = dependency.Value.Version; - if (!buildPackageMap.TryGetValue(dependency.Key, out var package)) - { - // This dependency is not one of the packages that will be compiled by this run of Universe. - // Must match an external dependency, including its Version. - var idx = -1; - if (!dependencyMap.TryGetValue(dependency.Key, out var externalVersions) - || (idx = externalVersions.FindIndex(0, externalVersions.Count, i => i.Version == dependencyVersion)) < 0) - { - Log.LogKoreBuildError( - project.FullPath, - KoreBuildErrors.UndefinedExternalDependency, - message: $"Undefined external dependency on {dependency.Key}/{dependencyVersion}"); - } - - if (idx >= 0) - { - externalVersions[idx].IsReferenced = true; - } - continue; - } - - // This package will be created in this Universe run. - var refVersion = VersionRange.Parse(dependencyVersion); - if (refVersion.IsFloating && refVersion.Float.Satisfies(package.PackageInfo.Version)) - { - continue; - } - else if (package.PackageInfo.Version.Equals(refVersion.MinVersion)) - { - continue; - } - else if (dependencyMap.TryGetValue(dependency.Key, out var externalDependency) && - externalDependency.Any(ext => ext.Version == dependencyVersion)) - { - // Project depends on external version of this package, not the version built in Universe. That's - // fine in benchmark apps for example. - continue; - } - - var shouldCascade = (solution.PatchPolicy & PatchPolicy.CascadeVersions) != 0; - if (!solution.ShouldBuild && !solution.IsPatching && shouldCascade) - { - var repoName = Path.GetFileName(Path.GetDirectoryName(solution.FullPath)); - Log.LogError($"{repoName} should not be marked 'IsPatching=false'. Version changes in other repositories mean it should be patched to perserve cascading version upgrades."); - - } - - if (shouldCascade) - { - inconsistentVersions.Add(new VersionMismatch - { - Solution = solution, - Project = project, - PackageId = dependency.Key, - ActualVersion = dependency.Value.Version, - ExpectedVersion = package.PackageInfo.Version, - }); - } - } - - if (inconsistentVersions.Count != 0) - { - var sb = new StringBuilder(); - sb.AppendLine(); - sb.AppendLine($"Repos are inconsistent. The following projects have PackageReferences that should be updated"); - foreach (var solution in inconsistentVersions.GroupBy(p => p.Solution.FullPath)) - { - sb.Append(" - ").AppendLine(Path.GetFileName(solution.Key)); - foreach (var project in solution.GroupBy(p => p.Project.FullPath)) - { - sb.Append(" - ").AppendLine(Path.GetFileName(project.Key)); - foreach (var mismatchedReference in project) - { - sb.AppendLine($" + {mismatchedReference.PackageId}/{{{mismatchedReference.ActualVersion} => {mismatchedReference.ExpectedVersion}}}"); - } - } - } - sb.AppendLine(); - Log.LogMessage(MessageImportance.High, sb.ToString()); - Log.LogError("Package versions are inconsistent. See build log for details."); - } - - foreach (var versions in dependencyMap.Values) - { - foreach (var item in versions.Where(i => !i.IsReferenced)) - { - // See https://github.com/aspnet/Universe/wiki/Build-warning-and-error-codes#potentially-unused-external-dependency for details - Log.LogMessage(MessageImportance.Normal, $"Potentially unused external dependency: {item.PackageId}/{item.Version}. See https://github.com/aspnet/Universe/wiki/Build-warning-and-error-codes for details."); - } - } - } - - private ITaskItem[] GetRepositoryBuildOrder(IEnumerable artifacts, IEnumerable solutions) - { - var repositories = solutions.Select(s => - { - var repoName = Path.GetFileName(Path.GetDirectoryName(s.FullPath)); - var repo = new Repository(repoName) - { - RootDir = Path.GetDirectoryName(s.FullPath) - }; - - var packages = artifacts - .Where(a => string.Equals(a.RepoName, repoName, StringComparison.OrdinalIgnoreCase)) - .ToDictionary(p => p.PackageInfo.Id, p => p, StringComparer.OrdinalIgnoreCase); - - foreach (var proj in s.Projects) - { - IList projectGroup; - if (packages.ContainsKey(proj.PackageId)) - { - // this project is a package producer and consumer - packages.Remove(proj.PackageId); - projectGroup = repo.Projects; - } - else - { - // this project is a package consumer - projectGroup = repo.SupportProjects; - } - - - projectGroup.Add(new Project(proj.PackageId) - { - Repository = repo, - PackageReferences = new HashSet(proj - .Frameworks - .SelectMany(f => f.Dependencies.Keys) - .Concat(proj.Tools.Select(t => t.Id)), StringComparer.OrdinalIgnoreCase), - }); - } - - foreach (var packageId in packages.Keys) - { - // these packages are produced from something besides a csproj. e.g. .Sources packages - repo.Projects.Add(new Project(packageId) { Repository = repo }); - } - - return repo; - }).ToList(); - - var graph = GraphBuilder.Generate(repositories, Log); - var repositoriesWithOrder = new List<(ITaskItem repository, int order)>(); - foreach (var repository in repositories) - { - var graphNodeRepository = graph.FirstOrDefault(g => g.Repository.Name == repository.Name); - if (graphNodeRepository == null) - { - continue; - } - - var order = TopologicalSort.GetOrder(graphNodeRepository); - var repositoryTaskItem = new TaskItem(repository.Name); - repositoryTaskItem.SetMetadata("Order", order.ToString()); - repositoryTaskItem.SetMetadata("RootPath", repository.RootDir); - repositoriesWithOrder.Add((repositoryTaskItem, order)); - } - - return repositoriesWithOrder - .OrderBy(r => r.order) - .Select(r => r.repository) - .ToArray(); - } - } -} diff --git a/build/tasks/BuildGraph/ExternalDependency.cs b/build/tasks/BuildGraph/ExternalDependency.cs deleted file mode 100644 index 5bdc67d0..00000000 --- a/build/tasks/BuildGraph/ExternalDependency.cs +++ /dev/null @@ -1,12 +0,0 @@ -// 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. - -namespace RepoTools.BuildGraph -{ - internal class ExternalDependency - { - public string PackageId { get; set; } - public string Version { get; set; } - public bool IsReferenced { get; set; } - } -} diff --git a/build/tasks/BuildGraph/GraphBuilder.cs b/build/tasks/BuildGraph/GraphBuilder.cs deleted file mode 100644 index 355989f1..00000000 --- a/build/tasks/BuildGraph/GraphBuilder.cs +++ /dev/null @@ -1,50 +0,0 @@ -// 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.IO; -using System.Linq; -using Microsoft.Build.Utilities; - -namespace RepoTools.BuildGraph -{ - public static class GraphBuilder - { - public static IList Generate(IList repositories, TaskLoggingHelper log) - { - // Build global list of primary projects - var primaryProjects = repositories.SelectMany(c => c.Projects) - .ToDictionary(p => p.Name, StringComparer.OrdinalIgnoreCase); - var graphNodes = repositories.Select(r => new GraphNode { Repository = r }) - .ToDictionary(r => r.Repository); - - foreach (var project in repositories.SelectMany(r => r.AllProjects)) - { - var thisProjectRepositoryNode = graphNodes[project.Repository]; - - foreach (var packageDependency in project.PackageReferences) - { - if (primaryProjects.TryGetValue(packageDependency, out var dependencyProject)) - { - var dependencyRepository = dependencyProject.Repository; - var dependencyNode = graphNodes[dependencyRepository]; - - if (ReferenceEquals(thisProjectRepositoryNode, dependencyNode)) - { - log.LogWarning("{0} has a package reference to a package produced in the same repo. {1} -> {2}", project.Repository.Name, Path.GetFileName(project.Path), packageDependency); - } - else - { - thisProjectRepositoryNode.Incoming.Add(dependencyNode); - } - - dependencyNode.Outgoing.Add(thisProjectRepositoryNode); - } - } - } - - return graphNodes.Values.ToList(); - } - } -} diff --git a/build/tasks/BuildGraph/GraphNode.cs b/build/tasks/BuildGraph/GraphNode.cs deleted file mode 100644 index b7197e8b..00000000 --- a/build/tasks/BuildGraph/GraphNode.cs +++ /dev/null @@ -1,18 +0,0 @@ -// 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.Collections.Generic; -using System.Diagnostics; - -namespace RepoTools.BuildGraph -{ - [DebuggerDisplay("{Repository.Name}")] - public class GraphNode - { - public Repository Repository { get; set; } - - public ISet Incoming { get; } = new HashSet(); - - public ISet Outgoing { get; } = new HashSet(); - } -} diff --git a/build/tasks/BuildGraph/Project.cs b/build/tasks/BuildGraph/Project.cs deleted file mode 100644 index ad03468a..00000000 --- a/build/tasks/BuildGraph/Project.cs +++ /dev/null @@ -1,28 +0,0 @@ -// 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.Diagnostics; - -namespace RepoTools.BuildGraph -{ - [DebuggerDisplay("{Name}")] - public class Project - { - public Project(string name) - { - Name = name; - } - - public string Name { get; } - - public string Version { get; set; } - - public string Path { get; set; } - - public Repository Repository { get; set; } - - public ISet PackageReferences { get; set; } = new HashSet(StringComparer.OrdinalIgnoreCase); - } -} diff --git a/build/tasks/BuildGraph/Repository.cs b/build/tasks/BuildGraph/Repository.cs deleted file mode 100644 index e5bdaf41..00000000 --- a/build/tasks/BuildGraph/Repository.cs +++ /dev/null @@ -1,33 +0,0 @@ -// 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.Diagnostics; -using System.Linq; - -namespace RepoTools.BuildGraph -{ - [DebuggerDisplay("{Name}")] - public class Repository : IEquatable - { - public Repository(string name) - { - Name = name; - } - - public string Name { get; private set; } - - public string RootDir { get; set; } - - public IList Projects { get; } = new List(); - - public IList SupportProjects { get; } = new List(); - - public IEnumerable AllProjects => Projects.Concat(SupportProjects); - - public bool Equals(Repository other) => string.Equals(Name, other.Name, StringComparison.OrdinalIgnoreCase); - - public override int GetHashCode() => StringComparer.OrdinalIgnoreCase.GetHashCode(Name); - } -} diff --git a/build/tasks/BuildGraph/TopologicalSort.cs b/build/tasks/BuildGraph/TopologicalSort.cs deleted file mode 100644 index 161a9913..00000000 --- a/build/tasks/BuildGraph/TopologicalSort.cs +++ /dev/null @@ -1,46 +0,0 @@ -// 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; - -namespace RepoTools.BuildGraph -{ - public class TopologicalSort : IComparer - { - public static readonly TopologicalSort Instance = new TopologicalSort(); - - public int Compare(GraphNode x, GraphNode y) - { - var xScore = GetOrder(x); - var yScore = GetOrder(y); - return xScore.CompareTo(yScore); - } - - public static int GetOrder(GraphNode node) - { - var visited = new List(); - return GetOrder(node, visited); - } - - private static int GetOrder(GraphNode node, List visited) - { - if (visited.Contains(node)) - { - var cycle = string.Join(" -> ", visited.Select(v => v.Repository.Name)); - throw new Exception($"Cycle detected in the build graph: {cycle} -> {node.Repository.Name}."); - } - - var score = 0; - visited.Add(node); - foreach (var dependentNode in node.Incoming) - { - score = Math.Max(score, GetOrder(dependentNode, visited)); - } - visited.RemoveAt(visited.Count - 1); - - return score + 1; - } - } -} diff --git a/build/tasks/CheckRepoGraph.cs b/build/tasks/CheckRepoGraph.cs deleted file mode 100644 index eecd3258..00000000 --- a/build/tasks/CheckRepoGraph.cs +++ /dev/null @@ -1,223 +0,0 @@ -// 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; -using System.Collections.Generic; -using System.Linq; -using System.IO; -using System.Text; -using System.Threading; -using Microsoft.Build.Framework; -using Microsoft.Build.Utilities; -using NuGet.Frameworks; -using NuGet.Packaging.Core; -using NuGet.Versioning; -using RepoTools.BuildGraph; -using RepoTasks.ProjectModel; -using RepoTasks.Utilities; - -namespace RepoTasks -{ - public class CheckRepoGraph : Task, ICancelableTask - { - private readonly CancellationTokenSource _cts = new CancellationTokenSource(); - - [Required] - public ITaskItem[] Solutions { get; set; } - - [Required] - public ITaskItem[] Artifacts { get; set; } - - [Required] - public ITaskItem[] Repositories { get; set; } - - [Required] - public string Properties { get; set; } - - public void Cancel() - { - _cts.Cancel(); - } - - public override bool Execute() - { - var packageArtifacts = Artifacts.Select(ArtifactInfo.Parse) - .OfType() - .Where(p => !p.IsSymbolsArtifact) - .ToDictionary(p => p.PackageInfo.Id, p => p, StringComparer.OrdinalIgnoreCase); - - var factory = new SolutionInfoFactory(Log, BuildEngine5); - var props = MSBuildListSplitter.GetNamedProperties(Properties); - - if (!props.TryGetValue("Configuration", out var defaultConfig)) - { - defaultConfig = "Debug"; - } - - var solutions = factory.Create(Solutions, props, defaultConfig, _cts.Token).OrderBy(f => f.Directory).ToList(); - Log.LogMessage($"Found {solutions.Count} and {solutions.Sum(p => p.Projects.Count)} projects"); - - if (_cts.IsCancellationRequested) - { - return false; - } - - var repoGraph = new AdjacencyMatrix(solutions.Count); - var packageToProjectMap = new Dictionary(); - - for (var i = 0; i < solutions.Count; i++) - { - var sln = repoGraph[i] = solutions[i]; - - foreach (var proj in sln.Projects) - { - if (!proj.IsPackable - || proj.FullPath.Contains("samples") - || proj.FullPath.Contains("tools/Microsoft.VisualStudio.Web.CodeGeneration.Design")) - { - continue; - } - - var id = new PackageIdentity(proj.PackageId, new NuGetVersion(proj.PackageVersion)); - - if (packageToProjectMap.TryGetValue(id, out var otherProj)) - { - Log.LogError($"Both {proj.FullPath} and {otherProj.FullPath} produce {id}"); - continue; - } - - packageToProjectMap.Add(id, proj); - } - - var sharedSrc = Path.Combine(sln.Directory, "shared"); - if (Directory.Exists(sharedSrc)) - { - foreach (var dir in Directory.GetDirectories(sharedSrc, "*.Sources")) - { - var id = GetDirectoryName(dir); - var artifactInfo = packageArtifacts[id]; - var sharedSrcProj = new ProjectInfo(dir, - Array.Empty(), - Array.Empty(), - true, - artifactInfo.PackageInfo.Id, - artifactInfo.PackageInfo.Version.ToNormalizedString()); - sharedSrcProj.SolutionInfo = sln; - var identity = new PackageIdentity(artifactInfo.PackageInfo.Id, artifactInfo.PackageInfo.Version); - packageToProjectMap.Add(identity, sharedSrcProj); - } - } - } - - if (Log.HasLoggedErrors) - { - return false; - } - - for (var i = 0; i < solutions.Count; i++) - { - var src = repoGraph[i]; - - foreach (var proj in src.Projects) - { - if (!proj.IsPackable - || proj.FullPath.Contains("samples")) - { - continue; - } - - foreach (var dep in proj.Frameworks.SelectMany(f => f.Dependencies.Values)) - { - if (packageToProjectMap.TryGetValue(new PackageIdentity(dep.Id, new NuGetVersion(dep.Version)), out var target)) - { - var j = repoGraph.FindIndex(target.SolutionInfo); - repoGraph.SetLink(i, j); - } - } - - foreach (var toolDep in proj.Tools) - { - if (packageToProjectMap.TryGetValue(new PackageIdentity(toolDep.Id, new NuGetVersion(toolDep.Version)), out var target)) - { - var j = repoGraph.FindIndex(target.SolutionInfo); - repoGraph.SetLink(i, j); - } - } - } - } - - var repos = Repositories.ToDictionary(i => i.ItemSpec, i => i, StringComparer.OrdinalIgnoreCase); - - for (var i = 0; i < repoGraph.Count; i++) - { - var src = repoGraph[i]; - var repoName = GetDirectoryName(src.Directory); - var repo = repos[repoName]; - - var policy = Enum.Parse(repo.GetMetadata("PatchPolicy")); - - if ((policy & PatchPolicy.AlwaysUpdate) != 0 && !src.IsPatching) - { - Log.LogError($"{repoName} is not currently set to patch, but it should because the policy is set to always include this in servicing updates. Update the configuration in submodule.props."); - continue; - } - - var srcShouldCascade = (policy & PatchPolicy.CascadeVersions) != 0; - for (var j = 0; j < repoGraph.Count; j++) - { - if (j == i) continue; - if (repoGraph.HasLink(i, j)) - { - var target = repoGraph[j]; - var targetRepoName = GetDirectoryName(target.Directory); - var targetRepo = repos[targetRepoName]; - - if (srcShouldCascade && !src.IsPatching && target.IsPatching) - { - Log.LogError($"{repoName} should be patching because it depend on {targetRepoName} and its patch policy is to cascade version changes. Update the configuration in submodule.props."); - } - } - } - } - - return !Log.HasLoggedErrors; - } - - private static string GetDirectoryName(string path) - => Path.GetFileName(path.TrimEnd(new[] { '\\', '/' })); - - private class AdjacencyMatrix - { - private readonly bool[,] _matrix; - private readonly SolutionInfo[] _items; - - public AdjacencyMatrix(int size) - { - _matrix = new bool[size, size]; - _items = new SolutionInfo[size]; - Count = size; - } - - public SolutionInfo this[int idx] - { - get => _items[idx]; - set => _items[idx] = value; - } - - public int FindIndex(SolutionInfo item) - { - return Array.FindIndex(_items, t => t.Equals(item)); - } - - public int Count { get; } - - public bool HasLink(int source, int target) => _matrix[source, target]; - - public void SetLink(int source, int target) - { - _matrix[source, target] = true; - } - } - } -} diff --git a/build/tasks/CodeGen/DirectedGraphXml.cs b/build/tasks/CodeGen/DirectedGraphXml.cs deleted file mode 100644 index e90d66ca..00000000 --- a/build/tasks/CodeGen/DirectedGraphXml.cs +++ /dev/null @@ -1,42 +0,0 @@ - -// 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.Xml.Linq; - -namespace RepoTasks.CodeGen -{ - class DirectedGraphXml - { - private readonly XNamespace _ns = "http://schemas.microsoft.com/vs/2009/dgml"; - private readonly XDocument _doc; - private readonly XElement _nodes; - private readonly XElement _links; - - public DirectedGraphXml() - { - _doc = new XDocument(new XElement(_ns + "DirectedGraph")); - _nodes = new XElement(_ns + "Nodes"); - _links = new XElement(_ns + "Links"); - _doc.Root.Add(_nodes); - _doc.Root.Add(_links); - } - - public void AddNode(string id) - { - _nodes.Add(new XElement(_ns + "Node", new XAttribute("Id", id), new XAttribute("Label", id))); - } - - public void AddLink(string source, string target) - { - _links.Add(new XElement(_ns + "Link", - new XAttribute("Source", source), - new XAttribute("Target", target))); - } - - public void Save(string path) - { - _doc.Save(path); - } - } -} diff --git a/build/tasks/CodeGen/GenerateSubmoduleGraph.cs b/build/tasks/CodeGen/GenerateSubmoduleGraph.cs deleted file mode 100644 index 7940b5cb..00000000 --- a/build/tasks/CodeGen/GenerateSubmoduleGraph.cs +++ /dev/null @@ -1,226 +0,0 @@ - -// 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; -using System.Collections.Generic; -using System.Linq; -using System.IO; -using System.Text; -using System.Threading; -using Microsoft.Build.Framework; -using Microsoft.Build.Utilities; -using NuGet.Frameworks; -using NuGet.Versioning; -using RepoTools.BuildGraph; -using RepoTasks.ProjectModel; -using RepoTasks.Utilities; -using RepoTasks.CodeGen; -using NuGet.Packaging.Core; - -namespace RepoTasks -{ - public class GenerateSubmoduleGraph : Task, ICancelableTask - { - private readonly CancellationTokenSource _cts = new CancellationTokenSource(); - - /// - /// Repositories that we are building new versions of. - /// - [Required] - public ITaskItem[] Solutions { get; set; } - - [Required] - public ITaskItem[] Artifacts { get; set; } - - [Required] - public ITaskItem[] Repositories { get; set; } - - [Required] - public string RepositoryRoot { get; set; } - - [Required] - public string Properties { get; set; } - - public void Cancel() - { - _cts.Cancel(); - } - - public override bool Execute() - { - var packageArtifacts = Artifacts.Select(ArtifactInfo.Parse) - .OfType() - .Where(p => !p.IsSymbolsArtifact) - .ToDictionary(p => p.PackageInfo.Id, p => p, StringComparer.OrdinalIgnoreCase); - - var factory = new SolutionInfoFactory(Log, BuildEngine5); - var props = MSBuildListSplitter.GetNamedProperties(Properties); - - Log.LogMessage(MessageImportance.High, $"Beginning cross-repo analysis on {Solutions.Length} solutions. Hang tight..."); - - if (!props.TryGetValue("Configuration", out var defaultConfig)) - { - defaultConfig = "Debug"; - } - - var solutions = factory.Create(Solutions, props, defaultConfig, _cts.Token).OrderBy(f => f.Directory).ToList(); - Log.LogMessage($"Found {solutions.Count} and {solutions.Sum(p => p.Projects.Count)} projects"); - - if (_cts.IsCancellationRequested) - { - return false; - } - - return GenerateGraph(packageArtifacts, solutions); - } - - private bool GenerateGraph(IDictionary packageArtifacts, IReadOnlyList solutions) - { - var repoGraph = new AdjacencyMatrix(solutions.Count); - var packageToProjectMap = new Dictionary(); - - for (var i = 0; i < solutions.Count; i++) - { - var sln = repoGraph[i] = solutions[i]; - - foreach (var proj in sln.Projects) - { - if (!proj.IsPackable || proj.FullPath.Contains("samples")) - { - continue; - } - - var id = new PackageIdentity(proj.PackageId, new NuGetVersion(proj.PackageVersion)); - - if (packageToProjectMap.TryGetValue(id, out var otherProj)) - { - Log.LogError($"Both {proj.FullPath} and {otherProj.FullPath} produce {id}"); - continue; - } - - packageToProjectMap.Add(id, proj); - } - - var sharedSrc = Path.Combine(sln.Directory, "shared"); - if (Directory.Exists(sharedSrc)) - { - foreach (var dir in Directory.GetDirectories(sharedSrc, "*.Sources")) - { - var id = Path.GetFileName(dir); - var artifactInfo = packageArtifacts[id]; - var sharedSrcProj = new ProjectInfo(dir, - Array.Empty(), - Array.Empty(), - true, - artifactInfo.PackageInfo.Id, - artifactInfo.PackageInfo.Version.ToNormalizedString()); - sharedSrcProj.SolutionInfo = sln; - var identity = new PackageIdentity(artifactInfo.PackageInfo.Id, artifactInfo.PackageInfo.Version); - packageToProjectMap.Add(identity, sharedSrcProj); - } - } - } - - if (Log.HasLoggedErrors) - { - return false; - } - - for (var i = 0; i < solutions.Count; i++) - { - var sln = repoGraph[i]; - - var deps = from proj in sln.Projects - from tfm in proj.Frameworks - from dep in tfm.Dependencies.Values - select dep; - - foreach (var dep in deps) - { - if (packageToProjectMap.TryGetValue(new PackageIdentity(dep.Id, new NuGetVersion(dep.Version)), out var target)) - { - var j = repoGraph.FindIndex(target.SolutionInfo); - repoGraph.SetLink(i, j); - } - } - - var toolDeps = from proj in sln.Projects - from tool in proj.Tools - select tool; - - foreach (var toolDep in toolDeps) - { - if (packageToProjectMap.TryGetValue(new PackageIdentity(toolDep.Id, new NuGetVersion(toolDep.Version)), out var target)) - { - var j = repoGraph.FindIndex(target.SolutionInfo); - repoGraph.SetLink(i, j); - } - } - } - - CreateDgml(repoGraph); - return !Log.HasLoggedErrors; - } - - - private void CreateDgml(AdjacencyMatrix repoGraph) - { - var dgml = new DirectedGraphXml(); - - for (var i = 0; i < repoGraph.Count; i++) - { - var node = repoGraph[i]; - var nodeName = Path.GetFileName(node.Directory); - dgml.AddNode(nodeName); - - for (var j = 0; j < repoGraph.Count; j++) - { - if (j == i) continue; - if (repoGraph.HasLink(i, j)) - { - var target = repoGraph[j]; - var targetName = Path.GetFileName(target.Directory); - dgml.AddLink(nodeName, targetName); - } - } - } - - dgml.Save(Path.Combine(RepositoryRoot, "modules", "SubmoduleGraph.dgml")); - } - - private class AdjacencyMatrix - { - private readonly bool[,] _matrix; - private readonly SolutionInfo[] _items; - - public AdjacencyMatrix(int size) - { - _matrix = new bool[size, size]; - _items = new SolutionInfo[size]; - Count = size; - } - - public SolutionInfo this[int idx] - { - get => _items[idx]; - set => _items[idx] = value; - } - - public int FindIndex(SolutionInfo item) - { - return Array.FindIndex(_items, t => t.Equals(item)); - } - - public int Count { get; } - - public bool HasLink(int source, int target) => _matrix[source, target]; - - public void SetLink(int source, int target) - { - _matrix[source, target] = true; - } - } - } -} diff --git a/build/tasks/CodeGen/RepositoryProject.cs b/build/tasks/CodeGen/RepositoryProject.cs deleted file mode 100644 index 1cb3b763..00000000 --- a/build/tasks/CodeGen/RepositoryProject.cs +++ /dev/null @@ -1,46 +0,0 @@ -// 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.IO; -using System.Text; -using Microsoft.Build.Construction; -using Microsoft.Build.Evaluation; - -namespace RepoTasks.CodeGen -{ - class RepositoryProject - { - private readonly ProjectRootElement _doc; - - public RepositoryProject(string repositoryRoot) - { - _doc = ProjectRootElement.Create(NewProjectFileOptions.None); - var import = _doc.CreateImportElement(@"$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props"); - var propGroup = _doc.AddPropertyGroup(); - if (repositoryRoot[repositoryRoot.Length - 1] != '\\') - { - repositoryRoot += '\\'; - } - propGroup.AddProperty("RepositoryRoot", repositoryRoot); - _doc.AddItemGroup(); - _doc.PrependChild(import); - _doc.AddImport(@"$(MSBuildToolsPath)\Microsoft.Common.targets"); - } - - public void AddProjectReference(string path) - { - _doc.AddItem("ProjectReference", path); - } - - public void AddProperty(string name, string value) - { - _doc.AddProperty(name, value); - } - - public void Save(string filePath) - { - _doc.Save(filePath, Encoding.UTF8); - } - } -} diff --git a/build/tasks/ProjectModel/DotNetCliReferenceInfo.cs b/build/tasks/ProjectModel/DotNetCliReferenceInfo.cs deleted file mode 100644 index c490dab9..00000000 --- a/build/tasks/ProjectModel/DotNetCliReferenceInfo.cs +++ /dev/null @@ -1,24 +0,0 @@ -// 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; - -namespace RepoTasks.ProjectModel -{ - internal class DotNetCliReferenceInfo - { - public DotNetCliReferenceInfo(string id, string version) - { - if (string.IsNullOrEmpty(id)) - { - throw new ArgumentException(nameof(id)); - } - - Id = id; - Version = version; - } - - public string Id { get; } - public string Version { get; } - } -} diff --git a/build/tasks/ProjectModel/PackageInfo.cs b/build/tasks/ProjectModel/PackageInfo.cs deleted file mode 100644 index bb499a1b..00000000 --- a/build/tasks/ProjectModel/PackageInfo.cs +++ /dev/null @@ -1,44 +0,0 @@ -// 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.IO; -using NuGet.Frameworks; -using NuGet.Packaging; -using NuGet.Versioning; - -namespace RepoTasks.ProjectModel -{ - internal class PackageInfo - { - public PackageInfo(string id, - NuGetVersion version, - IReadOnlyList dependencyGroups, - string source, - string packageType = "Dependency") - { - if (string.IsNullOrEmpty(id)) - { - throw new ArgumentException(nameof(id)); - } - - Id = id; - Version = version ?? throw new ArgumentNullException(nameof(version)); - PackageType = packageType; - Source = source; - DependencyGroups = dependencyGroups ?? Array.Empty(); - } - - public string Id { get; } - public NuGetVersion Version { get; } - public string PackageType { get; } - /// - /// Can be a https feed or a file path. May be null. - /// - public string Source { get; } - public IReadOnlyList DependencyGroups { get; } - - public override string ToString() => $"{Id}/{Version}"; - } -} diff --git a/build/tasks/ProjectModel/PackageReferenceInfo.cs b/build/tasks/ProjectModel/PackageReferenceInfo.cs deleted file mode 100644 index cea7d566..00000000 --- a/build/tasks/ProjectModel/PackageReferenceInfo.cs +++ /dev/null @@ -1,27 +0,0 @@ -// 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; - -namespace RepoTasks.ProjectModel -{ - internal class PackageReferenceInfo - { - public PackageReferenceInfo(string id, string version, bool isImplicitlyDefined) - { - if (string.IsNullOrEmpty(id)) - { - throw new ArgumentException(nameof(id)); - } - - Id = id; - Version = version; - IsImplicitlyDefined = isImplicitlyDefined; - } - - public string Id { get; } - public string Version { get; } - public bool IsImplicitlyDefined { get; } - } -} diff --git a/build/tasks/ProjectModel/PatchPolicy.cs b/build/tasks/ProjectModel/PatchPolicy.cs deleted file mode 100644 index a28451ca..00000000 --- a/build/tasks/ProjectModel/PatchPolicy.cs +++ /dev/null @@ -1,31 +0,0 @@ -// 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 NuGet.Frameworks; - -namespace RepoTasks.ProjectModel -{ - [Flags] - internal enum PatchPolicy - { - /// - /// Only produce new package versions if there were changes to product code. - /// - ProductChangesOnly = 1 << 0, - - /// - /// Packages should update in every patch. - /// - AlwaysUpdate = 1 << 1, - - /// - /// Produce new package versions if there were changes to product code, or if one of the package dependencies has updated. - /// - CascadeVersions = 1 << 2, - - AlwaysUpdateAndCascadeVersions = CascadeVersions | AlwaysUpdate, - } -} diff --git a/build/tasks/ProjectModel/ProjectFrameworkInfo.cs b/build/tasks/ProjectModel/ProjectFrameworkInfo.cs deleted file mode 100644 index 35a212f9..00000000 --- a/build/tasks/ProjectModel/ProjectFrameworkInfo.cs +++ /dev/null @@ -1,22 +0,0 @@ -// 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 NuGet.Frameworks; - -namespace RepoTasks.ProjectModel -{ - internal class ProjectFrameworkInfo - { - public ProjectFrameworkInfo(NuGetFramework targetFramework, IReadOnlyDictionary dependencies) - { - TargetFramework = targetFramework ?? throw new ArgumentNullException(nameof(targetFramework)); - Dependencies = dependencies ?? throw new ArgumentNullException(nameof(dependencies)); - } - - public NuGetFramework TargetFramework { get; } - public IReadOnlyDictionary Dependencies { get; } - } -} diff --git a/build/tasks/ProjectModel/ProjectInfo.cs b/build/tasks/ProjectModel/ProjectInfo.cs deleted file mode 100644 index 4f4b7a3a..00000000 --- a/build/tasks/ProjectModel/ProjectInfo.cs +++ /dev/null @@ -1,47 +0,0 @@ -// 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.IO; - -namespace RepoTasks.ProjectModel -{ - internal class ProjectInfo - { - public ProjectInfo(string fullPath, - IReadOnlyList frameworks, - IReadOnlyList tools, - bool isPackable, - string packageId, - string packageVersion) - { - if (!Path.IsPathRooted(fullPath)) - { - throw new ArgumentException("Path must be absolute", nameof(fullPath)); - } - - Frameworks = frameworks ?? throw new ArgumentNullException(nameof(frameworks)); - Tools = tools ?? throw new ArgumentNullException(nameof(tools)); - - FullPath = fullPath; - FileName = Path.GetFileName(fullPath); - Directory = Path.GetDirectoryName(FullPath); - IsPackable = isPackable; - PackageId = packageId; - PackageVersion = packageVersion; - } - - public string FullPath { get; } - public string FileName { get; } - public string Directory { get; } - public string PackageId { get; } - public string PackageVersion { get; } - public bool IsPackable { get; } - - public SolutionInfo SolutionInfo { get; set; } - - public IReadOnlyList Frameworks { get; } - public IReadOnlyList Tools { get; } - } -} diff --git a/build/tasks/ProjectModel/ProjectInfoFactory.cs b/build/tasks/ProjectModel/ProjectInfoFactory.cs deleted file mode 100644 index 40592f30..00000000 --- a/build/tasks/ProjectModel/ProjectInfoFactory.cs +++ /dev/null @@ -1,137 +0,0 @@ -// 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.IO; -using System.Linq; -using Microsoft.Build.Construction; -using Microsoft.Build.Evaluation; -using Microsoft.Build.Execution; -using NuGet.Frameworks; -using RepoTasks.Utilities; -using Microsoft.Build.Utilities; - -namespace RepoTasks.ProjectModel -{ - internal class ProjectInfoFactory - { - private readonly TaskLoggingHelper _logger; - - public ProjectInfoFactory(TaskLoggingHelper logger) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - } - - public ProjectInfo Create(string path, ProjectCollection projectCollection) - { - var project = GetProject(path, projectCollection); - var instance = project.CreateProjectInstance(ProjectInstanceSettings.ImmutableWithFastItemLookup); - - var targetFrameworks = instance.GetPropertyValue("TargetFrameworks"); - var targetFramework = instance.GetPropertyValue("TargetFramework"); - - var frameworks = new List(); - if (!string.IsNullOrEmpty(targetFrameworks) && string.IsNullOrEmpty(targetFramework)) - { - // multi targeting - foreach (var tfm in targetFrameworks.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)) - { - project.SetGlobalProperty("TargetFramework", tfm); - var innerBuild = project.CreateProjectInstance(ProjectInstanceSettings.ImmutableWithFastItemLookup); - - var tfmInfo = new ProjectFrameworkInfo(NuGetFramework.Parse(tfm), GetDependencies(innerBuild)); - - frameworks.Add(tfmInfo); - } - - project.RemoveGlobalProperty("TargetFramework"); - } - else if (!string.IsNullOrEmpty(targetFramework)) - { - var tfmInfo = new ProjectFrameworkInfo(NuGetFramework.Parse(targetFramework), GetDependencies(instance)); - - frameworks.Add(tfmInfo); - } - - var projectDir = Path.GetDirectoryName(path); - - var tools = GetTools(instance).ToArray(); - bool.TryParse(instance.GetPropertyValue("IsPackable"), out var isPackable); - - if (isPackable) - { - // the default packable setting is disabled for projects referencing this package. - isPackable = !frameworks.SelectMany(f => f.Dependencies.Keys).Any(d => d.Equals("Microsoft.NET.Test.Sdk", StringComparison.OrdinalIgnoreCase)); - } - - var packageId = instance.GetPropertyValue("PackageId"); - var packageVersion = instance.GetPropertyValue("PackageVersion"); - - return new ProjectInfo(path, - frameworks, - tools, - isPackable, - packageId, - packageVersion); - } - - private static object _projLock = new object(); - - private static Project GetProject(string path, ProjectCollection projectCollection) - { - var projects = projectCollection.GetLoadedProjects(path); - foreach(var proj in projects) - { - if (proj.GetPropertyValue("DesignTimeBuild") == "true") - { - return proj; - } - } - - var xml = ProjectRootElement.Open(path, projectCollection); - var globalProps = new Dictionary() - { - ["DesignTimeBuild"] = "true", - // Isolate the project from post-restore side effects - ["ExcludeRestorePackageImports"] = "true", - }; - - var project = new Project(xml, - globalProps, - toolsVersion: "15.0", - projectCollection: projectCollection) - { - IsBuildEnabled = false - }; - - return project; - } - - private IReadOnlyDictionary GetDependencies(ProjectInstance project) - { - var references = new Dictionary(StringComparer.OrdinalIgnoreCase); - foreach (var item in project.GetItems("PackageReference")) - { - bool.TryParse(item.GetMetadataValue("IsImplicitlyDefined"), out var isImplicit); - - var info = new PackageReferenceInfo(item.EvaluatedInclude, item.GetMetadataValue("Version"), isImplicit); - - if (references.ContainsKey(info.Id)) - { - _logger.LogKoreBuildWarning(project.ProjectFileLocation.File, KoreBuildErrors.DuplicatePackageReference, $"Found a duplicate PackageReference for {info.Id}. Restore results may be unpredictable."); - } - - references[info.Id] = info; - } - - return references; - } - - private static IEnumerable GetTools(ProjectInstance project) - { - return project.GetItems("DotNetCliToolReference").Select(item => - new DotNetCliReferenceInfo(item.EvaluatedInclude, item.GetMetadataValue("Version"))); - } - } -} diff --git a/build/tasks/ProjectModel/SolutionInfo.cs b/build/tasks/ProjectModel/SolutionInfo.cs deleted file mode 100644 index cacc5213..00000000 --- a/build/tasks/ProjectModel/SolutionInfo.cs +++ /dev/null @@ -1,44 +0,0 @@ -// 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.IO; - -namespace RepoTasks.ProjectModel -{ - internal class SolutionInfo - { - public SolutionInfo(string fullPath, string configName, IReadOnlyList projects, bool shouldBuild, bool isPatching) - { - if (string.IsNullOrEmpty(fullPath)) - { - throw new ArgumentException(nameof(fullPath)); - } - - if (string.IsNullOrEmpty(configName)) - { - throw new ArgumentException(nameof(configName)); - } - - FullPath = fullPath; - Directory = Path.GetDirectoryName(fullPath); - ConfigName = configName; - Projects = projects ?? throw new ArgumentNullException(nameof(projects)); - ShouldBuild = shouldBuild; - IsPatching = isPatching; - foreach (var proj in Projects) - { - proj.SolutionInfo = this; - } - } - - public string FullPath { get; } - public string Directory { get; } - public string ConfigName { get; } - public IReadOnlyList Projects { get; } - public bool ShouldBuild { get; } - public bool IsPatching { get; } - public PatchPolicy PatchPolicy { get; set; } - } -} diff --git a/build/tasks/ProjectModel/SolutionInfoFactory.cs b/build/tasks/ProjectModel/SolutionInfoFactory.cs deleted file mode 100644 index aac69cff..00000000 --- a/build/tasks/ProjectModel/SolutionInfoFactory.cs +++ /dev/null @@ -1,136 +0,0 @@ -// 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.Concurrent; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.Build.Construction; -using Microsoft.Build.Evaluation; -using Microsoft.Build.Framework; -using Microsoft.Build.Utilities; -using RepoTasks.Utilities; - -namespace RepoTasks.ProjectModel -{ - internal class SolutionInfoFactory - { - private readonly TaskLoggingHelper _logger; - private readonly IBuildEngine4 _buildEngine; - - public SolutionInfoFactory(TaskLoggingHelper logger, IBuildEngine4 buildEngine) - { - _logger = logger; - _buildEngine = buildEngine; - } - - public IReadOnlyList Create(IEnumerable solutionItems, IDictionary properties, string defaultConfig, CancellationToken ct) - { - var timer = Stopwatch.StartNew(); - - var solutions = new ConcurrentBag(); - - Parallel.ForEach(solutionItems, solution => - { - if (ct.IsCancellationRequested) - { - return; - } - - var solutionFile = solution.ItemSpec.Replace('\\', '/'); - var solutionProps = new Dictionary(properties, StringComparer.OrdinalIgnoreCase); - foreach (var prop in MSBuildListSplitter.GetNamedProperties(solution.GetMetadata("AdditionalProperties"))) - { - solutionProps[prop.Key] = prop.Value; - } - - if (!solutionProps.TryGetValue("Configuration", out var configName)) - { - solutionProps["Configuration"] = configName = defaultConfig; - } - - var key = $"SlnInfo:{solutionFile}:{configName}"; - var obj = _buildEngine.GetRegisteredTaskObject(key, RegisteredTaskObjectLifetime.Build); - - if (obj is SolutionInfo cachedSlnInfo) - { - solutions.Add(cachedSlnInfo); - return; - } - - _logger.LogMessage($"Analyzing {solutionFile} ({configName})"); - var projects = new ConcurrentBag(); - var projectFiles = GetProjectsForSolutionConfig(solutionFile, configName); - using (var projCollection = new ProjectCollection(solutionProps) { IsBuildEnabled = false }) - { - Parallel.ForEach(projectFiles, projectFile => - { - if (ct.IsCancellationRequested) - { - return; - } - - try - { - projects.Add(new ProjectInfoFactory(_logger).Create(projectFile, projCollection)); - } - catch (Exception ex) - { - _logger.LogErrorFromException(ex); - } - }); - } - - bool.TryParse(solution.GetMetadata("Build"), out var shouldBuild); - bool.TryParse(solution.GetMetadata("IsPatching"), out var isPatching); - - var solutionInfo = new SolutionInfo( - solutionFile, - configName, - projects.ToArray(), - shouldBuild, - isPatching); - - _buildEngine.RegisterTaskObject(key, solutionInfo, RegisteredTaskObjectLifetime.Build, allowEarlyCollection: true); - - solutions.Add(solutionInfo); - }); - - timer.Stop(); - _logger.LogMessage(MessageImportance.High, $"Finished design-time build in {timer.ElapsedMilliseconds}ms"); - return solutions.ToArray(); - } - - private IList GetProjectsForSolutionConfig(string filePath, string configName) - { - var sln = SolutionFile.Parse(filePath); - - if (string.IsNullOrEmpty(configName)) - { - configName = sln.GetDefaultConfigurationName(); - } - - var projects = new List(); - - var config = sln.SolutionConfigurations.FirstOrDefault(c => c.ConfigurationName == configName); - if (config == null) - { - throw new InvalidOperationException($"A solution configuration by the name of '{configName}' was not found in '{filePath}'"); - } - - foreach (var project in sln.ProjectsInOrder - .Where(p => - p.ProjectType == SolutionProjectType.KnownToBeMSBuildFormat // skips solution folders - && p.ProjectConfigurations.TryGetValue(config.FullName, out var projectConfig) - && projectConfig.IncludeInBuild)) - { - projects.Add(project.AbsolutePath.Replace('\\', '/')); - } - - return projects; - } - } -} diff --git a/build/tasks/RepoTasks.tasks b/build/tasks/RepoTasks.tasks index 1339fcba..5339c01d 100644 --- a/build/tasks/RepoTasks.tasks +++ b/build/tasks/RepoTasks.tasks @@ -4,13 +4,10 @@ - - - diff --git a/build/tasks/Utilities/ArtifactInfo.cs b/build/tasks/Utilities/ArtifactInfo.cs deleted file mode 100644 index 7116daae..00000000 --- a/build/tasks/Utilities/ArtifactInfo.cs +++ /dev/null @@ -1,70 +0,0 @@ -// 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.IO; -using System.Linq; -using NuGet.Frameworks; -using NuGet.Packaging; -using NuGet.Packaging.Core; -using NuGet.Versioning; -using Microsoft.Build.Framework; -using RepoTasks.ProjectModel; - -namespace RepoTasks.Utilities -{ - internal abstract class ArtifactInfo - { - public static ArtifactInfo Parse(ITaskItem item) - { - ArtifactInfo info; - switch (item.GetMetadata("ArtifactType").ToLowerInvariant()) - { - case "nugetpackage": - info = new Package { PackageInfo = GetPackageInfo(item) }; - break; - case "nugetsymbolspackage": - info = new Package { PackageInfo = GetPackageInfo(item), IsSymbolsArtifact = true }; - break; - default: - return UnknownType.Singleton; - } - - info.RepositoryRoot = item.GetMetadata("RepositoryRoot")?.TrimEnd(new [] { '\\', '/' }); - - if (!string.IsNullOrEmpty(info.RepositoryRoot)) - { - info.RepoName = Path.GetFileName(info.RepositoryRoot); - } - - return info; - } - - public string RepositoryRoot { get; private set; } - public string RepoName { get; private set; } - - public class UnknownType : ArtifactInfo - { - private UnknownType() { } - public static UnknownType Singleton { get; } = new UnknownType(); - } - - public class Package : ArtifactInfo - { - public PackageInfo PackageInfo { get; set; } - public bool IsSymbolsArtifact { get; set; } - } - - private static PackageInfo GetPackageInfo(ITaskItem item) - { - return new PackageInfo( - item.GetMetadata("PackageId"), - NuGetVersion.Parse(item.GetMetadata("Version")), - string.IsNullOrEmpty(item.GetMetadata("TargetFramework")) - ? MSBuildListSplitter.SplitItemList(item.GetMetadata("TargetFramework")).Select(s => new PackageDependencyGroup(NuGetFramework.Parse(s), Array.Empty())).ToArray() - : new [] { new PackageDependencyGroup(NuGetFramework.Parse(item.GetMetadata("TargetFramework")), Array.Empty()) }, - Path.GetDirectoryName(item.ItemSpec), - item.GetMetadata("PackageType")); - } - } -} diff --git a/build/tasks/Utilities/KoreBuildErrors.cs b/build/tasks/Utilities/KoreBuildErrors.cs deleted file mode 100644 index 8386f9cf..00000000 --- a/build/tasks/Utilities/KoreBuildErrors.cs +++ /dev/null @@ -1,31 +0,0 @@ -// 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. - -namespace RepoTasks.Utilities -{ - public static class KoreBuildErrors - { - public const string Prefix = "KRB"; - - // Typically used in repos in Directory.Build.targets - public const int PackagesHaveNotYetBeenPinned = 1001; - - // Warnings - public const int DotNetAssetVersionIsFloating = 2000; - public const int RepoVersionDoesNotMatchProjectVersion = 2001; - public const int RepoPackageVersionDoesNotMatchProjectPackageVersion = 2002; - public const int DuplicatePackageReference = 2003; - - // NuGet errors - public const int InvalidNuspecFile = 4001; - public const int PackageReferenceHasVersion = 4002; - public const int DotNetCliReferenceReferenceHasVersion = 4003; - public const int PackageVersionNotFoundInLineup = 4004; - public const int UndefinedExternalDependency = 4005; - public const int EmptyPackageReferenceVersion = 4006; - - // Other unknown errors - public const int PolicyFailedToApply = 5000; - public const int UnknownPolicyType = 5001; - } -} diff --git a/build/tasks/Utilities/LoggingExtensions.cs b/build/tasks/Utilities/LoggingExtensions.cs deleted file mode 100644 index 833edb1a..00000000 --- a/build/tasks/Utilities/LoggingExtensions.cs +++ /dev/null @@ -1,26 +0,0 @@ -// 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 Microsoft.Build.Utilities; - -namespace RepoTasks.Utilities -{ - public static class LoggingExtensions - { - public static void LogKoreBuildError(this TaskLoggingHelper logger, int code, string message, params object[] messageArgs) - => LogKoreBuildError(logger, null, code, message, messageArgs: messageArgs); - - public static void LogKoreBuildError(this TaskLoggingHelper logger, string filename, int code, string message, params object[] messageArgs) - { - logger.LogError(null, KoreBuildErrors.Prefix + code, null, filename, 0, 0, 0, 0, message, messageArgs: messageArgs); - } - - public static void LogKoreBuildWarning(this TaskLoggingHelper logger, int code, string message, params object[] messageArgs) - => LogKoreBuildWarning(logger, null, code, message, messageArgs: messageArgs); - - public static void LogKoreBuildWarning(this TaskLoggingHelper logger, string filename, int code, string message, params object[] messageArgs) - { - logger.LogWarning(null, KoreBuildErrors.Prefix + code, null, filename, 0, 0, 0, 0, message, messageArgs: messageArgs); - } - } -} diff --git a/build/tasks/Utilities/MSBuildListSplitter.cs b/build/tasks/Utilities/MSBuildListSplitter.cs deleted file mode 100644 index de4ff872..00000000 --- a/build/tasks/Utilities/MSBuildListSplitter.cs +++ /dev/null @@ -1,45 +0,0 @@ -// 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; - -namespace RepoTasks.Utilities -{ - internal static class MSBuildListSplitter - { - private static readonly char[] SemiColon = { ';' }; - - public static IEnumerable SplitItemList(string value) - { - return string.IsNullOrEmpty(value) - ? Enumerable.Empty() - : value.Split(SemiColon, StringSplitOptions.RemoveEmptyEntries); - } - - public static Dictionary GetNamedProperties(string input) - { - var values = new Dictionary(); - if (string.IsNullOrEmpty(input)) - { - return values; - } - - foreach (var item in input.Split(SemiColon, StringSplitOptions.RemoveEmptyEntries)) - { - var splitIdx = item.IndexOf('='); - if (splitIdx <= 0) - { - continue; - } - - var key = item.Substring(0, splitIdx).Trim(); - var value = item.Substring(splitIdx + 1); - values[key] = value; - } - - return values; - } - } -} diff --git a/global.json b/global.json index ac7ef896..bb204de3 100644 --- a/global.json +++ b/global.json @@ -3,6 +3,6 @@ "version": "2.2.100-preview2-009404" }, "msbuild-sdks": { - "Internal.AspNetCore.Sdk": "2.2.0-preview2-20181004.1" + "Internal.AspNetCore.Sdk": "2.2.0-preview2-20181004.6" } } diff --git a/scripts/UpdateBuildTools.ps1 b/scripts/UpdateBuildTools.ps1 index 9e2ac554..efcda1e0 100755 --- a/scripts/UpdateBuildTools.ps1 +++ b/scripts/UpdateBuildTools.ps1 @@ -66,6 +66,7 @@ try { exit 0 } + Invoke-Block { git add "$RepoRoot/global.json" } Invoke-Block { git add "$RepoRoot/korebuild-lock.txt" } Invoke-Block { git add "$RepoRoot/build/dependencies.props" }