From 3f6eb6abcedf4c98e3c700621231460ff3ff2c53 Mon Sep 17 00:00:00 2001 From: Julien Lebosquain Date: Thu, 30 May 2024 18:07:11 +0200 Subject: [PATCH] Use ILRepack tool instead of submodule --- .gitmodules | 3 -- nukebuild/Build.cs | 6 ++-- nukebuild/BuildTasksPatcher.cs | 34 ++++++++----------- nukebuild/_build.csproj | 4 +-- nukebuild/il-repack | 1 - .../Avalonia.Build.Tasks.csproj | 12 ++++--- 6 files changed, 27 insertions(+), 33 deletions(-) delete mode 160000 nukebuild/il-repack diff --git a/.gitmodules b/.gitmodules index 032bc879cc5c..2d11fdfa9e10 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,6 +4,3 @@ [submodule "src/Markup/Avalonia.Markup.Xaml/XamlIl/xamlil.github"] path = src/Markup/Avalonia.Markup.Xaml.Loader/xamlil.github url = https://github.com/kekekeks/XamlX.git -[submodule "nukebuild/il-repack"] - path = nukebuild/il-repack - url = https://github.com/Gillibald/il-repack diff --git a/nukebuild/Build.cs b/nukebuild/Build.cs index d1d6e043c1e1..c71a0c1e39e3 100644 --- a/nukebuild/Build.cs +++ b/nukebuild/Build.cs @@ -40,7 +40,8 @@ partial class Build : NukeBuild [PackageExecutable("Microsoft.DotNet.GenAPI.Tool", "Microsoft.DotNet.GenAPI.Tool.dll", Framework = "net8.0")] Tool ApiGenTool; - + [PackageExecutable("dotnet-ilrepack", "ILRepackTool.dll", Framework = "net8.0")] + Tool IlRepackTool; protected override void OnBuildInitialized() { @@ -307,7 +308,8 @@ void DoMemoryTest() .Executes(() => { BuildTasksPatcher.PatchBuildTasksInPackage(Parameters.NugetIntermediateRoot / "Avalonia.Build.Tasks." + - Parameters.Version + ".nupkg"); + Parameters.Version + ".nupkg", + IlRepackTool); var config = Numerge.MergeConfiguration.LoadFile(RootDirectory / "nukebuild" / "numerge.config"); EnsureCleanDirectory(Parameters.NugetRoot); if(!Numerge.NugetPackageMerger.Merge(Parameters.NugetIntermediateRoot, Parameters.NugetRoot, config, diff --git a/nukebuild/BuildTasksPatcher.cs b/nukebuild/BuildTasksPatcher.cs index f2dd217657ff..6bb71f43209c 100644 --- a/nukebuild/BuildTasksPatcher.cs +++ b/nukebuild/BuildTasksPatcher.cs @@ -2,9 +2,9 @@ using System.IO; using System.IO.Compression; using System.Linq; -using ILRepacking; using Mono.Cecil; using Mono.Cecil.Cil; +using Nuke.Common.Tooling; public class BuildTasksPatcher { @@ -56,7 +56,7 @@ private static string GetSourceLinkInfo(string path) return null; } - public static void PatchBuildTasksInPackage(string packagePath) + public static void PatchBuildTasksInPackage(string packagePath, Tool ilRepackTool) { using (var archive = new ZipArchive(File.Open(packagePath, FileMode.Open, FileAccess.ReadWrite), ZipArchiveMode.Update)) @@ -70,7 +70,7 @@ public static void PatchBuildTasksInPackage(string packagePath) Directory.CreateDirectory(tempDir); var temp = Path.Combine(tempDir, entry.Name); var output = temp + ".output"; - File.Copy(typeof(Microsoft.Build.Framework.ITask).Assembly.GetModules()[0].FullyQualifiedName, + File.Copy(GetAssemblyPath(typeof(Microsoft.Build.Framework.ITask)), Path.Combine(tempDir, "Microsoft.Build.Framework.dll")); var patched = new MemoryStream(); try @@ -78,22 +78,15 @@ public static void PatchBuildTasksInPackage(string packagePath) entry.ExtractToFile(temp, true); // Get Original SourceLinkInfo Content var sourceLinkInfoContent = GetSourceLinkInfo(temp); - var repack = new ILRepacking.ILRepack(new RepackOptions() - { - Internalize = true, - InputAssemblies = new[] - { - temp, - typeof(Mono.Cecil.AssemblyDefinition).Assembly.GetModules()[0].FullyQualifiedName, - typeof(Mono.Cecil.Rocks.MethodBodyRocks).Assembly.GetModules()[0].FullyQualifiedName, - typeof(Mono.Cecil.Pdb.PdbReaderProvider).Assembly.GetModules()[0].FullyQualifiedName, - typeof(Mono.Cecil.Mdb.MdbReaderProvider).Assembly.GetModules()[0].FullyQualifiedName, - }, - SearchDirectories = Array.Empty(), - DebugInfo = true, // Allowed read debug info - OutputFile = output - }); - repack.Repack(); + + var cecilAsm = GetAssemblyPath(typeof(Mono.Cecil.AssemblyDefinition)); + var cecilRocksAsm = GetAssemblyPath(typeof(Mono.Cecil.Rocks.MethodBodyRocks)); + var cecilPdbAsm = GetAssemblyPath(typeof(Mono.Cecil.Pdb.PdbReaderProvider)); + var cecilMdbAsm = GetAssemblyPath(typeof(Mono.Cecil.Mdb.MdbReaderProvider)); + + ilRepackTool.Invoke( + $"/internalize /out:\"{output}\" \"{temp}\" \"{cecilAsm}\" \"{cecilRocksAsm}\" \"{cecilPdbAsm}\" \"{cecilMdbAsm}\"", + tempDir); // 'hurr-durr assembly with the same name is already loaded' prevention using (var asm = AssemblyDefinition.ReadAssembly(output, @@ -161,4 +154,7 @@ public static void PatchBuildTasksInPackage(string packagePath) } } } + + private static string GetAssemblyPath(Type typeInAssembly) + => typeInAssembly.Assembly.GetModules()[0].FullyQualifiedName; } diff --git a/nukebuild/_build.csproj b/nukebuild/_build.csproj index 7c89b896c7ab..a2c4f890da95 100644 --- a/nukebuild/_build.csproj +++ b/nukebuild/_build.csproj @@ -20,7 +20,6 @@ - all @@ -29,6 +28,7 @@ + @@ -38,9 +38,7 @@ - - diff --git a/nukebuild/il-repack b/nukebuild/il-repack deleted file mode 160000 index 892f079ea8cb..000000000000 --- a/nukebuild/il-repack +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 892f079ea8cb0c178f0a68f53a7a7eac13acdda9 diff --git a/src/Avalonia.Build.Tasks/Avalonia.Build.Tasks.csproj b/src/Avalonia.Build.Tasks/Avalonia.Build.Tasks.csproj index 61069630a5e0..04b89ed4d9a8 100644 --- a/src/Avalonia.Build.Tasks/Avalonia.Build.Tasks.csproj +++ b/src/Avalonia.Build.Tasks/Avalonia.Build.Tasks.csproj @@ -1,6 +1,7 @@  - netstandard2.0 + netstandard2.0 + enable false tools $(DefineConstants);BUILDTASK;XAMLX_CECIL_INTERNAL;XAMLX_INTERNAL @@ -114,13 +115,14 @@ Markup/%(RecursiveDir)%(FileName)%(Extension) - - + + - - + + +