Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to vanilla 0.10 cecil #236

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

20 changes: 12 additions & 8 deletions ILRepack.IntegrationTests/ILRepack.IntegrationTests.csproj
Expand Up @@ -33,6 +33,18 @@
<Reference Include="FSharp.Core, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\FSharp.Core.4.0.0.1\lib\net40\FSharp.Core.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil, Version=0.11.1.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.11.1\lib\net40\Mono.Cecil.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil.Mdb, Version=0.11.1.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.11.1\lib\net40\Mono.Cecil.Mdb.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil.Pdb, Version=0.11.1.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.11.1\lib\net40\Mono.Cecil.Pdb.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil.Rocks, Version=0.11.1.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.11.1\lib\net40\Mono.Cecil.Rocks.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
<Private>True</Private>
Expand Down Expand Up @@ -90,14 +102,6 @@
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\cecil\Mono.Cecil.csproj">
<Project>{d68133bd-1e63-496e-9ede-4fbdbf77b486}</Project>
<Name>Mono.Cecil</Name>
</ProjectReference>
<ProjectReference Include="..\cecil\symbols\pdb\Mono.Cecil.Pdb.csproj">
<Project>{63e6915c-7ea4-4d76-ab28-0d7191eea626}</Project>
<Name>Mono.Cecil.Pdb</Name>
</ProjectReference>
<ProjectReference Include="..\ILRepack\ILRepack.csproj">
<Project>{4a253a60-d998-4ca2-b9d5-46567a2fbf80}</Project>
<Name>ILRepack</Name>
Expand Down
29 changes: 29 additions & 0 deletions ILRepack.IntegrationTests/NuGet/RepackNuGetTests.cs
Expand Up @@ -85,6 +85,28 @@ public void VerifiesMergesBclFine()
Assert.IsFalse(errors.Contains(PeverifyHelper.VER_E_TYPELOAD));
}

[Test]
[Platform(Include = "win")]
public void VerifiesMergesFineWhenOutPathIsOneOfInputs()
{
var platform = Platform.From(
Package.From("Microsoft.Bcl", "1.1.10")
.WithArtifact(@"lib\net40\System.Runtime.dll"),
Package.From("Microsoft.Bcl", "1.1.10")
.WithArtifact(@"lib\net40\System.Threading.Tasks.dll"),
Package.From("Microsoft.Bcl.Async", "1.0.168")
.WithArtifact(@"lib\net40\Microsoft.Threading.Tasks.dll"))
.WithExtraArgs(@"/targetplatform:v4,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0");

platform.Packages.ToObservable()
.SelectMany(NuGetHelpers.GetNupkgAssembliesAsync)
.Do(lib => TestHelpers.SaveAs(lib.Item2(), tempDirectory, lib.Item1))
.Select(lib => Path.GetFileName(lib.Item1))
.ToList()
.Do(list => RepackPlatformIntoPrimary(platform, list))
.First();
}

[Test]
[Platform(Include = "win")]
public void VerifiesMergedSignedAssemblyHasNoUnsignedFriend()
Expand Down Expand Up @@ -184,6 +206,13 @@ private static IEnumerable<string> GetSourceLinks(string pdbName)
}
}

void RepackPlatformIntoPrimary(Platform platform, IList<string> list)
{
list = list.OrderBy(f => f).ToList();
Console.WriteLine("Merging {0} into {1}", string.Join(",",list), list.First());
TestHelpers.DoRepackForCmd(new []{"/out:"+Tmp(list.First()), "/lib:"+tempDirectory}.Concat(platform.Args).Concat(list.Select(Tmp).OrderBy(x => x)));
}

void RepackPlatform(Platform platform, IList<string> list)
{
Assert.IsTrue(list.Count >= platform.Packages.Count(),
Expand Down
15 changes: 11 additions & 4 deletions ILRepack.IntegrationTests/NuGet/TestHelpers.cs
Expand Up @@ -38,11 +38,18 @@ public static void DoRepackForCmd(IEnumerable<string> args)

private static void ReloadAndCheckReferences(RepackOptions repackOptions)
{
var outputFile = AssemblyDefinition.ReadAssembly(repackOptions.OutputFile, new ReaderParameters(ReadingMode.Immediate));
var mergedFiles = repackOptions.ResolveFiles().Select(f => AssemblyDefinition.ReadAssembly(f, new ReaderParameters(ReadingMode.Deferred)));
foreach (var a in outputFile.MainModule.AssemblyReferences.Where(x => mergedFiles.Any(y => repackOptions.KeepOtherVersionReferences ? x.FullName == y.FullName : x.Name == y.Name.Name)))
using (var ar = new DefaultAssemblyResolver())
using (var outputFile = AssemblyDefinition.ReadAssembly(repackOptions.OutputFile, new ReaderParameters(ReadingMode.Immediate) { AssemblyResolver = ar }))
{
Assert.Fail($"Merged assembly retains a reference to one (or more) of the merged files: {a.FullName}");
var mergedFiles = repackOptions.ResolveFiles().Select(f => AssemblyDefinition.ReadAssembly(f, new ReaderParameters(ReadingMode.Deferred) { AssemblyResolver = ar })).ToList();
foreach (var a in outputFile.MainModule.AssemblyReferences.Where(x => mergedFiles.Any(y => repackOptions.KeepOtherVersionReferences ? x.FullName == y.FullName : x.Name == y.Name.Name)))
{
Assert.Fail($"Merged assembly retains a reference to one (or more) of the merged files: {a.FullName}");
}
foreach (var a in mergedFiles)
{
a.Dispose();
}
}
}

Expand Down
1 change: 1 addition & 0 deletions ILRepack.IntegrationTests/packages.config
Expand Up @@ -3,6 +3,7 @@
<package id="BamlParser" version="1.0.0" targetFramework="net40" />
<package id="fasterflect" version="2.1.3" targetFramework="net40" />
<package id="FSharp.Core" version="4.0.0.1" targetFramework="net40" />
<package id="Mono.Cecil" version="0.11.1" targetFramework="net40" />
<package id="Moq" version="4.2.1409.1722" targetFramework="net40" />
<package id="NUnit" version="2.6.4" targetFramework="net40" />
<package id="Rx-Core" version="2.2.5" targetFramework="net40" />
Expand Down
13 changes: 9 additions & 4 deletions ILRepack.Tests/ILRepack.Tests.csproj
Expand Up @@ -48,6 +48,15 @@
<HintPath>..\packages\fasterflect.2.1.3\lib\net40\Fasterflect.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Mono.Cecil, Version=0.11.1.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.11.1\lib\net40\Mono.Cecil.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil.Mdb, Version=0.11.1.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.11.1\lib\net40\Mono.Cecil.Mdb.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil.Pdb, Version=0.11.1.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.11.1\lib\net40\Mono.Cecil.Pdb.dll</HintPath>
</Reference>
<Reference Include="Moq">
<HintPath>..\packages\Moq.4.2.1409.1722\lib\net40\Moq.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -85,10 +94,6 @@
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\cecil\Mono.Cecil.csproj">
<Project>{d68133bd-1e63-496e-9ede-4fbdbf77b486}</Project>
<Name>Mono.Cecil</Name>
</ProjectReference>
<ProjectReference Include="..\ILRepack.IntegrationTests\Scenarios\ClassLibrary\ClassLibrary.csproj">
<Project>{801489b7-46cb-42d0-8581-0120f3566a8f}</Project>
<Name>ClassLibrary</Name>
Expand Down
3 changes: 2 additions & 1 deletion ILRepack.Tests/packages.config
Expand Up @@ -2,6 +2,7 @@
<packages>
<package id="BamlParser" version="1.0.0" targetFramework="net40" />
<package id="fasterflect" version="2.1.3" targetFramework="net40" />
<package id="Mono.Cecil" version="0.11.1" targetFramework="net40" />
<package id="Moq" version="4.2.1409.1722" targetFramework="net40" />
<package id="NUnit" version="2.6.4" targetFramework="net40" />
</packages>
</packages>
24 changes: 0 additions & 24 deletions ILRepack.sln
Expand Up @@ -12,12 +12,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ILRepack", "ILRepack\ILRepack.csproj", "{4A253A60-D998-4CA2-B9D5-46567A2FBF80}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Cecil", "cecil\Mono.Cecil.csproj", "{D68133BD-1E63-496E-9EDE-4FBDBF77B486}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Cecil.Pdb", "cecil\symbols\pdb\Mono.Cecil.Pdb.csproj", "{63E6915C-7EA4-4D76-AB28-0D7191EEA626}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Cecil.Mdb", "cecil\symbols\mdb\Mono.Cecil.Mdb.csproj", "{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ILRepack.Tests", "ILRepack.Tests\ILRepack.Tests.csproj", "{468ED600-2E3B-471C-BB8A-B0D968FD7FA2}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Integration Tests Scenarios", "Integration Tests Scenarios", "{04819B25-ABEA-46F7-90D5-149C8304F67F}"
Expand Down Expand Up @@ -61,24 +55,6 @@ Global
{4A253A60-D998-4CA2-B9D5-46567A2FBF80}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4A253A60-D998-4CA2-B9D5-46567A2FBF80}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4A253A60-D998-4CA2-B9D5-46567A2FBF80}.Release|Any CPU.Build.0 = Release|Any CPU
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Debug_unix|Any CPU.ActiveCfg = net_3_5_Debug|Any CPU
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Debug_unix|Any CPU.Build.0 = net_3_5_Debug|Any CPU
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Debug|Any CPU.ActiveCfg = net_3_5_Debug|Any CPU
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Debug|Any CPU.Build.0 = net_3_5_Debug|Any CPU
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Release|Any CPU.ActiveCfg = net_3_5_Release|Any CPU
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Release|Any CPU.Build.0 = net_3_5_Release|Any CPU
{63E6915C-7EA4-4D76-AB28-0D7191EEA626}.Debug_unix|Any CPU.ActiveCfg = net_3_5_Debug|Any CPU
{63E6915C-7EA4-4D76-AB28-0D7191EEA626}.Debug_unix|Any CPU.Build.0 = net_3_5_Debug|Any CPU
{63E6915C-7EA4-4D76-AB28-0D7191EEA626}.Debug|Any CPU.ActiveCfg = net_3_5_Debug|Any CPU
{63E6915C-7EA4-4D76-AB28-0D7191EEA626}.Debug|Any CPU.Build.0 = net_3_5_Debug|Any CPU
{63E6915C-7EA4-4D76-AB28-0D7191EEA626}.Release|Any CPU.ActiveCfg = net_3_5_Release|Any CPU
{63E6915C-7EA4-4D76-AB28-0D7191EEA626}.Release|Any CPU.Build.0 = net_3_5_Release|Any CPU
{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}.Debug_unix|Any CPU.ActiveCfg = net_3_5_Debug|Any CPU
{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}.Debug_unix|Any CPU.Build.0 = net_3_5_Debug|Any CPU
{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}.Debug|Any CPU.ActiveCfg = net_3_5_Debug|Any CPU
{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}.Debug|Any CPU.Build.0 = net_3_5_Debug|Any CPU
{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}.Release|Any CPU.ActiveCfg = net_3_5_Release|Any CPU
{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}.Release|Any CPU.Build.0 = net_3_5_Release|Any CPU
{468ED600-2E3B-471C-BB8A-B0D968FD7FA2}.Debug_unix|Any CPU.ActiveCfg = Debug_unix|Any CPU
{468ED600-2E3B-471C-BB8A-B0D968FD7FA2}.Debug_unix|Any CPU.Build.0 = Debug_unix|Any CPU
{468ED600-2E3B-471C-BB8A-B0D968FD7FA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand Down
32 changes: 14 additions & 18 deletions ILRepack/IKVMLineIndexer.cs
Expand Up @@ -17,7 +17,6 @@ internal class IKVMLineIndexer
{
private readonly IRepackContext repack;
private bool enabled;
private LineNumberWriter lineNumberWriter;
private string fileName;
private TypeReference sourceFileAttributeTypeReference;
private TypeReference lineNumberTableAttributeTypeReference;
Expand All @@ -41,29 +40,29 @@ public IKVMLineIndexer(IRepackContext ilRepack, bool doLineIndexing)

public void Reset()
{
lineNumberWriter = null;
fileName = null;
}

public void PreMethodBodyRepack(MethodBody body, MethodDefinition parent)
{
if (!enabled)
if (!enabled || !parent.DebugInformation.HasSequencePoints)
return;

Reset();
if (!parent.CustomAttributes.Any(x => x.Constructor.DeclaringType.Name == "LineNumberTableAttribute"))
{
lineNumberWriter = new LineNumberWriter(body.Instructions.Count / 4);
var lineNumberWriter = new LineNumberWriter(body.Instructions.Count / 4);
foreach (var sp in parent.DebugInformation.SequencePoints)
{
AddSeqPoint(sp, lineNumberWriter);
}
PostMethodBodyRepack(parent, lineNumberWriter);
}
}

public void ProcessMethodBodyInstruction(Instruction instr)
private void AddSeqPoint(SequencePoint currentSeqPoint, LineNumberWriter lineNumberWriter)
{
if (!enabled)
return;

var currentSeqPoint = instr.SequencePoint;
if (lineNumberWriter != null && currentSeqPoint != null)
if (currentSeqPoint != null)
{
if (fileName == null && currentSeqPoint.Document != null)
{
Expand All @@ -84,25 +83,22 @@ public void ProcessMethodBodyInstruction(Instruction instr)
{
if (lineNumberWriter.LineNo > 0)
{
lineNumberWriter.AddMapping(instr.Offset, -1);
lineNumberWriter.AddMapping(currentSeqPoint.Offset, -1);
}
}
else
{
if (lineNumberWriter.LineNo != currentSeqPoint.StartLine)
{
lineNumberWriter.AddMapping(instr.Offset, currentSeqPoint.StartLine);
lineNumberWriter.AddMapping(currentSeqPoint.Offset, currentSeqPoint.StartLine);
}
}
}
}

public void PostMethodBodyRepack(MethodDefinition parent)
private void PostMethodBodyRepack(MethodDefinition parent, LineNumberWriter lineNumberWriter)
{
if (!enabled)
return;

if (lineNumberWriter != null && lineNumberWriter.Count > 0)
if (lineNumberWriter.Count > 0)
{
CustomAttribute ca;
if (lineNumberWriter.Count == 1)
Expand Down Expand Up @@ -155,7 +151,7 @@ public void PostRepackReferences()
IMetadataScope ikvmRuntimeReference = repack.TargetAssemblyMainModule.AssemblyReferences.FirstOrDefault(r => r.Name == "IKVM.Runtime");
if (ikvmRuntimeReference == null)
{
ikvmRuntimeReference = repack.MergeScope(repack.GlobalAssemblyResolver.Resolve("IKVM.Runtime").Name);
ikvmRuntimeReference = repack.MergeScope(repack.GlobalAssemblyResolver.Resolve(new AssemblyNameReference("IKVM.Runtime", null)).Name);
}
if (ikvmRuntimeReference == null)
{
Expand Down