Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion tools/assembly-preparer/AssemblyPreparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,10 @@ bool RunSteps (IList<ConfigurationAwareStep> steps, out List<ProductException> e
// Subscribe once the assemblies have been loaded: accessing the AppBundleRewriter before
// that point would create it without finding the corlib and platform assemblies.
if (assemblySavedHandler is null && configuration.Assemblies.Count > 0) {
assemblySavedHandler = (_) => currentStepModifiedAssemblies = true;
assemblySavedHandler = (asm) => {
currentStepModifiedAssemblies = true;
configuration.ModifiedAssemblies.Add (asm);
};
configuration.AppBundleRewriter.AssemblySaved += assemblySavedHandler;
}

Expand Down
26 changes: 19 additions & 7 deletions tools/assembly-preparer/SaveAssembliesStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@ protected override void TryProcess ()
switch (action) {
case AssemblyAction.Copy:
case AssemblyAction.CopyUsed:
if (configuration.Application.IsPostProcessingAssemblies && assembly.InputPath != assembly.OutputPath) {
// During post-processing, copy unchanged assemblies to the output directory
// so all assemblies are in the same directory (required for AOT compilation).
CopyAssemblyToOutput (assembly.InputPath, assembly.OutputPath);
} else {
assembly.OutputPath = assembly.InputPath;
}
OutputWithoutRewriting (assembly);
continue;
case AssemblyAction.Link:
case AssemblyAction.Save:
if (!configuration.ModifiedAssemblies.Contains (assemblyDefinition)) {
// The assembly is marked to be saved (e.g. it's part of the set of assemblies to
// trim), but the assembly-preparer didn't actually modify it, so there's no need to
// re-serialize it - just output the original assembly.
OutputWithoutRewriting (assembly);
continue;
}
log.Log ($"Saving {assembly.InputPath} to {assembly.OutputPath}");
break;
default:
Expand Down Expand Up @@ -80,6 +81,17 @@ protected override void TryProcess ()
}
}

void OutputWithoutRewriting (Xamarin.Build.AssemblyPreparerInfo assembly)
{
if (Configuration.Application.IsPostProcessingAssemblies && assembly.InputPath != assembly.OutputPath) {
// During post-processing, copy unchanged assemblies to the output directory
// so all assemblies are in the same directory (required for AOT compilation).
CopyAssemblyToOutput (assembly.InputPath, assembly.OutputPath);
} else {
assembly.OutputPath = assembly.InputPath;
}
}

void RemoveCrossGen (AssemblyDefinition assemblyDefinition)
{
// Drop crossgened code from the assembly
Expand Down
3 changes: 3 additions & 0 deletions tools/dotnet-linker/LinkerConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ public List<ProductException> Exceptions {
public List<AssemblyDefinition> Assemblies => Application.LinkContext.Assemblies;
public required List<AssemblyPreparerInfo> AssemblyInfos;
public List<(string Path, AssemblyDefinition Assembly, string? OriginatingAssembly)> AddedAssemblies = new ();
// The set of assemblies that were modified (i.e. that AppBundleRewriter.SaveAssembly was called for).
// Assemblies that aren't modified don't need to be re-serialized when saved.
public HashSet<AssemblyDefinition> ModifiedAssemblies = new ();
#else
// The list of assemblies is populated in CollectAssembliesStep.
public List<AssemblyDefinition> Assemblies = new List<AssemblyDefinition> ();
Expand Down
Loading