|
|
|
@ -40,17 +40,48 @@ namespace Avalonia.Build.Tasks |
|
|
|
WrittenFile = writtenFile; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static CompileResult Compile(IBuildEngine engine, string input, string[] references, |
|
|
|
string projectDirectory, |
|
|
|
string output, bool verifyIl, MessageImportance logImportance, string strongNameKey, bool patchCom, |
|
|
|
bool skipXamlCompilation) |
|
|
|
{ |
|
|
|
var typeSystem = new CecilTypeSystem(references.Concat(new[] { input }), input); |
|
|
|
|
|
|
|
var asm = typeSystem.TargetAssemblyDefinition; |
|
|
|
|
|
|
|
if (!skipXamlCompilation) |
|
|
|
{ |
|
|
|
var compileRes = CompileCore(engine, typeSystem, projectDirectory, verifyIl, logImportance); |
|
|
|
if (compileRes == null && !patchCom) |
|
|
|
return new CompileResult(true); |
|
|
|
if (compileRes == false) |
|
|
|
return new CompileResult(false); |
|
|
|
} |
|
|
|
|
|
|
|
if (patchCom) |
|
|
|
ComInteropHelper.PatchAssembly(asm, typeSystem); |
|
|
|
|
|
|
|
var writerParameters = new WriterParameters { WriteSymbols = asm.MainModule.HasSymbols }; |
|
|
|
if (!string.IsNullOrWhiteSpace(strongNameKey)) |
|
|
|
writerParameters.StrongNameKeyBlob = File.ReadAllBytes(strongNameKey); |
|
|
|
|
|
|
|
asm.Write(output, writerParameters); |
|
|
|
|
|
|
|
return new CompileResult(true, true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public static CompileResult Compile(IBuildEngine engine, string input, string[] references, string projectDirectory, |
|
|
|
string output, bool verifyIl, MessageImportance logImportance, string strongNameKey, bool patchCom) |
|
|
|
static bool? CompileCore(IBuildEngine engine, CecilTypeSystem typeSystem, |
|
|
|
string projectDirectory, bool verifyIl, |
|
|
|
MessageImportance logImportance) |
|
|
|
{ |
|
|
|
var typeSystem = new CecilTypeSystem(references.Concat(new[] {input}), input); |
|
|
|
var asm = typeSystem.TargetAssemblyDefinition; |
|
|
|
var emres = new EmbeddedResources(asm); |
|
|
|
var avares = new AvaloniaResources(asm, projectDirectory); |
|
|
|
if (avares.Resources.Count(CheckXamlName) == 0 && emres.Resources.Count(CheckXamlName) == 0 && !patchCom) |
|
|
|
if (avares.Resources.Count(CheckXamlName) == 0 && emres.Resources.Count(CheckXamlName) == 0) |
|
|
|
// Nothing to do
|
|
|
|
return new CompileResult(true); |
|
|
|
return null; |
|
|
|
|
|
|
|
var clrPropertiesDef = new TypeDefinition("CompiledAvaloniaXaml", "XamlIlHelpers", |
|
|
|
TypeAttributes.Class, asm.MainModule.TypeSystem.Object); |
|
|
|
@ -364,27 +395,17 @@ namespace Avalonia.Build.Tasks |
|
|
|
|
|
|
|
if (emres.Resources.Count(CheckXamlName) != 0) |
|
|
|
if (!CompileGroup(emres)) |
|
|
|
return new CompileResult(false); |
|
|
|
return false; |
|
|
|
if (avares.Resources.Count(CheckXamlName) != 0) |
|
|
|
{ |
|
|
|
if (!CompileGroup(avares)) |
|
|
|
return new CompileResult(false); |
|
|
|
return false; |
|
|
|
avares.Save(); |
|
|
|
} |
|
|
|
|
|
|
|
loaderDispatcherMethod.Body.Instructions.Add(Instruction.Create(OpCodes.Ldnull)); |
|
|
|
loaderDispatcherMethod.Body.Instructions.Add(Instruction.Create(OpCodes.Ret)); |
|
|
|
|
|
|
|
if (patchCom) |
|
|
|
ComInteropHelper.PatchAssembly(asm, typeSystem); |
|
|
|
|
|
|
|
var writerParameters = new WriterParameters { WriteSymbols = asm.MainModule.HasSymbols }; |
|
|
|
if (!string.IsNullOrWhiteSpace(strongNameKey)) |
|
|
|
writerParameters.StrongNameKeyBlob = File.ReadAllBytes(strongNameKey); |
|
|
|
|
|
|
|
asm.Write(output, writerParameters); |
|
|
|
|
|
|
|
return new CompileResult(true, true); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|