You've already forked linux-packaging-mono
Imported Upstream version 5.8.0.22
Former-commit-id: df344e34b07851d296efb3e6604c8db42b6f7aa3
This commit is contained in:
parent
5f4a27cc8a
commit
7d05485754
3
external/linker/.gitignore
vendored
3
external/linker/.gitignore
vendored
@@ -26,3 +26,6 @@ bin/
|
||||
*.FileListAbsolute.txt
|
||||
|
||||
**/Dependencies/*.dll
|
||||
|
||||
corebuild/Tools
|
||||
corebuild/bootstrap.log
|
||||
|
||||
@@ -671,8 +671,10 @@ namespace Mono.Cecil.Cil {
|
||||
|
||||
var offset_mapping = new Dictionary<int, SequencePoint> (sequence_points.Count);
|
||||
|
||||
for (int i = 0; i < sequence_points.Count; i++)
|
||||
offset_mapping.Add (sequence_points [i].Offset, sequence_points [i]);
|
||||
for (int i = 0; i < sequence_points.Count; i++) {
|
||||
if (!offset_mapping.ContainsKey (sequence_points [i].Offset))
|
||||
offset_mapping.Add (sequence_points [i].Offset, sequence_points [i]);
|
||||
}
|
||||
|
||||
var instructions = method.Body.Instructions;
|
||||
|
||||
|
||||
1
external/linker/cecil/Mono.Cecil.PE/Image.cs
vendored
1
external/linker/cecil/Mono.Cecil.PE/Image.cs
vendored
@@ -39,6 +39,7 @@ namespace Mono.Cecil.PE {
|
||||
public uint Timestamp;
|
||||
public ModuleAttributes Attributes;
|
||||
|
||||
public DataDirectory Win32Resources;
|
||||
public DataDirectory Debug;
|
||||
public DataDirectory Resources;
|
||||
public DataDirectory StrongName;
|
||||
|
||||
@@ -160,12 +160,18 @@ namespace Mono.Cecil.PE {
|
||||
|
||||
// ExportTable 8
|
||||
// ImportTable 8
|
||||
|
||||
Advance (pe64 ? 56 : 40);
|
||||
|
||||
// ResourceTable 8
|
||||
|
||||
image.Win32Resources = ReadDataDirectory ();
|
||||
|
||||
// ExceptionTable 8
|
||||
// CertificateTable 8
|
||||
// BaseRelocationTable 8
|
||||
|
||||
Advance (pe64 ? 88 : 72);
|
||||
Advance (24);
|
||||
|
||||
// Debug 8
|
||||
image.Debug = ReadDataDirectory ();
|
||||
|
||||
@@ -87,21 +87,15 @@ namespace Mono.Cecil.PE {
|
||||
|
||||
void GetWin32Resources ()
|
||||
{
|
||||
var rsrc = GetImageResourceSection ();
|
||||
if (rsrc == null)
|
||||
if (!module.HasImage)
|
||||
return;
|
||||
|
||||
win32_resources = module.Image.GetReaderAt (rsrc.VirtualAddress, rsrc.SizeOfRawData, (s, reader) => new ByteBuffer (reader.ReadBytes ((int) s)));
|
||||
}
|
||||
DataDirectory win32_resources_directory = module.Image.Win32Resources;
|
||||
var size = win32_resources_directory.Size;
|
||||
|
||||
Section GetImageResourceSection ()
|
||||
{
|
||||
if (!module.HasImage)
|
||||
return null;
|
||||
|
||||
const string rsrc_section = ".rsrc";
|
||||
|
||||
return module.Image.GetSection (rsrc_section);
|
||||
if (size > 0) {
|
||||
win32_resources = module.Image.GetReaderAt (win32_resources_directory.VirtualAddress, size, (s, reader) => new ByteBuffer (reader.ReadBytes ((int) s)));
|
||||
}
|
||||
}
|
||||
|
||||
public static ImageWriter CreateWriter (ModuleDefinition module, MetadataBuilder metadata, Disposable<Stream> stream)
|
||||
@@ -846,10 +840,10 @@ namespace Mono.Cecil.PE {
|
||||
|
||||
void PatchResourceDataEntry (ByteBuffer resources)
|
||||
{
|
||||
var old_rsrc = GetImageResourceSection ();
|
||||
var rva = resources.ReadUInt32 ();
|
||||
resources.position -= 4;
|
||||
resources.WriteUInt32 (rva - old_rsrc.VirtualAddress + rsrc.VirtualAddress);
|
||||
|
||||
resources.WriteUInt32 (rva - module.Image.Win32Resources.VirtualAddress + rsrc.VirtualAddress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -943,8 +943,8 @@ namespace Mono.Cecil {
|
||||
|
||||
type.BaseType = GetTypeDefOrRef (ReadMetadataToken (CodedIndex.TypeDefOrRef));
|
||||
|
||||
type.fields_range = ReadFieldsRange (rid);
|
||||
type.methods_range = ReadMethodsRange (rid);
|
||||
type.fields_range = ReadListRange (rid, Table.TypeDef, Table.Field);
|
||||
type.methods_range = ReadListRange (rid, Table.TypeDef, Table.Method);
|
||||
|
||||
if (IsNested (attributes))
|
||||
type.DeclaringType = GetNestedTypeDeclaringType (type);
|
||||
@@ -965,21 +965,13 @@ namespace Mono.Cecil {
|
||||
return GetTypeDefinition (declaring_rid);
|
||||
}
|
||||
|
||||
Range ReadFieldsRange (uint type_index)
|
||||
{
|
||||
return ReadListRange (type_index, Table.TypeDef, Table.Field);
|
||||
}
|
||||
|
||||
Range ReadMethodsRange (uint type_index)
|
||||
{
|
||||
return ReadListRange (type_index, Table.TypeDef, Table.Method);
|
||||
}
|
||||
|
||||
Range ReadListRange (uint current_index, Table current, Table target)
|
||||
{
|
||||
var list = new Range ();
|
||||
|
||||
list.Start = ReadTableIndex (target);
|
||||
var start = ReadTableIndex (target);
|
||||
if (start == 0)
|
||||
return list;
|
||||
|
||||
uint next_index;
|
||||
var current_table = image.TableHeap [current];
|
||||
@@ -993,7 +985,8 @@ namespace Mono.Cecil {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
list.Length = next_index - list.Start;
|
||||
list.Start = start;
|
||||
list.Length = next_index - start;
|
||||
|
||||
return list;
|
||||
}
|
||||
@@ -1496,16 +1489,11 @@ namespace Mono.Cecil {
|
||||
|
||||
for (uint i = 1; i <= length; i++) {
|
||||
var type_rid = ReadTableIndex (Table.TypeDef);
|
||||
Range events_range = ReadEventsRange (i);
|
||||
Range events_range = ReadListRange (i, Table.EventMap, Table.Event);
|
||||
metadata.AddEventsRange (type_rid, events_range);
|
||||
}
|
||||
}
|
||||
|
||||
Range ReadEventsRange (uint rid)
|
||||
{
|
||||
return ReadListRange (rid, Table.EventMap, Table.Event);
|
||||
}
|
||||
|
||||
public bool HasProperties (TypeDefinition type)
|
||||
{
|
||||
InitializeProperties ();
|
||||
@@ -1585,16 +1573,11 @@ namespace Mono.Cecil {
|
||||
|
||||
for (uint i = 1; i <= length; i++) {
|
||||
var type_rid = ReadTableIndex (Table.TypeDef);
|
||||
var properties_range = ReadPropertiesRange (i);
|
||||
var properties_range = ReadListRange (i, Table.PropertyMap, Table.Property);
|
||||
metadata.AddPropertiesRange (type_rid, properties_range);
|
||||
}
|
||||
}
|
||||
|
||||
Range ReadPropertiesRange (uint rid)
|
||||
{
|
||||
return ReadListRange (rid, Table.PropertyMap, Table.Property);
|
||||
}
|
||||
|
||||
MethodSemanticsAttributes ReadMethodSemantics (MethodDefinition method)
|
||||
{
|
||||
InitializeMethodSemantics ();
|
||||
@@ -1729,11 +1712,6 @@ namespace Mono.Cecil {
|
||||
}
|
||||
}
|
||||
|
||||
Range ReadParametersRange (uint method_rid)
|
||||
{
|
||||
return ReadListRange (method_rid, Table.Method, Table.Param);
|
||||
}
|
||||
|
||||
public Collection<MethodDefinition> ReadMethods (TypeDefinition type)
|
||||
{
|
||||
var methods_range = type.methods_range;
|
||||
@@ -1794,7 +1772,7 @@ namespace Mono.Cecil {
|
||||
methods.Add (method); // attach method
|
||||
|
||||
var signature = ReadBlobIndex ();
|
||||
var param_range = ReadParametersRange (method_rid);
|
||||
var param_range = ReadListRange (method_rid, Table.Method, Table.Param);
|
||||
|
||||
this.context = method;
|
||||
|
||||
|
||||
@@ -189,10 +189,10 @@ namespace Mono.Cecil.Rocks {
|
||||
var instruction = self.Instructions [i];
|
||||
if (instruction.OpCode.Code != Code.Ldc_I8)
|
||||
continue;
|
||||
var l = (long)instruction.Operand;
|
||||
if (l >= uint.MaxValue)
|
||||
var l = (long) instruction.Operand;
|
||||
if (l >= int.MaxValue || l <= int.MinValue)
|
||||
continue;
|
||||
ExpandMacro (instruction, OpCodes.Ldc_I4, (uint)l);
|
||||
ExpandMacro (instruction, OpCodes.Ldc_I4, (int) l);
|
||||
self.Instructions.Insert (++i, Instruction.Create (OpCodes.Conv_I8));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,7 +234,7 @@ namespace Mono.CompilerServices.SymbolWriter
|
||||
|
||||
public override string ToString ()
|
||||
{
|
||||
return String.Format ("[Line {0}:{1,2}-{3,4}:{5}]", File, Row, Column, EndRow, EndColumn, Offset);
|
||||
return String.Format ("[Line {0}:{1},{2}-{3},{4}:{5}]", File, Row, Column, EndRow, EndColumn, Offset);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -280,7 +280,11 @@ namespace Mono.Cecil.Pdb {
|
||||
break;
|
||||
}
|
||||
case 'A':
|
||||
var index = used_namespace.IndexOf(' ');
|
||||
var index = used_namespace.IndexOf (' ');
|
||||
if (index < 0) {
|
||||
target = new ImportTarget (ImportTargetKind.ImportNamespace) { @namespace = used_namespace };
|
||||
break;
|
||||
}
|
||||
var alias_value = used_namespace.Substring (1, index - 1);
|
||||
var alias_target_value = used_namespace.Substring (index + 2);
|
||||
switch (used_namespace [index + 1]) {
|
||||
@@ -294,6 +298,15 @@ namespace Mono.Cecil.Pdb {
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case '*':
|
||||
target = new ImportTarget (ImportTargetKind.ImportNamespace) { @namespace = value };
|
||||
break;
|
||||
case '@':
|
||||
if (!value.StartsWith ("P:"))
|
||||
continue;
|
||||
|
||||
target = new ImportTarget (ImportTargetKind.ImportNamespace) { @namespace = value.Substring (2) };
|
||||
break;
|
||||
}
|
||||
|
||||
if (target != null)
|
||||
|
||||
@@ -143,7 +143,7 @@ namespace Mono.Cecil.Tests {
|
||||
Assert.AreEqual (DocumentHashAlgorithm.None, document.HashAlgorithm);
|
||||
Assert.AreEqual (DocumentLanguage.FSharp, document.Language);
|
||||
Assert.AreEqual (DocumentLanguageVendor.Microsoft, document.LanguageVendor);
|
||||
}, readOnly: Platform.OnMono, symbolReaderProvider: typeof(PdbReaderProvider), symbolWriterProvider: typeof(PdbWriterProvider));
|
||||
}, readOnly: Platform.OnMono, symbolReaderProvider: typeof (PdbReaderProvider), symbolWriterProvider: typeof (PdbWriterProvider));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -157,7 +157,15 @@ namespace Mono.Cecil.Tests {
|
||||
public void EmptyRootNamespace ()
|
||||
{
|
||||
TestModule ("EmptyRootNamespace.dll", module => {
|
||||
}, readOnly: Platform.OnMono, symbolReaderProvider: typeof(PdbReaderProvider), symbolWriterProvider: typeof(PdbWriterProvider));
|
||||
}, readOnly: Platform.OnMono, symbolReaderProvider: typeof (PdbReaderProvider), symbolWriterProvider: typeof (PdbWriterProvider));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void VisualBasicNamespace ()
|
||||
{
|
||||
TestModule ("AVbTest.exe", module => {
|
||||
}, readOnly: Platform.OnMono, symbolReaderProvider: typeof (PdbReaderProvider), symbolWriterProvider: typeof (PdbWriterProvider));
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
BIN
external/linker/cecil/symbols/pdb/Test/Resources/assemblies/AVbTest.pdb
vendored
Normal file
BIN
external/linker/cecil/symbols/pdb/Test/Resources/assemblies/AVbTest.pdb
vendored
Normal file
Binary file not shown.
4
external/linker/corebuild/build.cmd
vendored
4
external/linker/corebuild/build.cmd
vendored
@@ -1,6 +1,6 @@
|
||||
@if not defined _echo @echo off
|
||||
|
||||
REM build.cmd will bootstrap the cli and ultimately call "dotnet build"
|
||||
REM build.cmd will bootstrap the cli and ultimately call "dotnet pack"
|
||||
|
||||
@call %~dp0dotnet.cmd build %~dp0linker.sln %*
|
||||
@call %~dp0dotnet.cmd pack %~dp0integration\ILLink.Tasks\ILLink.Tasks.csproj %*
|
||||
@exit /b %ERRORLEVEL%
|
||||
|
||||
24
external/linker/corebuild/integration/ILLink.CustomSteps/ClearInitLocals.cs
vendored
Normal file
24
external/linker/corebuild/integration/ILLink.CustomSteps/ClearInitLocals.cs
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
|
||||
using Mono.Linker;
|
||||
using Mono.Linker.Steps;
|
||||
using Mono.Cecil;
|
||||
|
||||
namespace ILLink.CustomSteps
|
||||
{
|
||||
public class ClearInitLocalsStep : BaseStep
|
||||
{
|
||||
protected override void ProcessAssembly(AssemblyDefinition assembly)
|
||||
{
|
||||
foreach (ModuleDefinition module in assembly.Modules) {
|
||||
foreach (TypeDefinition type in module.Types) {
|
||||
foreach (MethodDefinition method in type.Methods) {
|
||||
if (method.Body != null) {
|
||||
method.Body.InitLocals = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
51
external/linker/corebuild/integration/ILLink.CustomSteps/ILLink.CustomSteps.csproj
vendored
Normal file
51
external/linker/corebuild/integration/ILLink.CustomSteps/ILLink.CustomSteps.csproj
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netcoreapp2.0;net46</TargetFrameworks>
|
||||
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netcoreapp2.0</TargetFrameworks>
|
||||
<RuntimeFrameworkVersion>2.0.0-beta-001509-00</RuntimeFrameworkVersion>
|
||||
<DefineConstants>$(DefineConstants);FEATURE_ILLINK</DefineConstants>
|
||||
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<AssemblyName>ILLink.CustomSteps</AssemblyName>
|
||||
<OutputType>Library</OutputType>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<ProjectGuid>{275C1D10-168A-4AC4-8F3E-AD969F580B9C}</ProjectGuid>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="ClearInitLocals.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\linker\Mono.Linker.csproj">
|
||||
<SetConfiguration Condition=" '$(Configuration)' == 'illink_Debug' ">Configuration=illink_Debug</SetConfiguration>
|
||||
<SetConfiguration Condition=" '$(Configuration)' == 'illink_Release' ">Configuration=illink_Release</SetConfiguration>
|
||||
<Project>{DD28E2B1-057B-4B4D-A04D-B2EBD9E76E46}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\cecil\Mono.Cecil.csproj">
|
||||
<SetConfiguration Condition=" '$(Configuration)' == 'illink_Debug' ">Configuration=netstandard_Debug</SetConfiguration>
|
||||
<SetConfiguration Condition=" '$(Configuration)' == 'illink_Debug' And '$(TargetFramework)' == 'net46' ">Configuration=net_4_0_Debug</SetConfiguration>
|
||||
<SetConfiguration Condition=" '$(Configuration)' == 'illink_Release' ">Configuration=netstandard_Release</SetConfiguration>
|
||||
<SetConfiguration Condition=" '$(Configuration)' == 'illink_Release' And '$(TargetFramework)' == 'net46' ">Configuration=net_4_0_Release</SetConfiguration>
|
||||
<Project>{D68133BD-1E63-496E-9EDE-4FBDBF77B486}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
|
||||
<!-- The reference to the linker will cause Mono.Cecil.Pdb to be
|
||||
built in the wrong configuration unless we apply this
|
||||
workaround. -->
|
||||
<Target Name="SetCecilConfiguration"
|
||||
AfterTargets="AssignProjectConfiguration">
|
||||
<ItemGroup>
|
||||
<ProjectReferenceWithConfiguration Condition=" '%(Filename)%(Extension)' == 'Mono.Cecil.Pdb.csproj' ">
|
||||
<SetConfiguration Condition=" '$(TargetFramework)' == 'net46' And '$(Configuration)' == 'illink_Debug' ">Configuration=net_4_0_Debug</SetConfiguration>
|
||||
<SetConfiguration Condition=" '$(TargetFramework)' == 'netcoreapp2.0' And '$(Configuration)' == 'illink_Debug' ">Configuration=netstandard_Debug</SetConfiguration>
|
||||
<SetConfiguration Condition=" '$(TargetFramework)' == 'net46' And '$(Configuration)' == 'illink_Release' ">Configuration=net_4_0_Release</SetConfiguration>
|
||||
<SetConfiguration Condition=" '$(TargetFramework)' == 'netcoreapp2.0' And '$(Configuration)' == 'illink_Release' ">Configuration=netstandard_Release</SetConfiguration>
|
||||
</ProjectReferenceWithConfiguration>
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
</Project>
|
||||
45
external/linker/corebuild/integration/ILLink.Tasks/ComputeRemovedAssemblies.cs
vendored
Normal file
45
external/linker/corebuild/integration/ILLink.Tasks/ComputeRemovedAssemblies.cs
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Build.Utilities;
|
||||
using Microsoft.Build.Framework;
|
||||
|
||||
namespace ILLink.Tasks
|
||||
{
|
||||
public class ComputeRemovedAssemblies : Task
|
||||
{
|
||||
/// <summary>
|
||||
/// The paths to the inputs to the linker.
|
||||
/// </summary>
|
||||
[Required]
|
||||
public ITaskItem[] InputAssemblies { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The paths to the linked assemblies.
|
||||
/// </summary>
|
||||
[Required]
|
||||
public ITaskItem[] KeptAssemblies { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The set of assemblies in the inputs that weren't kept by
|
||||
/// the linker. These items include the full metadata from
|
||||
/// the input assemblies, and only the filenames of the
|
||||
/// inputs are used to determine which assemblies were
|
||||
/// removed.
|
||||
/// </summary>
|
||||
[Output]
|
||||
public ITaskItem[] RemovedAssemblies { get; set; }
|
||||
|
||||
public override bool Execute()
|
||||
{
|
||||
var keptAssemblyNames = new HashSet<string> (
|
||||
KeptAssemblies.Select(i => Path.GetFileName(i.ItemSpec))
|
||||
);
|
||||
RemovedAssemblies = InputAssemblies.Where(i =>
|
||||
!keptAssemblyNames.Contains(Path.GetFileName(i.ItemSpec))
|
||||
).ToArray();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.IO;
|
||||
using Microsoft.Build.Utilities;
|
||||
using Microsoft.Build.Framework;
|
||||
|
||||
namespace ILLink.Tasks
|
||||
{
|
||||
/// <summary>
|
||||
/// This class exists as a workaround. It strips the publish
|
||||
/// dependency file of assemblies excluded from the publish
|
||||
/// output by the linker. Ideally we would pass appropriate
|
||||
/// parameters to the task that generates the deps file in
|
||||
/// the first place, instead of rewriting it. We may be
|
||||
/// ablee to do this once
|
||||
/// https://github.com/dotnet/sdk/pull/1052 is merged.
|
||||
/// </summary>
|
||||
public class DepsJsonLinker : Task
|
||||
{
|
||||
[Required]
|
||||
public ITaskItem InputDepsFilePath { get; set; }
|
||||
|
||||
[Required]
|
||||
public ITaskItem OutputDepsFilePath { get; set; }
|
||||
|
||||
[Required]
|
||||
public ITaskItem[] ManagedPublishAssemblies { get; set; }
|
||||
|
||||
[Required]
|
||||
public ITaskItem[] KeptAssemblies { get; set; }
|
||||
|
||||
|
||||
public override bool Execute()
|
||||
{
|
||||
string inputFile = InputDepsFilePath.ItemSpec;
|
||||
string outputFile = OutputDepsFilePath.ItemSpec;
|
||||
|
||||
string[] keptAssemblies = KeptAssemblies.Select(a => a.ItemSpec).ToArray();
|
||||
string[] allAssemblies = ManagedPublishAssemblies.Select(a => a.ItemSpec).ToArray();
|
||||
string[] removedAssemblies = allAssemblies.Except(keptAssemblies).ToArray();
|
||||
|
||||
var removedAssembliesSet = new HashSet<string> (removedAssemblies, StringComparer.InvariantCultureIgnoreCase);
|
||||
|
||||
JObject o = JObject.Parse (File.ReadAllText (inputFile));
|
||||
|
||||
JObject targets = (JObject)o["targets"];
|
||||
|
||||
// Remove targets
|
||||
foreach (JProperty target in targets.Children()) {
|
||||
JEnumerable<JToken> children = target.Value.Children ();
|
||||
for (int i = 0; i < children.Count(); ++i) {
|
||||
//foreach (JProperty subtarget in target.Value.Children()) {
|
||||
var subtarget = (JProperty) children.ElementAt (i);
|
||||
string name = subtarget.Name.Substring (0, subtarget.Name.IndexOf ('/'));
|
||||
if (removedAssembliesSet.Contains (name + ".dll")) {
|
||||
subtarget.Remove ();
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Remove dependencies
|
||||
var dependencies = subtarget.Value["dependencies"];
|
||||
if (dependencies != null) {
|
||||
for (int j = 0; j < dependencies.Count (); ++j) {
|
||||
var dependency = ((JProperty)dependencies.ElementAt (j));
|
||||
|
||||
if (removedAssembliesSet.Contains (dependency.Name + ".dll")) {
|
||||
|
||||
dependency.Remove ();
|
||||
j--;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove runtimes
|
||||
var runtimes = subtarget.Value["runtime"];
|
||||
if (runtimes != null) {
|
||||
for (int j = 0; j < runtimes.Count (); ++j) {
|
||||
var runtime = ((JProperty)runtimes.ElementAt (j));
|
||||
string runtimeFileName = runtime.Name.Substring (runtime.Name.LastIndexOf ('/') + 1);
|
||||
|
||||
if (removedAssembliesSet.Contains (runtimeFileName)) {
|
||||
runtime.Remove ();
|
||||
j--;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove libraries
|
||||
JObject libraries = (JObject)o["libraries"];
|
||||
|
||||
JEnumerable<JToken> libraryChildren = libraries.Children ();
|
||||
for (int i = 0; i < libraryChildren.Count (); ++i) {
|
||||
var library = (JProperty)libraryChildren.ElementAt (i);
|
||||
string name = library.Name.Substring (0, library.Name.IndexOf ('/'));
|
||||
if (removedAssembliesSet.Contains (name + ".dll")) {
|
||||
library.Remove ();
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
File.WriteAllText (outputFile, o.ToString ());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
108
external/linker/corebuild/integration/ILLink.Tasks/FindNativeDeps.cs
vendored
Normal file
108
external/linker/corebuild/integration/ILLink.Tasks/FindNativeDeps.cs
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Build.Utilities;
|
||||
using Microsoft.Build.Framework;
|
||||
using System.Reflection.PortableExecutable;
|
||||
using System.Reflection.Metadata;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
|
||||
namespace ILLink.Tasks
|
||||
{
|
||||
public class FindNativeDeps : Task
|
||||
{
|
||||
/// <summary>
|
||||
/// The managed assemblies to scan for references to native
|
||||
/// dependencies.
|
||||
/// </summary>
|
||||
[Required]
|
||||
public ITaskItem[] ManagedAssemblyPaths { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The set of native dependencies to keep even if they
|
||||
/// aren't found to be referenced by a managed assembly..
|
||||
/// </summary>
|
||||
public ITaskItem[] NativeDepsToKeep { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The paths to the available native dependencies. We
|
||||
/// expect that all references found point to existing
|
||||
/// native files.
|
||||
/// </summary>
|
||||
[Required]
|
||||
public ITaskItem[] NativeDepsPaths { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The set of native dependencies to keep, including those
|
||||
/// found in the analysis, and those explicitly marked keep
|
||||
/// by NativeDepsToKeep. This includes metadata from the
|
||||
/// input NativeDepsToKeep.
|
||||
/// </summary>
|
||||
[Output]
|
||||
public ITaskItem[] KeptNativeDepsPaths { get; set; }
|
||||
|
||||
public override bool Execute()
|
||||
{
|
||||
var allNative = new Dictionary<string, ITaskItem> ();
|
||||
foreach (var n in NativeDepsPaths)
|
||||
{
|
||||
var fileName = Path.GetFileName(n.ItemSpec);
|
||||
if (!allNative.ContainsKey(fileName))
|
||||
{
|
||||
allNative.Add(fileName, n);
|
||||
}
|
||||
}
|
||||
var keptNative = new List<ITaskItem> ();
|
||||
var managedAssemblies = ManagedAssemblyPaths.Select (i => i.ItemSpec).ToArray();
|
||||
foreach (string managedAssembly in managedAssemblies)
|
||||
{
|
||||
using (var peReader = new PEReader(new FileStream(managedAssembly, FileMode.Open, FileAccess.Read, FileShare.Read)))
|
||||
{
|
||||
if (peReader.HasMetadata)
|
||||
{
|
||||
var reader = peReader.GetMetadataReader();
|
||||
for (int i = 1, count = reader.GetTableRowCount(TableIndex.ModuleRef); i <= count; i++)
|
||||
{
|
||||
var moduleRef = reader.GetModuleReference(MetadataTokens.ModuleReferenceHandle(i));
|
||||
var moduleName = reader.GetString(moduleRef.Name);
|
||||
|
||||
var moduleRefCandidates = new[] { moduleName, moduleName + ".dll", moduleName + ".so", moduleName + ".dylib" };
|
||||
|
||||
ITaskItem referencedNativeFile = null;
|
||||
foreach (string moduleRefCandidate in moduleRefCandidates)
|
||||
{
|
||||
if (allNative.TryGetValue (moduleRefCandidate, out referencedNativeFile))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (referencedNativeFile != null)
|
||||
{
|
||||
keptNative.Add(referencedNativeFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
// DLLImport that wasn't satisfied
|
||||
Log.LogMessage(MessageImportance.High, "unsatisfied DLLImport: " + managedAssembly + " -> " + moduleName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var n in NativeDepsToKeep)
|
||||
{
|
||||
ITaskItem nativeFile = null;
|
||||
if (allNative.TryGetValue (n.ItemSpec, out nativeFile))
|
||||
{
|
||||
keptNative.Add(nativeFile);
|
||||
}
|
||||
}
|
||||
KeptNativeDepsPaths = keptNative.ToArray();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,8 @@
|
||||
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netcoreapp2.0</TargetFrameworks>
|
||||
<RuntimeFrameworkVersion>2.0.0-beta-001509-00</RuntimeFrameworkVersion>
|
||||
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
|
||||
<PackageOutputPath>../nupkgs</PackageOutputPath>
|
||||
<BaseOutputPath>../bin/</BaseOutputPath>
|
||||
<PackageOutputPath>$(BaseOutputPath)nupkgs</PackageOutputPath>
|
||||
|
||||
<!-- IsTool true causes the build output to be placed in the
|
||||
package's tools folder. This allows projects to reference the
|
||||
@@ -42,7 +43,8 @@
|
||||
references from being marked as dependencies. -->
|
||||
<!-- TODO: Remove the custom .nuspec once the P2P PrivateAssets
|
||||
issue is fixed. -->
|
||||
<NuspecFile>ILLink.Tasks.nuspec</NuspecFile>
|
||||
<NuspecFileName>ILLink.Tasks.nuspec</NuspecFileName>
|
||||
<NuspecFile>$(BaseOutputPath)$(NuspecFileName)</NuspecFile>
|
||||
<NuspecProperties>id=$(AssemblyName);authors=$(AssemblyName);description=linker tasks;</NuspecProperties>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -65,7 +67,7 @@
|
||||
Instead, we use GenerateNuspecDependsOn. We could probably also
|
||||
use BeforeTargets="GenerateNuspec". -->
|
||||
<PropertyGroup>
|
||||
<GenerateNuspecDependsOn>SetDynamicNuspecProperties;$(GenerateNuspecDependsOn)</GenerateNuspecDependsOn>
|
||||
<GenerateNuspecDependsOn>SetDynamicNuspecProperties;BinPlacePackageDeps;$(GenerateNuspecDependsOn)</GenerateNuspecDependsOn>
|
||||
</PropertyGroup>
|
||||
<Target Name="SetDynamicNuspecProperties"
|
||||
DependsOnTargets="LayoutPackage">
|
||||
@@ -74,11 +76,21 @@
|
||||
</PropertyGroup>
|
||||
</Target>
|
||||
|
||||
<!-- This target is necessary because the .nuspec includes the full
|
||||
path of the selected dlls in the package layout. We want the
|
||||
assets to be included in the package without the bin prefix, so
|
||||
we place the .nuspec and the included targets alongside the
|
||||
publish directories in the bin directory. -->
|
||||
<Target Name="BinPlacePackageDeps">
|
||||
<Copy SourceFiles="$(NuspecFileName)" DestinationFolder="$(BaseOutputPath)" />
|
||||
<Copy SourceFiles="ILLink.Tasks.targets" DestinationFolder="$(BaseOutputPath)" />
|
||||
</Target>
|
||||
|
||||
<Target Name="LayoutPackage">
|
||||
<ItemGroup>
|
||||
<TFMsToPublish Include="$(TargetFrameworks)" />
|
||||
<ProjectsToPublish Include="$(MSBuildProjectFile)">
|
||||
<AdditionalProperties>TargetFramework=%(TFMsToPublish.Identity);PublishDir=%(TFMsToPublish.Identity)</AdditionalProperties>
|
||||
<AdditionalProperties>TargetFramework=%(TFMsToPublish.Identity);PublishDir=$(BaseOutputPath)%(TFMsToPublish.Identity)</AdditionalProperties>
|
||||
</ProjectsToPublish>
|
||||
</ItemGroup>
|
||||
<MSBuild Projects="@(ProjectsToPublish)" Targets="Publish" />
|
||||
@@ -86,7 +98,6 @@
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="LinkTask.cs" />
|
||||
<Compile Include="DepsJsonLinker.cs" />
|
||||
<Compile Include="CompareSizes.cs" />
|
||||
<Compile Include="ComputeManagedAssemblies.cs" />
|
||||
<Compile Include="GetRuntimeLibraries.cs" />
|
||||
@@ -94,6 +105,8 @@
|
||||
<Compile Include="Utils.cs" />
|
||||
<Compile Include="Microsoft.NET.Build.Tasks/LockFileCache.cs" />
|
||||
<Compile Include="Microsoft.NET.Build.Tasks/BuildErrorException.cs" />
|
||||
<Compile Include="FindNativeDeps.cs" />
|
||||
<Compile Include="ComputeRemovedAssemblies.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- TODO: Uncomment this once we can avoid hard-coding this in a
|
||||
@@ -167,6 +180,10 @@
|
||||
<SetConfiguration>Configuration=illink_$(Configuration)</SetConfiguration>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="../../../cecil/Mono.Cecil.csproj" />
|
||||
|
||||
<ProjectReference Include="../ILLink.CustomSteps/ILLink.CustomSteps.csproj">
|
||||
<SetConfiguration>Configuration=illink_$(Configuration)</SetConfiguration>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Workaround for the SetConfiguration issue described above. -->
|
||||
@@ -174,7 +191,8 @@
|
||||
AfterTargets="AssignProjectConfiguration">
|
||||
<ItemGroup>
|
||||
<ProjectReferenceWithConfiguration Condition=" '%(Filename)%(Extension)' == 'Mono.Cecil.csproj' Or '%(Filename)%(Extension)' == 'Mono.Cecil.Pdb.csproj' ">
|
||||
<SetConfiguration>Configuration=netstandard_$(Configuration)</SetConfiguration>
|
||||
<SetConfiguration Condition=" '$(TargetFramework)' == 'net46' ">Configuration=net_4_0_$(Configuration)</SetConfiguration>
|
||||
<SetConfiguration Condition=" '$(TargetFramework)' == 'netcoreapp2.0' ">Configuration=netstandard_$(Configuration)</SetConfiguration>
|
||||
</ProjectReferenceWithConfiguration>
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
@@ -194,5 +212,7 @@
|
||||
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="15.1.1012"
|
||||
PrivateAssets="All" />
|
||||
<PackageReference Include="NuGet.ProjectModel" Version="4.3.0-preview1-2500" />
|
||||
<PackageReference Include="System.Reflection.Metadata" Version="1.3.0"
|
||||
PrivateAssets="All" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -48,10 +48,8 @@
|
||||
<!-- Used to enable incremental build for the link target. -->
|
||||
<PropertyGroup>
|
||||
<_LinkSemaphore>$(IntermediateOutputPath)Link.semaphore</_LinkSemaphore>
|
||||
<_LinkDepsSemaphore>$(IntermediateOutputPath)LinkDeps.semaphore</_LinkDepsSemaphore>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
<!--
|
||||
This target runs the linker during the publish pipeline. The
|
||||
publish pipeline has a target called ComputeFilesToPublish,
|
||||
@@ -76,12 +74,14 @@
|
||||
ComputeFilesToPublish, but after all of its dependencies. -->
|
||||
<Target Name="ComputeLinkedFilesToPublish"
|
||||
BeforeTargets="ComputeFilesToPublish"
|
||||
DependsOnTargets="_ComputeLinkedAssemblies"
|
||||
DependsOnTargets="_ComputeLinkedAssemblies;_FindNativeDeps"
|
||||
Condition=" '$(LinkDuringPublish)' == 'true' ">
|
||||
<!-- Rewrite ResolvedAssembliesToPublish, which is an input to
|
||||
ComputeFilesToPublish. -->
|
||||
<ItemGroup>
|
||||
<ResolvedAssembliesToPublish Remove="@(_ManagedResolvedAssembliesToPublish)" />
|
||||
<ResolvedAssembliesToPublish Remove="@(_NativeResolvedDepsToPublish)" />
|
||||
<ResolvedAssembliesToPublish Include="@(_NativeKeptDepsToPublish)" />
|
||||
<ResolvedAssembliesToPublish Include="@(_LinkedResolvedAssemblies)" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -141,7 +141,6 @@
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
|
||||
<!-- This calls the linker. Inputs are the managed assemblies to
|
||||
link, and root specifications. The semaphore enables msbuild to
|
||||
skip linking during an incremental build, when the semaphore is
|
||||
@@ -169,6 +168,37 @@
|
||||
</Touch>
|
||||
</Target>
|
||||
|
||||
<!-- FindNativeDeps scans the managed assemblies kept by the linker
|
||||
to find references to native files. It outputs the found native
|
||||
dependencies, and these are prevented from being published. -->
|
||||
<UsingTask TaskName="FindNativeDeps" AssemblyFile="$(LinkTaskDllPath)" />
|
||||
<Target Name="_FindNativeDeps"
|
||||
DependsOnTargets="_ComputeLinkedAssemblies">
|
||||
<ItemGroup>
|
||||
<_NativeResolvedDepsToPublish Include="@(ResolvedAssembliesToPublish)" />
|
||||
<_NativeResolvedDepsToPublish Remove="@(_ManagedResolvedAssembliesToPublish)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<_ManagedLinkedAssemblies Include="@(_LinkedResolvedAssemblies)" />
|
||||
<_ManagedLinkedAssemblies Include="@(_LinkedIntermediateAssembly)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<_NativeDepsToAlwaysKeep Include="coreclr.dll;libcoreclr.dylib;libcoreclr.so" />
|
||||
<_NativeDepsToAlwaysKeep Include="clrjit.dll;libclrjit.dylib;libclrjit.so" />
|
||||
<_NativeDepsToAlwaysKeep Include="hostfxr.dll;libhostfxr.dylib;libhostfxr.so" />
|
||||
<_NativeDepsToAlwaysKeep Include="hostpolicy.dll;libhostpolicy.dylib;libhostpolicy.so" />
|
||||
</ItemGroup>
|
||||
|
||||
<FindNativeDeps ManagedAssemblyPaths="@(_ManagedLinkedAssemblies)"
|
||||
NativeDepsPaths="@(_NativeResolvedDepsToPublish)"
|
||||
NativeDepsToKeep="@(_NativeDepsToAlwaysKeep)">
|
||||
<Output TaskParameter="KeptNativeDepsPaths" ItemName="_NativeKeptDepsToPublish" />
|
||||
</FindNativeDeps>
|
||||
|
||||
</Target>
|
||||
|
||||
|
||||
<!-- Computes the managed assemblies that are input to the
|
||||
linker. Includes managed assemblies from
|
||||
@@ -243,9 +273,10 @@
|
||||
assembly, because we root it separately using an xml file,
|
||||
which lets us explicitly root everything. -->
|
||||
<ItemGroup>
|
||||
<LinkerRootAssemblies Include="@(_ManagedResolvedAssembliesToPublish->'%(Filename)')" />
|
||||
<LinkerRootAssemblies Remove="@(PlatformLibraries->'%(Filename)')" />
|
||||
<LinkerRootAssemblies Include="System.Private.CoreLib" />
|
||||
<_LinkerRootAssemblies Include="@(_ManagedResolvedAssembliesToPublish->'%(Filename)')" />
|
||||
<_LinkerRootAssemblies Remove="@(PlatformLibraries->'%(Filename)')" />
|
||||
<_LinkerRootAssemblies Include="System.Private.CoreLib" />
|
||||
<LinkerRootAssemblies Include="@(_LinkerRootAssemblies)" />
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
@@ -286,38 +317,27 @@
|
||||
RootDescriptorFilePath="$(_IntermediateRootDescriptorPath)" />
|
||||
</Target>
|
||||
|
||||
<!-- Uses _PublishConflictPackageFiles, an input to the publish deps
|
||||
file generation target, to exclude the removed managed
|
||||
assemblies and native dependencies from the generated deps
|
||||
file. -->
|
||||
<UsingTask TaskName="ComputeRemovedAssemblies" AssemblyFile="$(LinkTaskDllPath)" />
|
||||
<Target Name="_ExcludeRemovedFilesFromDepFileGeneration"
|
||||
DependsOnTargets="_ComputeManagedResolvedAssembliesToPublish;_ComputeLinkedAssemblies;_FindNativeDeps;_HandlePublishFileConflicts"
|
||||
BeforeTargets="GeneratePublishDependencyFile"
|
||||
Condition=" '$(LinkDuringPublish)' == 'true' ">
|
||||
<ComputeRemovedAssemblies InputAssemblies="@(_ManagedResolvedAssembliesToPublish)"
|
||||
KeptAssemblies="@(_LinkedResolvedAssemblies)">
|
||||
<Output TaskParameter="RemovedAssemblies" ItemName="_RemovedManagedAssemblies" />
|
||||
</ComputeRemovedAssemblies>
|
||||
|
||||
<!-- This target needs to remove from the publish deps file those
|
||||
assemblies that were excluded from the publish output by the
|
||||
linker. Currently it does so by rewriting the publish
|
||||
dependency file (as opposed to generating one without the
|
||||
excluded assemblies in the first place).
|
||||
|
||||
TODO: update this to pass FilesToSkip to
|
||||
GeneratePublishDependencyFile once
|
||||
https://github.com/dotnet/sdk/pull/1052 is merged.
|
||||
-->
|
||||
<UsingTask TaskName="DepsJsonLinker" AssemblyFile="$(LinkTaskDllPath)" />
|
||||
<Target Name="_GenerateLinkedPublishDependencyFile"
|
||||
DependsOnTargets="_ComputeManagedAssembliesToLink;_ComputeLinkedAssemblies"
|
||||
AfterTargets="GeneratePublishDependencyFile"
|
||||
Condition=" '$(LinkDuringPublish)' == 'true' "
|
||||
Inputs="@(_ManagedResolvedAssembliesToPublish);@(_LinkedResolvedAssemblies);$(PublishDepsFilePath)"
|
||||
Outputs="$(_LinkDepsSemaphore)">
|
||||
<!-- DepsJsonLinker expects inputs in the form of filename.dll. -->
|
||||
<!-- We pass _ManagedResolvedAssembliesToPublish, which doesn't
|
||||
contain any .ni files. This correctly prevents stripping of
|
||||
the .ni files (which we want to continue publishing at the
|
||||
moment). -->
|
||||
<!-- This doesn't filter any assemblies from IntermediateAssembly,
|
||||
which should currently always be rooted by default. -->
|
||||
<DepsJsonLinker InputDepsFilePath="$(PublishDepsFilePath)"
|
||||
OutputDepsFilePath="$(PublishDepsFilePath)"
|
||||
ManagedPublishAssemblies="@(_ManagedResolvedAssembliesToPublish->'%(Filename)%(Extension)')"
|
||||
KeptAssemblies="@(_LinkedResolvedAssemblies->'%(Filename)%(Extension)')" />
|
||||
<Touch Files="$(_LinkDepsSemaphore)" AlwaysCreate="true">
|
||||
<Output TaskParameter="TouchedFiles" ItemName="FileWrites" />
|
||||
</Touch>
|
||||
<ItemGroup>
|
||||
<_RemovedNativeDeps Include="@(_NativeResolvedDepsToPublish)" />
|
||||
<_RemovedNativeDeps Remove="@(_NativeKeptDepsToPublish)" />
|
||||
|
||||
<_PublishConflictPackageFiles Include="@(_RemovedManagedAssemblies)" />
|
||||
<_PublishConflictPackageFiles Include="@(_RemovedNativeDeps)" />
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -36,6 +36,10 @@ namespace ILLink.Tests
|
||||
AddLinkerReference(csproj);
|
||||
|
||||
BuildAndLink(csproj, null);
|
||||
|
||||
int ret = RunApp(csproj, out string commandOutput);
|
||||
Assert.True(ret == 0);
|
||||
Assert.True(commandOutput.Contains("Hello World!"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user