Move PinVersions into RepoTasks (#535)
This commit is contained in:
parent
469195950e
commit
ca7f72e3f0
27
Universe.sln
27
Universe.sln
|
|
@ -1,27 +0,0 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26228.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PinVersions", "tools\PinVersions\PinVersions.csproj", "{DACA9DFB-508E-45EA-A5CF-C0F5C2BA181B}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shared", "shared", "{085280EC-7055-426A-BF9C-1B692B9599AB}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
tools\shared\DependencyGraphSpecProvider.cs = tools\shared\DependencyGraphSpecProvider.cs
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{DACA9DFB-508E-45EA-A5CF-C0F5C2BA181B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{DACA9DFB-508E-45EA-A5CF-C0F5C2BA181B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DACA9DFB-508E-45EA-A5CF-C0F5C2BA181B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{DACA9DFB-508E-45EA-A5CF-C0F5C2BA181B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
@ -22,7 +22,7 @@
|
|||
BuildInParallel="$(BatchBuilds)"
|
||||
StopOnFirstFailure="true"
|
||||
Targets="_BuildRepository"
|
||||
Properties="BuildGroup=%(BatchedRepository.BuildGroup)" />
|
||||
Properties="BuildGroup=%(BatchedRepository.BuildGroup);BuildNumber=$(BuildNumber)" />
|
||||
</Target>
|
||||
|
||||
<Target Name="_BuildRepository" DependsOnTargets="_PinVersions">
|
||||
|
|
@ -78,14 +78,16 @@
|
|||
<Message Text="============ Done building $(RepositoryToBuild) ============" Importance="High" />
|
||||
</Target>
|
||||
|
||||
<Target Name="_PinVersions" DependsOnTargets="_FindDotNetPath">
|
||||
<Target Name="_PinVersions">
|
||||
<ItemGroup>
|
||||
<PinPackageSources Include="$(BuildDir)" />
|
||||
<PinPackageSources Include="$(_DependencyPackagesDirectory)" Condition="Exists('$(_DependencyPackagesDirectory)')" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<PinToolBinary>$(RepositoryRoot)tools\PinVersions\bin\$(Configuration)\netcoreapp1.1\PinVersions.dll</PinToolBinary>
|
||||
<PinVersionArgs>$(DotNetPath) $(PinToolBinary) --graph-specs-root "$(_RestoreGraphSpecsDirectory) " -s "$(BuildDir) " "$(BuildRepositoryRoot) "</PinVersionArgs>
|
||||
<PinVersionArgs Condition="Exists('$(_DependencyPackagesDirectory)')">$(PinVersionArgs) -s "$(_DependencyPackagesDirectory) "</PinVersionArgs>
|
||||
</PropertyGroup>
|
||||
|
||||
<Exec Command="$(PinVersionArgs)" />
|
||||
<RepoTasks.PinVersions
|
||||
GraphSpecsRoot="$(_RestoreGraphSpecsDirectory)"
|
||||
BuildRepositoryRoot="$(BuildRepositoryRoot)"
|
||||
PackageSources="@(PinPackageSources)" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
<Project>
|
||||
<PropertyGroup>
|
||||
<!-- This repo does not have solutions to build -->
|
||||
<DisableDefaultTargets>true</DisableDefaultTargets>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
|
@ -214,9 +214,4 @@
|
|||
</PropertyGroup>
|
||||
</Target>
|
||||
|
||||
<Target Name="_FindDotNetPath">
|
||||
<GetDotNetHost>
|
||||
<Output TaskParameter="ExecutablePath" PropertyName="DotNetPath" />
|
||||
</GetDotNetHost>
|
||||
</Target>
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
// 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.Linq;
|
||||
using Microsoft.Build.Framework;
|
||||
using RepoTasks.VersionPinning;
|
||||
|
||||
namespace RepoTasks
|
||||
{
|
||||
public class PinVersions : Microsoft.Build.Utilities.Task
|
||||
{
|
||||
[Required]
|
||||
public string BuildRepositoryRoot { get; set; }
|
||||
|
||||
[Required]
|
||||
public ITaskItem[] PackageSources { get; set; }
|
||||
|
||||
public string GraphSpecsRoot { get; set; }
|
||||
|
||||
public override bool Execute()
|
||||
{
|
||||
if (PackageSources?.Length == 0)
|
||||
{
|
||||
Log.LogError($"Missing PackageSources. At least one item source must be specified.");
|
||||
return false;
|
||||
}
|
||||
|
||||
var graphSpecProvider = !string.IsNullOrEmpty(GraphSpecsRoot)
|
||||
? new DependencyGraphSpecProvider(GraphSpecsRoot)
|
||||
: DependencyGraphSpecProvider.Default;
|
||||
|
||||
using (graphSpecProvider)
|
||||
{
|
||||
var pinVersionUtility = new PinVersionUtility(
|
||||
BuildRepositoryRoot,
|
||||
PackageSources.Select(i => i.ItemSpec).ToList(),
|
||||
graphSpecProvider,
|
||||
Log);
|
||||
pinVersionUtility.Execute();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NuGet.ProjectModel" Version="4.0.0" />
|
||||
<PackageReference Include="NuGet.ProjectModel" Version="$(NuGetInMSBuildVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="$(RepoTasksSdkPath)\Sdk.targets" Condition="'$(RepoTasksSdkPath)' != '' "/>
|
||||
|
|
|
|||
|
|
@ -4,4 +4,5 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<UsingTask TaskName="RepoTasks.CalculateBuildGraph" AssemblyFile="$(_RepoTaskAssembly)" />
|
||||
</Project>
|
||||
<UsingTask TaskName="RepoTasks.PinVersions" AssemblyFile="$(_RepoTaskAssembly)" />
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -1,17 +1,19 @@
|
|||
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;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using NuGet.ProjectModel;
|
||||
|
||||
namespace UniverseTools
|
||||
namespace RepoTasks.VersionPinning
|
||||
{
|
||||
public class DependencyGraphSpecProvider : IDisposable
|
||||
{
|
||||
private readonly string _packageSpecDirectory;
|
||||
private readonly bool _deleteSpecDirectoryOnDispose;
|
||||
private readonly string _muxerPath;
|
||||
private readonly string _dotnetPath;
|
||||
|
||||
public DependencyGraphSpecProvider(string packageSpecDirectory)
|
||||
: this(packageSpecDirectory, deleteSpecDirectoryOnDispose: false)
|
||||
|
|
@ -22,7 +24,7 @@ namespace UniverseTools
|
|||
{
|
||||
_packageSpecDirectory = packageSpecDirectory;
|
||||
_deleteSpecDirectoryOnDispose = deleteSpecDirectoryOnDispose;
|
||||
_muxerPath = new Muxer().MuxerPath;
|
||||
_dotnetPath = Process.GetCurrentProcess().MainModule.FileName;
|
||||
}
|
||||
|
||||
public static DependencyGraphSpecProvider Default { get; } =
|
||||
|
|
@ -42,7 +44,7 @@ namespace UniverseTools
|
|||
|
||||
private void RunMSBuild(string solutionPath, string outputFile)
|
||||
{
|
||||
var psi = new ProcessStartInfo(_muxerPath);
|
||||
var psi = new ProcessStartInfo(_dotnetPath);
|
||||
|
||||
var arguments = new List<string>
|
||||
{
|
||||
|
|
@ -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.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
|
@ -6,6 +9,8 @@ using System.Linq;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.Build.Framework;
|
||||
using Microsoft.Build.Utilities;
|
||||
using NuGet.Common;
|
||||
using NuGet.Frameworks;
|
||||
using NuGet.LibraryModel;
|
||||
|
|
@ -13,19 +18,23 @@ using NuGet.ProjectModel;
|
|||
using NuGet.Protocol;
|
||||
using NuGet.Protocol.Core.Types;
|
||||
using NuGet.Versioning;
|
||||
using UniverseTools;
|
||||
|
||||
namespace PinVersions
|
||||
namespace RepoTasks.VersionPinning
|
||||
{
|
||||
class PinVersionUtility
|
||||
internal class PinVersionUtility
|
||||
{
|
||||
private readonly string _repositoryRoot;
|
||||
private readonly FindPackageByIdResource[] _findPackageResources;
|
||||
private readonly ConcurrentDictionary<string, Task<NuGetVersion>> _exactMatches = new ConcurrentDictionary<string, Task<NuGetVersion>>(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly DependencyGraphSpecProvider _provider;
|
||||
private readonly SourceCacheContext _sourceCacheContext;
|
||||
private readonly TaskLoggingHelper _logger;
|
||||
|
||||
public PinVersionUtility(string repositoryRoot, List<string> pinSources, DependencyGraphSpecProvider provider)
|
||||
public PinVersionUtility(
|
||||
string repositoryRoot,
|
||||
List<string> pinSources,
|
||||
DependencyGraphSpecProvider provider,
|
||||
TaskLoggingHelper logger)
|
||||
{
|
||||
_repositoryRoot = repositoryRoot;
|
||||
_findPackageResources = new FindPackageByIdResource[pinSources.Count];
|
||||
|
|
@ -36,14 +45,17 @@ namespace PinVersions
|
|||
}
|
||||
_provider = provider;
|
||||
_sourceCacheContext = new SourceCacheContext();
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
_logger.LogMessage(MessageImportance.High, $"Pinning package references for projects in {_repositoryRoot}");
|
||||
|
||||
var solutionPinMetadata = GetProjectPinVersionMetadata();
|
||||
foreach (var cliToolReference in solutionPinMetadata.CLIToolReferences)
|
||||
{
|
||||
Console.WriteLine($"Pinning CLI Tool {cliToolReference.Item1.Name}({cliToolReference.Item1.VersionRange} to {cliToolReference.Item2} for all projects in {_repositoryRoot}.");
|
||||
_logger.LogMessage(MessageImportance.Normal, $"Pinning CLI Tool {cliToolReference.Item1.Name}({cliToolReference.Item1.VersionRange} to {cliToolReference.Item2} for all projects in {_repositoryRoot}.");
|
||||
}
|
||||
|
||||
foreach (var item in solutionPinMetadata.PinVersionLookup)
|
||||
|
|
@ -53,7 +65,7 @@ namespace PinVersions
|
|||
|
||||
if (!(projectPinMetadata.Packages.Any() || solutionPinMetadata.CLIToolReferences.Any()))
|
||||
{
|
||||
Console.WriteLine($"No package or tool references to pin for {specProject.FilePath}.");
|
||||
_logger.LogMessage(MessageImportance.Normal, $"No package or tool references to pin for {specProject.FilePath}.");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -66,14 +78,14 @@ namespace PinVersions
|
|||
|
||||
if (projectPinMetadata.Packages.Any())
|
||||
{
|
||||
Console.WriteLine($"Pinning package versions for {specProject.FilePath}.");
|
||||
_logger.LogMessage(MessageImportance.Normal, $"Pinning package versions for {specProject.FilePath}.");
|
||||
}
|
||||
|
||||
var pinnedReferences = new XElement("ItemGroup");
|
||||
foreach (var packageReference in projectPinMetadata.Packages)
|
||||
{
|
||||
(var tfm, var libraryRange, var exactVersion) = packageReference;
|
||||
Console.WriteLine($"Pinning reference {libraryRange.Name}({libraryRange.VersionRange} to {exactVersion}.");
|
||||
_logger.LogMessage(MessageImportance.Normal, $"Pinning reference {libraryRange.Name}({libraryRange.VersionRange} to {exactVersion}.");
|
||||
var metadata = new List<XAttribute>
|
||||
{
|
||||
new XAttribute("Update", libraryRange.Name),
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp1.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\shared\*.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.DotNet.Cli.Utils" Version="1.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.CommandLineUtils" Version="1.1.0" />
|
||||
<PackageReference Include="System.ValueTuple" Version="4.3.0" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
using System;
|
||||
using Microsoft.Extensions.CommandLineUtils;
|
||||
using UniverseTools;
|
||||
|
||||
namespace PinVersions
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static int Main(string[] args)
|
||||
{
|
||||
var app = new CommandLineApplication();
|
||||
|
||||
var pinSourceOption = app.Option("-s|--source",
|
||||
"Feed containing packages to pin.",
|
||||
CommandOptionType.MultipleValue);
|
||||
|
||||
var packageSpecsDirectoryOption = app.Option("--graph-specs-root",
|
||||
"Directory containing package specs. (Optional)",
|
||||
CommandOptionType.SingleValue);
|
||||
|
||||
var repositoryArgument = app.Argument("Repository", "Repository directory");
|
||||
|
||||
app.OnExecute(() =>
|
||||
{
|
||||
if (!pinSourceOption.HasValue())
|
||||
{
|
||||
Console.Error.WriteLine($"Option {pinSourceOption.Template} must have a value.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(repositoryArgument.Value))
|
||||
{
|
||||
Console.Error.WriteLine($"Repository argument must be specified.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
var graphSpecProvider = packageSpecsDirectoryOption.HasValue() ?
|
||||
new DependencyGraphSpecProvider(packageSpecsDirectoryOption.Value().Trim()) :
|
||||
DependencyGraphSpecProvider.Default;
|
||||
|
||||
using (graphSpecProvider)
|
||||
{
|
||||
var pinVersionUtility = new PinVersionUtility(repositoryArgument.Value.Trim(), pinSourceOption.Values, graphSpecProvider);
|
||||
pinVersionUtility.Execute();
|
||||
}
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
return app.Execute(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue