Include global CLI tool packages in the LZMA (#809)

Fixes #803
This commit is contained in:
Nate McMaster 2018-01-25 18:04:40 -08:00 committed by GitHub
parent b083b73985
commit baa665db81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 168 additions and 24 deletions

View File

@ -49,6 +49,26 @@
Targets="Restore"
Properties="RestorePackagesPath=$(FallbackStagingDir);RuntimeFrameworkVersion=$(MicrosoftNETCoreApp21PackageVersion);DotNetRestoreSourcePropsPath=$(GeneratedFallbackRestoreSourcesPropsPath);AspNetUniverseBuildOffline=true" />
<!-- Add global CLI tools to the LZMA -->
<!-- Join categories (defined in artifacts.props) with package version info (defined in repos) -->
<RepoTasks.JoinItems
Left="@(ArtifactInfo)" LeftKey="PackageId" LeftMetadata="*" LeftItemSpec="PackageId"
Right="@(PackageArtifact->WithMetadataValue('LZMA', 'true')->WithMetadataValue('PackageType', 'DotnetTool'))">
<Output TaskParameter="JoinResult" ItemName="_DotnetToolPackages" />
</RepoTasks.JoinItems>
<ItemGroup>
<_DotnetToolPackages Update="@(_DotnetToolPackages)">
<DestFileName>$([System.String]::new('%(PackageId).%(Version)').ToLowerInvariant())</DestFileName>
<DestDirName>$([System.String]::new('%(PackageId)/%(Version)').ToLowerInvariant())</DestDirName>
</_DotnetToolPackages>
</ItemGroup>
<!-- No need to extract global CLI tool packages. They are extracted from the CliFallbackFolder into $HOME/.dotnet/tools by dotnet-install-tool. -->
<MakeDir Directories="$(FallbackStagingDir)\%(_DotnetToolPackages.DestDirName)\" Condition="'%(Identity)'!= ''" />
<Copy SourceFiles="$(MetapackageRestoreSource)%(_DotnetToolPackages.Identity).%(Version).nupkg" DestinationFiles="$(FallbackStagingDir)\%(DestDirName)\%(DestFileName).nupkg" Condition="'%(Identity)'!= ''" />
<!-- Create the archive -->
<Exec Command="$(ArchiverPath) -a $(FallbackOutputPath) $(FallbackStagingDir)" />
</Target>

View File

@ -2,20 +2,31 @@
<ItemDefinitionGroup>
<PackageArtifact>
<!-- When true, this dependency will be included in the Microsoft.AspNetCore.App metapackage. -->
<AppMetapackage>false</AppMetapackage>
<!-- When true, this dependency will be included in the Microsoft.AspNetCore.All metapackage. -->
<AllMetapackage>false</AllMetapackage>
<HostingStartup>false</HostingStartup>
<!-- When true, this dependency will be included in the Microsoft.AspNetCore.Analyzers metapackage. -->
<Analyzer>false</Analyzer>
<!-- When true, this dependency will be used to generate a deps.json for hosting startup. -->
<HostingStartup>false</HostingStartup>
<!-- When true, this dependency will be included in the LZMA. -->
<LZMA>false</LZMA>
<LZMATools>false</LZMATools>
<!--
Other known package types:
Dependency = for packages that are installed via PackageReference
DotnetCliTool = for packages that are installed via DotNetCliToolReference
DotnetTOol = for packages that installed via dotnet-install-tool
-->
<PackageType>Dependency</PackageType>
</PackageArtifact>
</ItemDefinitionGroup>
<ItemGroup>
<PackageArtifact Include="dotnet-dev-certs" Category="ship" LZMATools="true" />
<PackageArtifact Include="dotnet-sql-cache" Category="ship" LZMATools="true" />
<PackageArtifact Include="dotnet-user-secrets" Category="ship" LZMATools="true" />
<PackageArtifact Include="dotnet-watch" Category="ship" LZMATools="true" />
<PackageArtifact Include="dotnet-dev-certs" Category="ship" LZMA="true" PackageType="DotnetTool" />
<PackageArtifact Include="dotnet-sql-cache" Category="ship" LZMA="true" PackageType="DotnetTool" />
<PackageArtifact Include="dotnet-user-secrets" Category="ship" LZMA="true" PackageType="DotnetTool" />
<PackageArtifact Include="dotnet-watch" Category="ship" LZMA="true" PackageType="DotnetTool" />
<PackageArtifact Include="Microsoft.AspNet.Identity.AspNetCoreCompat" Category="noship" />
<PackageArtifact Include="Microsoft.AspNetCore" Category="ship" AppMetapackage="true"/>
<PackageArtifact Include="Microsoft.AspNetCore.App" Category="ship" />
@ -202,7 +213,7 @@
<PackageArtifact Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Category="ship" AllMetapackage="true"/>
<PackageArtifact Include="Microsoft.EntityFrameworkCore.SqlServer" Category="ship" AppMetapackage="true"/>
<PackageArtifact Include="Microsoft.EntityFrameworkCore.Tools" Category="ship" AppMetapackage="true" />
<PackageArtifact Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Category="ship" LZMATools="true" />
<PackageArtifact Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Category="ship" LZMA="true" PackageType="DotnetCliTool" />
<PackageArtifact Include="Microsoft.Extensions.ActivatorUtilities.Sources" Category="noship" />
<PackageArtifact Include="Microsoft.Extensions.ApplicationModelDetection" Category="noship" />
<PackageArtifact Include="Microsoft.Extensions.Caching.Abstractions" Category="ship" AppMetapackage="true" />
@ -282,7 +293,7 @@
<PackageArtifact Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Category="ship" LZMA="true" />
<PackageArtifact Include="Microsoft.VisualStudio.Web.CodeGeneration.EntityFrameworkCore" Category="ship" LZMA="true" />
<PackageArtifact Include="Microsoft.VisualStudio.Web.CodeGeneration.Templating" Category="ship" LZMA="true" />
<PackageArtifact Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Category="ship" LZMATools="true" />
<PackageArtifact Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Category="ship" LZMA="true" PackageType="DotnetCliTool" />
<PackageArtifact Include="Microsoft.VisualStudio.Web.CodeGeneration.Utils" Category="ship" LZMA="true" />
<PackageArtifact Include="Microsoft.VisualStudio.Web.CodeGenerators.Mvc" Category="ship" LZMA="true" />
<PackageArtifact Include="Microsoft.Web.Xdt.Extensions" Category="shipoob" />

View File

@ -13,16 +13,9 @@
<Private>false</Private>
<!-- When true, this dependency should be mirrored to aspnetcore's nightly build feeds. -->
<Mirror>false</Mirror>
<!-- When true, this dependency will be included in the metapackage. -->
<Metapackage>false</Metapackage>
<!-- When true, this dependency will be used to generate a deps.json for hosting startup that will be included in the runtime store. -->
<HostingStartup>false</HostingStartup>
<!-- When true, this dependency will be included in the LZMA. -->
<LZMA>false</LZMA>
<!-- When true, this tool dependency will be included in the metapackage. -->
<LZMATools>false</LZMATools>
</ExternalDependency>
</ItemDefinitionGroup>
<!-- .NET Core feed -->
<PropertyGroup>
<DotNetCoreFeed>https://dotnet.myget.org/F/dotnet-core/api/v3/index.json</DotNetCoreFeed>

View File

@ -196,10 +196,7 @@
<Error Text="Invalid configuration of %(PackageArtifact.Identity). Packages marked as LZMA='true' must be Category='ship'."
Condition="'%(PackageArtifact.Category)' != 'ship' AND '%(PackageArtifact.LZMA)' == 'true' " />
<Error Text="Invalid configuration of %(PackageArtifact.Identity). Packages marked as LZMATools='true' must be Category='ship'."
Condition="'%(PackageArtifact.Category)' != 'ship' AND '%(PackageArtifact.LZMATools)' == 'true' " />
<Error Text="Invalid configuration of %(PackageArtifact.Identity). Packages marked as AppMetapackage='true' must be Category='ship'."
<Error Text="Invalid configuration of %(PackageArtifact.Identity). Packages marked as AppMetapackage='true' must be Category='ship'."
Condition="'%(PackageArtifact.Category)' != 'ship' AND '%(PackageArtifact.AppMetapackage)' == 'true' " />
<Error Text="Invalid configuration of %(PackageArtifact.Identity). Packages marked as AllMetapackage='true' must be Category='ship'."

View File

@ -31,10 +31,10 @@ namespace RepoTasks
public override bool Execute()
{
// Parse input
var externalArchiveArtifacts = ExternalDependencies.Where(p => p.GetMetadata("LZMA") == "true");
var externalArchiveTools = ExternalDependencies.Where(p => p.GetMetadata("LZMATools") == "true");
var archiveArtifacts = PackageArtifacts.Where(p => p.GetMetadata("LZMA") == "true");
var archiveTools = PackageArtifacts.Where(p => p.GetMetadata("LZMATools") == "true");
var externalArchiveArtifacts = ExternalDependencies.Where(p => p.GetMetadata("LZMA") == "true" && p.GetMetadata("PackageType") == "Dependency");
var externalArchiveTools = ExternalDependencies.Where(p => p.GetMetadata("LZMA") == "true" && p.GetMetadata("PackageType") == "DotnetCliTool");
var archiveArtifacts = PackageArtifacts.Where(p => p.GetMetadata("LZMA") == "true" && p.GetMetadata("PackageType") == "Dependency");
var archiveTools = PackageArtifacts.Where(p => p.GetMetadata("LZMA") == "true" && p.GetMetadata("PackageType") == "DotnetCliTool");
var buildArtifacts = BuildArtifacts.Select(ArtifactInfo.Parse)
.OfType<ArtifactInfo.Package>()
.Where(p => !p.IsSymbolsArtifact);

122
build/tasks/JoinItems.cs Normal file
View File

@ -0,0 +1,122 @@
// 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 System.Text;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
namespace RepoTasks
{
public class JoinItems : Task
{
[Required]
public ITaskItem[] Left { get; set; }
[Required]
public ITaskItem[] Right { get; set; }
// The metadata to use as the new item spec. If not specified, LeftKey is used.
public string LeftItemSpec { get; set; }
// LeftKey and RightKey: The metadata to join on. If not set, then use the ItemSpec
public string LeftKey { get; set; }
public string RightKey { get; set; }
// LeftMetadata and RightMetadata: The metadata names to include in the result. Specify "*" to include all metadata
public string[] LeftMetadata { get; set; }
public string[] RightMetadata { get; set; }
[Output]
public ITaskItem[] JoinResult { get; private set; }
public override bool Execute()
{
bool useAllLeftMetadata = LeftMetadata != null && LeftMetadata.Length == 1 && LeftMetadata[0] == "*";
bool useAllRightMetadata = RightMetadata != null && RightMetadata.Length == 1 && RightMetadata[0] == "*";
var newItemSpec = string.IsNullOrEmpty(LeftItemSpec)
? LeftKey
: LeftItemSpec;
JoinResult = Left.Join(Right,
item => GetKeyValue(LeftKey, item),
item => GetKeyValue(RightKey, item),
(left, right) =>
{
// If including all metadata from left items and none from right items, just return left items directly
if (useAllLeftMetadata &&
string.IsNullOrEmpty(LeftKey) &&
string.IsNullOrEmpty(LeftItemSpec) &&
(RightMetadata == null || RightMetadata.Length == 0))
{
return left;
}
// If including all metadata from right items and none from left items, just return the right items directly
if (useAllRightMetadata &&
string.IsNullOrEmpty(RightKey) &&
string.IsNullOrEmpty(LeftItemSpec) &&
(LeftMetadata == null || LeftMetadata.Length == 0))
{
return right;
}
var ret = new TaskItem(GetKeyValue(newItemSpec, left));
// Weird ordering here is to prefer left metadata in all cases, as CopyToMetadata doesn't overwrite any existing metadata
if (useAllLeftMetadata)
{
// CopyMetadata adds an OriginalItemSpec, which we don't want. So we subsequently remove it
left.CopyMetadataTo(ret);
ret.RemoveMetadata("OriginalItemSpec");
}
if (!useAllRightMetadata && RightMetadata != null)
{
foreach (string name in RightMetadata)
{
ret.SetMetadata(name, right.GetMetadata(name));
}
}
if (!useAllLeftMetadata && LeftMetadata != null)
{
foreach (string name in LeftMetadata)
{
ret.SetMetadata(name, left.GetMetadata(name));
}
}
if (useAllRightMetadata)
{
// CopyMetadata adds an OriginalItemSpec, which we don't want. So we subsequently remove it
right.CopyMetadataTo(ret);
ret.RemoveMetadata("OriginalItemSpec");
}
return (ITaskItem)ret;
},
StringComparer.OrdinalIgnoreCase).ToArray();
return true;
}
static string GetKeyValue(string key, ITaskItem item)
{
if (string.IsNullOrEmpty(key))
{
return item.ItemSpec;
}
else
{
return item.GetMetadata(key);
}
}
}
}

View File

@ -12,6 +12,7 @@
<UsingTask TaskName="RepoTasks.CopyPackagesToSplitFolders" AssemblyFile="$(_RepoTaskAssembly)" />
<UsingTask TaskName="RepoTasks.CreateCommonManifest" AssemblyFile="$(_RepoTaskAssembly)" />
<UsingTask TaskName="RepoTasks.GenerateRestoreSourcesPropsFile" AssemblyFile="$(_RepoTaskAssembly)" />
<UsingTask TaskName="RepoTasks.JoinItems" AssemblyFile="$(_RepoTaskAssembly)" />
<UsingTask TaskName="RepoTasks.OrderBy" AssemblyFile="$(_RepoTaskAssembly)" />
<UsingTask TaskName="RepoTasks.ProcessSharedFrameworkDeps" AssemblyFile="$(_RepoTaskAssembly)" />
<UsingTask TaskName="RepoTasks.PublishToAzureBlob" AssemblyFile="$(_RepoTaskAssembly)" />