From f5710de3e57e7f14e2e22eb95be801d04f2f9f07 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Thu, 10 Aug 2017 11:40:41 -0700 Subject: [PATCH] Produce a lineup package containing all packages produced --- build/RepositoryBuild.targets | 7 +++- build/dependencies.props | 26 ++++++++++++++ build/repo.props | 7 ++++ build/repo.targets | 35 +++++++++++++++--- build/repobuild/AfterKoreBuild.targets | 6 ++++ build/repobuild/BeforeKoreBuild.props | 9 +++++ .../BuildGraph/DependencyGraphSpecProvider.cs | 3 ++ build/tasks/BuildGraph/GraphBuilder.cs | 19 ++++++++-- build/tasks/BuildGraph/GraphNode.cs | 5 ++- build/tasks/BuildGraph/Project.cs | 7 +++- build/tasks/BuildGraph/Repository.cs | 7 +++- build/tasks/BuildGraph/TopologicalSort.cs | 5 ++- build/tasks/CalculateBuildGraph.cs | 36 ++++++++++++++----- build/tasks/RepoTasks.csproj | 2 +- .../tasks/VersionPinning/PinVersionUtility.cs | 2 +- ...Internal.AspNetCore.Universe.Lineup.nuspec | 17 +++++++++ 16 files changed, 170 insertions(+), 23 deletions(-) create mode 100644 build/dependencies.props create mode 100644 build/repobuild/AfterKoreBuild.targets create mode 100644 build/repobuild/BeforeKoreBuild.props create mode 100644 lineups/Internal.AspNetCore.Universe.Lineup.nuspec diff --git a/build/RepositoryBuild.targets b/build/RepositoryBuild.targets index 96ce3623f9..72a0fcb2c1 100644 --- a/build/RepositoryBuild.targets +++ b/build/RepositoryBuild.targets @@ -1,5 +1,5 @@ - + %(RepositoryToBuildInOrder.Order) @@ -28,6 +28,11 @@ + $(RepositoryBuildArguments) '/p:Universe_Version=$(Version)' + $(RepositoryBuildArguments) '/p:Universe_LineupBuildDir=$(LineupBuildDir)' + $(RepositoryBuildArguments) '/p:Universe_IntermediateDir=$(IntermediateDir)' + $(RepositoryBuildArguments) '/p:CustomBeforeKoreBuildProps=$(MSBuildThisFileDirectory)repobuild\BeforeKoreBuild.props' + $(RepositoryBuildArguments) '/p:CustomAfterKoreBuildTargets=$(MSBuildThisFileDirectory)repobuild\AfterKoreBuild.targets' $(RepositoryBuildArguments) /p:BuildNumber=$(BuildNumber) /p:Configuration=$(Configuration) /p:CommitHash=$(CommitHash) $(RepositoryBuildArguments) /noconsolelogger '/l:RepoTasks.FlowLogger,$(MSBuildThisFileDirectory)tasks\bin\publish\RepoTasks.dll;Summary;FlowId=$(RepositoryToBuild)' diff --git a/build/dependencies.props b/build/dependencies.props new file mode 100644 index 0000000000..46e2ab135a --- /dev/null +++ b/build/dependencies.props @@ -0,0 +1,26 @@ + + + + + https://dotnet.myget.org/F/aspnetcore-ci-dev/api/v3/index.json + + + + + + + + + https://api.nuget.org/v3/index.json + + + + + + + + + + + + diff --git a/build/repo.props b/build/repo.props index 844540c47a..2e230882b2 100644 --- a/build/repo.props +++ b/build/repo.props @@ -1,6 +1,13 @@ + + + true + $(VersionPrefix) + $(Version)-$(VersionSuffix) + $(Version)-$(BuildNumber) + diff --git a/build/repo.targets b/build/repo.targets index 9df54315a5..234f821645 100644 --- a/build/repo.targets +++ b/build/repo.targets @@ -4,10 +4,11 @@ https://dotnet.myget.org/F/aspnetcore-volatile-dev/api/v2/package + $(ArtifactsDir)lineups\ <_CloneRepositoryRoot>$(RepositoryRoot).r\ <_DependencyBuildDirectory>$(RepositoryRoot).deps\build\ <_DependencyPackagesDirectory>$(_DependencyBuildDirectory) - <_RestoreGraphSpecsDirectory>$(RepositoryRoot)obj\package-specs\ + <_RestoreGraphSpecsDirectory>$(IntermediateDir)package-specs\ <_RepositoryListFileName>Repositories.props <_DefaultRepositoryList>$(MSBuildThisFileDirectory)$(_RepositoryListFileName) @@ -26,8 +27,25 @@ - + + + + + + + + + + + + @@ -107,7 +125,7 @@ + DependsOnTargets="_PrepareRepositories;_CreateRepositoriesListWithCommits;_UpdateNuGetConfig;_GenerateBuildGraph;_BuildRepositories;PublishLineupPackage" /> @@ -137,12 +155,19 @@ + Properties="BuildNumber=$(BuildNumber);KoreBuildRestoreTargetsImported=true" + BuildInParallel="$(BuildInParallel)" + ContinueOnError="true" /> - + + diff --git a/build/repobuild/AfterKoreBuild.targets b/build/repobuild/AfterKoreBuild.targets new file mode 100644 index 0000000000..6db507685d --- /dev/null +++ b/build/repobuild/AfterKoreBuild.targets @@ -0,0 +1,6 @@ + + + + + + diff --git a/build/repobuild/BeforeKoreBuild.props b/build/repobuild/BeforeKoreBuild.props new file mode 100644 index 0000000000..2a2c50dd2b --- /dev/null +++ b/build/repobuild/BeforeKoreBuild.props @@ -0,0 +1,9 @@ + + + + + $([MSBuild]::NormalizeDirectory($(Universe_IntermediateDir)))packages\ + + $(PolicyRestoreAdditionalSources);$([MSBuild]::NormalizeDirectory($(Universe_LineupBuildDir))) + + diff --git a/build/tasks/BuildGraph/DependencyGraphSpecProvider.cs b/build/tasks/BuildGraph/DependencyGraphSpecProvider.cs index b4b73dc27d..d16600578a 100644 --- a/build/tasks/BuildGraph/DependencyGraphSpecProvider.cs +++ b/build/tasks/BuildGraph/DependencyGraphSpecProvider.cs @@ -1,3 +1,6 @@ +// 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.IO; using NuGet.ProjectModel; diff --git a/build/tasks/BuildGraph/GraphBuilder.cs b/build/tasks/BuildGraph/GraphBuilder.cs index 8199335433..d70b1ba45d 100644 --- a/build/tasks/BuildGraph/GraphBuilder.cs +++ b/build/tasks/BuildGraph/GraphBuilder.cs @@ -1,12 +1,17 @@ -using System; +// 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, string root) + public static IList Generate(IList repositories, string root, TaskLoggingHelper log) { // Build global list of primary projects var primaryProjects = repositories.SelectMany(c => c.Projects) @@ -31,7 +36,15 @@ namespace RepoTools.BuildGraph var dependencyRepository = dependencyProject.Repository; var dependencyNode = graphNodes[dependencyRepository]; - thisProjectRepositoryNode.Incoming.Add(dependencyNode); + 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); } } diff --git a/build/tasks/BuildGraph/GraphNode.cs b/build/tasks/BuildGraph/GraphNode.cs index 8c2a023ab2..b7197e8b38 100644 --- a/build/tasks/BuildGraph/GraphNode.cs +++ b/build/tasks/BuildGraph/GraphNode.cs @@ -1,4 +1,7 @@ -using System.Collections.Generic; +// 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 diff --git a/build/tasks/BuildGraph/Project.cs b/build/tasks/BuildGraph/Project.cs index 10a821a336..72b5eee254 100644 --- a/build/tasks/BuildGraph/Project.cs +++ b/build/tasks/BuildGraph/Project.cs @@ -1,4 +1,7 @@ -using System; +// 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; @@ -14,6 +17,8 @@ namespace RepoTools.BuildGraph public string Name { get; } + public string Version { get; set; } + public string Path { get; set; } public Repository Repository { get; set; } diff --git a/build/tasks/BuildGraph/Repository.cs b/build/tasks/BuildGraph/Repository.cs index 6c5f9964f0..c1e3e5c619 100644 --- a/build/tasks/BuildGraph/Repository.cs +++ b/build/tasks/BuildGraph/Repository.cs @@ -1,4 +1,7 @@ -using System; +// 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.IO; @@ -49,6 +52,7 @@ namespace RepoTools.BuildGraph var repository = new Repository(name); ReadSharedSourceProjects(Path.Combine(repositoryPath, "shared"), repository, repository.Projects); + var srcDirectory = Path.GetFullPath(Path.Combine(repositoryPath, "src")) .Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); @@ -78,6 +82,7 @@ namespace RepoTools.BuildGraph { Repository = repository, Path = specProject.FilePath, + Version = specProject.Version?.ToString(), }; projectGroup.Add(project); diff --git a/build/tasks/BuildGraph/TopologicalSort.cs b/build/tasks/BuildGraph/TopologicalSort.cs index 4d362be3e4..161a9913d7 100644 --- a/build/tasks/BuildGraph/TopologicalSort.cs +++ b/build/tasks/BuildGraph/TopologicalSort.cs @@ -1,4 +1,7 @@ -using System; +// 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; diff --git a/build/tasks/CalculateBuildGraph.cs b/build/tasks/CalculateBuildGraph.cs index 6e1dc6de2b..59e0172ec6 100644 --- a/build/tasks/CalculateBuildGraph.cs +++ b/build/tasks/CalculateBuildGraph.cs @@ -15,19 +15,28 @@ namespace RepoTasks [Required] public ITaskItem[] Repositories { get; set; } - [Output] - public ITaskItem[] RepositoriesToBuildInOrder { get; set; } + /// + /// Directory that contains the package spec files. + /// + [Required] + public string PackageSpecsDirectory { get; set; } + + /// + /// Default to use for packages that may be produced from nuspec, not csproj. (e.g. .Sources packages). + /// + [Required] + public string DefaultPackageVersion { get; set; } /// /// The repository at which to root the graph at /// public string StartGraphAt { get; set; } - /// - /// Directory that contains the package spec files. - /// - [Required] - public string PackageSpecsDirectory { get; set; } + [Output] + public ITaskItem[] RepositoriesToBuildInOrder { get; set; } + + [Output] + public ITaskItem[] PackagesProduced { get; set; } public override bool Execute() { @@ -36,7 +45,7 @@ namespace RepoTasks var repositoryPaths = Repositories.Select(r => r.GetMetadata("RepositoryPath")).ToList(); var repositories = Repository.ReadAllRepositories(repositoryPaths, graphSpecProvider); - var graph = GraphBuilder.Generate(repositories, StartGraphAt); + var graph = GraphBuilder.Generate(repositories, StartGraphAt, Log); var repositoriesWithOrder = new List<(ITaskItem repository, int order)>(); foreach (var repositoryTaskItem in Repositories) { @@ -59,6 +68,17 @@ namespace RepoTasks .Select(r => r.repository) .ToArray(); + var packages = new List(); + foreach (var project in repositories.SelectMany(p => p.Projects)) + { + var pkg = new TaskItem(project.Name); + var version = project.Version ?? DefaultPackageVersion; + pkg.SetMetadata("Version", version); + packages.Add(pkg); + } + + PackagesProduced = packages.ToArray(); + return true; } } diff --git a/build/tasks/RepoTasks.csproj b/build/tasks/RepoTasks.csproj index d7ce16d52e..eaf591d21b 100644 --- a/build/tasks/RepoTasks.csproj +++ b/build/tasks/RepoTasks.csproj @@ -7,7 +7,7 @@ - + diff --git a/build/tasks/VersionPinning/PinVersionUtility.cs b/build/tasks/VersionPinning/PinVersionUtility.cs index c638c40200..c94e19fc62 100644 --- a/build/tasks/VersionPinning/PinVersionUtility.cs +++ b/build/tasks/VersionPinning/PinVersionUtility.cs @@ -81,7 +81,7 @@ namespace RepoTasks.VersionPinning _logger.LogMessage(MessageImportance.Normal, $"Pinning package versions for {specProject.FilePath}."); } - var pinnedReferences = new XElement("ItemGroup"); + var pinnedReferences = new XElement("ItemGroup", new XAttribute("Condition", "'$(PolicyDesignTimeBuild)' != 'true' AND !Exists('$(MSBuildThisFileDirectory)$(MSBuildProjectFile).nugetpolicy.g.targets')")); foreach (var packageReference in projectPinMetadata.Packages) { (var tfm, var libraryRange, var exactVersion) = packageReference; diff --git a/lineups/Internal.AspNetCore.Universe.Lineup.nuspec b/lineups/Internal.AspNetCore.Universe.Lineup.nuspec new file mode 100644 index 0000000000..2ca7e0c78f --- /dev/null +++ b/lineups/Internal.AspNetCore.Universe.Lineup.nuspec @@ -0,0 +1,17 @@ + + + + Internal.AspNetCore.Universe.Lineup + $version$ + Microsoft + This package used to unify dependency versions across all Universe repos. Internal use only. + + + + + + + +