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

Add unmanaged assembly skipping to ILStrip task #106267

Merged
merged 1 commit into from
Aug 12, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -237,5 +237,19 @@ public static void StripAssembly(string assemblyFile, string outputPath)
AssemblyDefinition assembly = AssemblyFactory.GetAssembly(assemblyFile);
AssemblyStripper.StripAssembly(assembly, outputPath);
}

public static bool TryStripAssembly(string assemblyFile, string outputPath)
{
try
{
StripAssembly(assemblyFile, outputPath);
return true;
}
// Skip unmanged assemblies
catch (ImageFormatException)
{
return false;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be helpful to catch general failures and report them as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The caller of this function has a try catch block reporting all the other failures.

}
}
}
14 changes: 9 additions & 5 deletions src/tasks/MonoTargetsTasks/ILStrip/ILStrip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,7 @@ public override bool Execute()
}
});

if (TrimIndividualMethods)
{
UpdatedAssemblies = ConvertAssembliesDictToOrderedList(_processedAssemblies, Assemblies).ToArray();
}
UpdatedAssemblies = ConvertAssembliesDictToOrderedList(_processedAssemblies, Assemblies).ToArray();

if (!result.IsCompleted && !Log.HasLoggedErrors)
{
Expand Down Expand Up @@ -130,7 +127,14 @@ private bool StripAssembly(ITaskItem assemblyItem)

try
{
AssemblyStripper.AssemblyStripper.StripAssembly (assemblyFile, outputPath);
if(!AssemblyStripper.AssemblyStripper.TryStripAssembly(assemblyFile, outputPath))
{
Log.LogMessage(MessageImportance.Low, $"[ILStrip] Skipping {assemblyFile} because it is not a managed assembly.");
}
else
{
_processedAssemblies.GetOrAdd(assemblyItem.ItemSpec, GetTrimmedAssemblyItem(assemblyItem, outputPath, assemblyFile));
}
}
catch (Exception ex)
{
Expand Down
Loading