Imported Upstream version 5.4.0.199

Former-commit-id: f4d318e4b2f128fa9f4d31b37bb3839a3fc0dfb2
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-09-25 16:57:44 +00:00
parent 536cd135cc
commit 5924117973
223 changed files with 3826 additions and 487 deletions

View File

@@ -39,10 +39,7 @@ namespace ILLink.Tasks
long totalUnlinked = 0;
foreach (string unlinkedFile in unlinkedFiles) {
try {
AssemblyName.GetAssemblyName (unlinkedFile);
}
catch (BadImageFormatException) {
if (!Utils.IsManagedAssembly (unlinkedFile)) {
continue;
}
string fileName = Path.GetFileName (unlinkedFile);
@@ -54,10 +51,7 @@ namespace ILLink.Tasks
long totalLinked = 0;
foreach (string linkedFile in linkedFiles) {
try {
AssemblyName.GetAssemblyName (linkedFile);
}
catch (BadImageFormatException) {
if (!Utils.IsManagedAssembly (linkedFile)) {
continue;
}
string fileName = Path.GetFileName (linkedFile);
@@ -71,15 +65,30 @@ namespace ILLink.Tasks
sizes[fileName] = assemblySizes;
}
Console.WriteLine ("{0, -60} {1,-20:N0} {2, -20:N0} {3, -10:P}",
"",
"Before linking (B)",
"After linking (B)",
"Size decrease");
Console.WriteLine ("{0, -60} {1,-20:N0} {2, -20:N0} {3, -10:P}",
"-----------",
"-----------",
"-----------",
"-----------"
);
Console.WriteLine ("{0, -60} {1,-20:N0} {2, -20:N0} {3, -10:P}",
"Total size of assemblies",
totalUnlinked,
totalLinked,
((double)totalUnlinked - (double)totalLinked) / (double)totalUnlinked);
Console.WriteLine ("-----------");
Console.WriteLine ("Details");
Console.WriteLine ("-----------");
Console.WriteLine ("{0, -60} {1,-20:N0} {2, -20:N0} {3, -10:P}",
"-----------",
"-----------",
"-----------",
"-----------"
);
foreach (string assembly in sizes.Keys) {
Console.WriteLine ("{0, -60} {1,-20:N0} {2, -20:N0} {3, -10:P}",

View File

@@ -10,6 +10,7 @@ using Microsoft.Build.Framework; // MessageImportance
using Microsoft.NET.Build.Tasks; // LockFileCache
using NuGet.ProjectModel; // LockFileTargetLibrary
using NuGet.Frameworks; // NuGetFramework.Parse(targetframework)
using Mono.Cecil;
namespace ILLink.Tasks
{
@@ -33,10 +34,8 @@ namespace ILLink.Tasks
{
var managedAssemblies = new List<ITaskItem>();
foreach (var f in Assemblies) {
try {
AssemblyName.GetAssemblyName(f.ItemSpec);
if (Utils.IsManagedAssembly(f.ItemSpec)) {
managedAssemblies.Add(f);
} catch (BadImageFormatException) {
}
}
ManagedAssemblies = managedAssemblies.ToArray();

View File

@@ -1,7 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PropertyGroup>
<VersionPrefix>0.1.4-preview</VersionPrefix>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFrameworks>netcoreapp2.0;net46</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netcoreapp2.0</TargetFrameworks>
<RuntimeFrameworkVersion>2.0.0-beta-001509-00</RuntimeFrameworkVersion>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<PackageOutputPath>../nupkgs</PackageOutputPath>
@@ -17,7 +18,7 @@
<!-- We want to package the tasks package together with its
package dependencies, the linker, and the linker's
dependencies, in order to prevent projects that contsume the
dependencies, in order to prevent projects that consume the
tasks package from pulling in the linker. To do this, we need
to include project references and package references in the
package, and prevent any of these references from being
@@ -41,8 +42,8 @@
references from being marked as dependencies. -->
<!-- TODO: Remove the custom .nuspec once the P2P PrivateAssets
issue is fixed. -->
<NuspecFile>ILLink.Tasks.nuspec</NuspecFile>
<NuspecProperties>id=$(AssemblyName);authors=$(AssemblyName);description=linker tasks;tfm=$(TargetFramework);</NuspecProperties>
<NuspecFile>ILLink.Tasks.nuspec</NuspecFile>
<NuspecProperties>id=$(AssemblyName);authors=$(AssemblyName);description=linker tasks;</NuspecProperties>
</PropertyGroup>
<!-- TODO: Remove this workaround once we're able to avoid using a
@@ -64,14 +65,25 @@
Instead, we use GenerateNuspecDependsOn. We could probably also
use BeforeTargets="GenerateNuspec". -->
<PropertyGroup>
<GenerateNuspecDependsOn>Publish;SetDynamicNuspecProperties;$(GenerateNuspecDependsOn)</GenerateNuspecDependsOn>
<GenerateNuspecDependsOn>SetDynamicNuspecProperties;$(GenerateNuspecDependsOn)</GenerateNuspecDependsOn>
</PropertyGroup>
<Target Name="SetDynamicNuspecProperties">
<Target Name="SetDynamicNuspecProperties"
DependsOnTargets="LayoutPackage">
<PropertyGroup>
<NuspecProperties>$(NuspecProperties)output=$(PublishDir);version=$(Version);</NuspecProperties>
<NuspecProperties>$(NuspecProperties)version=$(Version);</NuspecProperties>
</PropertyGroup>
</Target>
<Target Name="LayoutPackage">
<ItemGroup>
<TFMsToPublish Include="$(TargetFrameworks)" />
<ProjectsToPublish Include="$(MSBuildProjectFile)">
<AdditionalProperties>TargetFramework=%(TFMsToPublish.Identity);PublishDir=%(TFMsToPublish.Identity)</AdditionalProperties>
</ProjectsToPublish>
</ItemGroup>
<MSBuild Projects="@(ProjectsToPublish)" Targets="Publish" />
</Target>
<ItemGroup>
<Compile Include="LinkTask.cs" />
<Compile Include="DepsJsonLinker.cs" />
@@ -79,6 +91,7 @@
<Compile Include="ComputeManagedAssemblies.cs" />
<Compile Include="GetRuntimeLibraries.cs" />
<Compile Include="CreateRootDescriptorFile.cs" />
<Compile Include="Utils.cs" />
<Compile Include="Microsoft.NET.Build.Tasks/LockFileCache.cs" />
<Compile Include="Microsoft.NET.Build.Tasks/BuildErrorException.cs" />
</ItemGroup>
@@ -125,18 +138,17 @@
</ItemGroup>
-->
<ItemGroup>
<!-- TODO: Once https://github.com/dotnet/sdk/issues/952 is fixed,
use PrivateAssets="All" to prevent this project reference
from being marked as a dependency of the tasks package (while
still including it in the publish output). -->
<ProjectReference Include="../../../linker/Mono.Linker.csproj" />
<ProjectReference Include="../../../linker/Mono.Linker.csproj">
<!-- SetConfiguration isn't required when the configuration is
already set in the solution. However, it should be possible
to set it here to allow packing the tasks csproj on its
own. This would let us avoid some of the strange behavior
that shows up when trying to build from a .sln file.
already set in the solution. Setting it here allows packing
the tasks csproj on its own. This lets us avoid some of the
strange behavior that shows up when trying to build from a
.sln file.
There is a nuget bug that prevents this from working
properly during restore
@@ -152,11 +164,21 @@
(because some target gets its reference information from
the lock file, which doesn't have configuration info).
-->
<!--
<SetConfiguration>Configuration=netcore_$(Configuration)</SetConfiguration>
-->
<SetConfiguration>Configuration=illink_$(Configuration)</SetConfiguration>
</ProjectReference>
<ProjectReference Include="../../../cecil/Mono.Cecil.csproj" />
</ItemGroup>
<!-- Workaround for the SetConfiguration issue described above. -->
<Target Name="SetCecilConfiguration"
AfterTargets="AssignProjectConfiguration">
<ItemGroup>
<ProjectReferenceWithConfiguration Condition=" '%(Filename)%(Extension)' == 'Mono.Cecil.csproj' Or '%(Filename)%(Extension)' == 'Mono.Cecil.Pdb.csproj' ">
<SetConfiguration>Configuration=netstandard_$(Configuration)</SetConfiguration>
</ProjectReferenceWithConfiguration>
</ItemGroup>
</Target>
<ItemGroup>
<!-- TODO: Once we can avoid using a custom .nuspec, we should be
@@ -164,8 +186,13 @@
them from becoming package dependencies, and use an msbuild
itemgroup to include their assets in the package instead of
passing the publish path to the .nuspec. -->
<PackageReference Include="Microsoft.Build.Framework" Version="0.1.0-preview-00028-160627" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="0.1.0-preview-00028-160627" />
<!-- We use private assets for the Microsoft.Build packages to
prevent them from being published with the tasks dll, because
these are already a part of the SDK. -->
<PackageReference Include="Microsoft.Build.Framework" Version="15.1.1012"
PrivateAssets="All" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="15.1.1012"
PrivateAssets="All" />
<PackageReference Include="NuGet.ProjectModel" Version="4.3.0-preview1-2500" />
</ItemGroup>
</Project>

View File

@@ -8,6 +8,7 @@
</metadata>
<files>
<file src="ILLink.Tasks.targets" target="build" />
<file src="$output$*.dll" target="tools/$tfm$" />
<file src="netcoreapp2.0/**/*.dll" target="tools" />
<file src="net46/**/*.dll" target="tools" />
</files>
</package>

View File

@@ -1,7 +1,11 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<LinkTaskDllPath Condition=" '$(LinkTaskDllPath)' == '' ">$(MSBuildThisFileDirectory)../tools/$(TargetFramework)/ILLink.Tasks.dll</LinkTaskDllPath>
<_LinkTaskDirectoryRoot>$(MSBuildThisFileDirectory)../tools/</_LinkTaskDirectoryRoot>
<_LinkTaskTFM Condition=" '$(MSBuildRuntimeType)' == 'Core' ">netcoreapp2.0</_LinkTaskTFM>
<_LinkTaskTFM Condition=" '$(_LinkTaskTFM)' == '' ">net46</_LinkTaskTFM>
<_LinkTaskDirectory>$(_LinkTaskDirectoryRoot)$(_LinkTaskTFM)/</_LinkTaskDirectory>
<LinkTaskDllPath Condition=" '$(LinkTaskDllPath)' == '' ">$(_LinkTaskDirectory)ILLink.Tasks.dll</LinkTaskDllPath>
</PropertyGroup>
<PropertyGroup>
@@ -54,10 +58,15 @@
which computes the ItemGroup ResolvedFileToPublish. To extend
this target, we insert a target before
ComputeFilesToPublish. Our target rewrites the relevant inputs
(@(IntermediateAssembly) and
@(ResolvedAssembliesToPublish)). This lets ComputeFilesToPublish
be ignorant of the linker, but changes the meaning of
IntermediateAssembly and ResolvedAssembliesToPublish.
(@(IntermediateAssembly), @(ResolvedAssembliesToPublish)). This
lets ComputeFilesToPublish be ignorant of the linker, but
changes the meaning of IntermediateAssembly and
ResolvedAssembliesToPublish.
To include linked pdbs in the publish output, we also rewrite
the ComputeFilesToPublish input
@(_DebugSymbolsIntermediatePath). Note that this is a private
itemgroup, so relying on this is not ideal.
-->
<!-- DependsOnTargets here doesn't include the targets that compute
ResolvedAssembliesToPublish or IntermediateAssembly, because
@@ -82,6 +91,13 @@
<IntermediateAssembly Remove="@(IntermediateAssembly)" />
<IntermediateAssembly Include="@(_LinkedIntermediateAssembly)" />
</ItemGroup>
<!-- Rewrite _DebugSymbolsIntermediatePath, which is an input to
ComputeFilesToPublish. -->
<ItemGroup>
<_DebugSymbolsIntermediatePath Remove="@(_DebugSymbolsIntermediatePath)" Condition=" '$(_DebugSymbolsProduced)' == 'true' " />
<_DebugSymbolsIntermediatePath Include="@(_LinkedDebugSymbols)" Condition=" '$(_DebugSymbolsProduced)' == 'true' " />
</ItemGroup>
</Target>
@@ -100,10 +116,11 @@
</Target>
<!-- Computes _LinkedResolvedAssemblies and
_LinkedIntermediateAssembly. _LinkedResolvedAssemblies needs to
keep metadata from _ManagedResolvedAssembliesToPublish, since
this is used by ComputeFilesToPublish. -->
<!-- Computes _LinkedResolvedAssemblies,
_LinkedIntermediateAssembly, and
_LinkedDebugSymbols. _LinkedResolvedAssemblies needs to keep
metadata from _ManagedResolvedAssembliesToPublish, since this
is used by ComputeFilesToPublish. -->
<Target Name="_ComputeLinkedAssemblies"
DependsOnTargets="_ComputeManagedResolvedAssembliesToPublish;ILLink">
<ItemGroup>
@@ -115,6 +132,13 @@
<__LinkedIntermediateAssembly Include="@(IntermediateAssembly->'$(IntermediateLinkDir)/%(Filename)%(Extension)')" />
<_LinkedIntermediateAssembly Include="@(__LinkedIntermediateAssembly)" Condition="Exists('%(Identity)')" />
</ItemGroup>
<ItemGroup>
<__LinkedDebugSymbols Include="@(_DebugSymbolsIntermediatePath->'$(IntermediateLinkDir)/%(Filename)%(Extension)')"
Condition=" '$(_DebugSymbolsProduced)' == 'true' " />
<_LinkedDebugSymbols Include="@(__LinkedDebugSymbols)"
Condition="Exists('%(Identity)') And '$(_DebugSymbolsProduced)' == 'true' " />
</ItemGroup>
</Target>
@@ -132,7 +156,7 @@
the future we will want to generate these depending on the
scenario in which the linker is invoked. -->
<PropertyGroup>
<ExtraLinkerArgs Condition=" '$(ExtraLinkerArgs)' == '' ">-t -c link -l none</ExtraLinkerArgs>
<ExtraLinkerArgs Condition=" '$(ExtraLinkerArgs)' == '' ">-t -c link -l none -b true</ExtraLinkerArgs>
</PropertyGroup>
<ILLink AssemblyPaths="@(_ManagedAssembliesToLink)"
RootAssemblyNames="@(LinkerRootAssemblies)"
@@ -189,6 +213,11 @@
<ItemGroup>
<_ManagedResolvedAssembliesToPublish Remove="@(_ManagedResolvedAssembliesToPublish->WithMetadataValue('Filename', 'System.Private.CoreLib.ni'))" />
</ItemGroup>
<!-- Some of the managed dlls are satellite assemblies containing
binary resources that we don't want to link. -->
<ItemGroup>
<_ManagedResolvedAssembliesToPublish Remove="@(_ManagedResolvedAssembliesToPublish->WithMetadataValue('AssetType', 'resources'))" />
</ItemGroup>
</Target>

View File

@@ -0,0 +1,15 @@
using System;
using Mono.Cecil;
public class Utils
{
public static bool IsManagedAssembly (string fileName)
{
try {
ModuleDefinition module = ModuleDefinition.ReadModule (fileName);
return true;
} catch (BadImageFormatException) {
return false;
}
}
}